This is a short post to speed up your development if trying out your custom payment provider in the EPiServer Commerce Enoteca sample site and you have the need to redirect the user to an external online payment solution for example Netaxept.
This post is not about how to integrate to an external system but a tip how you should do the redirect.
Step one
Download the EPiServer Commerce 1 R3 Code Sample Package
Step two
Extract EPiServer.Business.Commerce.PayPal.zip from the sample package and unpack it somewhere on your hard drive.
Step three
Open the unpacked project in Visual Studio.
Have a look at the PayPalPaymentGateway.cs and go to the ProcessPayment method. At the end of the method there is the call to ProcessPaymentCheckout so next move to that method.
At the end of the ProcessPaymentCheckout the redirect url is constrcuted and a call to method RedirectParentPage is done. Move on and go to that method.
In RedirectParentPage method you can see that finally the actual redirect is done but it is done to a page PayPalRedirect.aspx and the target redirect url is passed as a parameter in querystring for it.
Next open the PayPalRedirect.aspx codebehind. There you can see some simple security checks are done that the RedirectUrl actually is to PayPal and if ok then a placeholder control is made visible and the RedirectTopWindow property is set. Have a look at the markup, this is where the magic happens with the help of JavaScript call to set the top window location.
Wrap up
So you should now have understanding how you can do redirect to an external payment solution in Enoteca sample site. Look at the PayPal sample also for the return page from the external site in the sample PayPal.aspx which finalizes the process and uses PayPalPaymentGateway class to redirect to the thank you page (PayPalPaymentLanding.aspx) which uses Enoteca CheckoutConfirmationStep control to display the success.
Update 16.10.2013 make it work in IE
Noticed that the redirect doesn’t work in IE10 (might be also IE9 and earlier versions don’t support the sandboxed iframe). Quick and dirty solution to make the redirect also work in IE is to edit the iframe attributes.
- find the file /Templates/Enoteca/Units/Placeable/CheckoutPaymentStep.ascx
- line 106 in markup, there is the definition for the iframe
- change the sandbox attribute value from sandbox=”allow-forms allow-same-origin allow-scripts” to sandbox=”allow-forms allow-same-origin allow-scripts allow-top-navigation“
[iframe id="paymentMethodsFrame" sandbox="allow-forms allow-same-origin allow-scripts allow-top-navigation" seamless="seamless" class="enoPaymentMethodFrame" src="" ][/iframe]