-
Notifications
You must be signed in to change notification settings - Fork 29
Description
During rspec test for processing stripe webhook events, this method:
def self.process_webhook(type, data)
account = Account.find_by!(stripe_customer_id: data["object"]["customer"])
account.subscription_events.create(
type: type,
data: data,
)
if type == "customer.subscription.updated"
handle_subscription_updated_event(account, data)
end
end
is returning this error:
Failure/Error: account = Account.find_by!( stripe_customer_id: data[:object][:customer] )
NoMethodError:
undefined method '[]' for nil:NilClass
Not sure if it is a result of not being able to parse the returned data from Stripe properly when converted to a hash with this line in the receive method of the stripe_webhooks_controller:
params[:data].permit!.to_h
or if it's an update to Stripe's API that's causing the issue now. I was able to nail it down to this line specifically in the subscription_event.rb model:
account = Account.find_by!(stripe_customer_id: data["object"]["customer"])
And by changing it to:
account = Account.find_by!( { 'stripe_customer_id': data['object']['customer'] } )
I was able to get the tests to pass.
Any info on why the lesser intuitive nature of the latter works and the former does not would be greatly appreciated to better grasp the concept!