Пример #1
0
        public IPaymentResponse AmexResponseHandler(IGatewayCharge gatewayCharge)
        {
            NameValueCollection nvcResponseQueryString = HttpUtility.ParseQueryString(gatewayCharge.QueryString);

            VpcRequest vpcRequest = new VpcRequest(_settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.Amex.VpcPaymentCaptureServerUrl), _settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.Amex.SecureSecret));

            vpcRequest.AddVpcResponseFields(nvcResponseQueryString);

            string vpcTxnResponseCode = vpcRequest.GetResultField("vpc_TxnResponseCode", "Unknown");
            string vpc3DSstatus       = vpcRequest.GetResultField("vpc_3DSstatus", "Unknown");
            string vpcTransactionNo   = vpcRequest.GetResultField("vpc_TransactionNo", "Unknown");
            string vpcMerchTxnRef     = vpcRequest.GetResultField("vpc_MerchTxnRef", "Unknown");
            string vpcAmount          = vpcRequest.GetResultField("vpc_Amount", "Unknown");

            if (vpcTxnResponseCode.Equals("0") && vpc3DSstatus.Equals("Y"))
            {
                try
                {
                    VpcRequest vpcCaptureRequest = new VpcRequest(_settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.Amex.VpcPaymentCaptureServerUrl), _settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.Amex.SecureSecret));

                    vpcCaptureRequest.AddVpcRequestFields("vpc_Version", _settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.Amex.VpcVersion));
                    vpcCaptureRequest.AddVpcRequestFields("vpc_Command", _settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.Amex.VpcCommand));
                    vpcCaptureRequest.AddVpcRequestFields("vpc_AccessCode", _settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.Amex.AccessKey));
                    vpcCaptureRequest.AddVpcRequestFields("vpc_Merchant", _settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.Amex.MerchantId));
                    vpcCaptureRequest.AddVpcRequestFields("vpc_TransNo", vpcTransactionNo);
                    vpcCaptureRequest.AddVpcRequestFields("vpc_MerchTxnRef", vpcMerchTxnRef);
                    vpcCaptureRequest.AddVpcRequestFields("vpc_Amount", vpcAmount);
                    vpcCaptureRequest.AddVpcRequestFields("vpc_User", _settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.Amex.UserName));
                    vpcCaptureRequest.AddVpcRequestFields("vpc_Password", _settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.Amex.Password));

                    vpcCaptureRequest.SendVpcCaptureRequest();

                    string vpcCaptureTxnResponseCode = vpcRequest.GetResultField("vpc_TxnResponseCode", "Unknown");
                    string paymentConfirmationNumber = vpcRequest.GetResultField("vpc_TransactionNo", "Unknown");
                    string vpcCaptureMerchTxnRef     = vpcRequest.GetResultField("vpc_MerchTxnRef", "Unknown");

                    if (vpcCaptureTxnResponseCode.Equals("0"))
                    {
                        return(GetPaymentResponse(true, PaymentGatewayError.None));
                    }
                    else
                    {
                        return(GetPaymentResponse(false, GetPaymentGatewayErrorCode(vpcCaptureTxnResponseCode)));
                    }
                }
                catch (Exception ex)
                {
                    _logger.Log(LogCategory.Error, new Exception("Failed to process transaction", ex));
                    return(GetPaymentResponse(false, GetPaymentGatewayErrorCode(ex.Message)));
                }
            }
            else
            {
                return(GetPaymentResponse(false, GetPaymentGatewayErrorCode(vpcTxnResponseCode)));
            }
        }
Пример #2
0
        protected override async Task <IPaymentRedirectResponse> PaymentRedirectChargeGenerator(ICharge charge)
        {
            try
            {
                VpcRequest vpcRequest = new VpcRequest(_settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.Amex.VpcPaymentServerUrl), _settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.Amex.SecureSecret));
                vpcRequest.AddVpcRequestFields("vpc_Version", _settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.Amex.VpcVersion));
                vpcRequest.AddVpcRequestFields("vpc_Command", _settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.Amex.VpcCommand));
                vpcRequest.AddVpcRequestFields("vpc_AccessCode", _settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.Amex.AccessKey));
                vpcRequest.AddVpcRequestFields("vpc_Merchant", _settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.Amex.MerchantId));
                vpcRequest.AddVpcRequestFields("vpc_ReturnURL", _settings.GetConfigSetting <string>(SettingKeys.PaymentGateway.Paypal.ReturnUrl));
                vpcRequest.AddVpcRequestFields("vpc_MerchTxnRef", charge.TransactionId.ToString());
                vpcRequest.AddVpcRequestFields("vpc_OrderInfo", $"Transaction charge for {charge.TransactionId.ToString()}");
                vpcRequest.AddVpcRequestFields("vpc_Amount", (Convert.ToDouble(charge.Amount) * 100).ToString());
                vpcRequest.AddVpcRequestFields("vpc_Locale", "en");

                string chargeUrl = vpcRequest.CreateAmexChargeRedirectUrl();
                return(GetPaymentRedirectResponse(chargeUrl, ""));
            }
            catch (Exception ex)
            {
                _logger.Log(LogCategory.Error, new Exception("Failed to create redirect charge", ex));
                return(GetPaymentRedirectResponse(null, ex.Message));
            }
        }