/// <summary>
        /// Voids a payment
        /// </summary>
        /// <param name="voidPaymentRequest">Request</param>
        /// <returns>Result</returns>
        public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest)
        {
            var result = new VoidPaymentResult();

            string transactionId = voidPaymentRequest.Order.AuthorizationTransactionId;
            if (String.IsNullOrEmpty(transactionId))
                transactionId = voidPaymentRequest.Order.CaptureTransactionId;

            var req = new DoVoidReq();
            req.DoVoidRequest = new DoVoidRequestType();
            req.DoVoidRequest.Version = GetApiVersion();
            req.DoVoidRequest.AuthorizationID = transactionId;

            var service = GetService();
            DoVoidResponseType response = service.DoVoid(req);

            string error;
            bool success = PaypalHelper.CheckSuccess(response, out error);
            if (success)
            {
                result.NewPaymentStatus = PaymentStatus.Voided;
                //result.VoidTransactionID = response.RefundTransactionID;
            }
            else
            {
                result.AddError(error);
            }
            return result;
        }
 /// <summary>
 /// Voids a payment
 /// </summary>
 /// <param name="voidPaymentRequest">Request</param>
 /// <returns>Result</returns>
 public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest)
 {
     var result = new VoidPaymentResult();
     result.AddError("Void method not supported");
     return result;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Voids order (from admin panel)
        /// </summary>
        /// <param name="order">Order</param>
        /// <returns>Voided order</returns>
        public virtual IList<string> Void(Order order)
        {
            if (order == null)
                throw new ArgumentNullException("order");

            if (!CanVoid(order))
                throw new NopException("Cannot do void for order.");

            var request = new VoidPaymentRequest();
            VoidPaymentResult result = null;
            try
            {
                request.Order = order;
                result = _paymentService.Void(request);

                if (result.Success)
                {
                    //update order info
                    order.PaymentStatus = result.NewPaymentStatus;
                    _orderService.UpdateOrder(order);

                    //add a note
                    order.OrderNotes.Add(new OrderNote
                    {
                        Note = "Order has been voided",
                        DisplayToCustomer = false,
                        CreatedOnUtc = DateTime.UtcNow
                    });
                    _orderService.UpdateOrder(order);

                    //check order status
                    CheckOrderStatus(order);
                }
            }
            catch (Exception exc)
            {
                if (result == null)
                    result = new VoidPaymentResult();
                result.AddError(string.Format("Error: {0}. Full exception: {1}", exc.Message, exc.ToString()));
            }

            //process errors
            string error = "";
            for (int i = 0; i < result.Errors.Count; i++)
            {
                error += string.Format("Error {0}: {1}", i, result.Errors[i]);
                if (i != result.Errors.Count - 1)
                    error += ". ";
            }
            if (!String.IsNullOrEmpty(error))
            {
                //add a note
                order.OrderNotes.Add(new OrderNote
                {
                    Note = string.Format("Unable to voiding order. {0}", error),
                    DisplayToCustomer = false,
                    CreatedOnUtc = DateTime.UtcNow
                });
                _orderService.UpdateOrder(order);

                //log it
                string logError = string.Format("Error voiding order #{0}. Error: {1}", order.Id, error);
                _logger.InsertLog(LogLevel.Error, logError, logError);
            }
            return result.Errors;
        }
        /// <summary>
        /// Voids a payment
        /// </summary>
        /// <param name="voidPaymentRequest">Request</param>
        /// <returns>Result</returns>
        public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest)
        {
            var result = new VoidPaymentResult();

            string transactionId = voidPaymentRequest.Order.AuthorizationTransactionId;
            if (String.IsNullOrEmpty(transactionId))
                transactionId = voidPaymentRequest.Order.CaptureTransactionId;

            var req = new DoVoidReq();
            req.DoVoidRequest = new DoVoidRequestType();
            req.DoVoidRequest.Version = GetApiVersion();
            req.DoVoidRequest.AuthorizationID = transactionId;


            using (var service2 = new PayPalAPIAASoapBinding())
            {
                if (!_paypalDirectPaymentSettings.UseSandbox)
                    service2.Url = "https://api-3t.paypal.com/2.0/";
                else
                    service2.Url = "https://api-3t.sandbox.paypal.com/2.0/";

                service2.RequesterCredentials = new CustomSecurityHeaderType();
                service2.RequesterCredentials.Credentials = new UserIdPasswordType();
                service2.RequesterCredentials.Credentials.Username = _paypalDirectPaymentSettings.ApiAccountName;
                service2.RequesterCredentials.Credentials.Password = _paypalDirectPaymentSettings.ApiAccountPassword;
                service2.RequesterCredentials.Credentials.Signature = _paypalDirectPaymentSettings.Signature;
                service2.RequesterCredentials.Credentials.Subject = "";

                DoVoidResponseType response = service2.DoVoid(req);

                string error = "";
                bool success = PaypalHelper.CheckSuccess(response, out error);
                if (success)
                {
                    result.NewPaymentStatus = PaymentStatus.Voided;
                    //result.VoidTransactionID = response.RefundTransactionID;
                }
                else
                {
                    result.AddError(error);
                }
            }
            return result;
        }
        /// <summary>
        /// Voids a payment
        /// </summary>
        /// <param name="voidPaymentRequest">Request</param>
        /// <returns>Result</returns>
        public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest)
        {
            var result = new VoidPaymentResult();

            var config = new HpsServicesConfig();
            config.SecretApiKey = _secureSubmitPaymentSettings.SecretApiKey;
            config.DeveloperId = "002914";
            config.VersionNumber = "1513";

            var creditService = new HpsCreditService(config);

            try
            {
                if (string.IsNullOrEmpty(voidPaymentRequest.Order.CaptureTransactionId))
                {
                    creditService.Void(Convert.ToInt32(voidPaymentRequest.Order.AuthorizationTransactionId));
                }
                else
                {
                    creditService.Void(Convert.ToInt32(voidPaymentRequest.Order.CaptureTransactionId));
                }

                result.NewPaymentStatus = PaymentStatus.Voided;
            }
            catch (HpsException ex)
            {
                result.AddError(ex.Message);
            }

            return result;
        }
        /// <summary>
        /// Voids a payment
        /// </summary>
        /// <param name="voidPaymentRequest">Request</param>
        /// <returns>Result</returns>
        public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest)
        {
            var result = new VoidPaymentResult();

            var webClient = new WebClient();
            var form = new NameValueCollection();
            form.Add("x_login", _authorizeNetPaymentSettings.LoginId);
            form.Add("x_tran_key", _authorizeNetPaymentSettings.TransactionKey);

            form.Add("x_delim_data", "TRUE");
            form.Add("x_delim_char", "|");
            form.Add("x_encap_char", "");
            form.Add("x_version", GetApiVersion());
            form.Add("x_relay_response", "FALSE");

            form.Add("x_method", "CC");
            form.Add("x_currency_code", _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId).CurrencyCode);

            string[] codes = voidPaymentRequest.Order.CaptureTransactionId == null ?
                voidPaymentRequest.Order.AuthorizationTransactionCode.Split(',') : voidPaymentRequest.Order.CaptureTransactionId.Split(',');
            //x_trans_id. When x_test_request (sandbox) is set to a positive response,
            //or when Test mode is enabled on the payment gateway, this value will be "0".
            form.Add("x_trans_id", codes[0]);

            string maskedCreditCardNumberDecrypted = _encryptionService.DecryptText(voidPaymentRequest.Order.MaskedCreditCardNumber);
            if (String.IsNullOrEmpty(maskedCreditCardNumberDecrypted) || maskedCreditCardNumberDecrypted.Length < 4)
            {
                result.AddError("Last four digits of Credit Card Not Available");
                return result;
            }
            var lastFourDigitsCardNumber = maskedCreditCardNumberDecrypted.Substring(maskedCreditCardNumberDecrypted.Length - 4);
            form.Add("x_card_num", lastFourDigitsCardNumber); // only last four digits are required for doing a credit
            form.Add("x_type", "VOID");

            // Send Request to Authorize and Get Response
            var responseData = webClient.UploadValues(GetAuthorizeNetUrl(), form);
            var reply = Encoding.ASCII.GetString(responseData);

            if (!String.IsNullOrEmpty(reply))
            {
                string[] responseFields = reply.Split('|');
                switch (responseFields[0])
                {
                    case "1":
                        result.NewPaymentStatus = PaymentStatus.Voided;
                        break;
                    case "2":
                        result.AddError(string.Format("Declined ({0}: {1})", responseFields[2], responseFields[3]));
                        break;
                    case "3":
                        result.AddError(string.Format("Error: {0}", reply));
                        break;
                }
            }
            else
            {
                result.AddError("Authorize.NET unknown error");
            }

            return result;
        }
        /// <summary>
        /// Voids a payment
        /// </summary>
        /// <param name="voidPaymentRequest">Request</param>
        /// <returns>Result</returns>
        public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest)
        {
            var result = new VoidPaymentResult();

            // Check license
            bool isLicensed = this._licenseService.IsLicensed(HttpContext.Current.Request.Url.Host);
            if (!isLicensed && voidPaymentRequest.Order.OrderTotal > 5.00M)
            {
                result.AddError("The trial license can be used to submit order of $5.00 or less. Please purchase a full license at our website.");
                return result;
            }

            string transactionId = voidPaymentRequest.Order.AuthorizationTransactionId;
            if (String.IsNullOrEmpty(transactionId))
                transactionId = voidPaymentRequest.Order.CaptureTransactionId;

            // Create the Payflow Data Objects.
            // Create the User data object with the required user details.
            UserInfo payflowUser = _payPalHelper.GetUserInfo();

            // Create the Payflow Connection data object with the required connection details.                        
            PayflowConnectionData payflowConn = new PayflowConnectionData(_payPalHelper.GetPayflowProHost());

            // Create a new Void Transaction.
            // The ORIGID is the PNREF no. for a previous transaction.
            VoidTransaction trans = new VoidTransaction(transactionId, payflowUser, payflowConn, PayflowUtility.RequestId);

            // Submit the Transaction
            Response resp = trans.SubmitTransaction();

            // Process the Payflow response.
            if (resp != null)
            {
                // Get the Transaction Response parameters.
                TransactionResponse trxResp = resp.TransactionResponse;
                if (trxResp != null)
                {
                    if (trxResp.Result == 0)
                    {
                        result.NewPaymentStatus = PaymentStatus.Voided;
                    }
                    else
                    {
                        result.AddError(string.Format("Void RESULT: {0}-{1}", trxResp.Result, trxResp.RespMsg));
                    }
                }
            }

            return result;
        }
Ejemplo n.º 8
0
 public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest)
 {
     var result = new VoidPaymentResult();
     result.AddError("Метод недействительности не поддерживается.");
     return result;
 }
        /// <summary>
        /// Voids a payment
        /// </summary>
        /// <param name="voidPaymentRequest">Request</param>
        /// <returns>Result</returns>
        public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest)
        {
            var result = new VoidPaymentResult();

            var voidResult = _sagePayServerWorkflowService.VoidTransaction(voidPaymentRequest.Order.OrderGuid.ToString());

            if (!voidResult.Success)
            {
                result.AddError(voidResult.Message);
            }
            else
            {
                result.NewPaymentStatus = PaymentStatus.Voided;
            }

            return result;
        }
        /// <summary>
        /// Voids a payment
        /// </summary>
        /// <param name="voidPaymentRequest">Request</param>
        /// <returns>Result</returns>
        public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest)
        {
            var result = new VoidPaymentResult();

            var orderGuid = voidPaymentRequest.Order.OrderGuid;

            if (orderGuid == Guid.NewGuid())
            {
                result.AddError("Order Unique identifier code does not exist!");
                return result;
            }

            var transx = _sagePayServerTransactionService.GetSagePayServerTransactionByVendorTxCode(orderGuid.ToString());

            if (transx == null)
            {
                result.AddError(String.Format("SagePay Server vendor transaction code {0} does not exist.", orderGuid.ToString()));
                return result;
            }

            var webClient = new WebClient();

            var data = new NVPCodec();

            data.Add("VPSProtocol", SagePayHelper.GetProtocol());
            data.Add("TxType", "VOID");
            data.Add("Vendor", _sagePayServerPaymentSettings.VendorName);

            var voidGuid = Guid.NewGuid();
            data.Add("VendorTxCode", voidGuid.ToString());

            data.Add("VPSTxId", transx.VPSTxId);
            data.Add("SecurityKey", transx.SecurityKey);
            data.Add("TxAuthNo", transx.TxAuthNo);

            var postURL = SagePayHelper.GetSageSystemUrl(_sagePayServerPaymentSettings.ConnectTo, "void");

            string strResponse = string.Empty;

            try
            {

                Byte[] responseData = webClient.UploadValues(postURL, data);

                strResponse = Encoding.ASCII.GetString(responseData);


            }
            catch (WebException ex)
            {

                result.AddError(String.Format(
                    @"Your server was unable to release this transaction with Sage Pay.
                    Check that you do not have a firewall restricting the POST and 
                    that your server can correctly resolve the address {0}. <br/>
                    The Status Number is: {1}<br/>
                    The Description given is: {2}", postURL, ex.Status, ex.Message));
                return result;
            }

            if (string.IsNullOrWhiteSpace(strResponse))
            {
                result.AddError(String.Format(
                    @"Your server was unable to register this transaction with Sage Pay.
                    Check that you do not have a firewall restricting the POST and 
                    that your server can correctly resolve the address {0}.", postURL));
                return result;
            }
            var strStatus = SagePayHelper.FindField("Status", strResponse);
            var strStatusDetail = SagePayHelper.FindField("StatusDetail", strResponse);

            switch (strStatus)
            {
                case "OK":

                    result.NewPaymentStatus = PaymentStatus.Voided;

                    break;

                case "MALFORMED":
                    result.AddError(string.Format("Error ({0}: {1}) <br/> {2}", strStatus, strStatusDetail, data.Encode()));
                    return result;

                case "INVALID":
                    result.AddError(string.Format("Error ({0}: {1}) <br/> {2}", strStatus, strStatusDetail, data.Encode()));
                    return result;

                default:
                    result.AddError(string.Format("Error ({0}: {1})", strStatus, strStatusDetail));
                    return result;

            }

            return result;
        }
        public VoidPaymentResult Void(VoidPaymentRequest voidPaymentRequest)
        {
            var order = voidPaymentRequest.Order;
            var result = new VoidPaymentResult();

            try
            {
                _klarnaCheckoutPaymentService.CancelPayment(order.AuthorizationTransactionId, order.Customer);

                result.NewPaymentStatus = PaymentStatus.Voided;

                order.OrderNotes.Add(new OrderNote
                {
                    Note = string.Format(CultureInfo.CurrentCulture, "KlarnaCheckout: The payment has been voided. Reservation: {0}",
                        order.AuthorizationTransactionId),
                    CreatedOnUtc = DateTime.UtcNow,
                    DisplayToCustomer = false
                });
                _orderService.UpdateOrder(order);
            }
            catch (KlarnaCheckoutException kce)
            {
                order.OrderNotes.Add(new OrderNote
                {
                    Note = "KlarnaCheckout: An error occurred when voiding the payment. See the error log for more information.",
                    CreatedOnUtc = DateTime.UtcNow,
                    DisplayToCustomer = false
                });
                _orderService.UpdateOrder(order);

                _logger.Error(string.Format(CultureInfo.CurrentCulture, "KlarnaCheckout: Error voiding payment. Order Id: {0}; Reservation: {1}",
                    order.Id, order.AuthorizationTransactionId),
                    exception: kce,
                    customer: order.Customer);

                result.AddError("An error occurred while voiding the order. See the error log for more information.");
            }

            return result;
        }