Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- exports.addPaymentSource = functions.firestore.document('Users/{userId}/paymentSources/{paymentID}').onWrite((change, context) => {
- let newPaymentSource = change.after.data();
- let token = newPaymentSource.token;
- return functions.firestore.document(`Users/${context.params.userId}`).get('customer_data')
- .then((snapshot) => {
- return snapshot.val();
- }).then((customer) => {
- return stripe.customers.createSource(customer, {newPaymentSource});
- }).then((response) => {
- return change.after.ref.parent.set(response);
- }, (error) => {
- return change.after.ref.parent.child('error').set(userFacingMessage(error));
- }).then(() => {
- return reportError(error, {user: context.params.userId});
- });
- });
Add Comment
Please, Sign In to add comment