Reference for every SDK callback — when each fires, what data it receives, and how they sequence.
Callbacks are how you connect the checkout lifecycle to your own UI — showing a loading state while the session loads, redirecting after a completed order, or displaying an error message when payment fails. This page documents every callback the SDK exposes, where to register each one, and the shape of the data they receive.
Callback order
In a typical integration, callbacks fire in this sequence:
FastSpring.init() callbacks
FastSpring.init() callbacksRegister these when initializing the SDK. They remain active for the lifetime of the sdk instance.
Fired when session data has been fetched and the checkout is ready for input.
const sdk = FastSpring.init({
checkoutUrl: '...',
onSessionLoaded: (data) => {
document.querySelector('#loading-spinner').hidden = true;
},
});View data object
| Field | Type | Description |
|---|---|---|
id | string | The session ID |
items | array | Line items in the session |
currency | string | Currency code (e.g. "USD") |
total | number | Order total |
complianceMessages | array | Compliance flags for the session (e.g. "SHOW_IOF_MESSAGE" for Brazilian IOF fees) |
Fired after a successful payment and order completion.
const sdk = FastSpring.init({
checkoutUrl: '...',
onOrderCompleted: (data) => {
window.location.href = `/confirmation?order=${data.id}`;
},
});View data object
| Field | Type | Description |
|---|---|---|
id | string | The order ID |
reference | string | Human-readable order reference |
items | array | Line items in the completed order |
currency | string | Currency code |
total | number | Order total |
account | object | Customer account details |
Fired when a payment attempt is rejected or encounters an error. The checkout stays open — the customer can correct their details and try again.
const sdk = FastSpring.init({
checkoutUrl: '...',
onPaymentFailed: (error) => {
document.querySelector('#error-message').textContent =
'Payment failed. Please check your card details and try again.';
},
});
onPaymentFailedfires on payment rejection — not on session load failure. For session load errors, use theonErrorcallback onsdk.checkout().
View error object
| Field | Type | Description |
|---|---|---|
type | string | Error type (e.g. "card_declined", "insufficient_funds") |
message | string | Human-readable error description |
sdk.checkout() callbacks
sdk.checkout() callbacksRegister these per sdk.checkout() call. They fire once for that session load attempt.
Fired when the session loads successfully and the checkout is ready for input. No arguments.
sdk.checkout('<SESSION_ID>', {
onSuccess: () => {
console.log('Checkout is ready.');
},
});Fired when the session fails to load.
sdk.checkout('<SESSION_ID>', {
onError: (error) => {
console.error('Session load failed:', error);
},
});View error object
| Field | Type | Description |
|---|---|---|
type | string | Error type |
message | string | Human-readable error description |
Common causes:
- Session ID is invalid or malformed
- Session has already been used
- Session has expired
Create a fresh session immediately before each
sdk.checkout()call. Sessions are single-use and expire — pre-creating or reusing them is the most common cause of this error.
Related pages
- Configuration: full
FastSpring.init()andsdk.checkout()options reference. - Integration Guide: end-to-end walkthrough showing callbacks in context.
- Sessions API: server-side session creation.
