I use gem stripe_event with stripe webhook.
My initial code is:
config/initializers/stripe.rb
StripeEvent.configure do |events|
events.subscribe 'checkout.session.completed', StripeCheckoutSessionService.new
end
app/services/stripe_checkout_session_service.rb
class StripeCheckoutSessionService
def call(event)
order = Order.find_by(checkout_session_id: event.data.object.id)
order.update(state: "paid")
end
end
My problem is that if order is nil, I have a 500 error, and I want to have a 422 error instead.
I try that :
app/services/stripe_checkout_session_service.rb
class StripeCheckoutSessionService
def call(event)
order = Order.find_by(checkout_session_id: event.data.object.id)
if order
order.update(state: "paid")
head :accepted
else
head :unprocessable_entity
end
end
end
head is not recognize by the service, I try to return a string instead and return head directly in the block but I'm locked now...
Does anybody have any idea for me ?