--- seo: title: Checkout form and token creation description: Learn how to create a checkout form and manage token creation. keywords: 'Developer docs' lang: en-US redirects: '/docs/content/dev-docs/concept/checkout-form-and-token-creation/': {} '/docs/content/concepts-and-features/concept/checkout-form-and-token-creation/': {} '/docs/concepts-and-features/concept/checkout-form-and-token-creation/': {} --- # Checkout form and token creation If you have not used FramePay previously, see [Get started with FramePay](/docs/dev-docs/basic-setup.md). FramePay processes your checkout form and injects UI elements that are rendered into secure, Rebilly hosted, iframes. When a customer submits a valid FramePay form you use `Framepay.createToken(form, extraData)` to generate a payment token. The values of `form` and `extraData` parameters depend on: - the configured payment method/s. - how you manage your customer information. You use the form in 3 contexts: - Specify the mounting points where FramePay injects UI elements. - Specify `data-rebilly` attributes to indicate which customer data is collected. - Create the payment token by passing the form to `Framepay.createToken(form, extraData)`. ## Mounting points The instructions to specify mounting points are detailed in the [Get started with FramePay](/docs/dev-docs/basic-setup.md) topic. ## Checkout form attributes There are only 2 payment methods (`payment card` and `bank account`) that require your customer information. Use `data-rebilly` attributes to specify which customer data is collected by FramePay. ### Customer name When you use the form to create a payment token, the only required customer data is the name of the customer. There are 2 options to specify the name of the customer: #### `fullName` in just one input ```javascript ... ... ``` #### `firstName` and `lastName` in two different inputs ```javascript ... ... ``` ### Other customer data You can optionally add the following `data-rebilly` attributes to your checkout form: - `organization` - `address` - `address2` - `city` - `region` - `country` - `postalCode` (optional: add a custom label using the `data-rebilly-label` attribute) - `phoneNumbers` (optional: add a custom label using the `data-rebilly-label` attribute) - `emails` (optional: add a custom label using the `data-rebilly-label` attribute) - `bic` (exclusive to the [BBAN](framepay-global-reference.md#framepay.bban.mount) methods) - `bankName` (exclusive to the [IBAN](framepay-global-reference.md#framepay.iban.mount) methods) ## Create payment tokens Use `Framepay.createToken(form, extraData)` to create a payment token with the customer data collected in the form. The `form` parameter can be: - a valid string `DOM` selector. - a `jQuery` instance. - a `Zepto` object that wraps an element within the page. - `null` value, when the payment method does not require customer data (only `payment card` and `bank account` payment methods do require customer data). ### Inject token data Is this an alternative way to `createToken`? FramePay can inject the newly created token into your payment form. This is useful for sending the token ID or payment instrument details directly to your own backend, as part of the payment form submission. To automatically inject token data into your form, use `hidden input fields` with one of these specific `data-rebilly` attributes: - `token` The token ID. - `payment-instrument` The [payment instrument](/docs/dev-docs/api/payment-tokens/posttoken/) details as a stringified object. This way, the token data is sent directly to your backend when the form is posted. ## Example This is an example of a checkout form with both visible customer inputs and hidden inputs: ```html
``` --- --- --- --- --- --- --- ## Framepay.errorCodes The errorCodes namespace, uses for overriding default error messages see [configuration i18n](framepay-configuration-reference.md#i18n) ## Framepay.initialize() Use this method to initialize FramePay with your publishable API key and customize the look and feel of elements. It accepts a single [`configuration`](framepay-configuration-reference.md) object. ```JavaScript // the basic configuration must contain your publishable API key Framepay.initialize({ publishableKey: 'pk_sandbox_1234567890', organizationId: 'your-organization-id', // no required property }); ```
Use your own publishable key
You must replace the key `pk_sandbox_1234567890` with your own. Start with a sandbox key. To create a publishable key, visit Rebilly. A key is specific to either the sandbox or live environment.

The `configuration` must contain at a [`publishableKey`](framepay-configuration-reference.md#publishablekey) otherwise an error will be thrown. It can optionally define CSS styles and className names to overwrite the style of FramePay. For the `configuration` details please take a look at [configuration](framepay-configuration-reference.md#i18n). ```JavaScript // first call Framepay.initialize(config); // where config is const config = { icon: { // icon for combined field display: true // false to hide }, classes: {}, // when needed, style: { base: { // shared `base` state color: '#fff', // generic JS property for DOM style '::placeholder': { // access to pseudo-element color: 'gray', // overwrite placeholder color only }, }, invalid: { color: 'red', '::placeholder': { color: 'firebrick', }, }, } }; ``` ## Framepay.update() Use this method has the same functionality as the `initialize` method, but this method will update actual configuration. ```javascript Framepay.update({ /* new configuration object */ }); ``` The update priority. Any properties which were established and not passed in the new configuration - will stay. ```javascript Framepay.initialize({ locale: Framepay.locale.es, icon: { display: true, }, style: { base: { color: '#fff', }, }, }); Framepay.update({ icon: { color: 'red', style: null } }); ``` The actual Rebilly configuration will be: ```javascript { locale: 'es', icon: { display: true, color: 'red' }, style: {} // default value } ``` ## Framepay.createToken() Use this method to create a token from the contents of a form. FramePay will automatically look for all elements that were mounted and any `input` fields with a `data-rebilly` attribute will be parsed automatically and sent alongside the elements' data. Alternatively you can provide an `extraData` object containing properties supported by the Rebilly API instead of including additional field in your form. ```JavaScript // create a token from the fields within a form Framepay.createToken(form); // optionally include extra data that is not found in the form Framepay.createToken(form, extraData); ``` This method returns a `Promise` with a single argument representing the API result of the operation. Validation or network errors can be caught using a `catch()` handler and displayed to the customer. ```JavaScript var form = document.querySelector('form'); form.addEventListener('submit', function (event) { event.preventDefault(); Framepay.createToken(form) .then(function (token) { // if we have a token field in the form // we can submit directly form.submit(); }) .catch(function (error) { // see error.code and error.message }); }); ``` If a `data-rebilly="token"` hidden input field is detected in your form the payment token will be automatically injected. However, the payment token ID is available as `token.id` if you prefer manual handling. In order for the token creation to work you must mount fields before triggering `createToken`. ### Extra data The `extraData` argument is optional and enables you to define specific values to include in your payment token request. The billing address values match the properties supported by `data-rebilly` input fields and can be provided as either form fields or as this object literal. These options can be defined within:
Option Description
method
string

When provided FramePay will attempt to process the form data to generate a payment token for this method. Always define this property.

Multiple methods

This property is required when using multiple payment methods at the same time in a form or when using methods other than payment-card or ach.

Accepts any of the [methods supported by Rebilly](/docs/dev-docs/api/payment-tokens/posttoken/).

billingAddress
objectoptional

This object defines the billing address of the customer.

These keys can be provided:
  • firstName
  • lastName
  • organization
  • address
  • address2
  • city
  • region
  • country
  • postalCode
  • phoneNumbers, an array of objects representing phone numbers. Each item must include a label and value
  • emails, an array of objects representing email addresses. Each item must include a label and value

Required values

Please note that the firstName and lastName values are required to create a payment token. If they are not present within your form's fields you must define them as extraData.

leadSource
objectoptional

A lead source is Rebilly's term for the marketing campaign responsible for a customer interaction (typically a customer purchasing something).

There are two ways to collect lead source information: either you provide it explicitly within the extraData option or use FramePay to collect Google UTM parameters from the web address hosting it.

If the lead source parameter is defined all UTM parameters from the web address will be ignored.

Lead source parameters

A lead source is just some additional metadata that attaches to the customer’s record, and contains attributes common from both Google analytics (UTM) and affiliate tracking applications:

  • source a UTM parameter
  • medium a UTM parameter
  • campaign a UTM parameter
  • content a UTM parameter
  • term a UTM parameter
  • affiliate an affiliate tracking parameter
  • subAffiliate an affiliate tracking parameter
  • clickId an affiliate tracking parameter
  • salesAgent a sales tracking parameter
  • currency and amount: the cost of the lead

These parameters are optional.

Prevent automatic attribution

If you want to prevent automatic lead source attribution from Google analytics UTM fields you can define this property as an empty object.

{`var extraData = {
   leadSource: {}
};`}
BIC
string

the SWIFT or BIC Code

Only for the BBAN and IBAN methods,
allowed in the data-rebilly fields

bankName
string

Bank name

Only for the BBAN and IBAN methods,
allowed in the data-rebilly fields

For example, if your form gathered the customer's name at a previous step and did not include the fields in the form used to create the token, then you would define it as extra data: ```JavaScript // within the event listener for the form submit var extraData = { billingAddress: { firstName: 'John', lastName: 'Doe' }, leadSource: { campaign: 'facebook', } }; // define extra data as the second argument Framepay.createToken(form, extraData) .then(function (token) { // if we have a token field in the form // we can submit directly form.submit(); }) .catch(function (error) { // see error.code and error.message }); }); ``` ### `data-rebilly` Fields See [data-rebilly fields](form-setup.md)