Back to Practice

Practice · Payments · Card 3

The user lands on /success. The code marks the order paid. What's wrong?

A controller that trusts the redirect. The bug is invisible 99% of the time. The 1% is the bug.

The code

# routes.rb
get "/orders/:id/success", to: "orders#success"

# orders_controller.rb
def success
  @order = Order.find(params[:id])
  @order.update!(status: "paid", paid_at: Time.current)
  GrantAccessJob.perform_later(@order.id)
  OrderMailer.with(order: @order).receipt.deliver_later
end

The question

The intent: "after the user pays at Stripe, they redirect to this URL, and we mark them paid." A user finds an edge case where they get access without the money clearing. What's the bug, and how would you fix it?

Take a moment. What does the redirect actually prove? What channel can you trust to know the money moved?