Prerequisite
- A Mangopay ClientId and API key (get a Sandbox API key for free)
- A User and their associated Wallet to complete the pay-in
- A card to register or payment method setup (see Testing - Payment methods for testing information)
Best practice – Check out our example appTo support you with your integration, be sure to make use of our example app on GitHub, which has a deployed demo.
Installation
You can install the Mangopay Checkout SDK using npm or yarn. Install with npm:Install via CDN
If you are using script tags to load files, include the Mangopay SDK script in your HTML:Warning – Load script from Mangopay Checkout domainTo maintain PCI compliance, the script must be loaded directly from the Mangopay Checkout domain:
http://checkout.mangopay.comThe script must not be bundled or hosted on other domains. You must reference it directly from our domain.
Content Security Policy (CSP)
Caution - Allow policies if using CSPIf your web page is using the Content-Security-Policy response header, you need to allow the policies below.
Policy | URLs |
---|---|
script-src | *.google.com |
connect-src | api.mangopay.comapi.sandbox.mangopay.com*.payline.com |
Initialization
Initialize the SDK and specify the configuration options.Example - Initialization
Initialization parameters
Property | Type | Description |
---|---|---|
elementOrSelector | HTMLElement | String REQUIRED | The container element or the selector of the container element. |
options | Object REQUIRED | The options of the Checkout SDK configuration. |
options
The child parameters of theoptions
object parameter:
Property | Type | Description |
---|---|---|
clientId | String REQUIRED | The unique identifier associated with the Mangopay API key, giving access to the Mangopay API. |
environment | String | The Mangopay environment. Allowed values: SANDBOX, PRODUCTION Default values: SANDBOX |
profilingMerchantId | String REQUIRED | The unique identifier associated with your fraud protection package. Contact Mangopay to obtain this value. |
amount | String REQUIRED | Information about the debited funds.The currency (ISO_4217 format) and value (expressed in minor units) of the debited funds. |
paymentMethods | Array REQUIRED | The payment methods presented to the user.Array of objects detailing the type and configuration options for specific payment methods. Each payment method includes configuration options tailored to its specific requirements. |
respectPaymentMethodsOrder | Boolean | Controls how payment methods are ordered and which one is initially active.When true , the SDK renders methods in the order provided by paymentMethods and the first item in that array becomes the initial selection.When false (default), card is rendered first and used as the initial selection; other methods are rendered in an order determined by the SDK.Default value: false |
branding | Object | The custom branding of the payment page (see Customization section below). |
locale | String | Object | The language for the payment page. Specify one of the built-in languages (en , fr ) or send an object with custom messages (see Customization section below). |
tenantId | String | The Mangopay tenant being used by the platform. Platforms that have contracted with Mangopay’s UK entity must set the value to UK .Allowed values: EU , UK
Default value: EU |
Configuration
Configure the MangopayCheckout parameters and delegates.Example - Vanilla JS
HTML
JavaScript
Example - ReactJS
JavaScript
MangopayCheckout parameters
Property | Type | Description |
---|---|---|
ref | React.RefObject<MangopayCheckoutForwardedRef> | React reference object: import { MangopayCheckoutForwardedRef } from '@mangopay/checkout-sdk-react'; |
onPaymentComplete | Function(event) | Triggered when the transaction is completed, whatever the outcome (whether successful or failed). |
options | Object | Checkout SDK configuration options |
disabled | Boolean | Applies a disabled state to the Checkout component such that user input is not accepted. |
onError | Function(event) | Triggered when an internal SDK error has occurred. |
onLoaded | Function(event) | Triggered when the Checkout SDK is loaded. |
onChange | Function(event) | Triggered when data exposed by the Checkout SDK is changed. |
onTokenizationComplete | Function(event) | Triggered when:
|
onPaymentComplete | Function(event) | Triggered when the transaction is completed, whatever the outcome (whether successful or failed). |
onCancel | Function() | Triggered when the payment process is canceled by the user. This can occur when the 3D Secure authentication window or PayPal, Google Pay, or Apple Pay popup is closed before completion. |
Updating options
After the SDK has been initialized you can update the options without needing to fully reinitialize again by using theupdateOptions
method. Make sure you pass a complete updated options
object as specified in the Configuration section.
Handling redirection
Warning – Use Mangopay Checkout domain as return URLWhen making the pay-in request from your backend, use the Mangopay Checkout URL as the
SecureModeReturnURL
or ReturnURL
(depending on the payment method):http://checkout.mangopay.comThe user must be returned to this URL after redirection.
options.onCreatePayment
function to request the transaction from your backend.
Subsequently, and when necessary for the transaction type, the Checkout SDK seamlessly manages additional redirect actions for 3DS authorization or otherwise validating the payment.
To manage transaction redirects effectively with the SDK:
1
Define onCreatePayment
In your
paymentMethods
configurations, define an options.onCreatePayment
attribute as a function.2
Within your function:
- Request a transaction from your server and subsequently, Mangopay.
- Return the unaltered transaction response object to the SDK.
3
The SDK:
- Redirects the user to the payment authentication page when necessary.
- Manages payment provider redirects back to the SDK.
- Triggers the
onPaymentComplete
event with the ID and status of the transaction. - Confirms the redirect result on your server by invoking the corresponding GET API of the transaction.
- Presents the payment result to the user.
Configuring card payments
To configure the card payment method, specifycard
as the type
of the paymentMethods
object. For the options
, use the following configuration parameters.
options
Property | Type | Description |
---|---|---|
options.supportedCardBrands | Array REQUIRED | The card brands supported. Allowed values: VISA, MASTERCARD, AMEX, MAESTRO, CB |
options.onCreateCardRegistration | Function REQUIRED | Use this attribute to request and return a Card Registration. |
options.onCreatePayment | Function REQUIRED | To handle 3DS redirects for card payments, use this attribute to request and return a pay-in. |
options.enableSaveCard | Boolean | If set to true , a Save Card checkbox will appear in the UI. When checked, SaveCard: true will be returned in the CreatePaymentData object, and you can forward this flag to your backend for further handling (read more about managing saved cards). |
options.savedCards | Array of SavedCard | A list of cards previously saved by the user. If provided, a button will appear within the card number input field that opens a dropdown of saved cards to select from. |
options.onDeactivateSavedCard | Function | A callback that is triggered when the user chooses to deactivate a saved card. Receives an object containing { cardId: string } . You can use this ID to inform your backend which card should be deactivated. |
Card configuration example
TypeScript
Card tokenization
In theoptions
for the card payment method, create a function to handle creation of Card Registration event handler in the paymentMethods
object:
- Your
onCreateCardRegistration
function calls your server, and passes it the card brand of the user. - Your server makes a request to Create a Card Registration.
- In response, your server receives a Card Registration object.
- In your
onCreateCardRegistration
function, return the unmodified Card Registration object to the SDK. - The SDK tokenizes the card and updates the Card Registration object to create the
CardId
which is used for payment.
TypeScript
tokenizationComplete output
REST
Requesting card pay-ins
You can use a registered card (CardId
) for requests with the following API objects:
- The Card Validation object, to validate a card without debit
- The Direct Card PayIn object, for one-shot card payments
- The Recurring PayIn Registration object, for recurring card payments
- The Preauthorization object, for 7-day preauthorized card payments
- The Deposit Preauthorization object, for 30-day preauthorized card payments
- Ensure that the
SecureModeReturnURL
parameter is set tohttps://checkout.mangopay.com
- Submit the
PreferredCardNetwork
value if it was received byonCreatePayment
Managing saved cards
The Checkout SDK can allow the user to save their card for a future payment.1
Enable saving cards
To enable saving cards, set
enableSaveCard
to true
to present a Save card checkbox on the user interface.2
Deactivate if card not saved
If the user doesn’t check the box, then the
CreatePaymentData
object returns SaveCard : false
. In this case, you must systematically call PUT Deactivate or edit a Card to deactivate it in the Mangopay API.3
If saved, store tokenized card in your system
If the user checks the box, the
SaveCard
flag is set to true
and passed to your onCreatePayment
handler. You can then store the card object in your system.4
Re-use saved cards
To present the user’s saved cards in the next payment session, send an array of card objects in the
savedCards
array in the payment method configuration.If sent, then a dropdown appears in the interface in the card number input field. When a saved card is selected, the SDK uses it for the payment process.5
Deactivate card if user removes it
In the dropdown, there is an option for the user to remove a saved card. In this case, the
onDeactivateSavedCard
is triggered and you must:- Remove the card in your system
- Call PUT Deactivate or edit a Card to deactivate it in the Mangopay API
Caution - Deactivate card systematically unless user saves itUnder no circumstances should card information be kept without the end user’s approval.If
CreatePaymentData
returns SaveCard : false
, indicating the user doesn’t wish to save it, then you must call PUT Deactivate or edit a Card to deactivate it in the Mangopay API.The same is true if the onDeactivateSavedCard
is triggered, indicating that the user wishes to remove the card.Diagram - Saved cards
The following diagram shows the flow of managing saved cards:Saved card example
TypeScript
Configuring Apple Pay
Note - Apple Pay integration requiredOffering Apple Pay requires additional setup by the platform, including certification and integration. For more information, see the Apple Pay guide.
Caution - Apple Pay on the Web availabilityApple Pay on the Web, using the JavaScript Checkout SDK, is only available on Mac and iOS devices. Apple Pay on the Web also requires additional certification.
apple_pay
as the type
of the paymentMethods
object. For the options
, use the following configuration parameters.
Apple Pay configuration options
Property | Type | Description |
---|---|---|
paymentRequest | Object REQUIRED | The specifications of the payment request. |
onCreatePayment | Function REQUIRED | Function called after the user has successfully authenticated a card for payment from the Apple Pay sheet. Use this attribute to implement backend creation of the Apple Pay PayIn from your server. After creating the pay-in, return the pay-in object to the SDK. |
paymentRequest
Property | Type | Description |
---|---|---|
countryCode | String REQUIRED | The platform’s two-letter ISO 3166 country code. |
currencyCode | String REQUIRED | The three-letter ISO 4217 code (EUR, GBP, etc) of a supported currency (depends on feature, contract, and activation settings). |
merchantCapabilities | Array REQUIRED | Information about the card types and authentication protocols you support (see Apple Pay documentation). |
supportedNetworks | Array REQUIRED | The card networks supported by MangopayAllowed values: visa , masterCard |
total | Object REQUIRED | The line item total for the payment (see Apple Pay documentation). |
merchantIdentifier | String REQUIRED | Your platform’s Apple Pay Merchant ID. |
merchantName | String REQUIRED | The name of your platform. |
onValidateMerchant | Function REQUIRED | Use this attribute to request and return a ApplePay session. Function called when the SDK receives an onvalidatemerchant merchant event from the Apple Pay sheet. The assigned function should implement backend creation of the merchant session object from your server. After creating the session object, return the session object to the SDK. |
requiredBillingContactFields | Array REQUIRED | The billing information to fulfill the order (see Apple Pay documentation). |
Requesting the merchant session from your server
Displaying the Apple Pay payment sheet using the Mangopay Checkout SDK works as follows:- You generate the merchant session from your server
- The SDK’s
onValidateMerchant
function calls your server and passes it the static hostnameapple-pay-gateway.apple.com
as the validation URL. In the China region, usecn-apple-pay-gateway.apple.com
. - Your server uses the validation URL to request a session from the Apple Pay server, as described in Requesting an Apple Pay Payment Session.
- In the response, your server receives an opaque merchant session object:
MerchantSession
. - You pass the merchant session object to the
completeMerchantValidation
method of the SDK (see Apple Pay documentation for more information on this method).
Requesting Apple Pay pay-in
To request the payment, use the Create an Apple Pay PayIn endpoint and include the Apple PayPaymentData
.
- Set up payment delegate – Assign a delegate function to the
onCreatePayment
attribute in your Apple Pay options. - Handle payment authorization – After the user successfully authorizes a card for payment through the Apple Pay sheet, the SDK will call your
onCreatePayment
function and pass thePaymentData
to it. - Create pay-in – Implement the backend creation of the Apple Pay PayIn on your server using the
PaymentData
provided. - Return pay-in object – After creating the pay-in, return the pay-in object to the SDK.
Apple Pay configuration example
TypeScript
Configuring Google Pay
Note - Google Pay setup requiredOffering Google Pay requires additional setup by the platform. For more information, see the How to process a Google Pay payment tutorial.
Caution - Add Mangopay Checkout to your Google ConsoleYou need to add
checkout.mangopay.com
along with your domain to the authorized list in the Google Business Console to view the Google Pay payment popup.This allows the Checkout SDK to ensure the Google Pay experience is presented appropriately to your users. Not following this guidance may impact your payment acceptance on Google Pay.google_pay
as the type
of the paymentMethods
object. For the options
, use the following configuration parameters.
Google Pay configuration options
Property | Type | Description |
---|---|---|
merchantInfo.merchantId | String REQUIRED | Your Google Pay Business ID, which you can find in Google Pay & Wallet Console. |
merchantInfo.merchantName | String REQUIRED | Your Google Pay Business Name, which you can find in Google Pay & Wallet Console. |
gateway | String REQUIRED | The orchestration used: in this case, whenthen. Allowed values: whenthen |
gatewayMerchantId | String REQUIRED | Your Mangopay ClientId . |
cardParameters.allowedAuthMethods | Array REQUIRED | The supported authentication methods: PAN_ONLY, meaning the card is registered in the user’s Google account and requires additional authentication; CRYPTOGRAM_3DS, meaning the card is enrolled in the customer’s Google Wallet and authentication is handled by Google, with no 3DS redirection and no liability for the platform. Allowed values: PAN_ONLY, CRYPTOGRAM_3DS |
cardParameters.allowedCardNetworks | Array REQUIRED | The card networks supported by Mangopay.Allowed values: VISA, MASTERCARD |
transactionInfo | Object REQUIRED | Information about the transaction and its authorization, such as whether the user agrees to the transaction, the total price and price status. For more information on this object parameter, see the Google Pay documentation. |
onCreatePayment | Function REQUIRED | Function called after the user has successfully authorized a card for payment from the Google Pay sheet.The assigned function should implement backend creation of the Google Pay PayIn from your server. After creating the pay-in, return the pay-in object to the SDK. |
button.buttonColor | String | The color of the button.Default value: defaultAllowed values:
|
button.buttonType | String | The type of the button, determining the text to display.Default value: buyAllowed values:
|
button.buttonLocale | String | The ISO 639-1 code representing the desired button language.Default value: The browser or operating system language settings.Allowed values: en, ar, bg, ca, cs, da, de, el, es, et, fi, fr, hr, id, it, ja, ko, ms, nl, no, pl, pt, ru, sk, sl, sr, sv, th, tr, uk, and zh. |
Obtaining Google Pay token
TheonTokenizationComplete
function is called after the user approves the payment on the Google Pay form. The output contains the paymentData
object (see Google Pay documentation) which is needed to request the Google Pay payment via the API from your backend.
Requesting Google Pay pay-in
To request the payment, use the Create a Google Pay PayIn endpoint. Include the Google PayPaymentData
and ensure that the SecureModeReturnURL
parameter is set to https://checkout.mangopay.com
.
- Set up payment delegate – Assign a delegate function to the
onCreatePayment
attribute in your Google Pay options. - Handle payment authorization – After the user successfully authorizes a card for payment through the Google Pay sheet, the SDK will call your
onCreatePayment
function and pass thePaymentData
to it. - Create pay-in – Implement the backend creation of the Google Pay PayIn on your server using the
PaymentData
provided. - Return pay-in object – After creating the pay-in, return the pay-in object to the SDK.
Google Pay configuration example
Configuring PayPal
Note – PayPal setup requiredOffering PayPal requires approval from PayPal and activation. For more information, see the PayPal article.
PayPal configuration options
To configure PayPal, specifypaypal
as the type
of the paymentMethods
object. For the options
, use the following configuration parameters.
Property | Type | Description |
---|---|---|
options.onCreatePayment | Function REQUIRED | Use this attribute to request and return a PayPal pay-in.The assigned function should implement backend creation of the PayPal pay-in from your server. |
options.merchantId | string REQUIRED | Unique identifier for your PayPal business account, required to process pay-ins.
|
PayPal configuration example
Requesting PayPal pay-in
To request the payment, use the Create a PayPal PayIn endpoint. Ensure that theReturnURL
parameter is set to https://checkout.mangopay.com
.
Obtaining browser info for a pay-in
ThebrowserInfo
object is required when submitting a pay-in request. To get the required values for the transaction, use the getBrowserInfo
function from the Checkout SDK instance. Pass on the values to your server.
Verifying the payment result
Once theonPaymentComplete
event is triggered, verify the status of the relevant Mangopay API object:
Caution – Check payment result from backendYou should confirm the transaction result returned by the Checkout SDK by calling the Mangopay API from your backend.
Verify payment result
Showing and dismissing the loading spinner
When processing a token request, the SDK shows a loading spinner and retains it until the loading state is set tofalse
. This provides a temporary state for the user until the full payment is complete, including calls from your platform’s backend.
The setLoading
method handles the loading state for displaying and dismissing the spinner.
Using Card Element
Card Element is a ready-made component that allows you to create your own card payment experience and tokenize card payment details. With Card Element, you can incorporate a custom pay button and have control over the tokenization process. When using Card Element, you still benefit from card data validation, and the ability to customize the payment form. Initialize thecardFormElement
with your ClientId
and select your environment (Sandbox or Production).
cardFormElement-specific options
Property | Type | Description |
---|---|---|
paymentMethod | Object | The payment method used with the card form element. Only 'card' is supported. See Configuring card payments section for details |
Vanilla JS usage example
HTML
TypeScript
ReactJS usage example
TypeScript
Branding
You can customize the appearance of the checkout using thebranding
object.
TypeScript - Branding example
Theme variables and rules
You can use therules
and variables
objects for further customization.
Variables
Variables are CSS variables that you can declare and use in your theme rules.TypeScript
Rules
Rules allows you to apply CSS styles to Checkout SDK components. To do so, target components by class names, with or without the CSS class selector prefix (FieldContainer
or .FieldContainer
), and specify the styles to apply. The feature supports all native CSS properties and nesting.
TypeScript
Localization
Mangopay Checkout SDK has built-in localization support for: DE, EN, ES, FR, NL, PTTypeScript
customLanguage
object.