Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Johannes Lantz 103 posts 528 karma points c-trib
    Sep 06, 2021 @ 16:14
    Johannes Lantz
    0

    Payment provider GetOrderReference 400

    Hi!

    I am creating a custom payment provider. I have been looking at the stripe payment provider for reference.

    https://github.com/vendrhub/vendr-payment-provider-stripe/blob/dev/src/Vendr.PaymentProviders.Stripe/StripePaymentProviderBase.cs#L63

    If I understand it correctly if the GetOrderReference fails. It should return base.GetOrderReference(request, settings);. I just wanted to doubble check that it's correct for ngrok to show 400 for the callback then?

    //Johannes

  • Matt Brailsford 3351 posts 17757 karma points MVP 8x c-trib
    Sep 07, 2021 @ 08:21
    Matt Brailsford
    100

    Hi Johannes,

    The job of the GetOrderReference method is to extract an order reference, usually from a webhook request from the payment gateway prior to the ProcessCallback method being called. This is usually only necessary for payment providers that need a globally registered webhook URL at the payment gateway (which the Stripe provider does).

    If you look at the Stripe provider you'll see in it's GetOrderReference method that it retrieves the stripe payment and then extracts the order reference from metadata which was set at the point of generating the payment intent.

    Generally speaking, if you don't need to register a global webhook handler at the gateway and it instead allows the passing of a callback/notificationUrl as part of setting up the payment which usually occurs in the GenerateForm method, then in those scenarios you'll want to use the callbackUrl that is passed to the GenerateForm method as those URLs already contain an order reference in the URL structure. Where a global webhook handler is required however, we can't have that order reference in the URL as this handler now needs to handle all webhook notifications for all payments through that payment gateway and so that is the reason for the GetOrderReference method. It gets called at the beginning of a callback request that doesn't have an order reference in it's path and is expected to extract from the webhook request body the order reference so that Vendr knows which order this relates to.

    Because this is all entirely dependent on the payment gateway and there is no standard of way of extracting an order reference, the base.GetOrderReference method just returns null and so Vendr will return a 400 status to signify that it was unable to work out which order that request relates to.

    In summary, if your payment gateway supports sending a notification URL as part of payment setup, then use the callbackUrl passed to the GenerateForm method for this. You then don't need to implement the GetOrderReference method. If on the other hand your payment gateway requires a globally registered notification URL for all webhook notifications, then you can use a similar URL template as documented in the Vendr Stripe payment provider docs and within GenerateForm be sure to store an order reference in some kind of meta data field on the payment and then in the GetOrderReference method which will get called as webhook handler, you'll want to fetch the payment gateway payment object and extract back out the order reference you stored in the meta data field. This then tells Vendr which order the request relates to, and it should then continue onto the ProcessCallback method.

    Hope this helps

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft