I am trying to write a firebase cloud function that attaches a payment method to a stripe customer, subscribes them to a plan, and writes the subscription object to firestore.
I actually just wrote a function that worked but am not sure what I changed.
exports.attachAndSubscribe = functions.firestore
.document('stripe_customers/{userId}')
.onUpdate(async (change, context) => {
const source = change.after.data();
const paymentMethod = source.paymentMethod;
await stripe.paymentMethods.attach(paymentMethod.id,
{customer: source.customer_id},
{invoice_settings: {default_payment_method: paymentMethod.id}
});
const subscription = await stripe.subscriptions.create(
{customer: source.customer_id,items: [{plan: 'plan_FnA3IsFL5Xc6Ct'}]
});
return admin.firestore()
.collection('stripe_customers')
.doc(userId)
.set(
{subscription: subscription});
});
When the function gets triggered I get the following error:
Stripe: Unknown arguments ([object Object]). Did you mean to pass an options object?
stripe.paymentMethods.attachthe only param available is customer, stripe.com/docs/api/payment_methods/attach?lang=node - duck