// ProcessCard() is used for Credit Card processing via Website Payments Pro, // just like other credit card gateways. // ProcessPaypal() is used for Express Checkout and PayPal payments. public override string ProcessCard(int OrderNumber, int CustomerID, decimal OrderTotal, bool useLiveTransactions, TransactionModeEnum TransactionMode, Address UseBillingAddress, string CardExtraCode, Address UseShippingAddress, string CAVV, string ECI, string XID, out string AVSResult, out string AuthorizationResult, out string AuthorizationCode, out string AuthorizationTransID, out string TransactionCommandOut, out string TransactionResponse) { String result = AppLogic.ro_OK; AuthorizationCode = String.Empty; AuthorizationResult = String.Empty; AuthorizationTransID = String.Empty; AVSResult = String.Empty; TransactionCommandOut = String.Empty; TransactionResponse = String.Empty; try { // the request details object contains all payment details DoDirectPaymentRequestDetailsType RequestDetails = new DoDirectPaymentRequestDetailsType(); // define the payment action to 'Sale' // (another option is 'Authorization', which would be followed later with a DoCapture API call) RequestDetails.PaymentAction = (PaymentActionCodeType)CommonLogic.IIF(AppLogic.TransactionModeIsAuthOnly(), (int)PaymentActionCodeType.Authorization, (int)PaymentActionCodeType.Sale); // define the total amount and currency for the transaction PaymentDetailsType PaymentDetails = new PaymentDetailsType(); BasicAmountType totalAmount = new BasicAmountType(); totalAmount.Value = Localization.CurrencyStringForGatewayWithoutExchangeRate(OrderTotal); totalAmount.currencyID = (CurrencyCodeType)Enum.Parse(typeof(CurrencyCodeType), AppLogic.AppConfig("Localization.StoreCurrency"), true); PaymentDetails.OrderTotal = totalAmount; PaymentDetails.InvoiceID = OrderNumber.ToString(); PaymentDetails.ButtonSource = PayPal.BN + "_DP_US"; PaymentDetails.OrderDescription = AppLogic.AppConfig("StoreName"); // define the credit card to be used CreditCardDetailsType creditCard = new CreditCardDetailsType(); creditCard.CreditCardNumber = UseBillingAddress.CardNumber; creditCard.ExpMonth = Localization.ParseUSInt(UseBillingAddress.CardExpirationMonth); creditCard.ExpYear = Localization.ParseUSInt(UseBillingAddress.CardExpirationYear); creditCard.ExpMonthSpecified = true; creditCard.ExpYearSpecified = true; creditCard.CVV2 = CardExtraCode; if (UseBillingAddress.CardType == "AmericanExpress") { creditCard.CreditCardType = (CreditCardTypeType)Enum.Parse(typeof(CreditCardTypeType), "Amex", true); } else { creditCard.CreditCardType = (CreditCardTypeType)Enum.Parse(typeof(CreditCardTypeType), UseBillingAddress.CardType, true); } creditCard.CreditCardTypeSpecified = true; PayerInfoType cardHolder = new PayerInfoType(); PersonNameType oPersonNameType = new PersonNameType(); oPersonNameType.FirstName = UseBillingAddress.FirstName; oPersonNameType.LastName = UseBillingAddress.LastName; oPersonNameType.MiddleName = String.Empty; oPersonNameType.Salutation = String.Empty; oPersonNameType.Suffix = String.Empty; cardHolder.PayerName = oPersonNameType; AddressType PayerAddress = new AddressType(); PayerAddress.Street1 = UseBillingAddress.Address1; PayerAddress.CityName = UseBillingAddress.City; PayerAddress.StateOrProvince = UseBillingAddress.State; PayerAddress.PostalCode = UseBillingAddress.Zip; PayerAddress.Country = (CountryCodeType)Enum.Parse(typeof(CountryCodeType), AppLogic.GetCountryTwoLetterISOCode(UseBillingAddress.Country), true); PayerAddress.CountrySpecified = true; if (UseShippingAddress != null) { AddressType shippingAddress = new AddressType(); shippingAddress.Name = (UseShippingAddress.FirstName + " " + UseShippingAddress.LastName).Trim(); shippingAddress.Street1 = UseShippingAddress.Address1; shippingAddress.Street2 = UseShippingAddress.Address2 + CommonLogic.IIF(UseShippingAddress.Suite != "", " Ste " + UseShippingAddress.Suite, ""); shippingAddress.CityName = UseShippingAddress.City; shippingAddress.StateOrProvince = UseShippingAddress.State; shippingAddress.PostalCode = UseShippingAddress.Zip; shippingAddress.Country = (CountryCodeType)Enum.Parse(typeof(CountryCodeType), AppLogic.GetCountryTwoLetterISOCode(UseShippingAddress.Country), true); shippingAddress.CountrySpecified = true; PaymentDetails.ShipToAddress = shippingAddress; } cardHolder.Address = PayerAddress; creditCard.CardOwner = cardHolder; RequestDetails.CreditCard = creditCard; RequestDetails.PaymentDetails = PaymentDetails; RequestDetails.IPAddress = CommonLogic.CustomerIpAddress(); // cart.ThisCustomer.LastIPAddress; if (RequestDetails.IPAddress == "::1") { RequestDetails.IPAddress = "127.0.0.1"; } // instantiate the actual request object PaymentRequest = new DoDirectPaymentRequestType(); PaymentRequest.Version = API_VER; PaymentRequest.DoDirectPaymentRequestDetails = RequestDetails; DDPReq = new DoDirectPaymentReq(); DDPReq.DoDirectPaymentRequest = PaymentRequest; DoDirectPaymentResponseType responseDetails = (DoDirectPaymentResponseType)IPayPal.DoDirectPayment(DDPReq); //if (LogToErrorTable) //{ // PayPalController.Log(XmlCommon.SerializeObject(DDPReq, DDPReq.GetType()), "DoDirectPayment Request"); // PayPalController.Log(XmlCommon.SerializeObject(responseDetails, responseDetails.GetType()), "DoDirectPayment Response"); //} if (responseDetails != null && responseDetails.Ack.ToString().StartsWith("success", StringComparison.InvariantCultureIgnoreCase)) { AuthorizationTransID = CommonLogic.IIF(TransactionMode.ToString().ToLower() == AppLogic.ro_TXModeAuthOnly.ToLower(), "AUTH=", "CAPTURE=") + responseDetails.TransactionID.ToString(); AuthorizationCode = responseDetails.CorrelationID; AVSResult = responseDetails.AVSCode; result = AppLogic.ro_OK; AuthorizationResult = responseDetails.Ack.ToString() + "|AVSCode=" + responseDetails.AVSCode.ToString() + "|CVV2Code=" + responseDetails.CVV2Code.ToString(); } else { if (responseDetails.Errors != null) { String Separator = String.Empty; for (int ix = 0; ix < responseDetails.Errors.Length; ix++) { AuthorizationResult += Separator; AuthorizationResult += responseDetails.Errors[ix].LongMessage; // record failed TX TransactionResponse += Separator; try { TransactionResponse += String.Format("|{0},{1},{2}|", responseDetails.Errors[ix].ShortMessage, responseDetails.Errors[ix].ErrorCode, responseDetails.Errors[ix].LongMessage); // record failed TX } catch { } Separator = ", "; } } result = AuthorizationResult; // just store something here, as there is no other way to get data out of this gateway about the failure for logging in failed transaction table } } catch { result = "Transaction Failed"; } return(result); }
public TransactionResult SubmitPaymentTransaction(CheckoutDetails details) { //init result structure TransactionResult ret = new TransactionResult(); //set up Request //instantiate DoDirectPaymentRequestType and RequestDetails objects DoDirectPaymentRequestType request = new DoDirectPaymentRequestType(); request.Version = PROCESSOR_VERSION; DoDirectPaymentRequestDetailsType requestDetails = new DoDirectPaymentRequestDetailsType(); request.DoDirectPaymentRequestDetails = requestDetails; //set payment action requestDetails.PaymentAction = PaymentActionCodeType.Sale; //set IP //requestDetails.IPAddress = Request.UserHostAddress; requestDetails.IPAddress = details[CheckoutKeys.IPAddress]; //set CreditCard info CreditCardDetailsType creditCardDetails = new CreditCardDetailsType(); requestDetails.CreditCard = creditCardDetails; creditCardDetails.CreditCardNumber = details[CheckoutKeys.CardNumber]; creditCardDetails.CreditCardType = (CreditCardTypeType)Enum.Parse(typeof(CreditCardTypeType), details[CheckoutKeys.CardType], true); creditCardDetails.CVV2 = details[CheckoutKeys.VerificationCode]; creditCardDetails.ExpMonth = Int32.Parse(details[CheckoutKeys.ExpireMonth]); creditCardDetails.ExpYear = Int32.Parse(details[CheckoutKeys.ExpireYear]); // Switch/Solo if (creditCardDetails.CreditCardType == CreditCardTypeType.Solo || creditCardDetails.CreditCardType == CreditCardTypeType.Switch) { creditCardDetails.StartMonth = Int32.Parse(details[CheckoutKeys.StartMonth]); creditCardDetails.StartYear = Int32.Parse(details[CheckoutKeys.StartYear]); creditCardDetails.IssueNumber = details[CheckoutKeys.IssueNumber]; } //set billing address PayerInfoType cardOwner = new PayerInfoType(); creditCardDetails.CardOwner = cardOwner; cardOwner.PayerName = new PersonNameType(); cardOwner.PayerName.FirstName = details[CheckoutKeys.FirstName]; cardOwner.PayerName.LastName = details[CheckoutKeys.LastName]; cardOwner.Address = new AddressType(); cardOwner.Address.Street1 = details[CheckoutKeys.Address]; //??? cardOwner.Address.Street2 = ""; cardOwner.Address.CityName = details[CheckoutKeys.City]; cardOwner.Address.StateOrProvince = details[CheckoutKeys.State]; cardOwner.Address.PostalCode = details[CheckoutKeys.Zip]; cardOwner.Address.CountrySpecified = true; cardOwner.Address.Country = (CountryCodeType)Enum.Parse(typeof(CountryCodeType), details[CheckoutKeys.Country], true); //set payment Details PaymentDetailsType paymentDetails = new PaymentDetailsType(); requestDetails.PaymentDetails = paymentDetails; paymentDetails.OrderTotal = new BasicAmountType(); //TODO: Add currency support paymentDetails.OrderTotal.currencyID = (CurrencyCodeType)Enum.Parse(typeof(CurrencyCodeType), details[CheckoutKeys.Currency]); //paymentDetails.OrderTotal.currencyID = CurrencyCodeType.USD; //No currency symbol. Decimal separator must be a period (.), and the thousands separator must be a comma (,) paymentDetails.OrderTotal.Value = details[CheckoutKeys.Amount]; DoDirectPaymentReq paymentRequest = new DoDirectPaymentReq(); paymentRequest.DoDirectPaymentRequest = request; //FINISH set up req //setup request Header, API credentials PayPalAPIAASoapBinding paypalInterface = new PayPalAPIAASoapBinding(); UserIdPasswordType user = new UserIdPasswordType(); //set api credentials - username, password, signature user.Username = Username; user.Password = Password; user.Signature = Signature; // setup service url paypalInterface.Url = ServiceUrl; paypalInterface.RequesterCredentials = new CustomSecurityHeaderType(); paypalInterface.RequesterCredentials.Credentials = user; //make call return response DoDirectPaymentResponseType paymentResponse = new DoDirectPaymentResponseType(); paymentResponse = paypalInterface.DoDirectPayment(paymentRequest); //write response xml to the ret object ret.RawResponse = SerializeObject(paymentResponse); switch (paymentResponse.Ack) { case AckCodeType.Success: case AckCodeType.SuccessWithWarning: ret.Succeed = true; ret.TransactionId = paymentResponse.TransactionID; ret.TransactionStatus = TransactionStatus.Approved; break; default: // show errors if Ack is NOT Success ret.Succeed = false; ret.TransactionStatus = TransactionStatus.Declined; if (paymentResponse.Errors != null && paymentResponse.Errors.Length > 0) { ret.StatusCode = PayPalProKeys.ErrorPrefix + paymentResponse.Errors[0].ErrorCode; } break; } return(ret); }
protected ProcessPaymentResult AuthorizeOrSale(ProcessPaymentRequest processPaymentRequest, bool authorizeOnly) { var result = new ProcessPaymentResult(); var customer = _customerService.GetCustomerById(processPaymentRequest.CustomerId); if (customer == null) { throw new Exception("Customer cannot be loaded"); } var req = new DoDirectPaymentReq(); req.DoDirectPaymentRequest = new DoDirectPaymentRequestType(); req.DoDirectPaymentRequest.Version = GetApiVersion(); var details = new DoDirectPaymentRequestDetailsType(); req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails = details; details.IPAddress = _webHelper.GetCurrentIpAddress(); if (authorizeOnly) { details.PaymentAction = PaymentActionCodeType.Authorization; } else { details.PaymentAction = PaymentActionCodeType.Sale; } //credit card details.CreditCard = new CreditCardDetailsType(); details.CreditCard.CreditCardNumber = processPaymentRequest.CreditCardNumber; details.CreditCard.CreditCardType = GetPaypalCreditCardType(processPaymentRequest.CreditCardType); details.CreditCard.ExpMonthSpecified = true; details.CreditCard.ExpMonth = processPaymentRequest.CreditCardExpireMonth; details.CreditCard.ExpYearSpecified = true; details.CreditCard.ExpYear = processPaymentRequest.CreditCardExpireYear; details.CreditCard.CVV2 = processPaymentRequest.CreditCardCvv2; details.CreditCard.CardOwner = new PayerInfoType(); details.CreditCard.CardOwner.PayerCountry = GetPaypalCountryCodeType(customer.BillingAddress.Country); details.CreditCard.CreditCardTypeSpecified = true; //billing address details.CreditCard.CardOwner.Address = new AddressType(); details.CreditCard.CardOwner.Address.CountrySpecified = true; details.CreditCard.CardOwner.Address.Street1 = customer.BillingAddress.Address1; details.CreditCard.CardOwner.Address.Street2 = customer.BillingAddress.Address2; details.CreditCard.CardOwner.Address.CityName = customer.BillingAddress.City; if (customer.BillingAddress.StateProvince != null) { details.CreditCard.CardOwner.Address.StateOrProvince = customer.BillingAddress.StateProvince.Abbreviation; } else { details.CreditCard.CardOwner.Address.StateOrProvince = "CA"; } details.CreditCard.CardOwner.Address.Country = GetPaypalCountryCodeType(customer.BillingAddress.Country); details.CreditCard.CardOwner.Address.PostalCode = customer.BillingAddress.ZipPostalCode; details.CreditCard.CardOwner.Payer = customer.BillingAddress.Email; details.CreditCard.CardOwner.PayerName = new PersonNameType(); details.CreditCard.CardOwner.PayerName.FirstName = customer.BillingAddress.FirstName; details.CreditCard.CardOwner.PayerName.LastName = customer.BillingAddress.LastName; //order totals var payPalCurrency = PaypalHelper.GetPaypalCurrency(_currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId)); details.PaymentDetails = new PaymentDetailsType(); details.PaymentDetails.OrderTotal = new BasicAmountType(); details.PaymentDetails.OrderTotal.Value = Math.Round(processPaymentRequest.OrderTotal, 2).ToString("N", new CultureInfo("en-us")); details.PaymentDetails.OrderTotal.currencyID = payPalCurrency; details.PaymentDetails.Custom = processPaymentRequest.OrderGuid.ToString(); details.PaymentDetails.ButtonSource = "nopCommerceCart"; //pass product names and totals to PayPal //if (_paypalDirectPaymentSettings.PassProductNamesAndTotals) //{ // //individual items //var cart = customer.ShoppingCartItems // .Where(x=>x.ShoppingCartType == ShoppingCartType.ShoppingCart) // .Where(x=>x.StoreId == processPaymentRequest.StoreId) // .ToList(); // var cartItems = new PaymentDetailsItemType[cart.Count]; // for (int i = 0; i < cart.Count; i++) // { // var sc = cart[i]; // decimal taxRate = decimal.Zero; // var customer = processPaymentRequest.Customer; // decimal scUnitPrice = _priceCalculationService.GetUnitPrice(sc, true); // decimal scSubTotal = _priceCalculationService.GetSubTotal(sc, true); // decimal scUnitPriceInclTax = _taxService.GetProductPrice(sc.ProductVariant, scUnitPrice, true, customer, out taxRate); // decimal scUnitPriceExclTax = _taxService.GetProductPrice(sc.ProductVariant, scUnitPrice, false, customer, out taxRate); // //decimal scSubTotalInclTax = _taxService.GetProductPrice(sc.ProductVariant, scSubTotal, true, customer, out taxRate); // //decimal scSubTotalExclTax = _taxService.GetProductPrice(sc.ProductVariant, scSubTotal, false, customer, out taxRate); // cartItems[i] = new PaymentDetailsItemType() // { // Name = sc.ProductVariant.FullProductName, // Number = sc.ProductVariant.Id.ToString(), // Quantity = sc.Quantity.ToString(), // Amount = new BasicAmountType() // { // currencyID = payPalCurrency, // Value = scUnitPriceExclTax.ToString("N", new CultureInfo("en-us")), // }, // Tax = new BasicAmountType() // { // currencyID = payPalCurrency, // Value = (scUnitPriceInclTax - scUnitPriceExclTax).ToString("N", new CultureInfo("en-us")), // }, // }; // }; // details.PaymentDetails.PaymentDetailsItem = cartItems; // //other totals (undone) // details.PaymentDetails.ItemTotal = null; // details.PaymentDetails.ShippingTotal = null; // details.PaymentDetails.TaxTotal = null; // details.PaymentDetails.HandlingTotal = null; //} //shipping if (customer.ShippingAddress != null) { if (customer.ShippingAddress.StateProvince != null && customer.ShippingAddress.Country != null) { var shippingAddress = new AddressType(); shippingAddress.Name = customer.ShippingAddress.FirstName + " " + customer.ShippingAddress.LastName; shippingAddress.Street1 = customer.ShippingAddress.Address1; shippingAddress.CityName = customer.ShippingAddress.City; shippingAddress.StateOrProvince = customer.ShippingAddress.StateProvince.Abbreviation; shippingAddress.PostalCode = customer.ShippingAddress.ZipPostalCode; shippingAddress.Country = (CountryCodeType)Enum.Parse(typeof(CountryCodeType), customer.ShippingAddress.Country.TwoLetterIsoCode, true); shippingAddress.CountrySpecified = true; details.PaymentDetails.ShipToAddress = shippingAddress; } } //send request 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 = ""; DoDirectPaymentResponseType response = service2.DoDirectPayment(req); string error = ""; bool success = PaypalHelper.CheckSuccess(response, out error); if (success) { result.AvsResult = response.AVSCode; result.AuthorizationTransactionCode = response.CVV2Code; if (authorizeOnly) { result.AuthorizationTransactionId = response.TransactionID; result.AuthorizationTransactionResult = response.Ack.ToString(); result.NewPaymentStatus = PaymentStatus.Authorized; } else { result.CaptureTransactionId = response.TransactionID; result.CaptureTransactionResult = response.Ack.ToString(); result.NewPaymentStatus = PaymentStatus.Paid; } } else { result.AddError(error); } } return(result); }
/// <summary> /// Process a payment /// </summary> /// <param name="processPaymentRequest">Payment info required for an order processing</param> /// <returns>Process payment result</returns> public override ProcessPaymentResult ProcessPayment(ProcessPaymentRequest processPaymentRequest) { var result = new ProcessPaymentResult(); var customer = _customerService.GetCustomerById(processPaymentRequest.CustomerId); var settings = CommonServices.Settings.LoadSetting <PayPalDirectPaymentSettings>(processPaymentRequest.StoreId); var req = new DoDirectPaymentReq(); req.DoDirectPaymentRequest = new DoDirectPaymentRequestType(); req.DoDirectPaymentRequest.Version = PayPalHelper.GetApiVersion(); var details = new DoDirectPaymentRequestDetailsType(); req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails = details; details.IPAddress = CommonServices.WebHelper.GetCurrentIpAddress(); if (details.IPAddress.IsEmpty()) { details.IPAddress = "127.0.0.1"; } if (settings.TransactMode == TransactMode.Authorize) { details.PaymentAction = PaymentActionCodeType.Authorization; } else { details.PaymentAction = PaymentActionCodeType.Sale; } //credit card details.CreditCard = new CreditCardDetailsType(); details.CreditCard.CreditCardNumber = processPaymentRequest.CreditCardNumber; details.CreditCard.CreditCardType = PayPalHelper.GetPaypalCreditCardType(processPaymentRequest.CreditCardType); details.CreditCard.ExpMonthSpecified = true; details.CreditCard.ExpMonth = processPaymentRequest.CreditCardExpireMonth; details.CreditCard.ExpYearSpecified = true; details.CreditCard.ExpYear = processPaymentRequest.CreditCardExpireYear; details.CreditCard.CVV2 = processPaymentRequest.CreditCardCvv2; details.CreditCard.CardOwner = new PayerInfoType(); details.CreditCard.CardOwner.PayerCountry = PayPalHelper.GetPaypalCountryCodeType(customer.BillingAddress.Country); details.CreditCard.CreditCardTypeSpecified = true; //billing address details.CreditCard.CardOwner.Address = new AddressType(); details.CreditCard.CardOwner.Address.CountrySpecified = true; details.CreditCard.CardOwner.Address.Street1 = customer.BillingAddress.Address1; details.CreditCard.CardOwner.Address.Street2 = customer.BillingAddress.Address2; details.CreditCard.CardOwner.Address.CityName = customer.BillingAddress.City; if (customer.BillingAddress.StateProvince != null) { details.CreditCard.CardOwner.Address.StateOrProvince = customer.BillingAddress.StateProvince.Abbreviation; } else { details.CreditCard.CardOwner.Address.StateOrProvince = "CA"; } details.CreditCard.CardOwner.Address.Country = PayPalHelper.GetPaypalCountryCodeType(customer.BillingAddress.Country); details.CreditCard.CardOwner.Address.PostalCode = customer.BillingAddress.ZipPostalCode; details.CreditCard.CardOwner.Payer = customer.BillingAddress.Email; details.CreditCard.CardOwner.PayerName = new PersonNameType(); details.CreditCard.CardOwner.PayerName.FirstName = customer.BillingAddress.FirstName; details.CreditCard.CardOwner.PayerName.LastName = customer.BillingAddress.LastName; //order totals var payPalCurrency = PayPalHelper.GetPaypalCurrency(_currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId)); details.PaymentDetails = new PaymentDetailsType(); details.PaymentDetails.OrderTotal = new BasicAmountType(); details.PaymentDetails.OrderTotal.Value = Math.Round(processPaymentRequest.OrderTotal, 2).ToString("N", new CultureInfo("en-us")); details.PaymentDetails.OrderTotal.currencyID = payPalCurrency; details.PaymentDetails.Custom = processPaymentRequest.OrderGuid.ToString(); details.PaymentDetails.ButtonSource = SmartStoreVersion.CurrentFullVersion; //shipping if (customer.ShippingAddress != null) { if (customer.ShippingAddress.StateProvince != null && customer.ShippingAddress.Country != null) { var shippingAddress = new AddressType(); shippingAddress.Name = customer.ShippingAddress.FirstName + " " + customer.ShippingAddress.LastName; shippingAddress.Street1 = customer.ShippingAddress.Address1; shippingAddress.CityName = customer.ShippingAddress.City; shippingAddress.StateOrProvince = customer.ShippingAddress.StateProvince.Abbreviation; shippingAddress.PostalCode = customer.ShippingAddress.ZipPostalCode; shippingAddress.Country = (CountryCodeType)Enum.Parse(typeof(CountryCodeType), customer.ShippingAddress.Country.TwoLetterIsoCode, true); shippingAddress.CountrySpecified = true; details.PaymentDetails.ShipToAddress = shippingAddress; } } //send request using (var service = new PayPalAPIAASoapBinding()) { service.Url = PayPalHelper.GetPaypalServiceUrl(settings); service.RequesterCredentials = PayPalHelper.GetPaypalApiCredentials(settings); DoDirectPaymentResponseType response = service.DoDirectPayment(req); string error = ""; bool success = PayPalHelper.CheckSuccess(Helper, response, out error); if (success) { result.AvsResult = response.AVSCode; result.AuthorizationTransactionCode = response.CVV2Code; if (settings.TransactMode == TransactMode.Authorize) { result.AuthorizationTransactionId = response.TransactionID; result.AuthorizationTransactionResult = response.Ack.ToString(); result.NewPaymentStatus = PaymentStatus.Authorized; } else { result.CaptureTransactionId = response.TransactionID; result.CaptureTransactionResult = response.Ack.ToString(); result.NewPaymentStatus = PaymentStatus.Paid; } } else { result.AddError(error); } } return(result); }
/// <summary> /// Authorizes the payment /// </summary> /// <param name="paymentInfo">Payment info required for an order processing</param> /// <param name="customer">Customer</param> /// <param name="orderGuid">Unique order identifier</param> /// <param name="processPaymentResult">Process payment result</param> /// <param name="authorizeOnly">A value indicating whether to authorize only; true - authorize; false - sale</param> protected void AuthorizeOrSale(PaymentInfo paymentInfo, Customer customer, Guid orderGuid, ProcessPaymentResult processPaymentResult, bool authorizeOnly) { InitSettings(); DoDirectPaymentReq req = new DoDirectPaymentReq(); req.DoDirectPaymentRequest = new DoDirectPaymentRequestType(); req.DoDirectPaymentRequest.Version = this.APIVersion; DoDirectPaymentRequestDetailsType details = new DoDirectPaymentRequestDetailsType(); req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails = details; details.IPAddress = NopContext.Current.UserHostAddress; if (authorizeOnly) { details.PaymentAction = PaymentActionCodeType.Authorization; } else { details.PaymentAction = PaymentActionCodeType.Sale; } details.CreditCard = new CreditCardDetailsType(); details.CreditCard.CreditCardNumber = paymentInfo.CreditCardNumber; details.CreditCard.CreditCardType = GetPaypalCreditCardType(paymentInfo.CreditCardType); details.CreditCard.ExpMonthSpecified = true; details.CreditCard.ExpMonth = paymentInfo.CreditCardExpireMonth; details.CreditCard.ExpYearSpecified = true; details.CreditCard.ExpYear = paymentInfo.CreditCardExpireYear; details.CreditCard.CVV2 = paymentInfo.CreditCardCvv2; details.CreditCard.CardOwner = new PayerInfoType(); details.CreditCard.CardOwner.PayerCountry = GetPaypalCountryCodeType(paymentInfo.BillingAddress.Country); details.CreditCard.CreditCardTypeSpecified = true; details.CreditCard.CardOwner.Address = new AddressType(); details.CreditCard.CardOwner.Address.CountrySpecified = true; details.CreditCard.CardOwner.Address.Street1 = paymentInfo.BillingAddress.Address1; details.CreditCard.CardOwner.Address.Street2 = paymentInfo.BillingAddress.Address2; details.CreditCard.CardOwner.Address.CityName = paymentInfo.BillingAddress.City; if (paymentInfo.BillingAddress.StateProvince != null) { details.CreditCard.CardOwner.Address.StateOrProvince = paymentInfo.BillingAddress.StateProvince.Abbreviation; } else { details.CreditCard.CardOwner.Address.StateOrProvince = "CA"; } details.CreditCard.CardOwner.Address.Country = GetPaypalCountryCodeType(paymentInfo.BillingAddress.Country); details.CreditCard.CardOwner.Address.PostalCode = paymentInfo.BillingAddress.ZipPostalCode; details.CreditCard.CardOwner.Payer = paymentInfo.BillingAddress.Email; details.CreditCard.CardOwner.PayerName = new PersonNameType(); details.CreditCard.CardOwner.PayerName.FirstName = paymentInfo.BillingAddress.FirstName; details.CreditCard.CardOwner.PayerName.LastName = paymentInfo.BillingAddress.LastName; details.PaymentDetails = new PaymentDetailsType(); details.PaymentDetails.OrderTotal = new BasicAmountType(); details.PaymentDetails.OrderTotal.Value = paymentInfo.OrderTotal.ToString("N", new CultureInfo("en-us")); details.PaymentDetails.OrderTotal.currencyID = PaypalHelper.GetPaypalCurrency(IoC.Resolve <ICurrencyService>().PrimaryStoreCurrency); details.PaymentDetails.Custom = orderGuid.ToString(); details.PaymentDetails.ButtonSource = "nopCommerceCart"; //ShoppingCart cart = IoC.Resolve<IShoppingCartService>().GetShoppingCartByCustomerSessionGUID(ShoppingCartTypeEnum.ShoppingCart, NopContext.Current.Session.CustomerSessionGUID); //PaymentDetailsItemType[] cartItems = new PaymentDetailsItemType[cart.Count]; //for (int i = 0; i < cart.Count; i++) //{ // ShoppingCartItem item = cart[i]; // cartItems[i] = new PaymentDetailsItemType() // { // Name = item.ProductVariant.FullProductName, // Number = item.ProductVariant.ProductVariantID.ToString(), // Quantity = item.Quantity.ToString(), // Amount = new BasicAmountType() // { // currencyID = PaypalHelper.GetPaypalCurrency(IoC.Resolve<ICurrencyService>().PrimaryStoreCurrency), // Value = (item.Quantity * item.ProductVariant.Price).ToString("N", new CultureInfo("en-us")) // } // }; //}; //details.PaymentDetails.PaymentDetailsItem = cartItems; //shipping if (paymentInfo.ShippingAddress != null) { if (paymentInfo.ShippingAddress.StateProvince != null && paymentInfo.ShippingAddress.Country != null) { AddressType shippingAddress = new AddressType(); shippingAddress.Name = paymentInfo.ShippingAddress.FirstName + " " + paymentInfo.ShippingAddress.LastName; shippingAddress.Street1 = paymentInfo.ShippingAddress.Address1; shippingAddress.CityName = paymentInfo.ShippingAddress.City; shippingAddress.StateOrProvince = paymentInfo.ShippingAddress.StateProvince.Abbreviation; shippingAddress.PostalCode = paymentInfo.ShippingAddress.ZipPostalCode; shippingAddress.Country = (CountryCodeType)Enum.Parse(typeof(CountryCodeType), paymentInfo.ShippingAddress.Country.TwoLetterIsoCode, true); shippingAddress.CountrySpecified = true; details.PaymentDetails.ShipToAddress = shippingAddress; } } DoDirectPaymentResponseType response = service2.DoDirectPayment(req); string error = string.Empty; bool Success = PaypalHelper.CheckSuccess(response, out error); if (Success) { processPaymentResult.AVSResult = response.AVSCode; processPaymentResult.AuthorizationTransactionCode = response.CVV2Code; if (authorizeOnly) { processPaymentResult.AuthorizationTransactionId = response.TransactionID; processPaymentResult.AuthorizationTransactionResult = response.Ack.ToString(); processPaymentResult.PaymentStatus = PaymentStatusEnum.Authorized; } else { processPaymentResult.CaptureTransactionId = response.TransactionID; processPaymentResult.CaptureTransactionResult = response.Ack.ToString(); processPaymentResult.PaymentStatus = PaymentStatusEnum.Paid; } } else { processPaymentResult.Error = error; processPaymentResult.FullError = error; } }
public void ProcessDirectPayment(PayPalInformation paypalinformation) { DoDirectPaymentRequestType DoDirectPmtReqType = new DoDirectPaymentRequestType(); DoDirectPmtReqType.DoDirectPaymentRequestDetails = new DoDirectPaymentRequestDetailsType(); // Set payment action DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentAction = PaymentActionCodeType.Sale; // Set IP DoDirectPmtReqType.DoDirectPaymentRequestDetails.IPAddress = HttpContext.Current.Request.UserHostAddress; // Set CreditCard info. DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard = new CreditCardDetailsType(); DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CreditCardNumber = paypalinformation.Order.CreditCard.Number; DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CreditCardType = ( CreditCardTypeType )StringToEnum(typeof(CreditCardTypeType), paypalinformation.Order.CreditCard.CardType); DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CVV2 = paypalinformation.Order.CreditCard.SecurityCode; DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.ExpMonth = paypalinformation.Order.CreditCard.ExpMonth; DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.ExpYear = paypalinformation.Order.CreditCard.ExpYear; // Set the billing address DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner = new PayerInfoType(); DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName = new PersonNameType(); DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName.FirstName = paypalinformation.Order.EndUser.FirstName; DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.PayerName.LastName = paypalinformation.Order.EndUser.LastName; DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address = new AddressType(); DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Street1 = paypalinformation.Order.CreditCard.Address.AddressLine; DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Street2 = paypalinformation.Order.CreditCard.Address.AddressLine2; DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.CityName = paypalinformation.Order.CreditCard.Address.City; DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.StateOrProvince = paypalinformation.Order.CreditCard.Address.State; DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.PostalCode = paypalinformation.Order.CreditCard.Address.PostalCode; DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.CountrySpecified = true; DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Country = CountryCodeType.US; DoDirectPmtReqType.DoDirectPaymentRequestDetails.CreditCard.CardOwner.Address.Phone = paypalinformation.Order.EndUser.ContactInformation.Phone; PaymentDetailsItemType[] itemArray = new PaymentDetailsItemType[paypalinformation.Order.OrderDetails.Products.Length]; PaymentDetailsItemType items = null; // Loop through all items that were added to the shopping cart. for (int i = 0; i < paypalinformation.Order.OrderDetails.Products.Length; i++) { items = new PaymentDetailsItemType(); items.Amount = new BasicAmountType(); items.Amount.Value = paypalinformation.Order.OrderDetails.Products[i].Price.ToString(); items.Amount.currencyID = CurrencyCodeType.USD; items.Quantity = paypalinformation.Order.OrderDetails.Products[i].Quantity.ToString(); //items.Tax = new BasicAmountType(); //items.Tax.Value = CalculationManager.CalcSalesTax( Convert.ToDecimal( items.Amount.Value ) ).ToString(); //items.Tax.currencyID = CurrencyCodeType.USD; items.Name = paypalinformation.Order.OrderDetails.Products[i].Name; items.Number = paypalinformation.Order.OrderDetails.Products[i].ProductID.ToString(); itemArray.SetValue(items, i); } // set payment Details DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails = new PaymentDetailsType(); DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.Custom = System.DateTime.Now.ToLongTimeString(); DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.OrderDescription = ""; DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.PaymentDetailsItem = new PaymentDetailsItemType[itemArray.Length]; DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.PaymentDetailsItem = itemArray; for (int ii = 0; ii < itemArray.Length; ii++) { DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.PaymentDetailsItem.SetValue(itemArray[ii], ii); } // Order summary. DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal = new BasicAmountType(); DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.currencyID = CurrencyCodeType.USD; DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.OrderTotal.Value = paypalinformation.Order.OrderTotal.ToString(); DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShippingTotal = new BasicAmountType(); DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShippingTotal.currencyID = CurrencyCodeType.USD; DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShippingTotal.Value = paypalinformation.Order.ShippingTotal.ToString(); DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.TaxTotal = new BasicAmountType(); DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.TaxTotal.currencyID = CurrencyCodeType.USD; DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.TaxTotal.Value = paypalinformation.Order.Tax.ToString(); DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ItemTotal = new BasicAmountType(); DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ItemTotal.currencyID = CurrencyCodeType.USD; DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ItemTotal.Value = paypalinformation.Order.SubTotal.ToString(); //set ship to address DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress = new AddressType(); DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.Name = paypalinformation.Order.EndUser.FirstName + " " + paypalinformation.Order.EndUser.LastName; DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.Street1 = paypalinformation.Order.ShippingAddress.AddressLine; DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.CityName = paypalinformation.Order.ShippingAddress.City; DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.StateOrProvince = paypalinformation.Order.ShippingAddress.State; DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.PostalCode = paypalinformation.Order.ShippingAddress.PostalCode; DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.CountrySpecified = true; DoDirectPmtReqType.DoDirectPaymentRequestDetails.PaymentDetails.ShipToAddress.Country = CountryCodeType.US; // credentials DoDirectPaymentReq DoDPReq = new DoDirectPaymentReq(); DoDPReq.DoDirectPaymentRequest = DoDirectPmtReqType; DoDPReq.DoDirectPaymentRequest.Version = "2.20"; try { //make call return response DoDirectPaymentResponseType DPRes = new DoDirectPaymentResponseType(); DPRes = PPInterface.DoDirectPayment(DoDPReq); string errors = CheckForErrors(DPRes); if (errors == string.Empty) { IsSubmissionSuccess = true; paypalinformation.Order.TransactionID = DPRes.TransactionID; } else { IsSubmissionSuccess = false; SubmissionError = errors; } } catch (Exception ex) { throw ex; } }
public PayPalReturn Pay(string orderNumber, string paymentAmount, string buyerLastName, string buyerFirstName, string buyerAddress, string buyerCity, string buyerStateOrProvince, string buyerCountryCode, string buyerCountryName, string buyerZipCode, string creditCardType, string creditCardNumber, string CVV2, string expMonth, string expYear) { //PayPal Return Structure PayPalReturn rv = new PayPalReturn(); rv.IsSucess = false; DoDirectPaymentRequestDetailsType requestDetails = new DoDirectPaymentRequestDetailsType(); requestDetails.CreditCard = new CreditCardDetailsType(); requestDetails.CreditCard.CardOwner = new PayerInfoType(); requestDetails.CreditCard.CardOwner.Address = new AddressType(); requestDetails.PaymentDetails = new PaymentDetailsType(); requestDetails.PaymentDetails.OrderTotal = new BasicAmountType(); requestDetails.CreditCard.CardOwner.PayerName = new PersonNameType(); //Request requestDetails.PaymentAction = PaymentActionCodeType.Sale; requestDetails.IPAddress = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]; //Payment requestDetails.PaymentDetails.OrderTotal.currencyID = CurrencyCodeType.USD; requestDetails.PaymentDetails.OrderTotal.Value = paymentAmount; //Credit card requestDetails.CreditCard.CreditCardNumber = creditCardNumber; requestDetails.CreditCard.CreditCardType = (CreditCardTypeType)Enum.Parse(typeof(CreditCardTypeType), creditCardType, true); requestDetails.CreditCard.ExpMonth = Convert.ToInt32(expMonth); requestDetails.CreditCard.ExpYear = Convert.ToInt32(expYear); requestDetails.CreditCard.CVV2 = CVV2; requestDetails.CreditCard.CreditCardTypeSpecified = true; requestDetails.CreditCard.ExpMonthSpecified = true; requestDetails.CreditCard.ExpYearSpecified = true; //Card Owner requestDetails.CreditCard.CardOwner.PayerName.FirstName = buyerFirstName; requestDetails.CreditCard.CardOwner.PayerName.LastName = buyerLastName; requestDetails.CreditCard.CardOwner.Address.Street1 = buyerAddress; requestDetails.CreditCard.CardOwner.Address.CityName = buyerCity; requestDetails.CreditCard.CardOwner.Address.StateOrProvince = buyerStateOrProvince; requestDetails.CreditCard.CardOwner.Address.CountryName = buyerCountryName; requestDetails.CreditCard.CardOwner.Address.Country = (CountryCodeType)Enum.Parse(typeof(CountryCodeType), buyerCountryCode, true); requestDetails.CreditCard.CardOwner.Address.PostalCode = buyerZipCode; requestDetails.CreditCard.CardOwner.Address.CountrySpecified = true; requestDetails.CreditCard.CardOwner.PayerCountry = (CountryCodeType)Enum.Parse(typeof(CountryCodeType), buyerCountryCode, true); requestDetails.CreditCard.CardOwner.PayerCountrySpecified = true; DoDirectPaymentReq request = new DoDirectPaymentReq(); request.DoDirectPaymentRequest = new DoDirectPaymentRequestType(); request.DoDirectPaymentRequest.DoDirectPaymentRequestDetails = requestDetails; request.DoDirectPaymentRequest.Version = "51.0"; //Headers CustomSecurityHeaderType headers = new CustomSecurityHeaderType(); headers.Credentials = new UserIdPasswordType(); headers.Credentials.Username = ConfigurationManager.AppSettings["PayPalAPIUsername"]; headers.Credentials.Password = ConfigurationManager.AppSettings["PayPalAPIPassword"]; headers.Credentials.Signature = ConfigurationManager.AppSettings["PayPalAPISignature"]; //Client PayPalAPIAASoapBinding client = new PayPalAPIAASoapBinding(); client.RequesterCredentials = headers; client.Timeout = 15000; DoDirectPaymentResponseType response = client.DoDirectPayment(request); if (response.Ack == AckCodeType.Success || response.Ack == AckCodeType.SuccessWithWarning) { rv.IsSucess = true; rv.TransactionID = response.TransactionID; } else { rv.ErrorMessage = response.Errors[0].LongMessage; } return(rv); }
/// <summary> /// Authorizes the payment /// </summary> /// <param name="paymentInfo">Payment info required for an order processing</param> /// <param name="customer">Customer</param> /// <param name="OrderGuid">Unique order identifier</param> /// <param name="processPaymentResult">Process payment result</param> /// <param name="authorizeOnly">A value indicating whether to authorize only; true - authorize; false - sale</param> protected void AuthorizeOrSale(PaymentInfo paymentInfo, Customer customer, Guid OrderGuid, ProcessPaymentResult processPaymentResult, bool authorizeOnly) { InitSettings(); DoDirectPaymentReq req = new DoDirectPaymentReq(); req.DoDirectPaymentRequest = new DoDirectPaymentRequestType(); req.DoDirectPaymentRequest.Version = this.APIVersion; DoDirectPaymentRequestDetailsType details = new DoDirectPaymentRequestDetailsType(); req.DoDirectPaymentRequest.DoDirectPaymentRequestDetails = details; details.IPAddress = HttpContext.Current.Request.UserHostAddress; if (authorizeOnly) { details.PaymentAction = PaymentActionCodeType.Authorization; } else { details.PaymentAction = PaymentActionCodeType.Sale; } details.CreditCard = new CreditCardDetailsType(); details.CreditCard.CreditCardNumber = paymentInfo.CreditCardNumber; details.CreditCard.CreditCardType = GetPaypalCreditCardType(paymentInfo.CreditCardType); details.CreditCard.ExpMonthSpecified = true; details.CreditCard.ExpMonth = paymentInfo.CreditCardExpireMonth; details.CreditCard.ExpYearSpecified = true; details.CreditCard.ExpYear = paymentInfo.CreditCardExpireYear; details.CreditCard.CVV2 = paymentInfo.CreditCardCVV2; details.CreditCard.CardOwner = new PayerInfoType(); details.CreditCard.CardOwner.PayerCountry = GetPaypalCountryCodeType(paymentInfo.BillingAddress.Country); details.CreditCard.CardOwner.Address = new AddressType(); details.CreditCard.CardOwner.Address.CountrySpecified = true; details.CreditCard.CardOwner.Address.Street1 = paymentInfo.BillingAddress.Address1; details.CreditCard.CardOwner.Address.Street2 = paymentInfo.BillingAddress.Address2; details.CreditCard.CardOwner.Address.CityName = paymentInfo.BillingAddress.City; if (paymentInfo.BillingAddress.StateProvince != null) { details.CreditCard.CardOwner.Address.StateOrProvince = paymentInfo.BillingAddress.StateProvince.Abbreviation; } details.CreditCard.CardOwner.Address.Country = GetPaypalCountryCodeType(paymentInfo.BillingAddress.Country); details.CreditCard.CardOwner.Address.PostalCode = paymentInfo.BillingAddress.ZipPostalCode; details.CreditCard.CardOwner.PayerName = new PersonNameType(); details.CreditCard.CardOwner.PayerName.FirstName = paymentInfo.BillingAddress.FirstName; details.CreditCard.CardOwner.PayerName.LastName = paymentInfo.BillingAddress.LastName; details.PaymentDetails = new PaymentDetailsType(); details.PaymentDetails.OrderTotal = new BasicAmountType(); details.PaymentDetails.OrderTotal.Value = paymentInfo.OrderTotal.ToString("N", new CultureInfo("en-us")); details.PaymentDetails.OrderTotal.currencyID = PaypalHelper.GetPaypalCurrency(CurrencyManager.PrimaryStoreCurrency); details.PaymentDetails.Custom = OrderGuid.ToString(); details.PaymentDetails.ButtonSource = "nopCommerceCart"; DoDirectPaymentResponseType response = service2.DoDirectPayment(req); string error = string.Empty; bool Success = PaypalHelper.CheckSuccess(response, out error); if (Success) { processPaymentResult.AuthorizationTransactionID = response.TransactionID; processPaymentResult.AuthorizationTransactionResult = response.Ack.ToString(); //TODO save AVSCode and CVVCode in datatabase processPaymentResult.AVSResult = response.AVSCode; processPaymentResult.AuthorizationTransactionCode = response.CVV2Code; if (authorizeOnly) { processPaymentResult.PaymentStatus = PaymentStatusEnum.Authorized; } else { processPaymentResult.PaymentStatus = PaymentStatusEnum.Paid; } //processPaymentResult.AuthorizationDate = response.Timestamp; //processPaymentResult.AuthorizationDate = DateTime.Now; } else { processPaymentResult.Error = error; processPaymentResult.FullError = error; } }