Return to view from PostProcessPaymentAsync

11 meses atrás
Hello All,

I am implementing a new payment gateway. Here I have to follow 2 steps

1. Create an order via payment gateway API, which will send us the authToken on successful Order creation which is valid for 30 minutes.

2. Now with this AuthToken, I need to launch that payment gateway SDK, for which I need to redirect the user to a new custom view with the response model (containing authToken). The view will contain the required JS file references to launch the payment gateway SDK to complete the payment.

Once that view is opened, the user can able to make a payment. Once payment is done, I will receive a response back with the order Id and transaction response. Then I need to redirect the user to other views with Order details.

I have finished step 1 and received a response back from the payment gateway with authToken. Appreciate your help on how to redirect the user to a new custom view with the token I received.

Thanks,
11 meses atrás
This is how I do it

Create a route
            endpointRouteBuilder.MapControllerRoute("Mollie.Payment",
                $"/plugins/Mollie/payment/{{orderId:int?}}",
                new { controller = "MollieCheckout", action = "PaymentMethod" });

Create Controller Routine in MollieCheckoutController
[IgnoreAntiforgeryToken]
public virtual async Task<IActionResult> PaymentMethod(string orderId)
{
             // do stuff withthe orderId and any other parameters

            // create model and return the view
            var molliePaymentMethodModel = await _mollieCheckoutModelFactory.PrepareMolliePaymentMethodModelAsync(filterByCountryId, order.Id);

            return View("~/Plugins/SSI.Payments.Mollie/Views/Payment.cshtml", molliePaymentMethodModel);
}

In PostProcessPaymentAsync redirect to the controller routine
...
string url = _webHelper.GetStoreLocation() + "plugins/Mollie/payment/" + orderId.ToString();
_httpContextAccessor.HttpContext.Response.Redirect(url);
}
11 meses atrás
Thank you, Is there a way to pass my model object to the controller as a parameter instead of a query string?
When I do like below in the Route
  endpointRouteBuilder.MapControllerRoute("Mollie.Payment",
                $"/plugins/Mollie/payment/{{response:string}}",
                new { controller = "MollieCheckout", action = "PaymentMethod" });

the entire response object containing the authToken also displays it in the browser URL. I don't want that to show in the URL but want the parameter in the controller.

Is there a way to achieve it?


Yidna wrote:
This is how I do it

Create a route
            endpointRouteBuilder.MapControllerRoute("Mollie.Payment",
                $"/plugins/Mollie/payment/{{orderId:int?}}",
                new { controller = "MollieCheckout", action = "PaymentMethod" });

Create Controller Routine in MollieCheckoutController
[IgnoreAntiforgeryToken]
public virtual async Task<IActionResult> PaymentMethod(string orderId)
{
             // do stuff withthe orderId and any other parameters

            // create model and return the view
            var molliePaymentMethodModel = await _mollieCheckoutModelFactory.PrepareMolliePaymentMethodModelAsync(filterByCountryId, order.Id);

            return View("~/Plugins/SSI.Payments.Mollie/Views/Payment.cshtml", molliePaymentMethodModel);
}

In PostProcessPaymentAsync redirect to the controller routine
...
string url = _webHelper.GetStoreLocation() + "plugins/Mollie/payment/" + orderId.ToString();
_httpContextAccessor.HttpContext.Response.Redirect(url);
}
11 meses atrás
Why not move your code from PostProcessPaymentAsync to the Controller and just pass in the OrderId
11 meses atrás
Yidna wrote:
Why not move your code from PostProcessPaymentAsync to the Controller and just pass in the OrderId


Thanks, I did and now the model is passed to my View. My view consists of only Javascript and it's giving me "Uncaught ReferenceError: $ is not defined". Though my Jquery file is loaded.

I added external script files using
<!script src="https://code.jquery.com/jquery-latest.min.js"></!script>
<!script src="//payment gateway js file references"></!script>

<!script type="text/javascript">
  var flow_config = {
        merchantId: '@Model.mercid',
        OrderId: '@Model.orderid',
        authToken: '@Model.authToken',
        childWindow: true,
    }
  var responseHandler = function (txn) {

        console.log("callback received status:: ", txn.status)

        console.log("callback received response:: ", txn.response)

    }
var config = {
        responseHandler: responseHandler,
        merchantLogo: "",
        flowConfig: flow_config,
        flowType: "payments"
    }

//my code to open the payment gateway SDK
$(document).ready(function () {
        window.loadSdk(config);
    });

</!script>

Somehow it's not opening and  I see the error - "Uncaught ReferenceError: $ is not defined"
11 meses atrás
The error - "Uncaught ReferenceError: $ is not defined", probably means  that the jQuery JavaScript has not yet loaded.   Remove your <script> tags and put this at the top of your View .cshtml file .

@{
        NopHtml.AppendScriptParts(ResourceLocation.Footer, "your .js file");
    }

(Adjust "your .js file" as needed, and if AppendScriptParts does not work, try AddScriptParts)
11 meses atrás
New York wrote:
The error - "Uncaught ReferenceError: $ is not defined", probably means  that the jQuery JavaScript has not yet loaded.   Remove your <script> tags and put this at the top of your View .cshtml file .

@{
        NopHtml.AppendScriptParts(ResourceLocation.Footer, "your .js file");
    }

(Adjust "your .js file" as needed, and if AppendScriptParts does not work, try AddScriptParts)


I tried all of these its not working.
11 meses atrás
Are you still getting error - "Uncaught ReferenceError: $ is not defined"?

You can use the browser's dev tools / console to issue some $(...) queries to see if jquery is finally loaded.