CheckoutInstance
represents an active checkout session. It is returned from createCheckout()
and provides properties, events, and methods to manage the checkout lifecycle.
Properties
Unique identifier for this checkout session.
Current state of the checkout. Possible values:
"initializing"
, "ready"
, "processing"
, "completed"
, "error"
, or "action_required"
.The order identifier associated with the checkout (available once initialization completes).
Whether this checkout instance has been destroyed (i.e., cleaned up).
Methods
Once you have aCheckoutInstance
, you can control or query it with the following methods.
updatePrice(priceId)
Update the current checkout to use a different price. This allows you to switch the product/plan on the fly.The new price identifier to switch to.
You cannot call
updatePrice
while a payment is already in progress (while in the "processing"
state).getStatus()
Retrieve the current status and details of the checkout session. Returns:id
: Checkout IDstate
: Current stateorderId
:Order ID (if initialized)priceId
: Current price IDisDestroyed
: Whether the instance has been destroyed
destroy()
Destroy the checkout instance, clean up the embedded UI, and release resources. After callingdestroy()
, the CheckoutInstance
will emit a 'destroy'
event and no longer be usable.
isReady()
Returnstrue
if the checkout is fully initialized and ready to accept payment details. Use this to check if calling updatePrice()
or allowing user input is safe.
isProcessing()
Returnstrue
if a payment is currently in progress (the checkout is in a processing state). You might use this to prevent certain actions (like triggering another checkout) while a payment is mid-flight.
Events
You can subscribe to checkout events using thecheckout.on(eventName, handler)
method. The following events are emitted by a CheckoutInstance
:
success
Emitted when the payment is completed successfully (the subscription or purchase was created and confirmed). The handler receives a result object containing details of the successful transaction.The order identifier
Transaction status (e.g.
"succeeded"
)The transaction identifier
error
Emitted when the checkout encounters an error or the payment fails. The handler receives an error object.Description of the issue
Error code (if available)
Request identifier for debugging