sebastien
06/02/2017, 4:36 PMstripe.customers.create({
email: user.email,
description: user.name,
source: cardDetails.cardToken
}, (err, customer) => {
if (err) {
console.log(err)
send(res, 400, { error: `Stripe customer with card details ${cardDetailsId} could not be created for user ${userId}` })
} else {
// then update user with obtained Stripe customer id
const updateUser = `mutation {
updateUser(id: "${userId}", stripeId: "${customer.id}") {
id
}
}`
<http://request.post|request.post>({
url: endpoint,
headers: {
'Authorization' : graphcoolToken,
'content-type': 'application/json',
},
body: JSON.stringify({query: updateUser}),
}).on('error', (e) => {
send(res, 400, { error: `User ${userId} could not be updated` })
}).on('response', (response) => {
send(res, 200, { message: `User ${userId} was successfully registered at Stripe` })
})
}
}
)
I set the endpoint to my Graphcool simple API endpoint and graphcoolToken to a permanent auth token that I generated. I also have the update permission on users fully open for now.