Beispiel #1
0
 public static ProcessorArgumentCollection AsProcessorArgumentCollection(this CreditCardFormData creditCard)
 {
     return(new ProcessorArgumentCollection()
     {
         { "creditCardType", creditCard.CreditCardType },
         { "cardholderName", creditCard.CardholderName },
         { "cardNumber", creditCard.CardNumber },
         { "expireMonth", creditCard.ExpireMonth },
         { "expireYear", creditCard.ExpireYear },
         { "cardCode", creditCard.CardCode },
         { "customerIp", creditCard.CustomerIp }
     });
 }
        /// <summary>
        /// Processes the Authorize and AuthorizeAndCapture transactions
        /// </summary>
        /// <param name="invoice">The <see cref="IInvoice"/> to be paid</param>
        /// <param name="payment">The <see cref="IPayment"/> record</param>
        /// <param name="transactionMode">Authorize or AuthorizeAndCapture</param>
        /// <param name="amount">The money amount to be processed</param>
        /// <param name="creditCard">The <see cref="CreditCardFormData"/></param>
        /// <returns>The <see cref="IPaymentResult"/></returns>
        public IPaymentResult ProcessPayment(IInvoice invoice, IPayment payment, TransactionMode transactionMode, decimal amount, CreditCardFormData creditCard)
        {
            var address = invoice.GetBillingAddress();
                                                                                
            var names = creditCard.CardholderName.Split(' ');

            // Declare a response
			Paymentech.Response response;

			// Create an authorize transaction
            var transaction = new Transaction(RequestType.NEW_ORDER_TRANSACTION);
			// Populate the required fields for the given transaction type. You can use’
			// the Paymentech Transaction Appendix to help you populate the transaction’

            transaction["OrbitalConnectionUsername"] = _settings.Username;
            transaction["OrbitalConnectionPassword"] = _settings.Password;
            /*
                * Message Types
                * MO – Mail Order transaction
                * RC – Recurring Payment
                * EC– eCommerce transaction
                * IV – IVR [PINLess Debit Only]
            */
			transaction["IndustryType"] = "EC";

            /*
                * Message Types
                * A – Authorization request
                * AC – Authorization and Mark for Capture
                * FC – Force-Capture request
                * R – Refund request
            */           
			transaction["MessageType"] = transactionMode == TransactionMode.Authorize ? "A" : "AC";

			transaction["MerchantID"] = _settings.MerchantId;
			transaction["BIN"] = _settings.Bin;
            
            // Credit Card Number
            transaction["AccountNum"] = creditCard.CardNumber.Replace(" ", "").Replace("-", "").Replace("|", "");

            transaction["OrderID"] = invoice.InvoiceNumber.ToString(CultureInfo.InstalledUICulture);

            transaction["Amount"] = string.Format("{0:0}", amount * 100);
            // Expiration date
            var creditCardExpMonth = creditCard.ExpireMonth;
            var creditCardExpYear = creditCard.ExpireYear.Length > 2
                ? creditCard.ExpireYear.Substring(2, 2)
                : creditCard.ExpireYear;

			transaction["Exp"] = creditCardExpMonth.PadLeft(2) + creditCardExpYear;

			transaction["AVSname"] = address.Name;
			transaction["AVSaddress1"] = address.Address1;  
			transaction["AVSaddress2"] = address.Address2;
			transaction["AVScity"] = address.Locality;
			transaction["AVSstate"] = address.Region;
			transaction["AVSzip"] = address.PostalCode;
			transaction["AVScountryCode"] = address.CountryCode;
			transaction["CardSecVal"] = creditCard.CardCode;

            transaction["TraceNumber"] = invoice.InvoiceNumber.ToString();

            if (string.IsNullOrEmpty(creditCard.CreditCardType))
            {
                creditCard.CreditCardType = GetCreditCardType(creditCard.CardNumber);
            }

            if (creditCard.CreditCardType.ToLower().Contains("visa") || creditCard.CreditCardType.ToLower().Contains("chase"))
            {
                transaction["CAVV"] = creditCard.AuthenticationVerification;

                // If no value for creditCard.CardCode, then CardSecValInd cannot be 1.  Send 2 or 9 instead
                if (string.IsNullOrEmpty(creditCard.CardCode))
                {
                    transaction["CardSecValInd"] = "9";
                }
                else
                {
                    transaction["CardSecValInd"] = "1";
                }
            }
            else if (creditCard.CreditCardType.ToLower().Contains("mastercard"))
            {
                transaction["AAV"] = creditCard.AuthenticationVerification;
                transaction["CardSecValInd"] = "";
            }
            transaction["AuthenticationECIInd"] = creditCard.AuthenticationVerificationEci;

            /*
                * CardSecValInd
                * 1 - Value is Present
                * 2 - Value on card but illegible
                * 9 - Cardholder states data not available              
            */
            // Only send if ChaseNet, Visa and Discover transactions
            // transaction["CardSecValInd"] = "1";

            /*
                * CardSecValInd                               
                * A – Auto Generate the CustomerRefNum
                * S – Use CustomerRefNum Element            
            */

            // profile management will not be supported, do not send CustomerProfileFromOrderInd
			//transaction["CustomerProfileFromOrderInd"] = "A";

            /*
                * CustomerProfileOrderOverrideInd                   
                * NO No mapping to order data
                * OI Use <CustomerRefNum> for <OrderID> and <ECOrderNum> or <MailOrderNum>
                * OD Use <CustomerReferNum> for <Comments> 
                * OA Use <CustomerRefNum> for <OrderID> and <Comments>
            */
			transaction["CustomerProfileOrderOverrideInd"] = "NO";

            transaction["Comments"] = invoice.InvoiceNumber.ToString(CultureInfo.InstalledUICulture);

			response = transaction.Process();

            // API Error
            if (response == null)
            {
                return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception("Chase Paymentech unknown error")), invoice, false);
            }

            string approvalStatus = "";
            if (response.XML != null)
            {
                var xml = XDocument.Parse(response.MaskedXML);
                if (xml.Descendants("ApprovalStatus").FirstOrDefault() != null)
                {
                    approvalStatus = xml.Descendants("ApprovalStatus").First().Value;
                }
            }


            if (response.Error)
            {
                return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception(string.Format("Error {0}", response))), invoice, false);
            } 
            if (response.Declined)
            {
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.AuthorizeDeclinedResult, string.Format("Declined ({0} : {1})", response.ResponseCode, response.Message));
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.TransactionReferenceNumber, response.TxRefNum);
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.AuthorizationTransactionCode, string.Format("{0},{1},{2}", response.AuthCode, response.ResponseCode, approvalStatus));
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.AvsResult, response.AVSRespCode);
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.Cvv2Result, string.Format("{0},{1}", response.CVV2RespCode, response.CVV2ResponseCode));
                return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception(string.Format("Declined ({0} : {1})", response.ResponseCode, response.Message))), invoice, false);
            }
            if (response.Approved)
            {
                var txRefIdx = "";
                if (response.XML != null)
                {
                    var xml = XDocument.Parse(response.MaskedXML);
                    txRefIdx = xml.Descendants("TxRefIdx").First().Value;
                }

                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.TransactionReferenceNumber, response.TxRefNum);
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.TransactionReferenceIndex, txRefIdx);
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.AuthorizationTransactionCode, string.Format("{0},{1},{2}", response.AuthCode, response.ResponseCode, approvalStatus));
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.AvsResult, response.AVSRespCode);
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.Cvv2Result, string.Format("{0},{1}", response.CVV2RespCode, response.CVV2ResponseCode));

                payment.Authorized = true;
                if (transactionMode == TransactionMode.AuthorizeAndCapture)
                {
                    payment.Collected = true;
                }
                return new PaymentResult(Attempt<IPayment>.Succeed(payment), invoice, true);
            }

            return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception(string.Format("Error {0}", response))), invoice, false);
		}
        /// <summary>
        /// Processes the Authorize and AuthorizeAndCapture transactions
        /// </summary>
        /// <param name="invoice">The <see cref="IInvoice"/> to be paid</param>
        /// <param name="payment">The <see cref="IPayment"/> record</param>
        /// <param name="transactionMode">Authorize or AuthorizeAndCapture</param>
        /// <param name="amount">The money amount to be processed</param>
        /// <param name="creditCard">The <see cref="CreditCardFormData"/></param>
        /// <returns>The <see cref="IPaymentResult"/></returns>
        public IPaymentResult ProcessPayment(IInvoice invoice, IPayment payment, TransactionMode transactionMode, decimal amount, CreditCardFormData creditCard)
        {
            var address = invoice.GetBillingAddress();
                                                                                
            var names = creditCard.CardholderName.Split(' ');

            // Declare a response
			Paymentech.Response response;

			// Create an authorize transaction
            var transaction = new Transaction(RequestType.NEW_ORDER_TRANSACTION);
			// Populate the required fields for the given transaction type. You can use’
			// the Paymentech Transaction Appendix to help you populate the transaction’

            /*
                * Message Types
                * MO – Mail Order transaction
                * RC – Recurring Payment
                * EC– eCommerce transaction
                * IV – IVR [PINLess Debit Only]
            */
			transaction["IndustryType"] = "EC";

            /*
                * Message Types
                * A – Authorization request
                * AC – Authorization and Mark for Capture
                * FC – Force-Capture request
                * R – Refund request
            */           
			transaction["MessageType"] = transactionMode == TransactionMode.Authorize ? "A" : "AC";

			transaction["MerchantID"] = "041756";
			transaction["BIN"] = "000001";

            
            // Credit Card Number
            transaction["AccountNum"] = creditCard.CardNumber;

            transaction["OrderID"] = invoice.InvoiceNumber.ToString(CultureInfo.InstalledUICulture);

			transaction["Amount"] = amount.ToString("0.00", CultureInfo.InstalledUICulture);

            // Expiration date
			transaction["Exp"] = creditCard.ExpireMonth.PadLeft(2) + creditCard.ExpireYear;

			transaction["AVSname"] = address.Name;
			transaction["AVSaddress1"] = address.Address1;  
			transaction["AVSaddress2"] = address.Address2;
			transaction["AVScity"] = address.Locality;
			transaction["AVSstate"] = address.Region;
			transaction["AVSzip"] = address.PostalCode;
			transaction["AVScountryCode"] = address.CountryCode;
			transaction["CardSecVal"] = creditCard.CardCode;

            /*
                * CardSecValInd
                * 1 - Value is Present
                * 2 - Value on card but illegible
                * 9 - Cardholder states data not available              
            */
            transaction["CardSecValInd"] = "1";

            /*
                * CardSecValInd                               
                * A – Auto Generate the CustomerRefNum
                * S – Use CustomerRefNum Element            
            */
			transaction["CustomerProfileFromOrderInd"] = "A";

            /*
                * CustomerProfileOrderOverrideInd                   
                * NO No mapping to order data
                * OI Use <CustomerRefNum> for <OrderID> and <ECOrderNum> or <MailOrderNum>
                * OD Use <CustomerReferNum> for <Comments> 
                * OA Use <CustomerRefNum> for <OrderID> and <Comments>
            */
			transaction["CustomerProfileOrderOverrideInd"] = "NO";

            transaction["Comments"] = invoice.InvoiceNumber.ToString(CultureInfo.InstalledUICulture);

			response = transaction.Process();

            // API Error
            if (response == null)
            {
                return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception("Chase Paymentech unknown error")), invoice, false);
            }


            if (response.Error)
            {
                return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception(string.Format("Error {0}", response))), invoice, false);
            } 
            if (response.Declined)
            {
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.AuthorizeDeclinedResult, string.Format("Declined ({0} : {1})", response.ResponseCode, response.Message));
                return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception(string.Format("Declined ({0} : {1})", response.ResponseCode, response.Message))), invoice, false);
            }
            if (response.Approved)
            {
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.TransactionReferenceNumber, string.Format("Approved ({0})", response.TxRefNum));
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.AuthorizationTransactionCode, string.Format("{0},{1}", response.ResponseCode));
                payment.ExtendedData.SetValue(Constants.ExtendedDataKeys.AvsResult, response.AVSRespCode);
                payment.Authorized = true;
                if (transactionMode == TransactionMode.AuthorizeAndCapture)
                {
                    payment.Collected = true;
                }
                return new PaymentResult(Attempt<IPayment>.Succeed(payment), invoice, true);
            }

            return new PaymentResult(Attempt<IPayment>.Fail(payment, new Exception(string.Format("Error {0}", response))), invoice, false);
		}