Checkout Toolkit Integration
A checkout solution without the PCI-DSS compliance worry.
Checkout Toolkit has been specially designed to embed directly into your shopping cart payment fields to give your business more control over the entire checkout experience.
Tutorial: How to Build a Hosted Checkout Page and Embed a Checkout Toolkit
Looking for a quick start? This tutorial will walk you through the steps of building a hosted checkout page with Rapyd Checkout and then embedding it in your website using Rapyd’s Checkout Toolkit.
How to Integrate Checkout Toolkit
Companion Code Sample for Video: Checkout Toolkit Demo
Supported End-User Devices
The following end-user devices are supported:
Device | Description |
---|---|
Mobile Phone Browsers | Width is responsive and is supported from 320px onwards. For optimal readability, define the screen width. The height size is dynamic and changes according to the content. Note: Do not set a limit on the height. |
Desktop Browsers | Supports a width of 500px and above. The height size is dynamic and can change according to the content. Note: Do not set a limit on the height. |
Before embedding the iframe into your page, refer to Hosted Checkout Page Integration and follow steps 1 and 2 to create your Checkout Page.
Once you create the Checkout page, in the response to the Create Checkout Page, you’ll receive the ID of the checkout page object, a string starting with checkout_
, (for example: id: "checkout_9ebe58dcb9d75e8f972a35350f96c2fa").
Filtered for just one payment method type category
You need to specify one payment method type category in the Create Checkout request, or alternatively, one payment method type or one list of payment method types of the same category.
Add the following code to your checkout page:
Add a <script> tag with the URL of the Rapyd Checkout Toolkit:
<script src="https://checkouttoolkit.rapyd.net"></script>
Note
To run this method in the sandbox, use the following code:
<script src="https://sandboxcheckouttoolkit.rapyd.net"></script>
Add a <div> tag with id="rapyd-checkout":
<div id="rapyd-checkout"></div>
Initialize the Checkout Page object with the following fields:
JavaScript
Instantiating ‘checkout’ with parametersInstantiating 'checkout' & setting variables let checkout = new RapydCheckoutToolkit({ pay_button_text: "Click to pay", // Text that appears on the 'Pay' button. // String. Maximum length is 16 characters. // Default is "Place Your Order". Optional. pay_button_color: "blue", // Color of the 'Pay' button. String. // Standard CSS color name or hexadecimal code such as #323fff. // Default is the color that is returned in the 'merchant_color' // field of the response to 'Create Checkout Page'. Optional. id: "checkout_9ebe58dcb9d75e8f972a35350f96c2fa", // ID of the 'Create Checkout Page' response. String. Required. wait_on_payment_confirmation: false, // Default is 'false'. Optional. // You can keep the Toolkit open in a pending state. // The iframe will close when the payment session has been completed. // The timeout is set to 10 minutes. wait_on_payment_redirect: false, // Default is 'false'. Optional. // The iframe will close when the payment session has been completed. // The user will redirect to complete the 3DS Verification. hide_submit_button: false, // Default is 'false'. Optional. // The submit button will not be visible if set to 'true'. (See CHECKOUT_SUBMIT_PAYMENT event). // This is relevant only for the Checkout Toolkit (not other toolkit solutions). close_on_complete: true, // Causes the embedded Rapyd Checkout Toolkit window to close // When the payment is complete. Boolean. Default is 'true'. Optional. page_type: “collection” // Default is "collection". Optional. });
Call display Checkout() to display the checkout page.
checkout.displayCheckout();
Optional step. If
close_on_complete
is set to false, callcheckout.closeCheckout()
to close the Rapyd Checkout Toolkit window.checkout.closeCheckout();
Optional Step. You can pass the
hide_submit_payment
field as 'true' in order to hide the submit payment button created by the Rapyd Checkout Toolkit. Then, by triggering theCHECKOUT_SUBMIT_PAYMENT
event, you can manage the submit button. Relevant only for Checkout Toolkit.JavaScript
const iframeElement = document.getElementById('rapyd-checkout-frame'); iframeElement.contentWindow.postMessage({type: "CHECKOUT_SUBMIT_PAYMENT"}, '*');
Insert your code that runs when the following events occur. Use your code to read the event field in the window object.
JavaScript
window.addEventListener('onCheckoutPaymentSuccess', (event) => { console.log(event.detail) // Returns 'Payment' object. // Client code. }) window.addEventListener('onCheckoutPaymentFailure', (event) => { console.error(event.detail.error) // Returns an error message from the API. // Client code. }) window.addEventListener('onLoading', (event) => { console.log(event.detail.loading) // returns true or false depending on the loading state // client code }) window.addEventListener('onCheckoutPaymentPending', (event) => { console.log(event.detail) // Returns 'Payment' object. // Client code. }) window.addEventListener('onCheckoutPaymentExpired', (event) => { console.error(event.detail.error) // Returns a constant error message // The event is triggered when the payment status is 'EXP'. // "CHECKOUT_PAYMENT_EXPIRED" }) window.addEventListener('onCheckoutUpdateCardSuccess', (event) => { console.log(event.detail) // Returns payment method object. // client code }) window.addEventListener('onCheckoutDeleteCardSuccess', (event) => { console.log(event.detail) // Returns deleted payment method object. // client code
Here's an example of a Rapyd Checkout page created using the Toolkit:
HTML
HTML <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Rapyd Checkout Toolkit</title> <script src="https://checkouttoolkit.rapyd.net"></script> <script> window.onload = function () { let checkout = new RapydCheckoutToolkit({ pay_button_text: "Click to pay", pay_button_color: "blue", id: "checkout_9ebe58dcb9d75e8f972a35350f96c2fa" }); checkout.displayCheckout(); } window.addEventListener('onCheckoutPaymentSuccess', function (event) { console.log(event.detail) }); window.addEventListener('onCheckoutPaymentFailure', function (event) { console.log(event.detail.error) }); </script> </head> <body style="background-color: #f1f1f1; display: flex; align-items: center; flex-direction: column; margin: 0"> <h1>Rapyd Checkout Toolkit Demo</h1> <div style="width: 500px" id="rapyd-checkout"></div> </body> </html>
On successful payment, the clients receive a onCheckoutPaymentSuccess
event with the payment object.
Note the following fields and the tasks associated with each of them.
Payment Object Fields
Field | Description | Action |
---|---|---|
status | Indicates the status of the payment (Read-only). Responses - (One of the following):
| You can use this field to check the payment status, whether it is active, awaiting completion, or closed and paid. |
redirect_url | Third party URL where the customer is supposed to complete the payment, for example: card payments with 3DS authentication, bank redirect payments, redirect to eWallets. |
|
instructions | Describes the required steps that the customer should take for completing the payment. (Read-only). | When the payment status is ACT and instructions are provided, you can display them to the customer. |
textual_codes | A text code or a set of text codes for the customer to use to complete the steps described in the instructions field. (Read-only). | When the payment status is ACT and textual_codes are provided, display them along with the key and value to the customer. |
visual_codes | An image or a set of images for the customer to use to complete the steps described in the instructions field, for example, a QR code or barcode. (Read-only). | When the payment status is ACT and visual_codes are provided, display them along with the key and value to the customer.
|
Recommendation: Be sure to implement navigation elements (e.g. back, return, or cancel) on your website when embedding the Toolkit Integration solution.
You can use the toolkit to tailor your Checkout page according to your preference.
Translations
You have the option of changing the default language of your payment page to any of the currently available languages in the list below:
Simplified Chinese | Traditional Chinese | English |
Estonian | German | Greek |
Hindi | Icelandic | Indonesian |
Italian | Japanese | Korean |
Bahasa Malayu (Malaysian) | Lithuanian | Russian |
Portuguese | Slovak | Slovenian |
Spanish | Thai | Turkish |
Tagalog | Ukrainian | Vietnamese |
Danish |
Specify it in the language parameter field when generating the Checkout page.
Note: See the full list of languages at Hosted Page Language Support.
Pending Status for the Checkout Toolkit
You can pass the wait_on_payment confirmation
field as 'true' to keep the iframe open in a pending state. The onCheckoutPaymentPending
event is triggered, which returns the payment object. The user is redirected to a pending status page while they complete their payment. Pay codes or instructions are displayed if they are present in the payment object.
The pending status page has a default timeout of 10 minutes. The iframe is then closed and the onCheckoutPaymentExpired
event is triggered if the payment is not completed within that timeframe.
The merchant can pass the payment_expiration
parameter for the Create Checkout Page request to shorten the 10 minute payment timeframe.
Note: Do not set a limit on the height.
3DS Authentication Redirect
You can pass the wait_on_payment_redirect
field as 'true' to apply a checkout experience for card payments with 3DS verification included. The onCheckoutPaymentPending
event is triggered, which returns the payment object. The user is redirected and completes the 3DS verification.
The iframe closes when the onCheckoutPaymentSuccess
event is triggered when the payment is completed, or if the onCheckoutPaymentFailure
event is triggered if the payment is incomplete or an error is encountered.
Custom CSS
Elements
The table below lists all the available elements:
Description of Body Parameters
Body Parameter | Description |
---|---|
tooltip | Tooltips, used for displaying extra information about certain fields, e.g. CVV Code in card payments |
submit | Submit button |
input | Input fields |
dropdown | Drop down lists |
clear | Clear button, used for clearing the input in input fields and drop down lists |
global | An element designed for general configurations Note: See below for more details |
Global Elements
fonts array: global.fonts is an array of custom fonts, which can hold either a url or an object, as seen in the example below. The family set in global.fonts can be used in the fontFamily CSS property.
CSS
global = { fonts: [ "https://fonts.googleapis.com/css2?family=Mulish:wght@200&display=swap", { family: 'myCustomFont', src: '/fonts/myCustomFontRegular.woff2', fontWeight: 400 }, { family: 'myCustomFont', src: '/fonts/myCustomFontBold.woff2', fontWeight: 700 } ] }
fontSizes: the configured sizes apply to all the texts in Checkout Toolkit. You can override the global.fontSizes by configuring fonts per element. The fontSizes supports every CSS unit, (for example, rem, px).
Note
We recommend using rem units, to keep the app responsive to all device sizes (as the UI is designed on rem units).
Rapyd's UI is based on a root font-size of 10 pixel (1 rem = 10px).
Variants and States
Every element can be configured with one or more of the following variants or pseudo-classes and pseudo-elements:
Variants and States | Decription | Elements that it applies to |
---|---|---|
placeholder | Applied to the element's placeholder |
|
disabled | Applied when the element is disabled |
|
hover | Applied when the element is in a hover state |
|
active | Applied when the element is in an active state |
|
error | Applied when the element is in an error state |
|
focus | Applied when the element is in focus while navigating a web page using the TAB key (or equivalent) |
|
selection | Applied to a selected text within an element |
|
item | Applied to all the items in a drop down field |
|
list | Applied to the full list in a drop down field |
|
base | The default style |
|
CSS Properties
Each specified property name must be in camel case, for example, borderRadius not border-radius.
Toolkit Default Theme and Available CSS Properties
CSS
const defaultTheme = { "global": { "fonts": [], "fontSizes": { "extraSmall": "1.2rem", "small": "1.4rem", "medium": "1.6rem", "large": "2rem", "extraLarge": "4rem" }, "input": { "base": { "borderColor": "#e9ecef", "backgroundColor": "#fff", "borderRadius": "4px", "color": "#1a1a1a", "fontSize": "1.4rem", "fontWeight": 500, "fontFamily": "" }, "active": { "borderColor": "#0046ff", "backgroundColor": "", "color": "", "labelColor": "#0046ff" }, "error": { "borderColor": "#ff3650", "backgroundColor": "", "color": "", "labelColor": "#ff3650" }, "focus": { "outline": "none" }, "placeholder": { "fontSize": "1.4rem", "fontWeight": 500, "color": "#9ba2a7", "fontFamily": "" }, "selection": { "color": "", "backgroundColor": "" }, "disabled": { "backgroundColor": "#fbfbfb", "color": "" } }, "cardFields": { "title": { "color": "" }, "saveForFutureLabel": { "color": "" } }, "requiredFields": { "title": { "color": "" } }, "orderDetails": { "title": { "color": "" }, "totalLabel": { "color": "" }, "totalValue": { "color": "" } }, "pciMessage": { "color": "" }, "dropdown": { "backgroundColor": "", "title": { "color": "" }, "base": { "fontSize": "1.4rem", "fontWeight": 500, "color": "#1a1a1a", "borderColor": "#e9ecef", "backgroundColor": "#fff", "borderRadius": "4px", "fontFamily": "" }, "active": { "borderColor": "#0046ff", "backgroundColor": "", "color": "" }, "error": { "borderColor": "#ff3650", "backgroundColor": "", "color": "#ff3650" }, "focus": { "outline": "none" }, "placeholder": { "fontSize": "1.4rem", "fontWeight": 500, "color": "#000", "fontFamily": "" }, "disabled": { "color": "#9ba2a7", "backgroundColor": "#fbfbfb" }, "item": { "transition": "0.3s", "base": { "backgroundColor": "#fff", "color": "#1a1a1a", "fontFamily": "" }, "active": { "backgroundColor": "#e9ecef", "color": "" }, "hover": { "backgroundColor": "#f6f6f9", "color": "" }, "selected": { "backgroundColor": "#e9ecef", "color": "" } }, "list": { "backgroundColor": "#ffffff", "borderRadius": "4px", "boxShadow": "0 0 4px 0 rgba(110, 119, 125, 0.16)", "border": "solid 2px #e9ecef" } }, "submit": { "base": { "backgroundColor": "", "color": "", "fontWeight": "", "fontSize": "", "borderRadius": "", "fontFamily": "", "border": "", "boxShadow": "", "width": "", "height": "", "padding": "", "cursor": "" }, "hover": { "backgroundColor": "", "color": "", "fontWeight": "", "borderRadius": "", "border": "", "boxShadow": "", "transition": "0.3s" }, "active": { "color": "", "backgroundColor": "" } }, "clear": { "base": { "width": "24px", "height": "24px", "padding": "10px", "borderRadius": "50%", "backgroundColor": "transparent", "cursor": "pointer" }, "hover": { "backgroundColor": "#e9ecef", "transition": "0.3s" }, "active": { "backgroundColor": "#d7dbdf" } }, "tooltip": { "button": { "base": { "width": "16px", "height": "16px", "border": "solid 1px #6e777d", "borderRadius": "50%", "backgroundColor": "#ffffff" }, "hover": { "backgroundColor": "#e9ecef", "border": "", "borderRadius": "", "transition": "0.3s" }, "active": { "backgroundColor": "#e9ecef", "border": "", "borderRadius": "" } }, "content": { "base": { "padding": "16px 18px", "borderRadius": "4px", "boxShadow": "0 0 6px 0 rgba(0, 0, 0, 0.12)", "border": "solid 1px #ededed", "backgroundColor": "#ffffff" }, "hover": { "padding": "", "borderRadius": "", "boxShadow": "", "border": "", "backgroundColor": "", "transition": "3000ms" } } }, "cart": { "background": "none", "border": "none", "fontFamily": "inherit", "description": { "fontSize": "1.2rem", "fontWeight": 400, "color": "#1a1a1a" }, "amount": { "fontSize": "1.4rem", "fontWeight": 600, "color": "#1a1a1a" }, "quantityTitle": { "fontSize": "1.2rem", "color": "#6e777d" }, "quantityValue": { "fontSize": "1.4rem", "fontWeight": 600, "color": "#4a4a4a" }, "image": { "width": "", "height": "80px", "border": "none", "borderRadius": 0, "hover": { "border": "none", "borderRadius": 0, "transition": "0.3s" }, "focus": { "outline": "none" } } }, "instructions": { "title": { "color": "" }, "text": { "color": "" }, "numbering": { "background": "", "text": "" } } };
Pass a Style Object
You can pass a style object in the init method, together with the rest of the fields. See example below:
JavaScript
let checkout = new RapydCheckoutToolkit({ pay_button_text: "Click to pay", // Text that appears on the 'Pay' button. // String. Maximum length is 16 characters. // Default is "Place Your Order". Optional. // If the client will pass a backgroundColor in the style object pay_button_color: "blue", // Color of the 'Pay' button. String. // Standard CSS color name or hexadecimal code such as #323fff. // Default is the color that is returned in the 'merchant_color' // field of the response to 'Create Checkout Page'. Optional. id: "checkout_9ebe58dcb9d75e8f972a35350f96c2fa", // ID of the 'Create Checkout Page' response. String. Required. close_on_complete: true, // Causes the embedded Rapyd Checkout Toolkit window to close // when the payment is complete. Boolean. Default is 'true'. Optional. style: { global: { fonts: [ "https://fonts.googleapis.com/css2?family=Mulish:wght@200&display=swap", { family: 'myCustomFont', src: '/fonts/myCustomFontRegular.woff2', fontWeight: 400 }, { family: 'myCustomFont', src: '/fonts/myCustomFontBold.woff2', fontWeight: 700 } ] }, submit: { base: { backgroundColor: '#0000FF', // If passed for the 'submit' element, it will override the pay_button_color field. fontFamily: 'myCustomFont', } } });