Skip to main content
elements.checkout() is the hand-off from a selected method to a public payment session. It calls your createOrder callback, receives the session created by your backend, and starts the provider’s browser presentation. It does not verify a payment. A success-looking provider page, redirect, overlay callback, or browser event never authorizes fulfilment. Complete the provider callback or return in your backend with the SDK’s completePayment().

Checkout sequence

1

Select method

Buyer selects a method in renderMethods().
2

Initiate payment

Buyer clicks your payment button.
3

Call checkout

Your frontend calls elements.checkout().
4

Trigger callback

Your createOrder callback calls your HTTPS backend endpoint.
5

Create session

Your backend validates fresh availability and calls SDK createOrder().
6

Launch session

Elements launches the returned public provider session.
7

Receive callback

The provider callback or trusted return reaches your backend.
8

Verify and fulfil

Your backend calls SDK completePayment() and decides fulfilment.
checkout() fails before it calls your server when no method is selected. It also requires createOrder when you call it. The relevant browser errors are elements_method_missing and elements_create_order_missing.
createOrder is your backend callback, not a Payment Elements function. It receives the selected gateway, mode, customer values, and public providerOptions; it must call your backend, where your AvraAPI SDK creates the public payment session. elements.checkout() is the package function that invokes this callback and presents that session.

Provider presentations

The returned public session determines how the package starts checkout. Your server chooses the gateway and mode; the browser must not invent them.
An Elements presentation is not a supported substitute for server-side completion. In particular, a browser return URL and a provider overlay callback are not payment proof.

DirectPay embedded target

For DirectPay’s embedded mode, choose a stable page container. The package clears it before mounting each provider session.
Only DirectPay uses directPayContainer; it does not change redirect, PayHere, or OnePay behaviour.

State-change events

Pass onStateChange when creating Elements. All events are UI signals only.
No event in this table means payment_status = succeeded. Do not mark an order paid or fulfil it from any browser event.

Error handling

checkout() rejects with a PaymentElementsError when the package can produce a safe error. It has code, message, reason where relevant, and availabilityUnavailable for stale-availability failures. onError receives { code, message }.

Final payment decision

After the provider callback or return reaches your backend, call the SDK’s completePayment() using the preserved server-only completion context. Use its normalized status to decide whether to fulfil, leave pending, cancel, fail, or review the merchant order. Follow Payment response & completion for the authoritative completion flow and outcomes.

Your application functions in these examples

Payment Elements provides AvraAPIPaymentElements.create(), renderForm(), renderMethods(), checkout(), destroy(), onStateChange, onError, and the browser-safe PaymentElementsError values documented above. It does not provide your backend endpoint or your application UI helpers. The functions marked Your … function in this page are sample names that you must implement in your own application:
  • createOrder — calls your backend endpoint; that endpoint uses your server-side AvraAPI SDK createOrder() call.
  • showCheckoutMessage, updateSelectedMethod, setCheckoutBusy, and disablePaymentButton — update your checkout UI.
  • refreshCheckoutPage — reloads or re-fetches your server-generated checkout availability.
  • The final SDK completePayment() call — runs only in your backend callback or return handler, never in the Payment Elements browser package.
They are intentionally not functions shipped by @avraapi/payment-elements. Replace each sample with your application’s own implementation.
Last modified on October 1, 2026