示例#1
0
        /// <summary>
        /// Process a payment
        /// </summary>
        /// <param name="processPaymentRequest">Payment info required for an order processing</param>
        /// <returns>Process payment result</returns>
        public ProcessPaymentResult ProcessPayment(ProcessPaymentRequest processPaymentRequest)
        {
            var result = new ProcessPaymentResult();

            var eWaygateway = new GatewayConnector();

            var customer       = _customerService.GetCustomerById(processPaymentRequest.CustomerId);
            var billingAddress = customer.BillingAddress;

            var eWayRequest = new Transaction
            {
                Customer = new Customer
                {
                    CompanyName = billingAddress.Company,
                    FirstName   = billingAddress.FirstName,
                    LastName    = billingAddress.LastName,
                    Email       = billingAddress.Email,
                    Address     = new Address
                    {
                        Street1    = billingAddress.Address1,
                        Street2    = billingAddress.Address2,
                        City       = billingAddress.City,
                        Country    = billingAddress.Country?.TwoLetterIsoCode?.ToLower(),
                        PostalCode = billingAddress.ZipPostalCode
                    },
                    Reference = customer.CustomerGuid.ToString()
                },
                PaymentDetails = new PaymentDetails
                {
                    CurrencyCode     = "NZD",
                    InvoiceReference = processPaymentRequest.OrderGuid.ToString(),
                    InvoiceNumber    = processPaymentRequest.OrderGuid.ToString(),
                    TotalAmount      = Convert.ToInt32(processPaymentRequest.OrderTotal * 100)
                },
                TransactionType = TransactionTypes.Purchase,
                SecuredCardData = processPaymentRequest.CreditCardName
            };

            // Do the payment
            eWaygateway.RapidEndpoint = GetRapidEndpoint();
            var eWayResponse = eWaygateway.ProcessRequest(eWayRequest);

            if (eWayResponse == null ||
                eWayResponse.Errors != null ||
                !(eWayResponse.TransactionStatus?.Status ?? false) ||
                !eWayResponse.TransactionStatus.ProcessingDetails.ResponseMessage.StartsWith("A"))
            {
                // invalid response recieved from server.
                result.AddError("An error occurred while processing your order.  Please check your Credit Card details and try again.");
                _logger.Error($"Error recieved from eWay: [Error: {eWayResponse?.Errors?.ToJson()}] [ResponseMessage: {eWayResponse?.TransactionStatus?.ToJson()}]");

                return(result);
            }

            _logger.Information($"Successful eWay payment with result [{eWayResponse.TransactionStatus?.ToJson()}]");

            result.NewPaymentStatus = PaymentStatus.Paid;

            return(result);
        }
示例#2
0
        /// <summary>
        /// Process a payment
        /// </summary>
        /// <param name="processPaymentRequest">Payment info required for an order processing</param>
        /// <returns>Process payment result</returns>
        public ProcessPaymentResult ProcessPayment(ProcessPaymentRequest processPaymentRequest)
        {
            var result = new ProcessPaymentResult();

            var eWaygateway = new GatewayConnector();

            var eWayRequest = new GatewayRequest
            {
                EwayCustomerID  = _eWayPaymentSettings.CustomerId,
                CardNumber      = processPaymentRequest.CreditCardNumber,
                CardExpiryMonth = processPaymentRequest.CreditCardExpireMonth.ToString("D2"),
                CardExpiryYear  = processPaymentRequest.CreditCardExpireYear.ToString(),
                CardHolderName  = processPaymentRequest.CreditCardName,
                InvoiceAmount   = Convert.ToInt32(processPaymentRequest.OrderTotal * 100)
            };

            //Integer

            var customer       = _customerService.GetCustomerById(processPaymentRequest.CustomerId);
            var billingAddress = customer.BillingAddress;

            eWayRequest.PurchaserFirstName    = billingAddress.FirstName;
            eWayRequest.PurchaserLastName     = billingAddress.LastName;
            eWayRequest.PurchaserEmailAddress = billingAddress.Email;
            eWayRequest.PurchaserAddress      = billingAddress.Address1;
            eWayRequest.PurchaserPostalCode   = billingAddress.ZipPostalCode;
            eWayRequest.InvoiceReference      = processPaymentRequest.OrderGuid.ToString();
            eWayRequest.InvoiceDescription    = _storeContext.CurrentStore.Name + ". Order #" + processPaymentRequest.OrderGuid;
            eWayRequest.TransactionNumber     = processPaymentRequest.OrderGuid.ToString();
            eWayRequest.CVN         = processPaymentRequest.CreditCardCvv2;
            eWayRequest.EwayOption1 = string.Empty;
            eWayRequest.EwayOption2 = string.Empty;
            eWayRequest.EwayOption3 = string.Empty;

            // Do the payment, send XML doc containing information gathered
            eWaygateway.Uri = GeteWayUrl();
            var eWayResponse = eWaygateway.ProcessRequest(eWayRequest);

            if (eWayResponse != null)
            {
                // Payment succeeded get values returned
                if (eWayResponse.Status && (eWayResponse.Error.StartsWith(APPROVED_RESPONSE) || eWayResponse.Error.StartsWith(HONOUR_RESPONSE)))
                {
                    result.AuthorizationTransactionCode   = eWayResponse.AuthorisationCode;
                    result.AuthorizationTransactionResult = eWayResponse.InvoiceReference;
                    result.AuthorizationTransactionId     = eWayResponse.TransactionNumber;
                    result.NewPaymentStatus = PaymentStatus.Paid;
                    //processPaymentResult.AuthorizationDate = DateTime.UtcNow;
                }
                else
                {
                    result.AddError("An invalid response was recieved from the payment gateway." + eWayResponse.Error);
                    //full error: eWAYRequest.ToXml().ToString()
                }
            }
            else
            {
                // invalid response recieved from server.
                result.AddError("An invalid response was recieved from the payment gateway.");
                //full error: eWAYRequest.ToXml().ToString()
            }

            return(result);
        }