コード例 #1
0
        /// <summary>
        /// Captures payment
        /// </summary>
        /// <param name="capturePaymentRequest">Capture payment request</param>
        /// <returns>Capture payment result</returns>
        public CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
        {
            var result = new CapturePaymentResult();

            result.AddError("Capture method not supported");
            return(result);
        }
コード例 #2
0
ファイル: WxPayPaymentProcessor.cs プロジェクト: wiksin/SuGa
        /// <summary>
        /// 捕捉付款
        /// </summary>
        /// <param name="capturePaymentRequest">捕捉请求支付</param>
        /// <returns>Capture payment result</returns>
        public CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
        {
            var result = new CapturePaymentResult();

            result.AddError("不支持捕获方法");
            return(result);
        }
コード例 #3
0
        /// <summary>
        /// Captures payment
        /// </summary>
        /// <param name="capturePaymentRequest">Capture payment request</param>
        /// <returns>Capture payment result</returns>
        public override CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
        {
            var result = new CapturePaymentResult();

            result.AddError(_localizationService.GetResource("Common.Payment.NoCaptureSupport"));
            return(result);
        }
コード例 #4
0
        public CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
        {
            CapturePaymentResult capture = new CapturePaymentResult();

            capture.AddError("Capture method not supported.");
            return(capture);
        }
コード例 #5
0
        /// <summary>
        /// Captures payment
        /// </summary>
        /// <param name="capturePaymentRequest">Capture payment request</param>
        /// <returns>Capture payment result</returns>
        public CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
        {
            var result = new CapturePaymentResult();

            string authorizationId = capturePaymentRequest.Order.AuthorizationTransactionId;
            var    req             = new DoCaptureReq();

            req.DoCaptureRequest                   = new DoCaptureRequestType();
            req.DoCaptureRequest.Version           = GetApiVersion();
            req.DoCaptureRequest.AuthorizationID   = authorizationId;
            req.DoCaptureRequest.Amount            = new BasicAmountType();
            req.DoCaptureRequest.Amount.value      = Math.Round(capturePaymentRequest.Order.OrderTotal, 2).ToString("N", new CultureInfo("en-us"));
            req.DoCaptureRequest.Amount.currencyID = PaypalHelper.GetPaypalCurrency(_currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId));
            req.DoCaptureRequest.CompleteType      = CompleteCodeType.COMPLETE;

            var service = GetService();
            DoCaptureResponseType response = service.DoCapture(req);

            string error;
            bool   success = PaypalHelper.CheckSuccess(response, out error);

            if (success)
            {
                result.NewPaymentStatus         = PaymentStatus.Paid;
                result.CaptureTransactionId     = response.DoCaptureResponseDetails.PaymentInfo.TransactionID;
                result.CaptureTransactionResult = response.Ack.ToString();
            }
            else
            {
                result.AddError(error);
            }
            return(result);
        }
コード例 #6
0
        public CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
        {
            CapturePaymentResult capturePaymentResult = new CapturePaymentResult();
            Processor            processor            = new Processor("prd.txngw.com", 86, this._iPaySettings.CompanyKey, 30000);

            processor.EncryptionMode = EncryptionModeType.TripleDES;
            processor.AddEncryptionKey("0502114302159200");
            processor.AddEncryptionKey("0029512034112050");
            processor.AddEncryptionKey("0215920005021143");
            processor.SetValue("TERMINAL_ID", this._iPaySettings.TerminalId.ToString());
            processor.SetValue("SERVICE_FORMAT", "1010");
            processor.SetValue("CURRENCY_CODE", Convert.ToInt32(this._iPaySettings.CurrencyCode).ToString());
            processor.SetValue("CURRENCY_INDICATOR", "1");
            processor.SetValue("TRANSACTION_ID", capturePaymentRequest.Order.AuthorizationTransactionId);
            processor.SetValue("SERVICE", "CC");
            processor.SetValue("SERVICE_TYPE", "DEBIT");
            processor.SetValue("SERVICE_SUBTYPE", "CAPTURE");
            processor.SetValue("AMOUNT", capturePaymentRequest.Order.OrderTotal.ToString("0.00", (IFormatProvider)CultureInfo.InvariantCulture));
            processor.Build();
            processor.ProcessRequest();
            string xmlValue1 = this.GetXMLValue(processor.ResponseXml, "RESPONSE_TEXT");
            string xmlValue2 = this.GetXMLValue(processor.ResponseXml, "MRC");
            string xmlValue3 = this.GetXMLValue(processor.ResponseXml, "ARC");

            if (xmlValue3 == "00" && xmlValue2 == "00")
            {
                if (xmlValue1 == "TRAN CAPTURED")
                {
                    capturePaymentResult.CaptureTransactionId     = this.GetXMLValue(processor.ResponseXml, "APPROVAL_CODE");
                    capturePaymentResult.CaptureTransactionResult = xmlValue1;
                    capturePaymentResult.NewPaymentStatus         = PaymentStatus.Paid;
                }
                else
                {
                    capturePaymentResult.AddError(string.Format("Error: {0}:ARC{1}:MRC{2}", xmlValue1, xmlValue3, xmlValue2));
                }
            }
            else
            {
                capturePaymentResult.AddError(string.Format("Error: {0}:ARC{1}:MRC{2}", xmlValue1, xmlValue3, xmlValue2));
            }

            processor.ResetObjects();

            return(capturePaymentResult);
        }
コード例 #7
0
ファイル: TestPaymentMethod.cs プロジェクト: abcwarehouse/nop
        /// <summary>
        /// Captures payment
        /// </summary>
        /// <param name="capturePaymentRequest">Capture payment request</param>
        /// <returns>Capture payment result</returns>
        public Task <CapturePaymentResult> CaptureAsync(CapturePaymentRequest capturePaymentRequest)
        {
            var result = new CapturePaymentResult();

            result.AddError("Capture method not supported");

            return(Task.FromResult(result));
        }
コード例 #8
0
        /// <summary>
        /// Captures payment
        /// </summary>
        /// <param name="capturePaymentRequest">Capture payment request</param>
        /// <returns>Capture payment result</returns>
        public CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
        {
            var result     = new CapturePaymentResult();
            var apiPayment = new Models.PaymentOrderMechantUpdate
            {
                apiId         = _manualPaymentSettings.AppId,
                merch_Id      = _manualPaymentSettings.MerchantUniqueId,
                merch_orderId = capturePaymentRequest.Order.OrderGuid.ToString(),
                order_status  = "CAPTURE"
            };

            using (var client = new HttpClient())
            {
                var content = new StringContent(JsonConvert.SerializeObject(apiPayment));
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                using (var res = client.PostAsync(String.Format("{0}api/v1/SecurePayment/UpdateOrder", _manualPaymentSettings.AppUrl), content))
                {
                    res.Wait();
                    if (res.Result.IsSuccessStatusCode)
                    {
                        var data = res.Result.Content.ReadAsStringAsync();
                        var ret  = JsonConvert.DeserializeObject <Models.ApiResponse>(data.Result.ToString());
                        switch (ret.responseCode.ToUpper())
                        {
                        case "APPROVED":
                            result.NewPaymentStatus = Core.Domain.Payments.PaymentStatus.Paid;
                            break;

                        default:
                            result.AddError(ret.responseText);
                            break;
                        }
                    }
                    else
                    {
                        result.AddError("Unable to process your request, Please try again later.");
                    }
                }
            }
            return(result);
        }
コード例 #9
0
        /// <summary>
        /// Captures payment
        /// </summary>
        /// <param name="capturePaymentRequest">Capture payment request</param>
        /// <returns>Capture payment result</returns>
        public CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
        {
            CapturePaymentResult result = new CapturePaymentResult();

            if (ePayPaymentSettings.UseRemoteInterface)
            {
                int pbsResponse  = -1;
                int epayresponse = -1;

                try
                {
                    decimal orderTotal = Math.Round(capturePaymentRequest.Order.OrderTotal, 2);
                    string  amount     = (orderTotal * 100).ToString("0", CultureInfo.InvariantCulture);

                    dk.ditonlinebetalingssystem.ssl.Payment payment = new dk.ditonlinebetalingssystem.ssl.Payment();
                    payment.capture(Convert.ToInt32(ePayPaymentSettings.MerchantId), Convert.ToInt32(capturePaymentRequest.Order.AuthorizationTransactionId), Convert.ToInt32(amount), "", ePayPaymentSettings.RemotePassword, ref pbsResponse, ref epayresponse);

                    if (epayresponse == -1)
                    {
                        result.NewPaymentStatus = PaymentStatus.Paid;
                    }
                    else
                    {
                        result.AddError("Could not capture: pbsResponse:" + pbsResponse + " epayresponse: " + epayresponse);
                    }
                }
                catch (Exception error)
                {
                    result.AddError("Could not capture: " + error.Message);
                }
            }
            else
            {
                result.AddError("Remote interface is not activated.");
            }

            return(result);
        }
コード例 #10
0
        /// <summary>
        /// Captures payment
        /// </summary>
        /// <param name="capturePaymentRequest">Capture payment request</param>
        /// <returns>Capture payment result</returns>
        public CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
        {
            var result = new CapturePaymentResult();

            string authorizationId = capturePaymentRequest.Order.AuthorizationTransactionId;
            var    req             = new DoCaptureReq();

            req.DoCaptureRequest                   = new DoCaptureRequestType();
            req.DoCaptureRequest.Version           = GetApiVersion();
            req.DoCaptureRequest.AuthorizationID   = authorizationId;
            req.DoCaptureRequest.Amount            = new BasicAmountType();
            req.DoCaptureRequest.Amount.Value      = Math.Round(capturePaymentRequest.Order.OrderTotal, 2).ToString("N", new CultureInfo("en-us"));
            req.DoCaptureRequest.Amount.currencyID = PaypalHelper.GetPaypalCurrency(_currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId));
            req.DoCaptureRequest.CompleteType      = CompleteCodeType.Complete;

            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   = "";

                DoCaptureResponseType response = service2.DoCapture(req);

                string error   = "";
                bool   success = PaypalHelper.CheckSuccess(response, out error);
                if (success)
                {
                    result.NewPaymentStatus         = PaymentStatus.Paid;
                    result.CaptureTransactionId     = response.DoCaptureResponseDetails.PaymentInfo.TransactionID;
                    result.CaptureTransactionResult = response.Ack.ToString();
                }
                else
                {
                    result.AddError(error);
                }
            }
            return(result);
        }
コード例 #11
0
        /// <summary>
        /// Some payment gateways allow you to authorize payments before they're captured. It allows store owners to review order
        /// details before the payment is actually done.
        /// </summary>
        /// <param name="capturePaymentRequest">Capture payment request</param>
        /// <returns>Capture payment result</returns>
        public CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
        {
            var result = new CapturePaymentResult();

            Order order = capturePaymentRequest.Order;

            if (int.TryParse(order.AuthorizationTransactionId, out int transactionNumber))
            {
                decimal amount = Math.Round(order.OrderTotal, 2);

                PayexInterface payex         = GetPayexInterface();
                CaptureResult  captureResult = payex.Capture(transactionNumber, amount, order.OrderGuid.ToString())
                                               .GetAwaiter().GetResult();

                result.CaptureTransactionResult = captureResult.ErrorCode;
                result.CaptureTransactionId     = captureResult.TransactionNumber;

                if (captureResult.IsTransactionSuccessful)
                {
                    result.NewPaymentStatus = PaymentStatus.Paid;
                    // Add order note
                    var note = new StringBuilder();
                    note.AppendLine("PayEx: Capture succeeded");
                    note.AppendLine(string.Format("Amount: {0:n2}", amount));
                    note.AppendLine("TransactionNumber: " + captureResult.TransactionNumber);
                    note.AppendLine("TransactionStatus: " + captureResult.TransactionStatus);
                    order.OrderNotes.Add(
                        new OrderNote
                    {
                        Note = note.ToString(),
                        DisplayToCustomer = false,
                        CreatedOnUtc      = DateTime.UtcNow
                    });
                    _orderService.UpdateOrder(order);
                }
                else
                {
                    result.AddError(captureResult.GetErrorDescription());
                }
            }
            else
            {
                result.Errors.Add(
                    string.Format(
                        "The order did not contain a valid TransactionNumber in the AuthorizationTransactionId field ('{0}').",
                        order.AuthorizationTransactionId));
            }

            return(result);
        }
コード例 #12
0
        /// <summary>
        /// Captures payment
        /// </summary>
        /// <param name="capturePaymentRequest">Capture payment request</param>
        /// <returns>Capture payment result</returns>
        public CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
        {
            var result = new CapturePaymentResult();

            var releaseResult = _sagePayServerWorkflowService.ReleaseTransaction(capturePaymentRequest.Order.OrderGuid.ToString(), capturePaymentRequest.Order.OrderTotal);

            if (!releaseResult.Success)
            {
                result.AddError(releaseResult.Message);
            }
            else
            {
                result.NewPaymentStatus         = PaymentStatus.Paid;
                result.CaptureTransactionResult = releaseResult.Message;
            }

            return(result);
        }
コード例 #13
0
        /// <summary>
        /// Captures payment
        /// </summary>
        /// <param name="capturePaymentRequest">Capture payment request</param>
        /// <returns>Capture payment result</returns>
        public override CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
        {
            var result = new CapturePaymentResult
            {
                NewPaymentStatus = capturePaymentRequest.Order.PaymentStatus
            };

            var settings     = Services.Settings.LoadSetting <TSetting>(capturePaymentRequest.Order.StoreId);
            var currencyCode = Services.WorkContext.WorkingCurrency.CurrencyCode ?? "EUR";

            var authorizationId = capturePaymentRequest.Order.AuthorizationTransactionId;

            var req = new DoCaptureReq();

            req.DoCaptureRequest                   = new DoCaptureRequestType();
            req.DoCaptureRequest.Version           = ApiVersion;
            req.DoCaptureRequest.AuthorizationID   = authorizationId;
            req.DoCaptureRequest.Amount            = new BasicAmountType();
            req.DoCaptureRequest.Amount.Value      = Math.Round(capturePaymentRequest.Order.OrderTotal, 2).ToString("N", new CultureInfo("en-us"));
            req.DoCaptureRequest.Amount.currencyID = (CurrencyCodeType)Enum.Parse(typeof(CurrencyCodeType), currencyCode, true);
            req.DoCaptureRequest.CompleteType      = CompleteCodeType.Complete;

            using (var service = GetApiAaService(settings))
            {
                var response = service.DoCapture(req);

                var error   = "";
                var success = IsSuccess(response, out error);

                if (success)
                {
                    result.NewPaymentStatus         = PaymentStatus.Paid;
                    result.CaptureTransactionId     = response.DoCaptureResponseDetails.PaymentInfo.TransactionID;
                    result.CaptureTransactionResult = response.Ack.ToString();
                }
                else
                {
                    result.AddError(error);
                }
            }
            return(result);
        }
コード例 #14
0
        /// <summary>
        /// Captures payment
        /// </summary>
        /// <param name="capturePaymentRequest">Capture payment request</param>
        /// <returns>Capture payment result</returns>
        public CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
        {
            var result = new CapturePaymentResult();
            CheckoutCaptureRequest outrequest = new CheckoutCaptureRequest
            {
                checkout_id = capturePaymentRequest.Order.AuthorizationTransactionId
            };

            WebClientResponse wcresponse = ProcessWebClient(outrequest);

            foreach (string error in wcresponse.Errors)
            {
                result.AddError(error);
            }
            if (result.Errors.Count <= 0 && wcresponse.state == "captured")
            {
                result.NewPaymentStatus = PaymentStatus.Paid;
            }
            return(result);
        }
コード例 #15
0
        /// <summary>
        /// Captures payment
        /// </summary>
        /// <param name="capturePaymentRequest">Capture payment request</param>
        /// <returns>Capture payment result</returns>
        public CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
        {
            var result = new CapturePaymentResult();

            string googleOrderNumber   = capturePaymentRequest.Order.AuthorizationTransactionId;
            var    chargeOrderRequest  = new GCheckout.OrderProcessing.ChargeOrderRequest(googleOrderNumber);
            var    chargeOrderResponse = chargeOrderRequest.Send();

            if (chargeOrderResponse.IsGood)
            {
                result.NewPaymentStatus         = PaymentStatus.Paid;
                result.CaptureTransactionResult = chargeOrderResponse.ResponseXml;
            }
            else
            {
                result.AddError(chargeOrderResponse.ErrorMessage);
            }

            return(result);
        }
コード例 #16
0
        /// <summary>
        /// Captures payment
        /// </summary>
        /// <param name="capturePaymentRequest">Capture payment request</param>
        /// <returns>Capture payment result</returns>
        public override CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
        {
            var result = new CapturePaymentResult()
            {
                NewPaymentStatus = capturePaymentRequest.Order.PaymentStatus
            };

            var    settings        = CommonServices.Settings.LoadSetting <TSetting>(capturePaymentRequest.Order.StoreId);
            string authorizationId = capturePaymentRequest.Order.AuthorizationTransactionId;

            var req = new DoCaptureReq();

            req.DoCaptureRequest                   = new DoCaptureRequestType();
            req.DoCaptureRequest.Version           = PayPalHelper.GetApiVersion();
            req.DoCaptureRequest.AuthorizationID   = authorizationId;
            req.DoCaptureRequest.Amount            = new BasicAmountType();
            req.DoCaptureRequest.Amount.Value      = Math.Round(capturePaymentRequest.Order.OrderTotal, 2).ToString("N", new CultureInfo("en-us"));
            req.DoCaptureRequest.Amount.currencyID = (CurrencyCodeType)Enum.Parse(typeof(CurrencyCodeType), Helper.CurrencyCode, true);
            req.DoCaptureRequest.CompleteType      = CompleteCodeType.Complete;

            using (var service = new PayPalAPIAASoapBinding())
            {
                service.Url = PayPalHelper.GetPaypalServiceUrl(settings);
                service.RequesterCredentials = PayPalHelper.GetPaypalApiCredentials(settings);
                DoCaptureResponseType response = service.DoCapture(req);

                string error   = "";
                bool   success = PayPalHelper.CheckSuccess(_helper, response, out error);
                if (success)
                {
                    result.NewPaymentStatus         = PaymentStatus.Paid;
                    result.CaptureTransactionId     = response.DoCaptureResponseDetails.PaymentInfo.TransactionID;
                    result.CaptureTransactionResult = response.Ack.ToString();
                }
                else
                {
                    result.AddError(error);
                }
            }
            return(result);
        }
コード例 #17
0
        /// <summary>
        /// Captures payment
        /// </summary>
        /// <param name="capturePaymentRequest">Capture payment request</param>
        /// <returns>Capture payment result</returns>
        public CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
        {
            var result = new CapturePaymentResult();

            var codes = capturePaymentRequest.Order.AuthorizationTransactionCode.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            _httpClient.DefaultRequestHeaders.Add("developer-id", _paySafePaymentSettings.DeveloperId);
            _httpClient.DefaultRequestHeaders.Add("user-id", _paySafePaymentSettings.UserId);
            _httpClient.DefaultRequestHeaders.Add("user-api-key", _paySafePaymentSettings.UserApiKey);

            var json = JsonConvert.SerializeObject(new { transaction = new Dictionary <string, string> {
                                                             { "action", "authcomplete" }
                                                         } });
            var data = new StringContent(json, Encoding.UTF8, "application/json");

            try
            {
                var response          = _httpClient.PutAsync($"{GetUrl()}/{codes[0]}", data).Result;
                var paySafeResponse   = JsonConvert.DeserializeObject <PaySafeResponse>(response.Content.ReadAsStringAsync().Result);
                var transactionResult = paySafeResponse.Transaction;

                if (response.IsSuccessStatusCode)
                {
                    result.CaptureTransactionId = $"{transactionResult.Id},{transactionResult.AuthCode}";

                    result.NewPaymentStatus = PaymentStatus.Paid;
                }
            }
            catch (Exception exception)
            {
                _logger.Error("PaySafe Error", exception);
                result.AddError("Exception Occurred: " + exception.Message);
                return(result);
            }

            return(result);
        }
コード例 #18
0
        /// <summary>
        /// Captures payment
        /// </summary>
        /// <param name="capturePaymentRequest">Capture payment request</param>
        /// <returns>Capture payment result</returns>
        public CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
        {
            var result = new CapturePaymentResult();

            WebClient           webClient = new WebClient();
            NameValueCollection form      = new NameValueCollection();

            form.Add("x_login", _authorizeNetPaymentSettings.LoginId);
            form.Add("x_tran_key", _authorizeNetPaymentSettings.TransactionKey);

            //we should not send "x_test_request" parameter. otherwise, the transaction won't be logged in the sandbox
            //if (_authorizeNetPaymentSettings.UseSandbox)
            //    form.Add("x_test_request", "TRUE");
            //else
            //    form.Add("x_test_request", "FALSE");

            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);
            form.Add("x_type", "PRIOR_AUTH_CAPTURE");

            var orderTotal = Math.Round(capturePaymentRequest.Order.OrderTotal, 2);

            form.Add("x_amount", orderTotal.ToString("0.00", CultureInfo.InvariantCulture));
            string[] codes = capturePaymentRequest.Order.AuthorizationTransactionCode.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 reply = null;

            Byte[] responseData = webClient.UploadValues(GetAuthorizeNETUrl(), form);
            reply = Encoding.ASCII.GetString(responseData);

            if (!String.IsNullOrEmpty(reply))
            {
                string[] responseFields = reply.Split('|');
                switch (responseFields[0])
                {
                case "1":
                    result.CaptureTransactionId     = string.Format("{0},{1}", responseFields[6], responseFields[4]);
                    result.CaptureTransactionResult = string.Format("Approved ({0}: {1})", responseFields[2], responseFields[3]);
                    //result.AVSResult = responseFields[5];
                    //responseFields[38];
                    result.NewPaymentStatus = PaymentStatus.Paid;
                    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>
        /// Captures payment
        /// </summary>
        /// <param name="capturePaymentRequest">Capture payment request</param>
        /// <returns>Capture payment result</returns>
        public CapturePaymentResult Capture(CapturePaymentRequest capturePaymentRequest)
        {
            var result = new CapturePaymentResult();

            var orderGuid = capturePaymentRequest.Order.OrderGuid;

            if (orderGuid == Guid.NewGuid())
            {
                result.AddError("Order Unique identifier 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", "RELEASE");
            data.Add("Vendor", _sagePayServerPaymentSettings.VendorName);
            data.Add("VendorTxCode", orderGuid.ToString());
            data.Add("VPSTxId", transx.VPSTxId);
            data.Add("SecurityKey", transx.SecurityKey);
            data.Add("TxAuthNo", transx.TxAuthNo);

            data.Add("ReleaseAmount", capturePaymentRequest.Order.OrderTotal.ToString("F2", CultureInfo.InvariantCulture));

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

            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.Paid;
                //result.CaptureTransactionId = null;
                result.CaptureTransactionResult = strStatusDetail;

                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);
        }