Skip to content

Instantly share code, notes, and snippets.

@cadecairos
Created September 21, 2017 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cadecairos/b327c4490b3a42c3a9c5d6f649874a7e to your computer and use it in GitHub Desktop.
Save cadecairos/b327c4490b3a42c3a9c5d6f649874a7e to your computer and use it in GitHub Desktop.
retrieveSubscription timeout with customer expand
// this function process a webhook event received from Stripe
function(request, reply) {
var event = request.payload;
var charge = event.data.object;
if (event.type !== 'charge.succeeded') {
return reply('This hook only processes charge succeeded events');
}
// TBH I don't know why we do this, but it's not relevant, if there is a reason.
stripe.retrieveCharge(
charge.id,
function(fetchChargeErr, charge) {
if (fetchChargeErr) {
return reply(boom.badImplementation('An error occurred while fetching the invoice for this charge', fetchChargeErr));
}
if (!charge.invoice || !charge.invoice.subscription) {
return reply('Charge not part of a subscription');
}
// this is where I hit the issue - with the `expand: ["customer"]` option,
// the request hangs until the HTTP client library hits the request timeout limit
// Without the expand, this request has no problem
stripe.retrieveSubscription(
charge.invoice.customer,
charge.invoice.subscription,
{
expand: ["customer"]
},
function(retrieveSubscriptionErr, subscription) {
if (retrieveSubscriptionErr) {
return reply(boom.badImplementation('An error occurred while fetching the subscription for this charge\'s invoice', retrieveSubscriptionErr));
}
//removed body of function
}
);
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment