I am a newbie to all the technologies mentioned. So, I apologize in advance if this question shouldn't be here.
So I am trying to write the firestore equivalent of the example stripe-firebase realtime database-cloud functions integration provided by firebase. It is located here: https://github.com/firebase/functions-samples/blob/master/stripe/functions/index.js
I successfully converted the exports.createStripeCustomer function. But I am having trouble with addPaymentSource.
This is what I have so far:
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});
});
});
Deployment happens successfully, but the function fails with the following error.
TypeError: functions.firestore.document(...).get is not a function at exports.addPaymentSource.functions.firestore.document.onWrite (/user_code/index.js:73:77) at Object. (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:112:27) at next (native) at /user_code/node_modules/firebase-functions/lib/cloud-functions.js:28:71 at __awaiter (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:24:12) at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:82:36) at /var/tmp/worker/worker.js:728:24 at process._tickDomainCallback (internal/process/next_tick.js:135:7)
Clearly 'get' doesn't seem to be a function. I got this function from the following reference document. https://firebase.google.com/docs/reference/functions/functions.firestore.DocumentSnapshot
I seem to be missing something. I have been stuck on this for a couple of days. So, any help would be greatly appreciated. Thanks in advance.
firebase.database().ref(`Users/${context.params.userId}`)
and then read the matching resource using.on()
. – psmvac/pay
page and hands u a token to store alongside the new order. It's PCI compliant. – Ronnie Royston