Payment method with redirection link

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
3 года назад
I'm working on a payment plugin where I need to retrieve the redirection link from the payment partner.

I'm writing this logic in the "PostProcessPayment" method, but in this method I need to use an await-keyword to wait for the responds from the partner with the redirection link. However, instead of waiting the program jumps out of the "PostProcessPayment" method and continues in the check-out controller and therefore the "_webHelper.IsRequestBeingRedirected" is still false when it gets there. So no redirections are made.

How can I resolve this problem? I've tried removing the await keyword and using .GetAwaiter().GetResult() instead, but then the "OpcCompleteRedirectionPayment" in the check-out controller fails.
3 года назад
What was it you were trying to await?  (some _httpClient.Method()?? )
3 года назад
Yes, I'm using httpClient.SendAsync(request) to send the request and capture the response. In this response I'll receive the link that I need to use for redirection. But this line is no longer executed since, the program jumps out before the actual request is even made.
3 года назад
RE:  "...this line is no longer executed since, the program jumps out before the actual request is even made."

I don't follow you.  How do you know the request is not being made?

In any case, there is similar that could work for you in \Plugins\Nop.Plugin.Payments.PayPalStandard\Services\PayPalStandardHttpClient.cs

            var response = await _httpClient.PostAsync(url, requestContent);
            response.EnsureSuccessStatusCode();
            return await response.Content.ReadAsStringAsync();
3 года назад
New York wrote:
RE:  "...this line is no longer executed since, the program jumps out before the actual request is even made."

I don't follow you.  How do you know the request is not being made?


I'm using a breakpoint at the entering of the PostProcessPayment method, but after this line with the await-keyword it jumps back to the check out controller in the web project. So I'm now trying without the use of await and .GetAwaiter instead, but have the same issue.



        public void PostProcessPayment(PostProcessPaymentRequest postProcessPaymentRequest)
        {
            IPaymentClient paymentClient = new PaymentClient("test_***");
            PaymentRequest paymentRequest = new PaymentRequest()
            {
                Amount = new Amount(Currency.EUR, postProcessPaymentRequest.Order.OrderSubTotalDiscountInclTax),
                Description = $"Quims Beta - ID: {postProcessPaymentRequest.Order.OrderGuid.ToString()}",
                RedirectUrl = "https://localhost:44396/checkout/completed/"
            };





            PaymentResponse paymentResponse = paymentClient.CreatePaymentAsync(paymentRequest).GetAwaiter().GetResult();


            if (paymentResponse.Links.Checkout.Href.Length > 1)
            {
             _httpContextAccessor.HttpContext.Response.Redirect(paymentResponse.Links.Checkout.Href);
            }


            return;
        }



But thanks for the tip about the standard Paypall plugin, I'll take a look there how it's done!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.