Martijn Michel
Martijn Michel

Reputation: 39

How to setup Stripe Ideal with webtask.io webhook

I have been trying for 2 days to setup a webhook for ideal payments in Stripe. First id like to test it using Stripe's inbuilt test methods but so far i cant even get a good response.

Can anybody help me out with a example for creating a source that runs webhook -> /charge when source.chargeable? Ive tried a dozen of examples from stripes own docs to all over the internet. Right now as a webhook i have this (which is from the stripe docs):

module.exports = function(ctx, req, res) {
  var stripe = require("stripe")("sk_test_dfgfdgdf");

  const charge = stripe.charges.create({
    amount: 999,
    currency: 'usd',
    description: 'Example charge',
    source: ctx,
  })
};

Upvotes: 0

Views: 131

Answers (1)

karllekko
karllekko

Reputation: 7268

There is a full example of receiving a webhook with Node(Express) here — that would be a good place to start, just plug in your API key and webhook secret, then run the app and enter your URL in https://dashboard.stripe.com/account/webhooks.

Once you have the event and parse it, you need to check the event type. If it's source.chargeable, then you can call the API to make the charge. You will most likely need to save information to a local database about the original order when it was submitted, as you will receive the webhook asynchronously some time after the user started the checkout flow. You can look up the saved order to determine any metadata to set on the charge/the Stripe customer object to use, etc. But for now a simple approach would be like this :

if(event.type == "source.chargeable"){
  const source = event.data.object;
  const charge = await stripe.charges.create({
    amount: source.amount,
    currency: source.currency,
    source: source.id,
  });
}

Upvotes: 0

Related Questions