Checkout Experience

The Checkout Experience can handle various use cases:

One Off Payment

This form collects the payer's information (name, etc.) and then asks the payer to pick a payment method. Depending on the payment method, it either asks the payer for their card details, bank account details, or to make a bank transfer.

This form is for one time payments, which means, card or bank account details are not being stored.

Customization Options

When creating a Checkout Session, you have the option to configure the form to skip the payer information page.

 

Fonts

Colors

 

Hide fields

Hide payer page

Action button label

Locale

 

Hide Flywire logo

Rendering via Javascript (with API)
 
 
 
 
 
 
 
Rendering via iframe
 
 
 
 
 
 
 

Checkout Session Settings

Checkout Session type one_off
Checkout Session schema one_off
For details see Checkout for One Off Payments

Fields

The payer information fields can be pre-filled when creating a Checkout Session.

First name

Parameter to pre-fill this field: payor.first_name

 

Last name

Parameter to pre-fill this field: payor.last_name

 

Email

Parameter to pre-fill this field: payor.email

 

City

Parameter to pre-fill this field: payor.city

 

Country

Parameter to pre-fill this field: payor.country

 

State

Parameter to pre-fill this field: payor.state

This field is only displayed when the country is “United States” or “China”. When it is displayed, it is required.

 

Address

Parameter to pre-fill this field: payor.address

 

Post code

Parameter to pre-fill this field: payor.zip

 

Phone number

Parameter to pre-fill this field: payor.phone

 

Action Button

Action button that sends the form.

 

Flywire-managed recurring payments

This form collects the payer's information (name, etc.) and then asks the payer to pick their desired installment plan.

Customization Options

When creating a Checkout Session, you have the option to configure the form to skip the payer information page.

 

Fonts

Colors

 

Hide fields

Hide payer page

Action button label

Locale

 

Hide Flywire logo

Rendering via Javascript (with API)
 
 
 
 
 
 
 
Rendering via iframe
 
 
 
 
 
 
 

Checkout Session Settings

Checkout Session type recurring
Checkout Session schema none - parameter has to be left out
For details see Creating a Checkout Session for Flywire-Managed Recurring Payments

Fields

The payer information fields can be pre-filled when creating a Checkout Session.

First name

Parameter to pre-fill this field: payor.first_name

 

Last name

Parameter to pre-fill this field: payor.last_name

 

Email

Parameter to pre-fill this field: payor.email

 

City

Parameter to pre-fill this field: payor.city

 

Country

Parameter to pre-fill this field: payor.country

 

State

Parameter to pre-fill this field: payor.state

This field is only displayed when the country is “United States” or “China”. When it is displayed, it is required.

 

Address

Parameter to pre-fill this field: payor.address

 

Post code

Parameter to pre-fill this field: payor.zip

 

Phone number

Parameter to pre-fill this field: payor.phone

 

Action Button

Action button that sends the form.

 

Implementing the Checkout Experience

Example page

CSS

Add CSS to adjust the layout of the form in the iframe.

iframe

Source

You’ll get the hostedFormUrl from the response after you created a Checkout Session.

See Example for getting the hostedFormUrl for an example of where to find the url.

Dimensions

Give the iframe a fixed height and width to avoid it filling up the whole screen.

Event listener

Implement an event listener in the parent window to receive the postMessages after the form is completed.

See Example for a postMessage of the event listener for an example.

<!DOCTYPE html>
<head>
    <style>
        .my-iframe {
            padding: 18px;
            margin: 32px 0px;
            background: #FFFFFF;
        }
    </style>
</head>
<body>

    <!-- iframe to display the Flywire form -->
    <iframe
        src="{hostedFormUrl}"
        id="flywireform"
        title="Flywire Payment Form"
        class="my-iframe"
        height="928"
        width="660">
    </iframe>

    <script>
     window.addEventListener("message", (event) => {
    // IMPORTANT: Verify the origin of the data to ensure it is from Flywire
    // The use of indexOf ensures that the origin ends with ".flywire.com"
    if (event.origin.indexOf(".flywire.com")) {
        // If the message was sent from Flywire:
        // Extract the data from the event
        const result = event.data;
        if (result.source !== 'checkout_session') {
            return;
        }

        // Check if the session was successful and confirm_url is present:
        if (result.success && result.confirm_url) {
            // The session was successful and the confirm_url has been returned
            const confirm_url = result.confirm_url;
            console.log(result);
            // Use the confirm_url to confirm the Checkout Session
            console.log("Confirm URL:", confirm_url.url);
        } else {
            // Handle failure accordingly
            console.error("Session unsuccessful or confirm_url missing.");
        }
    }
});
    </script>
</body>
</html>

Example for getting the hostedFormUrl

This is a response after creating a Checkout Session that contains the url you need to provide under src="{hostedFormUrl}":

hosted_form object

Only relevant when you render the form via iframe. More info:

warnings array

errors array

You can decide which information from the response you want to filter out in your backend before passing the URL to your frontend.

{
"id": "494d2e9d-c0c9-407c-9094-5b3b2a02c00f",
"expires_in_seconds": 1800,
"hosted_form": {
	"url": "https://payment-checkout-dev-apache.flywire.cc/v1/form?session_id=494d2e9d-c0c9-407c-9094-5b3b2a02c00f",
	"method": "GET"
},
"warnings": []
}

Example for a postMessage of the event listener

After your payer sent the form, the event listener will return a successful postMessage.

A successful postMessage confirms that the form was submitted and that you can confirm the Checkout Session now. However, it does not indicate payment success. Payment status updates will be sent via callback notifications, see Payment Status Notifications for details.

The postMessage contains the following information:

confirm_url object

Contains the confirm URL. The confirm URL is the full url for the request to confirm the session, already resolved with the correct session ID.

payor object

The email address your payer entered in the UI Form. You need to use this email address to send mandatory emails to your payer, see

Make sure you use the email address you got via the postMessage for the emails to your payer. Even if you already have an email address in your system, your payer might have updated the email address in the UI Form.
{
confirm_url: {
	method: "POST",
	url: "https://api-platform.flywire.com/payments/v1/checkout/sessions/494d2e9d-c0c9-407c-9094-5b3b2a02c00f/confirm",
},
payor: {
email: "[email protected]"
},
source: "checkout_session",
success: true
}

Example page

SDK script

Add the Flywire SDK script in the header of your page:

Production:

https://artifacts.flywire.com/sdk/js/v0/main.js

Sandbox:

https://artifacts.flywire.com/sdk/js/v0/sandbox.main.js

Container

Only if you embed Checkout Experience within a container. Define a container where the Checkout Experience will be rendered.

Configuration script

Initialize the Flywire SDK with your frontend key

You receive the frontend key together with your other credentials when you register for the Flywire API.

Create the form

Must be payment.

Load the Checkout Experience via the session ID, see Configuration.

Set the display mode, see Configuration.

Event listeners

Define what happens after the element is closed, see Event listeners for a detailed example.

Mount

See Mounting.

<!DOCTYPE html>
<head>
    <script src="https://artifacts.flywire.com/sdk/js/v0/sandbox.main.js"></script>
</head>
<body>
    <div id="my-container-id"></div>
						
    <script type="module" crossorigin="anonymous" async type="text/javascript">
        (async () => {
            var sdk = await window.FlywireSDK(
                "your-frontend-key-here" // Replace with your actual frontend key
            );
	
	var elements = await sdk.elements();			
	var checkout = await elements.create("payment", {
		sessionId: "your-session-id-here", // Replace with your actual session ID
		displayMode: "container"				
  	});
					
     checkout.onEvent("success", handleSuccess); // Handle success event
     checkout.onEvent("error", handleError);    // Handle error event
						
   	 checkout.mount("my-container-id"); // Mount the element to the container

    })();
    </script>
</body>
</html>

Configuration

Session ID

To get a session ID, you need to create a Checkout Session, see:

Display Mode

There are two different display modes:

  • container: To embed the element in a container in your website.

  • full-screen: To display the element in a pop-up (a modal that covers the full-screen with a background)

If you don't provide this value, the default is full-screen.

You need to also ensure you are using the right settings for Mounting depending on the display mode.
var element = await elements.create("payment", {
	sessionId: "your-session-id-here", // Replace with your actual session ID
	displayMode: "container"

Event listeners

There are two key events you need to set up event listeners for:

Success Event (success)

This event is triggered when the element was sent successfully.

 

Optionally: Display a custom success message to your payer.

Mandatory: Send the postMessage data to your backend. The postMessage contains the confirm URL you need to confirm the Checkout Session, see The postMessage of the Event Listener.

A successful postMessage confirms that the form was submitted and that you can confirm the Checkout Session now. However, it does not indicate payment success. Payment status updates will be sent via callback notifications, see Payment Status Notifications for details.

Error Event (error)

This event is triggered when there was an error or when the payer closed the element.

Optionally: Display a custom error message to your payer.

Mandatory: Send the error message to your backend for troubleshooting.

// Success event handler
element.onEvent("success", (sessionResult) => {
    // Custom success message for your payer
    const customSuccessMessage = "Your payment was successful.";

    // Send the session result to the backend
    fetch('/your-backend-endpoint', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify(sessionResult),
    });

    // Show the custom success message to the payer
    alert(customSuccessMessage);
}); 

// Error event handler
element.onEvent("error", (error) => {
    // Custom error message for your payer
    const customErrorMessage = "Something went wrong. Please try again.";

    // Send the error details to the backend
    fetch('/your-backend-endpoint', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
        },
        body: JSON.stringify(error),
    });

    // Show the custom error message to the payer
    alert(customErrorMessage);
});

Mounting

Mounting as a pop-up in a full-screen overlay

For mounting the Checkout Experience as a full-screen pop-up, the displayMode must be set to full-screen (see Configuration). Don't specify a container ID, simply use the mount function.

 

element.mount(); // Mount the element as a pop-up in a full screen overlay 

Mounting in a container

When you are mounting the Checkout Experience in a container, you need to state a container ID here and ensure to include a container with the same ID on your website .

If you provided a valid container ID and the element still gets rendered as a pop-up, check your displayMode settings. It must be set to container, not full-screen (see Configuration).

checkout.mount("my-container-id"); // Mount the element to the container