Copied to clipboard

Flag this post as spam?

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


  • Nalysa 48 posts 269 karma points
    Oct 02, 2020 @ 08:00
    Nalysa
    0

    Custom Payment Provider Callback

    Hi,

    I have an issue with the callback on a custom payment provider. Somehow the payment gateway gives a 400 Bad Request. It seems like the ProcessCallback method was never called on this process, and it doesn't create any order on Vendr store.

    This is the url for the callback:

    <ngrok url>/umbraco/vendr/payment/callback/xendit-checkout/71ec7b35-22f6-4740-b6ce-1bcfb1a1f0bf
    

    Any help would be appreciated. Thanks.

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Oct 02, 2020 @ 08:18
    Matt Brailsford
    0

    Hi Nalysa,

    Does your payment gateway have a log of requests? and can you see your ngrok based url in the log? Are you also accessing the site via your ngrok URL so that the Vendr callback urls are created using the ngrok URL?

    Matt

  • Nalysa 48 posts 269 karma points
    Oct 02, 2020 @ 08:47
    Nalysa
    0

    Hi Matt,

    Currently the checkout process is going well. I can do the payment with my custom payment provider and then the page get redirected to the confirmation page. But there is no order created on Vendr store although the checkout process seems correct.

    Yes, I accessing the site from my ngrok URL. I can't see the url in the log, but i've set the callback url with my ngrok url.

    Is there something I missed?

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Oct 02, 2020 @ 08:58
    Matt Brailsford
    0

    Hey Nalysa,

    How do you notify your payment gateway of your callback URL? Is it globally registered in the payment gateway portal and shared by all orders? Or do you pass the callback URL per transaction when you tell the gateway about the payment your about to send it?

    Matt

  • Nalysa 48 posts 269 karma points
    Oct 02, 2020 @ 09:06
    Nalysa
    0

    Hi Matt,

    The callback URL is globally registered in the payment gateway portal, so I don't need to pass the callback URL per transaction.

    Nalysa

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Oct 02, 2020 @ 09:14
    Matt Brailsford
    100

    Hi Nalsya,

    Ok, so then in that scenario it also requires that your payment provider implements the GetOrderReference method (an example you can find in the Stripe payment provider here https://github.com/vendrhub/vendr-payment-provider-stripe/blob/dev/src/Vendr.PaymentProviders.Stripe/StripePaymentProviderBase.cs#L37-L61)

    The reason for this is that the globally registered callback URLs basically identify which payment provider / method the payment is associated with, however it can't know which order it relates to so the GetOrderReference method extracts from the callback which order it relates to so that Vendr can direct it accordingly.

    The easiest way to get an OrderReference is to use an extension method in Vendr and store it as meta data against the transaction. Then when your callback URL is requested, it should then fetch that meta data and parse out the order order reference you passed in. (an example of the Stripe provider settings a meta data entry with an order reference https://github.com/vendrhub/vendr-payment-provider-stripe/blob/dev/src/Vendr.PaymentProviders.Stripe/StripeCheckoutOneTimePaymentProvider.cs#L95)

    So in summary,

    • Store an order reference on the transaction
    • Implement the GetOrderReference method to parse and return this order reference as part of a callback
    • Implement your callback method to then handle the rest of callback finalizing the order / transaction

    Matt

  • Nalysa 48 posts 269 karma points
    Oct 05, 2020 @ 03:41
    Nalysa
    0

    Hi Matt,

    I've put the order reference as a meta data entry.

    return new PaymentFormResult()
    {
        MetaData = new Dictionary<string, string>
        {
            { "orderReference", order.GenerateOrderReference()}
        },
        Form = new PaymentForm(paymentFormLink, FormMethod.Get)
    };
    

    However, I'm still a little confused about how to get and return this order reference on GetOrderReference method. Can you provide me with sample code or further explanation for my GetOrderReference method implementation?

    Thanks

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Oct 05, 2020 @ 08:16
    Matt Brailsford
    0

    Hi Nalysa,

    Sorry, you need to record that as meta data on the payment for the 3rd party payment system, not for Vendr. Then, when your callback is triggered, it will first hit the GetOrderReference method where you should then extract this from the info the 3rd party sends you, his will then tell Vendr what order it relates to and it will then hit your callback URL to complete the order finalization.

    Matt

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Oct 05, 2020 @ 08:20
    Matt Brailsford
    0

    This is how the Stripe payment provider does it.

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

    When it it setting up the payment details to send to stripe, it adds the order reference as meta data + as the ClientReferenceId on the payment. Then in GetOrderReference it parses it back out so that Vendr then knows which order the callback relates to.

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

    Matt

  • Nalysa 48 posts 269 karma points
    Oct 05, 2020 @ 08:26
    Nalysa
    0

    Thanks Matt, I got it

    Unfortunately, I faced another issue. After returning the transaction info on ProcessCallback(), the order was successfully created on Vendr store but the order status is Error (payment status is Captured) so that after the payment process, the checkout page got redirected to /cart/ instead of /checkout/order-confirmation/. Could you help me solve this?

    return CallbackResult.Ok(
        new TransactionInfo
        {
            AmountAuthorized = AmountFromMinorUnits(payment.PaidAmount),
            PaymentStatus = GetPaymentStatus(payment.Status),
            TransactionId = payment.Id,
            TransactionFee = payment.FeesPaidAmount
        }
    );
    
  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Oct 05, 2020 @ 08:38
    Matt Brailsford
    0

    Hi Nalysa,

    The order is set to the Error state when the continue URL is called and generally only goes into the Error order status for a number of reasons.

    1) FinalizeAtContinueUrl is set to true on the payment provider which subsequently calls the ProcessCallback and this either returned a BadRequest HTTP response

    2) The order being processed didn't match the order reference Vendr expected it to, which usually occurs if you are sent to the confirmation URL of an order that is not the order that Vendr retrieved.

    3) The order payment status is of type Error

    4) The order has it's order status set the error order status as defined in the store settings

    You'll want to check to see if any of the above are true and if so look into why that is the case and rectify it.

    Hope this helps

    Matt

  • Nalysa 48 posts 269 karma points
    Oct 08, 2020 @ 02:18
    Nalysa
    0

    Thanks Matt, removing the TransactionFee make it works.

    Anyway, what's the best way to handle an expired invoice? The payment gateway will send a callback when an invoice has expired (it's optional actually). I try to create a TransactionInfo with Cancelled payment status, but apparently the user still get the order confirmation email, which I think it should be an order cancellation email. Should I enable the callback for expired invoices or just leave it as is?

    Best regards

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Oct 08, 2020 @ 08:21
    Matt Brailsford
    0

    Hi Nalysa,

    Vendr automatically sends a confirmation when an order finalized, but a finalized order isn't necessarily captured. You should maybe check in the confirmation email template what the status of the order is and change the wording depending on the status.

    If you need to send other emails when the payment status changes you'll need to use Vendr's event system to listen for these changes and send the appropriate email (you can define your own emails, and use the email template service to send them).

    https://vendr.net/docs/core/1-3-0/key-concepts/events/

    Hope this helps

    Matt

  • Nalysa 48 posts 269 karma points
    Oct 08, 2020 @ 09:28
    Nalysa
    0

    Thanks Matt, really appreciate your helps.

    Best regards, Nalysa

Please Sign in or register to post replies

Write your reply to:

Draft