Skip to content

Customer Phone keeps getting deleted after subscription dele #625

Open
@rossano-montori

Description

@rossano-montori

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 });
};

Code

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

logs payment log customerupdated log

Kind Regards

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

Opened

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions