/// <summary> /// Process 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> public void ProcessPayment(PaymentInfo paymentInfo, Customer customer, Guid orderGuid, ref ProcessPaymentResult processPaymentResult) { InitSettings(); GatewayConnector eWAYgateway = new GatewayConnector(); GatewayRequest eWAYRequest = new GatewayRequest(); if (useSandBox) eWAYRequest.EwayCustomerID = ewayTestCustomerID; else eWAYRequest.EwayCustomerID = ewayLiveCustomerID; eWAYRequest.CardNumber = paymentInfo.CreditCardNumber; eWAYRequest.CardExpiryMonth = paymentInfo.CreditCardExpireMonth.ToString("D2"); eWAYRequest.CardExpiryYear = paymentInfo.CreditCardExpireYear.ToString(); eWAYRequest.CardHolderName = paymentInfo.CreditCardName; //Integer eWAYRequest.InvoiceAmount = Convert.ToInt32(paymentInfo.OrderTotal * 100); eWAYRequest.PurchaserFirstName = paymentInfo.BillingAddress.FirstName; eWAYRequest.PurchaserLastName = paymentInfo.BillingAddress.LastName; eWAYRequest.PurchaserEmailAddress = paymentInfo.BillingAddress.Email; eWAYRequest.PurchaserAddress = paymentInfo.BillingAddress.Address1; eWAYRequest.PurchaserPostalCode = paymentInfo.BillingAddress.ZipPostalCode; eWAYRequest.InvoiceReference = orderGuid.ToString(); eWAYRequest.InvoiceDescription = SettingManager.GetSettingValue("Common.StoreName") + ". Order #" + orderGuid.ToString(); eWAYRequest.TransactionNumber = orderGuid.ToString(); eWAYRequest.CVN = paymentInfo.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(); GatewayResponse 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))) { processPaymentResult.AuthorizationTransactionCode = eWAYResponse.AuthorisationCode; processPaymentResult.AuthorizationTransactionResult = eWAYResponse.InvoiceReference; processPaymentResult.AuthorizationTransactionId = eWAYResponse.TransactionNumber; processPaymentResult.PaymentStatus = PaymentStatusEnum.Paid; //processPaymentResult.AuthorizationDate = DateTime.UtcNow; } else { processPaymentResult.Error = "An invalid response was recieved from the payment gateway." + eWAYResponse.Error; processPaymentResult.FullError = "An invalid response was recieved from the payment gateway." + eWAYRequest.ToXml().ToString() + ". " + eWAYResponse.Error; } } else { // invalid response recieved from server. processPaymentResult.Error = "An invalid response was recieved from the payment gateway."; processPaymentResult.FullError = "An invalid response was recieved from the payment gateway." + eWAYRequest.ToXml().ToString(); } }