-
-
Notifications
You must be signed in to change notification settings - Fork 316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pay::Stripe::PaymentMethod.sync attaching to wrong customer in rare (?) conditions #842
Comments
Hey @fschwahn - The code already does return if the pay_customer = Pay::Customer.find_by(processor: :stripe, processor_id: object.customer)
return unless pay_customer That said, we may need to add an additional check like you mentioned. Also, I am wondering if it is possible that you actually had a For example: irb(main):006:0> pay_customer = Pay::Customer.find_by(processor: :stripe, processor_id: nil)
=>
#<Pay::Customer:0x000000055555555b8
...
irb(main):007:0> _
=>
#<Pay::Customer:0x000000055555555b8
id: 716567020,
owner_type: "User",
owner_id: 555555555,
processor: "stripe",
processor_id: nil,
default: true,
data: nil,
deleted_at: nil,
created_at: Thu, 17 Aug 2023 00:48:02.303326000 UTC +00:00,
updated_at: Thu, 17 Aug 2023 00:48:02.303326000 UTC +00:00,
payment_method_token: nil>
irb(main):008:0> |
Yes, I forgot to mention that. We have a few of those in our database, because creating the customer in Stripe failed (in our case due to an invalid email address). I see now that this is quite an edge case, but probably still worth to add the guard? |
Yeah, this should definitely return if object.customer is |
This is issue is a bit weird, but what happened in our app is this:
customer.updated
-webhook is triggered (because the default payment method changed)Pay::Stripe::PaymentMethod.sync
is invoked (here: https://github.com/pay-rails/pay/blob/master/lib/pay/stripe/webhooks/customer_updated.rb#L16)::Stripe::PaymentMethod.retrieve
hasobject.customer == nil
Pay::Customer.find_by(processor: :stripe, processor_id: object.customer)
just returns anyPay::Customer
without a processor_id set.--> Payment method is attached to the wrong
Pay::Customer
I'm not sure why
object.customer
was nil for the returned payment method object, this may well have been a temporary Stripe bug, but it still seems dangerous.Maybe
Pay::Stripe::PaymentMethod.sync
should return (or raise?) in caseobject.customer
is nil?The text was updated successfully, but these errors were encountered: