2
votes

I'm integrating an actvie merchant gateway into my rails app which uses spree , but always get Cannot transition state via :next from :payment (Reason(s): No payment found) although there is a payment method.

i'm using Spree 3.1-stable here's my code :

payment = @order.payments.create({
    amount: @order.total,
    payment_method: payment_method,
    source: credit_card,
  })
# @order.next! through Cannot transition state via :next from :payment (Reason(s): No payment found)
@order.next!

any idea about how can i fix such error

1

1 Answers

2
votes

Orders flow through a state machine, beginning at a cart state and ending up at a complete state. The intermediary states can be configured using the Checkout Flow API.

The default states are as follows:

cart address delivery payment confirm complete The payment state will only be triggered if payment_required? returns true.

The confirm state will only be triggered if confirmation_required? returns true.

The complete state can only be reached in one of two ways:

No payment is required on the order. Payment is required on the order, and at least the order total has been received as payment. Assuming that an order meets the criteria for the next state, you will be able to transition it to the next state by calling next on that object. If this returns false, then the order does not meet the criteria. To work out why it cannot transition, check the result of an errors method call.

Changing state from payment to complete require at least one payment that completed.!

so

payment = @order.payments.create({
amount: @order.total,
payment_method: payment_method,
source: credit_card, })

payment.complete!

# @order.next! through Cannot transition state via :next from :payment (Reason(s): No payment found)
@order.next!