Flow library reference
Last updated: October 23, 2024
Use the Flow library reference to learn how to customize the Flow user experience with the available configuration options, and how to handle errors.
Initializes a CheckoutWebComponent
instance.
1/**2* @param {object} appearance - customizes the visual appearance of the CheckoutWebComponent elements.3* @param {object} componentOptions - customizes the options for the individual Flow components.4* @param {string} componentOptions.card.data.cardholderName - the name to pre-populate the cardholder name input field for card payments with.5* @param {string} componentOptions.card.displayCardholderName - the position of the cardholder name input field for card payments. Value can be either top, bottom, or hidden.6* @param {bool} componentOptions.flow.expandFirstPaymentMethod - sets whether to automatically expand the first payment method, if there are multiple payment methods.7* @param {string} environment - sets the environment that the library should point and send requests to.8* @param {string} locale - sets the customer's locale.9* @param {object} paymentSession - the response from the PaymentSession.10* @param {string} publicKey - your public API key.11* @param {object} translations - customizes text translations for natively supported languages, or adds custom text for locales and languages not natively supported.12*13* @return {CheckoutWebComponent} The CheckoutWebComponent instance.14*/1516const checkout = await CheckoutWebComponents({17appearance,18componentOptions: {19flow: {20expandFirstPaymentMethod: false,21},22card: {23displayCardholderName: 'bottom',24data: {25cardholderName: 'Jia Tsang',26},27},28}29environment: 'sandbox',30locale: 'en',31paymentSession,32publicKey: 'pk_01234',33translations,34});
Initializes a FlowComponent
instance.
1/**2* @param {string} name - a name for the FlowComponent instance.3* @param {object} options - the event callbacks for the FlowComponent.4*5* @return {FlowComponent} The FlowComponent instance.6*/7const flowComponent = checkout.create('flow', {8showPayButton: false,9});
Submits a FlowComponent
, if you require your own pay button.
Information
This option is not available for digital wallets, including Apple Pay and Google Pay.
1/**2* @return {FlowComponent} The FlowComponent instance.3*/4function submit() {5return FlowComponent;6}
Checks if the FlowComponent
has captured all details from the customer and can be submitted.
1/**2* @return {boolean} Validity of the FlowComponent for submission.3*/4function isValid() {5return boolean;6}
Checks if the FlowComponent
can be rendered. Call this before mounting the FlowComponent
.
1/**2* @return {Promise<boolean>}3*/4function isAvailable() {5return Promise<boolean>;6}
Mounts a FlowComponent
to a page. You can either provide:
1/**2* @param {string} - the Element Selector or DOM Element object to mount to3*4* @return {FlowComponent}5*/6function mount('#elem') {7return FlowComponent;8}
Unmounts a FlowComponent
from the page.
This stops rendering the component, and removes all life-cycles from the browser.
1/**2* @return {FlowComponent}3*/4function unmount() {5return FlowComponent;6}
Fired when a FlowComponent
is initialized and ready for the customer to interact.
FlowComponent
is the instance that fired the event.
1const flowComponent = checkout.create('flow', {2onReady: (_self) => {3// Hide loading overlay4hideLoadingOverlay();5},6});7flowComponent.mount('#flow-container');
Fired when a FlowComponent
changes after a customer interaction.
FlowComponent
is the instance that fired the event.
1const flowComponent = checkout.create('flow', {2onChange: (self) => {3// Enable/disable custom pay button based on input validity4if (self.isValid()) {5submitButton.removeAttribute('disabled');6} else {7submitButton.setAttribute('disabled', true);8}9},10});11flowComponent.mount('#flow-container');
Fired when you or the customer have triggered a FlowComponent
submission.
FlowComponent
is the instance that fired the event.
1const flowComponent = checkout.create('flow', {2onSubmit: (_self) => {3// Show loading overlay to prevent further user interaction4showLoadingOverlay();5},6});7flowComponent.mount('#flow-container');
Fired when the payment has been completed synchronously.
This event will not be fired if the payment requires asynchronous action. For example, 3DS authentication.
FlowComponent
is the instance that fired the event.
The PaymentResponse
object contains information on the successful payment:
id
- a unique identifier for the payment.status
- the payment status. This value will always returnApproved
.type
- the name of the payment method that was used for the payment.
1const flowComponent = checkout.create('flow', {2onPaymentCompleted: async (_self, paymentResponse) => {3// Complete order in server side4await completeOrder(paymentResponse.id);5},6});7flowComponent.mount('#flow-container');
Fired when an error occurs. See the CheckoutError reference for more information.
FlowComponent
is the instance that fired the event.
1const flowComponent = checkout.create('flow', {2onError: async (_self, error) => {3// Display payment request failure message4if (error.code === 'payment_request_failed') {5showErrorMessage('Payment could not be processed. Please try again.');6}7},8});9flowComponent.mount('#flow-container');
Triggered when a wallet payment button is clicked. For example, Apple Pay, Google Pay, or PayPal.
You can use this to perform checks before beginning the payment process.
FlowComponent
is the instance that triggered the callback.
1const flowComponent = checkout.create('flow', {2handleClick: (_self) => {3if (acceptedTermsAndConditions) {4return { continue: true };5}6return { continue: false };7},8});9flowComponent.mount('#flow-container');
The Flow CheckoutError
class extends the standard JavaScript Error
class and contains the following properties:
Property | Type | Description |
---|---|---|
|
| A human-readable description of the error. The description is subject to change. For example, to improve clarity. To ensure you catch errors correctly, you should reference the values returned by the |
|
| The error class name. This will always return |
|
| The type of error encountered, as one of the following values: |
|
| A code representing the error. To see how to resolve the errors, see the Error codes section. |
|
| Additional error properties. All error types provide the following properties in the
Errors of type |
Integration errors are caused by an invalid use of the Flow Components library.
Errors of type Integration
contain the following properties within the details
object:
Property | Type | Description |
---|---|---|
|
| The unique identifier of the browser session that created the |
|
| The unique identifier of the provided payment session response. |
|
| The name of the payment method used for the payment. |
|
| The Element selector or DOM object that caused the mounting error. This property is only returned for errors with an |
Request errors are caused by network request failures.
Errors of type Request
contain the following properties within the details
object:
Property | Type | Description |
---|---|---|
|
| The unique identifier of the browser session that created the |
|
| The unique identifier of the provided payment session response. |
|
| The name of the payment method used for the payment. |
|
| The unique identifier for the declined payment request. |
| Array of | Additional error codes returned from the network request. |
|
| The unique identifier for the network request. |
|
| The HTTP response status code for the network request. |
Payment method errors are caused by unexpected failures when integrating a payment method's client-side library.
Errors of type PaymentMethod
contain the following properties within the details
object:
Property | Type | Description |
---|---|---|
|
| The unique identifier of the browser session that created the |
|
| The unique identifier of the provided payment session response. |
|
| The name of the payment method used for the payment. |
Submit errors are caused by invalid attempts to submit a payment request. For example, if you call the submit()
method before the customer has completed all of the required input fields.
Errors of type Submit
contain the following properties within the details
object:
Property | Type | Description |
---|---|---|
|
| The unique identifier of the browser session that created the |
|
| The unique identifier of the provided payment session response. |
|
| The name of the payment method used for the payment. |
Flow was loaded in a non-browser environment.
You should only load and execute Flow client-side.
If your integration involves server-side rendering or you have automated testing, check for existence of the Window object before you load Flow.
The result returned in a callback execution was invalid.
If you provide a custom callback, ensure it returns a result.
Flow supports Promises
returned in callbacks, in addition to direct results.
1const flowComponent = checkout.create('flow', {2handleClick: async (_self) => {3const canProceedPayment = await checkIfPaymentCanProceed();4return {5continue: canProceedPayment,6};7},8});910flowComponent.mount('#flow-container');
Flow has already been mounted to DOM with mount()
and cannot be mounted again.
If you need to mount Flow again because the checkout page changed, use the unmount()
method first before you call mount()
again.
1const flowComponent = cko.create('flow');2flowComponent.mount('#flow-container');34// Changes to the checkout page56flowComponent.unmount();7flowComponent.mount('#flow-container-2');
The payment request was submitted with the submit()
method before the customer had provided all of the details required by the chosen payment method.
If you're rendering a custom pay button and passed showPayButton: false
when you created the FlowComponent
, check that the customer inputs are valid with the isValid()
method before you submit a payment request.
1const flowComponent = checkout.create('flow');2flowComponent.mount('#flow-container');34const submitButton = element.querySelector('#submit');5submit.addEventListener(() => {6if (isFormValid() && flowComponent.isValid()) {7flowComponent.submit();8}9});
The isAvailable()
method was not called before mounting the FlowComponent
with mount()
. The component may not be supported by the customer device.
After you create the FlowComponent
, call the isAvailable()
method to verify that the payment method is supported by the customer device. This does not apply to a FlowComponent
of type payments
.
1const applepayElement = document.querySelector('#applepay-container');2const applepayComponent = checkout.create('applepay');34if (await applepayComponent.isAvailable()) {5applepayComponent.mount(applepayElement);6}
The name specified when creating the FlowComponent
using the create()
method is not supported.
If you are providing enabled_payment_methods
or disabled_payment_methods
options when you create the payment session, ensure you also include the payment method that you want to offer.
You should also ensure that the currency
and billing.address.country
values provided to the payment session match the payment method's requirements.
The Element selector or DOM object you provided when calling the mount()
method could not be found.
Ensure the Element selector you provide to the mount()
method is already mounted to the DOM. Alternatively, you can query for the DOM object and provide the reference when you call mount()
.
1const applepayElement = document.querySelector('#applepay-container');2const applepayComponent = checkout.create('applepay');34if (await applepayComponent.isAvailable()) {5applepayComponent.mount(applepayElement);6}
The payment attempt for the payment method specified in details.type
failed due to an unexpected failure.
Unexpected failures may occur when Flow integrates with a payment method's client-side library, or makes network requests to the payment method's endpoints.
If you persistently encounter the error for a specific payment method, this could be caused by your account configuration. For example, incomplete onboarding to a payment method. Contact your Account Manager or [email protected].
The payment request was declined.
The payment's ID is provided in the details.paymentId
property. You can fetch the details of the payment by performing a Get payment details request or searching for the payment record in the Dashboard.
The details.requestErrorCodes
property will contain one of the following error codes:
not_enough_funds
: the customer does not have enough funds for the transactioninvalid_payment_session_data
: invalid details were provided when creating the payment session, see the API reference for additional field detailsinvalid_customer_data
: invalid details were provided by the customermerchant_misconfiguration
: your account has invalid configurationstry_again
: the payment request was declined due to technical issues, contact your Account Manager or [email protected].
Flow automatically displays error messages to the customer, with suggested next actions to improve retry success.
The payment request failed due to unexpected error or network issue.
Any additional error codes from the network requests will be provided in the details.requestErrorCodes
property. See the possible error codes for the Payment endpoint for more details.
Customers can typically complete their payment after a retry.
If you persistently encounter the error for a specific payment method, this could be caused by your account configuration. Contact your Account Manager or [email protected].
The payment session response provided when initializing CheckoutWebComponent
was invalid.
After you create a payment session in your server-side integration, ensure you return the entire payment session response object to the client-side and provide it to Flow.