vendrhub / vendr-checkout

A ready made checkout flow for Vendr, the eCommerce solution for Umbraco v8+
https://vendr.net/add-ons/vendr-checkout/
MIT License
14 stars 17 forks source link

Using the Callback URL #29

Closed wr-dev closed 2 years ago

wr-dev commented 2 years ago

Hi Matt

Loving Vendr more than ever. We're using Vendr Checkout - you've done a great job trying to make this work for every scenario. We're currently on 2.0.x but will get it to 2.1.0 before live I think.

We're doing a more "standard" checkout this time, using a horrible payment provider called GlobalPay. They're really quite rubbish. Docs are average: https://developer.globalpay.com/ecommerce/hosted-solution/HPP-Guide#hpp-guide

I'm using the ctx.Urls.CallbackUrl which is working pretty well (love the way it gets the contextual data for you), however the way GlobalPay works, is it actually renders the content of a single URL (so not async) to the browser, on their domain, after POSTing to it, so I'm having to render some Javascript to do a redirect back to the site. The only PP I've ever seen that does this.

Could you just confirm for me whether I should be sending the user back to the ctx.Urls.ContinueUrl if successful, or should I be manually updating the order to be Completed and sending them to /checkout/order-confirmation? Or /basket with an error if it failed?

For some reason, this is setting my order status to Error, but payment is Captured, so it's kind of working. If I return anything but a 200 to GlobalPay, it dies. I can't see anything that tells me why it's in Error, but I suspect because I'm not (and can't) use return CallbackResult.OK as you have in the source I've seen.

It's not that clear to me what the Continue/Cancel/Error URLs should be used for (if anything) - sorry if I'm being daft.

I could do this with a simple SurfaceController and manually update the order, but I don't want to do that if I don't need to. Feel it may well give me a bit more control though, so if it's not clear what I'm asking, I'll probably go that way.

Thank you!

Tom

            var url = "?";
            var qs = postDataAsNameValueCollection;
            var isComplete = qs["RESULT"] == "00";

            var response = request.CreateResponse(HttpStatusCode.OK);
            response.Content = new StringContent($"<html><head><script>window.location.href='{url}';</script></head><body><p>Redirecting back to the website</body></html>");

            // should I complete the order manually here? Or does the consumer of the CallbackResult do that?

            return new CallbackResult()
            {
                HttpResponse = response,
                TransactionInfo = new TransactionInfo() 
                {
                    AmountAuthorized = priceFromPayment,
                    PaymentStatus = isComplete ? PaymentStatus.Captured : PaymentStatus.Error,
                    TransactionFee = 0m,
                    TransactionId = qs["ORDER_ID"]
                },
                MetaData = new Dictionary<string, string>()
                {
                    { "globalPayResult", qs["RESULT"] },
                    { "globalPayAuthCode", qs["AUTHCODE"] },
                    { "globalPayMessage", qs["MESSAGE"] },
                    { "globalPayOrderId", qs["ORDER_ID"] }
                }
            };
mattbrailsford commented 2 years ago

Hey @wr-dev

More than happy to help you get this working, but this should really be on the support forums at https://our.umbraco.com/packages/website-utilities/vendr/vendr-support/ as it's not really an issue with Vendr Checkout.

If you can raise the question there I'll get back to you with some advice.

Many thanks