/// <summary> /// Do the post to the gateway and retrieve the response /// </summary> /// <param name="Request">Request</param> /// <returns>Response</returns> public GatewayResponse ProcessRequest(GatewayRequest Request) { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(_uri); request.Method = "POST"; request.Timeout = _timeout; request.ContentType = "application/x-www-form-urlencoded"; request.KeepAlive = false; byte[] requestBytes = Encoding.ASCII.GetBytes(Request.ToXml()); request.ContentLength = requestBytes.Length; // Send the data out over the wire Stream requestStream = request.GetRequestStream(); requestStream.Write(requestBytes, 0, requestBytes.Length); requestStream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (StreamReader sr = new StreamReader(response.GetResponseStream(), System.Text.Encoding.ASCII)) { string _serverXml = sr.ReadToEnd(); return(new GatewayResponse(_serverXml)); } }
/// <summary> /// Do the post to the gateway and retrieve the response /// </summary> /// <param name="Request">Request</param> /// <returns>Response</returns> public GatewayResponse ProcessRequest(GatewayRequest Request) { HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(_uri); request.Method = "POST"; request.Timeout = _timeout; request.ContentType = "application/x-www-form-urlencoded"; request.KeepAlive = false; byte[] requestBytes = Encoding.ASCII.GetBytes(Request.ToXml()); request.ContentLength = requestBytes.Length; // Send the data out over the wire Stream requestStream = request.GetRequestStream(); requestStream.Write(requestBytes, 0, requestBytes.Length); requestStream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (StreamReader sr = new StreamReader(response.GetResponseStream(), System.Text.Encoding.ASCII)) { string _serverXml = sr.ReadToEnd(); return new GatewayResponse(_serverXml); } }
/// <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(); } }
/// <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(); } }