Customer Phone keeps getting deleted after subscription dele #625
Description
Bug report
- Extension name: invertase/stripe-firebase-extensions
Describe the bug
On events: customer.subscription.created
The webhook handleWebHook keeps overwriting with empty value the customer phone to the customer profile.
In my stripe API call to create a checkout i run correctly with
phone_number_collection: {
enabled: true,
},
Indeed my payment page does force you to insert phone number.
In details, this is what's going wrong, i've spotted the error in the soure code:
functions/src/index.ts
// NOTE: This is a costly operation and should happen at the very end.
// Copy the billing deatils to the customer object.
if (createAction && subscription.default_payment_method) {
await copyBillingDetailsToCustomer(
subscription.default_payment_method as Stripe.PaymentMethod
);
}
// the copyBillingDetailsToCustomer implementation, the bug is easily spotted once you go live, the phone from billing_details is always empty even if you have
const copyBillingDetailsToCustomer = async (
payment_method: Stripe.PaymentMethod
): Promise<void> => {
const customer = payment_method.customer as string;
const { name, phone, address } = payment_method.billing_details;
await stripe.customers.update(customer, { name, phone, address });
};
To Reproduce
Just give it a try, whatever payment that requires phone ends up with a empty phone field on customer page on stripe and in firebase payment. The only place where it doesn't get erased is inside the invoice.
Expected behavior
It is expected that the phone number gets updated when it's available; if for some reasons the phone number is empty (due to stripe errors or stripe delay in the update), it should not overwrite the pre-existing value.
Screenshots
Kind Regards