mercredi 30 août 2017

Notify page from background

BACKGROUND:

I have an ASP.MVC application. When user pay for his shopping cart (integration with external payment system) then he is redirected to "payment awaiting" page.

This page should "await" for information from server (payment system) that transaction is finished and than redirect to another page.

Worflow: Submit cart => Redirect to bank & pay => Redirect to "awaiting" page => await => redirect to final page

at the same time: Notification from Payment System (via POST on controller) => ??? (how to notify awaiting page) ???

PROBLEM:

How to achieve the "awaiting" proces? I think I could use SignalR (never used before). But if external system executes POST request from payment system than in my opinion there is no "recipient" context I could send message for.

CODE:

I tried something like this:

Hub code:

public class PaymentHub : Hub
{
    public void Send(string paymentNumber, string basketId)
    {
        Clients.All.notifyPaymentSuccess(paymentNumber, basketId);
    }
}

View Script:

@Scripts.Render("~/bundles/jQuerySignalR")
<script src="~/signalr/hubs"></script>

<script>
        $(function () {
            var paymentHub = $.connection.paymentHub;

            paymentHub.client.notifyPaymentSuccess = function (paymentNumber, basketId) {
                $('#tempContent').append('<li><strong>' + paymentNumber + '</strong>: ' + basketId + '</li>');
            };

            $.connection.hub.start();
        });
</script>

Payment system enpoint action:

public ActionResult PaymentStatus(PaymentStatusViewModel model)
{
    var paymentHub = GlobalHost.ConnectionManager.GetHubContext<PaymentHub>();
    paymentHub.Clients.All.Send(model.tr_id, model.tr_id);

    //...
}

But when I test it, nothing happens... Could You help me with it? Or maybe You have a better way to achieve this awaiting proces?




Aucun commentaire:

Enregistrer un commentaire