# Embedded components overview > Learn how to use Payabli's embedded components to create customized checkout experiences without handling sensitive payment information yourself Payabli offers a set of embedded JavaScript UI components that let you create customized checkout experiences without handling sensitive payment information. You can use the embedded components to process transactions or save payment methods while remaining PCI compliant. Payment methods saved via the embedded components can be used with the Payabli API to perform functions like subscriptions, queries, and more. See [Tokenization Overview](/guides/platform-tokenization-overview) for more information. ## Choose a component Use the interactive quiz below to find the right embedded component for your application. To decide which embedded component to use, consider the functionality you need for your app. Payabli offers embedded components tailored to different use cases: Capture a payment method or make a sale using any payment method. This is the most flexible component. It's ideal for tokenizing payment methods or making sales directly from your page. Add acceptance for digital wallet payments like Apple Pay. It can be paired with other components to give your customer a range of options. Embed a virtual terminal tool in your page or app, letting you add secure payment acceptance in a contained environment. Save payment method data without expanding your PCI scope. This component is a modal that opens over content, and is designed only for storing payment methods. Which component is right for you depends on whether you need to make transactions, save payment method data, or both. For example, if you need to both save a payment method and execute payments, the EmbeddedMethod UI might be the best choice. If you just need to make transactions from your website or app, the VirtualTerminal UI could be the right choice. Overall, the EmbeddedMethod UI is the most popular and flexible option. You can extend the EmbeddedMethod UI and PayMethod UI components even further by using a flow designed around returning a temporary payment token. See [Extend Embedded Components with the Temporary Token Flow](/guides/platform-developer-tokenization-temp-flow) for more. ## Usage Payabli's embedded components are customizable and easy to implement. To load Payabli's embedded components, add a script tag that points to Payabli's `component.js` library. After adding the script tag, create an instance of the `PayabliComponent` class with your configuration. See the [Configuration reference](/guides/pay-in-components-embeddedmethod-ui#configuration-reference) for each component for more information about configuration options. ```javascript Sandbox ``` ```javascript Production ``` ### Library URLs See the [component.js Changelog](/developers/embedded-components/changelog) to see the latest changes. Beginning October 22, 2023 embedded components no longer supports versions older than 1.9.0. The sandbox and production library URLs are evergreen, meaning that the URL always points to the latest version. * Sandbox: `https://embedded-component-sandbox.payabli.com/component.js` * Production: `https://embedded-component.payabli.com/component.js` You must add the `data-test` configuration variable to your script tag when using the sandbox library. Don't include `data-test` when working with the production library. ### Authentication Payabli's embedded components authenticate with the `token` field passed in the embedded component's configuration. The API token must be a public token. If you are using a Creator component, the API token must be set up for the Creator. See [Payabli API tokens](/developers/api-reference/api-overview#authentication) for more information. ### `PayabliComponent` class The `PayabliComponent` class has the following methods: Show the component if it's hidden. Hide the component. Replace the component configuration. Trigger an action. Valid actions are `method`, `pay`, `auth` and `reinit`. `parameters` is an optional structure that lets you dynamically overwrite the matching fields passed via configuration for `customerData` and `paymentDetail`. This action executes a tokenization of the payment information (saves the payment method). This action doesn't process a payment. This is the default action. This action processes a payment. This action processes an authorization that needs to be captured later. This action doesn't process a payment. This action resets the component state. We recommend using this method when the component is in an error or declined state and you want to retry a transaction. ```javascript payabliExec example var dynamicData= { customerData: { firstName: 'John', lastName: 'Doe' }, paymentDetails: { totalAmount: 11.55 } }; // This action executes a payment using the customerData and paymentDetails objects // declared in the dynamicData variable mycomponent.payabliExec('pay', dynamicData); ``` ## Customize styles To customize the component's styles, you can pass a URL to a CSS file in the `customCssUrl` parameter of the component configuration. ```js customCssUrl example const payabliConfig0 = { type: "methodLightbox", rootContainer: "pay-component-1", buttonLabelInModal: 'Save Payment Method', defaultOpen: 'ach', hideComponent: true, customCssUrl: 'www.example.com/mycssfile.css', ... } ``` ### Make the component background transparent By default, the embedded components have a white background. To make the component's background transparent, add the following CSS to the stylesheet that's linked with the `customCssUrl` parameter: ```css /* ... the rest of your custom css ... */ /* transparent while loading */ #main-loading-layer { background-color: transparent !important; } /* transparent after loading */ body { background-color: transparent !important; } ``` ### Component containers The embedded components are loaded inside of an iframe. Each component creates a container for the iframe with a specific ID. You can use these IDs to target the component container in your CSS or JavaScript code. Here are the IDs for each component: * EmbeddedMethod: `payabliComponentsIframeContainerMethodEmbedded` * PayMethod: `payabliComponentsIframeContainerMethod ` * VirtualTerminal: `payabliComponentsIframeContainerEterminal` * ExpressCheckout: `payabliComponentsIframeContainerExpressCheckout` ### Component elements You can also reference specific elements inside of the component and create custom styles for them. The elements inside the component have the following IDs:
ID Element
`cardNumber` Card number input
`cardNumberContainer` Card number container
`cardExpirationDate` Card expiration date input
`cardExpirationDateContainer` Card expiration date container
`cardCvv` Card CVV input
`cardCvvContainer` Card CVV container
`cardZipcode` Card zip code input
`cardZipcodeContainer` Card zip code container
`cardHolderName` Cardholder name input
`cardHolderNameContainer` Cardholder name container
`achAccountType` Bank account type selector
`achAccountTypeContainer` Bank account type container
`achAccountHolderName` Bank account holder input
`achAccountHolderNameContainer` Bank account holder container
`achRouting` Bank routing input
`achRoutingContainer` Bank routing container
`achAccount` Bank account input
`achAccountContainer` Bank account container
This example targets the card number, expiration date, CVV, ZIP code, and cardholder name fields. It adds a solid, 1 pixel black border to the fields. ```css Form style example #cardNumber, #cardExpirationDate, #cardCvv, #cardZipcode, #cardHolderName { border: solid 1px #000000; } ``` ## Customize input fields The input fields inside of the component can be styled individually via the component's configuration object. ### Input grid layout The component's inputs are laid out in a grid with 3 rows and 12 columns. You can specify size and placement of each input in the grid without any CSS by using the `row`, `order`, and `size` fields.
Row 0 Size=1 Size=1 Size=1 Size=1 Size=1 Size=1 Size=1 Size=1 Size=1 Size=1 Size=1 Size=1
Row 1 Size=2 Size=3 Size=5 Size=1 Size=1
Row 2 Size=8 Size=4
### Input configuration reference You can style inputs in the component configuration using the following parameters: Label for input field. Placeholder for input field. Enable/disable floating label within input field. Value for input field. Size of input field in columns (1-12). Row to place the input within component grid (0-2), 0 being the top row. Order of input field within the row (0-99+), 0 being the left position. For `achRouting` and `achAccount` inputs only. When `true`, duplicates the ACH account number and routing number fields and requires that the fields match. This helps make sure the user enters valid account and routing numbers. Only available for the EmbeddedMethod UI. For `cardZipcode` input only. Accepted values are `us` and `ca`. Controls which zip code formats are accepted. If `ca` is included, then Canadian payments are enabled. ### Input configuration examples Here are some examples of different input configurations: ```js Card field configuration example card: { enabled: true, amex: true, discover: true, visa: true, mastercard: true, jcb: true, diners: true, inputs: { cardNumber: { size: 4, row: 1, order: 0, label: "Your Card Number" }, cardExpirationDate: { size: 4, row: 1, order: 1, }, cardZipcode: { label: "ZIP/POSTAL CODE", placeholder: "Zip/Postal Code", floating: false, size: 6, row: 2, order: 1, country: ["us", "ca"] } } }, ``` ```js ACH field configuration example ach: { enabled: true, checking: true, savings: true, inputs: { achRouting: { label: "Routing Number", size: 6, row: 1, order: 0, confirm: false // Display the field twice to ensure the fields match }, achAccount: { label: "Account Number", size: 6, row: 2, order: 0, confirm: true } } } ``` ## Interactive demos The following demos show the EmbeddedMethod UI component with different configurations. ### Card This is a basic example of the EmbeddedMethod UI component with default card configuration. This demo shows the component in action with transaction processing and visual feedback. When the component processes a transaction, the demo displays the JSON response. ### ACH This is a basic example of the EmbeddedMethod UI component with default ACH configuration. This demo shows the component in action with transaction processing and visual feedback. When the component processes a transaction, the demo displays the JSON response. ### RDC This is a basic example of the EmbeddedMethod UI component with default RDC configuration. This demo shows the component in action with transaction processing and visual feedback. When the component processes a transaction, the demo displays the JSON response. ### Customized This is an example of the EmbeddedMethod component with customized input fields and configuration switching logic. See the [Interactive demo for EmbeddedMethod UI](/guides/pay-in-components-embeddedmethod-ui#interactive-demo) for a live preview of this example. Customized EmbeddedMethod UI ## Handle responses and errors The embedded components return response objects to callback functions that you define in the component configuration. You can use these callback functions to handle responses and errors, such as displaying messages to users. There are four possible callback functions that are triggered based on the component's state: * `functionCallBackSuccess`: Triggered for successful transactions (2XX responses) and declined transactions (4XX responses). * `functionCallBackError`: Triggered for validation errors. * `functionCallBackReady`: Triggered when the component is ready to process a transaction. * `functionCallBackCancel`: Triggered when the user closes the component's modal. ### Callback support reference The callback functions supported are different for each component type. The following table shows which callback functions are supported by each component type:
Component Callback
EmbeddedMethod UI functionCallBackSuccess, functionCallBackReady, functionCallBackError
PayMethod UI functionCallBackSuccess, functionCallBackError
VirtualTerminal UI functionCallBackSuccess, functionCallBackError
ExpressCheckout UI functionCallBackSuccess, functionCallBackReady, functionCallBackError, functionCallBackCancel
### Declined transactions For a declined transaction, the `functionCallBackSuccess` callback is triggered. To determine whether a transaction was successful or declined, check the `responseText` field in the response object. A successful transaction returns `"Success"` in the `responseText` field, and a declined transaction returns `"Declined"`. After a declined transaction, we recommend calling the `payabliExec("reinit")` method to reinitialize the component so that the user can try again. This example shows how to handle successful transactions, declined transactions, and internal Payabli processing errors. See the [Response reference](/guides/pay-in-components-embeddedmethod-ui#response-reference) for each component to see more information about the response object. ```js functionCallBackSuccess example functionCallBackSuccess: function (response) { // This callback covers both 2XX and 4XX responses console.log(response); switch (response.responseText) { case "Success": // Tokenization was successful alert(`Success: ${response.responseData.resultText}`); break; case "Declined": /* Transaction or tokenization failed due to processor decline or validation errors Recommend reinitialization of the component so that the user can try again with different card data */ alert(`Declined: ${response.responseData.resultText}`); paycomponent0.payabliExec("reinit"); break; default: /* Other response text. These are normally errors with Payabli internal validations before processor engagement. We recommend reinitializing the component. If the problem persists, contact Payabli to help debug */ alert(`Error: ${response.responseText}`); paycomponent0.payabliExec("reinit"); break; } } ``` See [Payment response codes and errors](/guides/platform-return-codes-and-errors-reference#ach-response-codes) for more information about server errors and response codes. ### Error handling The `functionCallbackError` callback is triggered for validation errors. You can use this callback to display custom error messages to users or log errors for debugging. The `functionCallBackError` callback has a different response object based on the component type: * EmbeddedMethod UI, PayMethod UI, VirtualTerminal UI: [`functionCallBackError` response](/guides/pay-in-components-embeddedmethod-ui#functioncallbackerror-response) * ExpressCheckout UI: [ExpressCheckout UI documentation](/guides/pay-in-components-express-checkout#functioncallbackerror-response). ## Playground The [Embedded Component Playground](https://playground.payabli.com) lets you experiment with some component types with a live preview in your browser. ## Related resources See these related resources to help you get the most out of Payabli. * **[EmbeddedMethod UI](/guides/pay-in-components-embeddedmethod-ui)** - Learn how to use the EmbeddedMethod UI embedded component to add the ability to securely store a payment profile or execute a sale * **[ExpressCheckout UI](/guides/pay-in-components-express-checkout)** - Learn how to use the ExpressCheckout UI component on your site or in your app to securely accept digital wallet payments * **[Embedded components framework integrations](/guides/pay-in-developer-components-frameworks)** - Learn how to use Payabli's embedded components with front-end frameworks like React and Vue * **[PayMethod UI](/guides/pay-in-components-paymethod-ui)** - Learn how to use the PayMethod UI embedded component to securely store a payment profile with a low-code modal-based UI. * **[VirtualTerminal UI](/guides/pay-in-components-virtual-terminal-ui)** - Learn how to use the VirtualTerminal UI component on your site or in your app to securely accept payments * **[Payment methods for testing](/guides/test-accounts-reference)** - Use these payment methods to test your integration with Payabli * **[Payment response codes and errors](/guides/platform-return-codes-and-errors-reference)** - Learn about payment response codes for different payment methods * **[Extend embedded components with the temporary token flow](/guides/platform-developer-tokenization-temp-flow)** - Use the temporary token flow with embedded components to have complete control over user transaction experience without expanding PCI scope