Skip to main content

Prerequisites

  • An active Payrails session (see Quick Start)
  • The Session reference returned by Payrails.createSession(...)
  • At least one payment button already created (CardPaymentButton or GooglePayButton)
  • Your backend can call the Payrails lookup action on an execution

How amount updates work

Updating the checkout amount requires two coordinated steps — one on your backend and one on the client. Both must happen before the payment is triggered, and they must agree on the same amount.
  1. Backend: Call the Payrails lookup action on the execution with the new amount. This authorizes the updated amount on the Payrails side.
  2. Client: Call session.update() with the same new amount. This tells the SDK what amount to send in the next payment request.
ImportantIf the amount authorized by your backend (via lookup) and the amount sent by the SDK (via update()) do not match, Payrails will reject the payment with a 401 HTTP error. Keep the two in sync.

Steps

1. Calculate the new amount in your UI logic

Compute the final amount before calling your backend. The value must be a numeric string matching the format your backend expects.

2. Call your backend to update the execution via the lookup action

Your backend must call the Payrails lookup action with the new amount before the client updates the SDK. Pass the executionId from the active session so your backend knows which execution to update.
Your backend endpoint should call the Payrails lookup action:
Wait for your backend to confirm success before proceeding to step 3.

3. Call session.update() with the same new amount

Once your backend has successfully updated the execution, update the SDK with the matching amount. The value and currency must be identical to what was sent to the backend.
update() is synchronous and requires no suspend context.

4. Trigger payment as normal

The updated amount is applied automatically on the next pay() call. No additional configuration is required.

Full example — tip selection before payment

Important: update() is reset on redirect session recovery

If the session is refreshed during a redirect flow (via onSessionExpired), the amount override is cleared and the value from the new session init payload takes effect. If your checkout flow involves redirects, re-call session.update() after session recovery if a merchant-side amount override is still needed.

Troubleshooting

Problem: Payment fails with a 401 HTTP error after calling update() Solution: The amount set on the SDK and the amount authorized on the backend via the lookup action do not match. Ensure both use exactly the same value and currency strings, and that your backend lookup call succeeded before session.update() was called. Problem: IllegalStateException — “No active Payrails session” Solution: session.update() was called before createSession() completed. Ensure the session is fully initialized before calling update(). Problem: IllegalArgumentException — “AmountUpdate.value must be a valid positive number” Solution: The value string is not a valid positive number (it may be empty, zero, negative, or contain non-numeric characters). Validate your amount calculation before passing it to AmountUpdate.

See also

Last modified on September 30, 2026