Avarda checkout needs to be able to send a callback to Merchant. If a callback is discovered the checkout iframe needs to be reloaded (javascript:AvardaCheckoutClient.init()
) with the same original purchaseId. Purchaseid is submitted as querystring parameter in the callback. CallbackURL is defined in the javascript option Querystring Parameters (purchaseId, callback, PaymentSatus).
Server side – Callback page
if (!string.IsNullOrWhiteSpace(Callback) && (Callback.Equals("1") || Callback.Equals("2")))
{
// Load iframe with original purchaseid submitted in the Querystring
// no initializePurchase should be called
// Callback == 1 then the callback is due to card payment
// Callback == 2 then the callback is due to session cookie setting for safari
}
else if (!string.IsNullOrWhiteSpace(PaymentStatus) && !string.IsNullOrWhiteSpace(Purchaseid))
{
if (PaymentStatus.Equals("Success"))
{
// Successful direct bank payment detected - redirect to done page.
return RedirectToAction("Done", new { purchaseid = Purchaseid });
}
else
{
// Unsuccessful direct bank payment -
// Load iframe with the original purchaseid submitted in the querystring
// no initializePurchase should be called
}
}
else
{
// No callback detected - treat the request as a new purchase.
// Call initializePurchase and get purchaseid
}
Java script – callback url
<script type="text/javascript">
var url =
'http://localhost:50423/Avarda/index?purchaseId=@Html.Raw(Model.PurchaseID)';
// See IInitOptions interface for availible options.
var options = {
divId: 'CheckOutDiv',
purchaseId: '@Html.Raw(Model.PurchaseID)',
callbackUrl: url,
done: function (purchaseId) {
window.location.href =
'/Avarda/Done?purchaseId=@Html.Raw(Model.PurchaseID)';
},
customCssUrl: '',
replaceDefaultCss: false,
redirectUrl: 'http://localhost:50423/home/',
};
AvardaCheckOutClient.init(otions);
</script>