I have deployed a cloud function to my Firebase In order to use Firebase as my backend server to handle Stripe payment. The link of the sample Firebase cloud functions i have used: https://github.com/firebase/functions-samples/tree/master/stripe
Here is the function I should trigger when I charge the user in my app
exports.createStripeCharge = functions.database.ref('/stripe_customers/{userId}/charges/{id}').onWrite((event) => {
const val = event.data.val();
if (val === null || val.id || val.error) return null;
return admin.database().ref(`/stripe_customers/${event.params.userId}/customer_id`).once('value').then((snapshot) => {
return snapshot.val();
}).then((customer) => {
const amount = val.amount;
const idempotency_key = event.params.id;
let charge = {amount, currency, customer};
if (val.source !== null) charge.source = val.source;
return stripe.charges.create(charge, {idempotency_key});
}).then((response) => {
return event.data.adminRef.set(response);
}).catch((error) => {
return event.data.adminRef.child('error').set(userFacingMessage(error));
}).then(() => {
return reportError(error, {user: event.params.userId});
});
});
I know that the above function will be triggered when my database changed. My question is, what is the proper way to pass the Stripe payment detail to my Firebase Database? I am not sure what should I pass to my firebase database after reading the stripe document.
Could anyone help me with this question? Thanks!!
P.S. My developing environment: Objective C, IOS application.