Payment Element

The payment element can process payments with different payment methods.

How to control which payment method gets rendered

The payment elements requires you to create a Checkout Session first. The type of Checkout Session you create determines which payment method gets rendered. For example, creating a Checkout Session for "card tokenization" renders the "card tokenization" payment element.

  • For Smart Rendering: The mapping between the Checkout Session type and the payment element is determined by the session ID used when creating the element.

  • For iframe Rendering: After creating a Checkout Session, the hosted-form-URL specifies which payment element is rendered in the iframe.

For Cards

Card tokenization (save card)

This form collects the payer and card details. The data is then saved as a payment method token and mandate ID for future payments. No payment is being made with this form, which is why it doesn't show a payment amount.

Customization Options

 

Fonts

Colors

 

Hide fields

Action button label

Locale

 

Hide Flywire logo

Smart Rendering
 
 
 
 
 
 
iframe Rendering
 
 
 
 
 
 

Checkout Session Settings

Checkout Session type tokenization
Checkout Session schema cards
For details see

Checkout for Self-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

 

Card Number

The field only accepts valid card numbers.

 

Expiry Date (MM/YY)

The expiry date (can’t be in the past).

 

CVV

The CVV of the card.

 

Card Element

Terms and conditions

Mandatory and/or optional checkboxes the payer has to tick before they can send the form. The checkboxes and their content depend on the payment method and other factors.

 

Action Button

Action button that sends the form.

 

Card tokenization and pay (save card and make payment)

This form collects the payer and card details, and immediately makes the first payment. The data is then saved as a payment method token and mandate ID for future payments

Customization Options

 

Fonts

Colors

 

Hide fields

Action button label

Locale

 

Hide Flywire logo

Smart Rendering
 
 
 
 
 
 
iframe Rendering
 
 
 
 
 
 

Checkout Session Settings

Checkout Session type tokenization_and_pay
Checkout Session schema cards
For details see

Checkout for Self-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

 

Card Number

The field only accepts valid card numbers.

 

Expiry Date (MM/YY)

The expiry date (can’t be in the past).

 

CVV

The CVV of the card.

 

Card Element

Amount

The amount your payer pays in their currency and the amount you receive in your currency. If your payer pays in a different currency, they get a breakdown about how the exchange rate is calculated.

 

Terms and conditions

Mandatory and/or optional checkboxes the payer has to tick before they can send the form. The checkboxes and their content depend on the payment method and other factors.

 

Action Button

Action button that sends the form.

 

Card new mandate (use existing card for different plan)

This form allows the payer to confirm their card's CVV to create a new mandate ID for recurring payments. It uses a saved card (which already has a payment method token) for a different plan (which requires a new mandate). The payer simply re-enters the CVV to prove consent for the new mandate.

Customization Options

 

Fonts

Colors

 

Action button label

Locale

 

Hide Flywire logo

Smart Rendering
 
 
 
 
 
iframe Rendering
 
 
 
 
 

Checkout Session Settings

Checkout Session type new_mandate
Checkout Session schema cards
For details see Creating a Checkout Session for Self-Managed Recurring Payments

Fields

First name

The payer's first name (read-only)

 

Last name

The payer's last name (read-only)

 

Card details

The card details (read-only)

 

CVV

The CVV of the card.

 

Charging information

Information for the payer.

 

Action Button

Action button that sends the form.

 

Pre-Authorization Payment

This form collects the payer and card details. The funds are being reserved on the card and you can capture them later.

Customization Options

 

Fonts

Colors

 

Hide fields

Action button label

Locale

 

Hide Flywire logo

Smart Rendering
 
 
 
 
 
 
iframe Rendering
 
 
 
 
 
 

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

 

Card Number

The field only accepts valid card numbers.

 

Expiry Date (MM/YY)

The expiry date (can’t be in the past).

 

CVV

The CVV of the card.

 

Card Element

Amount

The amount your payer pays in their currency and the amount you receive in your currency. If your payer pays in a different currency, they get a breakdown about how the exchange rate is calculated.

 

Terms and conditions

Mandatory and/or optional checkboxes the payer has to tick before they can send the form. The checkboxes and their content depend on the payment method and other factors.

 

Action Button

Action button that sends the form.

 

For Direct Debit

Direct debit tokenization (save bank account)

This form collects the payer and bank account details. The data is then saved as a payment method token and mandate ID for future payments. No payment is being made with this form, which is why it doesn't show a payment amount.

Customization Options

 

Fonts

Colors

 

Hide fields

Action button label

Locale

 

Hide Flywire logo

Smart Rendering
 
 
 
 
 
 
iframe Rendering
 
 
 
 
 
 

Checkout Session Settings

Checkout Session type tokenization
Checkout Session schema dd_sepa or dd_bacs or dd_eft or dd_ach
For details see

Checkout for Self-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

 

IBAN

Only shown for for SEPA.

 

BIC code

Only shown for SEPA when a NON-EEA country is selected.

 

Routing number

Only shown for for ACH.

 

Account number

Only shown for ACH.

 

Account type

Only shown for ACH.

Either checking or savings account.

 

Account number

Only shown for for BACS.

 

Sort code

Only shown for BACS.

 

Terms and conditions

Mandatory and/or optional checkboxes the payer has to tick before they can send the form. The checkboxes and their content depend on the payment method and other factors.

 

Action Button

Action button that sends the form.

 

Direct debit tokenization and pay (save bank account and make payment)

This form collects the payer and bank account details, and immediately makes the first payment. The data is then saved as a payment method token and mandate ID for future payments.

Supported direct debit schemes:

  • SEPA

Customization Options

 

Fonts

Colors

 

Hide fields

Action button label

Locale

 

Hide Flywire logo

Smart Rendering
 
 
 
 
 
 
iframe Rendering
 
 
 
 
 
 

Checkout Session Settings

Checkout Session type tokenization_and_pay
Checkout Session schema dd_sepa
For details see

Checkout for Self-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

 

IBAN

Only shown for for SEPA.

 

BIC code

Only shown for SEPA when a NON-EEA country is selected.

 

Amount

The amount your payer pays in their currency and the amount you receive in your currency. If your payer pays in a different currency, they get a breakdown about how the exchange rate is calculated.

 

Terms and conditions

Mandatory and/or optional checkboxes the payer has to tick before they can send the form. The checkboxes and their content depend on the payment method and other factors.

 

Action Button

Action button that sends the form.

 

 

Implementing the Payment Element

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 the element within a container. Define a container where the element 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.

Define the appearance of the element

See Element appearance.

Create and configure the element

Which element do you want to create?

Available elements:

Load the type of the payment element via the session ID.

See Element configuration.

How do you want to display the elements?

See Element configuration.

Which fields do you want to display?

See Element configuration.

Event listeners

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

<!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({
    appearance: {
        fonts: [
            {
                url: "https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700&amp;display=swap",
                fontFamily: "Roboto",
            },
        ],
        variables: { primaryColor: "#5a81f0" },
    },
    locale: "en",
});
             
    var element = await elements.create("payment", {
    sessionId: "your-session-id-here", // Replace with your actual session ID
    displayMode: "container",
    fields: {
        first_name: { hidden: false },
        last_name: { hidden: false },
        country: { hidden: true },
        address: { hidden: true },
        city: { hidden: true },
        phone: { hidden: false },
        email: { hidden: false },
        state: { hidden: false },
        zip: { hidden: false },
    },
});
					
     element.onEvent("success", handleSuccess); // Handle success event
     element.onEvent("error", handleError);    // Handle error event
						
     element.mount("my-container-id"); // Mount the element to the container
        })();
    </script>
</body>
</html>

Element appearance

Fonts

Here you can customize the font of the element:

url string (url)

Provide a URL pointing to a Google Font or a URL from the same origin as your website.

For security reasons, only same-origin URLs and Google Font URLs are allowed.

fontFamily string

Specify the font family name as you would in a CSS stylesheet. This replaces the default font-family used in the element’s CSS.

Ensure the font family name matches the one defined in the URL.

Variables

primaryColor

Here you can customize the primary color of the element. Provide the hex value of the color you want to use.

Locale

Defines in which language the element is shown.

If you don't provide the locale, the default is English.

var elements = await sdk.elements({
    appearance: {
        fonts: [
            {
                url: "https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700&amp;display=swap",
                fontFamily: "Roboto",
            },
        ],
        variables: { primaryColor: "#5a81f0" },
    },
    locale: "en",
});

Element configuration

Session ID

When you are creating a payment element, the session ID is needed to determine which payment element gets rendered.

To get the session ID, you need to create a Checkout Session. The type of Checkout Session you create determines the type of payment element, for example creating a Checkout Session for "card tokenization" renders the "card tokenization" payment element.

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 the element depending on the display mode.

Fields

Here you can hide fields from being displayed in the element with the hidden parameter:

  • true: field will be hidden

  • false: field will be shown (default)

Not providing a field means the field will be shown.

All payer fields are mandatory for completing the payment. This means for hidden fields you must provide a valid value when you create the Checkout Session. If you don't provide a value or it is invalid, the field will be shown, even if it is set to hidden. This ensures that missing values don't block you from displaying the element.

Possible fields:

  • first_name

  • last_name

  • country

  • address

  • city

  • phone

  • email

  • state

  • zip

var element = await elements.create("payment", {
    sessionId: "your-session-id-here", // Replace with your actual session ID
    displayMode: "container",
    fields: {
        first_name: { hidden: false },
        last_name: { hidden: false },
        country: { hidden: true },
        address: { hidden: true },
        city: { hidden: true },
        phone: { hidden: false },
        email: { hidden: false },
        state: { hidden: false },
        zip: { hidden: false },
    },
});

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 the element

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

For mounting the element as a full-screen pop-up , the displayMode must be set to full-screen. 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 element 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.

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

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
}