Payment gateway with redirect
Hi, has anybody tried this? After looking at respective classes (Checkout, Preview) it seems I would lost CheckoutState in case of redirect. Perhaps it would be OK to store the CheckoutState in cookies or somewhere else between redirects. I would love to hear also Telerik's guidance on how to proceed in such case.
Currenlty, I ended up with something like this. I modified the Confrimation step to do an automatic postback after 5 secs:
<script type="text/javascript">
$(function ()
window.setTimeout(function()
__doPostBack('', 'paymentPostBack');
, 5000);
);
</script>
Then I listen for a postback with special event argument in Confirmation code behind:
if (Page.IsPostBack && Page.Request["__EVENTARGUMENT"] == "paymentPostBack")
var cookie = HttpContext.Current.Request.Cookies["shoppingCartId_payment"];
var pr = new SporoPayPaymentRequest();
pr.Vs = "0085416";
pr.Ss = "1234567890";
pr.Suma = (double)CheckoutState.Total;
pr.Pu_predcislo = "000000";
pr.Pu_cislo = "0013662162";
pr.Param = "cartOrderId=" + cookie.Value;
pr.Url = "localhost:60876/paymentresult";
pr.UrlBase = "epaymentsimulator.monogram.sk/SLSP_SporoPay.aspx";
if (pr.Validate())
pr.SignMessage("Z3qY08EpvLlAAoMZdnyUdQ==");
Page.Response.Redirect(pr.PaymentRequestUrl);
build the request and redirect to payment gateway (currently simulator). I also have to store order cart Id, because in confirmation, it is already reset, therefore I store it in separate cookie in Preview step:
protected override void PlaceOrderButton_Click(object sender, EventArgs e)
var cookie = HttpContext.Current.Request.Cookies["shoppingCartId"];
HttpContext.Current.Response.Cookies["shoppingCartId_payment"].Value = cookie.Value;
base.PlaceOrderButton_Click(sender, e);
For capturing payment result I created new control (SimpleView) that I've placed on /paymentresult page:
protected override void OnLoad(EventArgs e)
ISignedResponse paymentResponse = new SporoPayPaymentHttpResponse(Page.Request);
if (((EPaymentMessage)paymentResponse).Validate())
paymentResponse.VerifySignature("Z3qY08EpvLlAAoMZdnyUdQ==");
switch (paymentResponse.GetPaymentResponse())
case PaymentResponse.OK:
var pms = Page.Request.QueryString["param"];
var orderId = pms.Substring(pms.IndexOf("=") + 1);
var manager = OrdersManager.GetManager();
var order = manager.GetOrder(Guid.Parse(orderId));
//set as paid
order.OrderStatus = OrderStatus.Paid;
manager.SaveChanges();
break;
After it gets the response, it sets order as paid. The order Id is transferred back in response, I believe each gateway has this functionality.
This works for me, but it completely bypasses the payment system in SF.
Hello Robert,
Thanks for using Sitefinity.
This feature is in planning for integration into the native eCommerce widgets however as of 5.2 we don't support it out of the box. Your method is just fine. If you want to look at additional solutions you can read through this forum post which outlines another implementation.
Hello,
Regards,
Boyan Barnev
the Telerik team