Guest User

Untitled

a guest
Jul 19th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. exports.addPaymentSource = functions.firestore.document('Users/{userId}/paymentSources/{paymentID}').onWrite((change, context) => {
  2. let newPaymentSource = change.after.data();
  3. let token = newPaymentSource.token;
  4.  
  5. return functions.firestore.document(`Users/${context.params.userId}`).get('customer_data')
  6. .then((snapshot) => {
  7. return snapshot.val();
  8. }).then((customer) => {
  9. return stripe.customers.createSource(customer, {newPaymentSource});
  10. }).then((response) => {
  11. return change.after.ref.parent.set(response);
  12. }, (error) => {
  13. return change.after.ref.parent.child('error').set(userFacingMessage(error));
  14. }).then(() => {
  15. return reportError(error, {user: context.params.userId});
  16. });
  17. });
Add Comment
Please, Sign In to add comment