Created
September 21, 2017 19:19
-
-
Save cadecairos/b327c4490b3a42c3a9c5d6f649874a7e to your computer and use it in GitHub Desktop.
retrieveSubscription timeout with customer expand
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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