#nerder-customerdelete-event

1 messages ยท Page 1 of 1 (latest)

warm plazaBOT
#

Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

civic spire
#

Hmm have you tested it already? My understanding is that this event is only generated in case the request to detach/delete PaymentMethod is triggered.

fallow hinge
#

I've tested it but I expected it to be fired

#

since the customer is not there anymore, the payment method is not attached to anyone so it should be detached no?

civic spire
#

You wouldn't be able to use the PaymentMethod if the customer gets deleted afaik. and there are webhook events for customer deletion I believe.

Taking a step back, what's the usecase here? Trying to understand why you'd rely on payment_method.detached events in such cases versus customer object related webhook events?

fallow hinge
#

it's just to not duplicate the logic

#

for now my use case is quite simple, in customer.deleted I only want to remove the payment_methods attached to it

#

but might make sense for me to handle customer.deleted and recursively remove all the payment_methods of that customer (in my DB)

#

it was strange to not see this firing

civic spire
#

Yeah that's the path I'd go, as payment_method.detached won't have a reason listed as to why this payment method was detached

fallow hinge
#

i expected it to behave as customer.subscription.deleted in a sense

#

it will be called as a consequence of customer.deleted

#

but it was the wrong assumption ๐Ÿ™‚

civic spire
#

๐Ÿ‘

#

๐Ÿ‘‹

fallow hinge
#

Hey sorry

#

just testing your proposal

#

there is a small issue

#

since the customer is deleted i could not retreive the payment methods attached to ti

#

imagine i'm doing something like this:

    const paymentMethods = await this.customerRepository.retrievePaymentMethods(stripeAccount, customer);

    await Promise.all([
      ...paymentMethods.map(paymentMethod =>
        this.customerPaymentMethodRepository.remove(stripeAccount, gymId, paymentMethod, customer),
      ),
    ]);
#

where retrievePaymentMethod is this:

  async retrievePaymentMethods(
    stripeAccount: StripeAccountId,
    customer: Stripe.Customer,
  ): Promise<Stripe.PaymentMethod[]> {
    this.logger.log(`Retrieve all payment methods for customer [${customer.id}]`);
    const allPaymentMethods = await this.stripe.customers.listPaymentMethods(customer.id, {
      stripeAccount,
    });

    if (!allPaymentMethods.data.length) {
      return null;
    }

    return allPaymentMethods.data;
  }
}
#

this will fail, because that customer is deleted now

civic spire
#

but might make sense for me to handle customer.deleted and recursively remove all the payment_methods of that customer (in my DB)
I am assuming you have some sort of mapping between pm_xxx and cus_xxx objects in your DB?

fallow hinge
#

Yes, i can get it from there as well

#

Ok I see what you mean

civic spire
#

๐Ÿ™‚ ๐Ÿ‘

fallow hinge
#

sorry to bother ๐Ÿ™‚

civic spire
#

NP! ๐Ÿ™‚ Happy to help

warm plazaBOT
digital comet
#

nerder-customerdelete-event