问题
I want to customize nopCommerce eWayHosted
plugin for other payment gateway(Easy Pay). I change the payment URL and the parameters.
public void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest)
{
var strPost = "storeId=" + _eWayHostedPaymentSettings.CustomerId;
strPost += Format("amount", postProcessPaymentRequest.Order.OrderTotal.ToString("0.00", CultureInfo.InvariantCulture));
strPost += Format("orderRefNum", postProcessPaymentRequest.Order.Id.ToString());
strPost += Format("postBackURL", "http://www.smmotors.org/onepagecheckout");
var url = _eWayHostedPaymentSettings.PaymentPage + "?" + strPost;
var objRequest = (HttpWebRequest)WebRequest.Create(url);
objRequest.Method = WebRequestMethods.Http.Get;
var objRequest1 = (HttpWebRequest)WebRequest.Create(url);
objRequest1.Method = WebRequestMethods.Http.Post;
var objResponse = (HttpWebResponse)objRequest.GetResponse();
At this point
The Easypay
server sends back a parameter named auth_token
to the postbackURL
which is sent as a GET parameter.
But Var objResponse
cannot get auth_token
& postBackURL
. Whats The Reason & solution
//get the response from the transaction generate page
string resultXml;
using (var sr = new StreamReader(objResponse.GetResponseStream()))
{
resultXml = sr.ReadToEnd();
// Close and clean up the StreamReader
sr.Close();
}
//parse the result message
var resultObj = ParseRequestResults(resultXml);
if (resultObj.Result)
{
//redirect the user to the payment page
HttpContext.Current.Response.Redirect(resultObj.Uri);
}
else
{
throw new NopException(resultObj.Error);
}
}
Below Is The Plug-in Integration Steps:
Following process will be followed by merchants to embed the Easypay
Plug-in in their stores:
• Merchant acquires an account through Easypay
agents. A Welcome email containing unique Store ID and URL is sent to the Merchant after successful registration.
• Merchant logins the Easy Pay portal and access ‘Guide to Integration’ menu where Merchant is presented with step by step instructions to integrate the Easypay
plug- in to their shopping cart/online retail shop.
Following is the sample of flow merchant should find after logging into the Easypay
portal.
Merchants having unique store ID embed Easypay
plug-in on checkout page of their online stores/ websites. This will integrate “Pay through Easypay
as a payment solution in their websites. The integration of Easypay
plug-in is a simple two-step process:
- The merchant needs to POST following parameter to the
Easypay
on the f o l l owi n g URL:
Production (Live) Environment: https://easypay.easypaisa.com.pk/easypay/Index.jsf Sandbox Environment: https://easypaystg.easypaisa.com.pk/easypay/Index.jsf
• amount
• storeId
• postBackURL
• orderRefNum
After successful redirection the customer would land on the Easypay Checkout Screen where there is a form to be filled regarding the transaction information.
- After completing the form in Step 1 the customer will be pressing the Proceed Button and lands back on the merchant website on the same URL given in postbackURL variable in the first step. This will be a confirmation screen on merchant’s website to perform a handshake between Easypay and merchant’s website. The Easypay sends back a parameter named auth_token to the postbackURL which is sent as a GET parameter. Now the merchant needs to post back following two parameters again to the following URL:
Production (Live) Environment: https://easypay.easypaisa.com.pk/easypay/Confirm.jsf Sandbox Environment: https://easypaystg.easypaisa.com.pk/easypay/Confirm.jsf • auth_token • postBackURL
After this redirection the Easypay authenticates the auth_token sent by merchant with the one it has in the previous step, and upon successful authentication it will make customer land on the successful checkout screen sending back following two variables to the second postBackURL: • status • desc • orderRefNumber
Sample Code Snippet for .NET
For the first redirection:
using (var client = new HttpClient())
{
var values = new List<KeyValuePair<string, string>>();
values.Add(new KeyValuePair<string, string>("storeId", "43"));
values.Add(new KeyValuePair<string, string>("amount", "10"));
values.Add(new KeyValuePair<string, string>("postBackURL", "http://www.my.onlinestore.com/transaction/MessageHandler"));
values.Add(new KeyValuePair<string, string>("orderRefNum", "1101"));
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync("https://easypay.easypaisa.com.pk/easypay/Index.jsf", content); var responseString = await response.Content.ReadAsStringAsync();
}
For the second redirection:
using (var client = new HttpClient())
{
var values = new List<KeyValuePair<string, string>>();
values.Add(new KeyValuePair<string, string>("auth_token", Request.Querystring["auth_token"])); values.Add(new KeyValuePair<string, string>("postBackURL", "http://www.my.online-
store.com/transaction/MessageHandler1"));
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync("https://easypay.easypaisa.com.pk/easypay/Confirm.jsf", content); var responseString = await response.Content.ReadAsStringAsync();
}
来源:https://stackoverflow.com/questions/39858074/how-customise-nop-commerce-ewayhosted-plugin-for-other-payment-gateway