asp.net-mvcasp.net-mvc-4stripe-paymentswebhooksasp.net-webhooks

ASPNET Waiting for a Webhook Response/Result on a WebPage


We have a web page which takes a Stripe payment, once the payment is complete Stripe can call a webhook on our server.

At this point, we can mark an Order as complete and complete any other additional tasks.

How can we have the order webpage update/move the user onto to order complete?

Should we consistently hit the server in AJAX to check if it's now complete, or is there a better way of doing this.


Solution

  • Q: How can we have the order webpage update/move the user onto to order complete?

    Most payment engines will redirect the payment session to a URL of your choosing with a result code or a different URL per result code. These can generally be configured at the moment the request is being made or for the entire site in a general configuration. These results should not be relied on for the actual payment as that is the job for the web hook. They can be trusted enough for your site to show a general success/fail error message and let the user continue doing whatever.


    Stripe also allows for this, you can specify a success_url (or successUrl in the client integration).

    See Create a Checkout Session on your server for how to pass this URL to the request. You can also include a cancel_url. See the last 2 parameters in the code sample below:

    curl https://api.stripe.com/v1/checkout/sessions \
      -u sk_test_4eC39HqLyjWDarjtT1zdp7dc: \
      -d payment_method_types[]=card \
      -d line_items[][name]=T-shirt \
      -d line_items[][description]="Comfortable cotton t-shirt" \
      -d line_items[][images][]="https://example.com/t-shirt.png" \
      -d line_items[][amount]=500 \
      -d line_items[][currency]=usd \
      -d line_items[][quantity]=1 \
      -d success_url="https://example.com/success" \
      -d cancel_url="https://example.com/cancel"
    

    See also Checkout Purchase Fulfillment.

    When your customer successfully completes their payment or initiates a subscription using Checkout, Stripe redirects them to the URL that you specified in the success_url parameter (or successUrl in the client integration). Typically, this is a page on your website that informs your customer that their payment was successful.

    And as I stated above do not rely on this as the actual indicator if the payment succeeded. You should use the web hooks for that.

    Do not rely on the redirect to the success_url alone for fulfilling purchases as:

    • Malicious users could directly access the success_url without paying and gain access to your goods or services.
    • Customers may not always reach the success_url after a successful payment. It is possible they close their browser tab before the redirect occurs.