private XDocument GetProcessCardCommand(Address billingAddress, Address shippingAddress, string cardExtraCode, string customerId, string orderTotal, string orderShipping, string orderTax, string orderNumber, TransactionModeEnum transactionMode) { string cardNumber = AppLogic.SafeDisplayCardNumber(billingAddress.CardNumber, "", 0); return(new XDocument( new XElement("Transaction", new XAttribute("TransactionMode", transactionMode.ToString()) , new XElement("M_ID", M_id) , new XElement("M_KEY", M_key) , new XElement("C_NAME", billingAddress.FirstName + ' ' + billingAddress.LastName) , new XElement("C_ADDRESS", billingAddress.Address1) , new XElement("C_CITY", billingAddress.City) , new XElement("C_STATE", billingAddress.State) , new XElement("C_ZIP", billingAddress.Zip) , new XElement("C_COUNTRY", billingAddress.Country) , new XElement("C_EMAIL", billingAddress.EMail) , new XElement("C_CARDNUMBER", cardNumber) , new XElement("C_EXP", billingAddress.CardExpirationMonth.PadLeft(2, '0') + billingAddress.CardExpirationYear.ToString().Substring(2, 2)) , new XElement("C_CVV", cardExtraCode) , new XElement("T_CUSTOMER_NUMBER", customerId) , new XElement("T_AMT", orderTotal) , new XElement("T_SHIPPING", orderShipping) , new XElement("T_TAX", orderTax) , new XElement("T_ORDERNUM", orderNumber) , new XElement("C_TELEPHONE", billingAddress.Phone) , new XElement("C_FAX", "") , new XElement("C_SHIP_NAME", shippingAddress.FirstName + ' ' + shippingAddress.LastName) , new XElement("C_SHIP_ADDRESS", shippingAddress.Address1) , new XElement("C_SHIP_CITY", shippingAddress.City) , new XElement("C_SHIP_STATE", shippingAddress.State) , new XElement("C_SHIP_ZIP", shippingAddress.Zip) , new XElement("C_SHIP_COUNTRY", shippingAddress.Country) ))); }
// 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); }