Set up Hosted Fields
Use Hosted Fields to create a form on a webpage that customers can use to create a single-use token. You can then use the single use token to complete the following actions:
- Make a payment with a card or a bank account.
- Save their payment details.
- Update their payment details.
Before you begin
To integrate with Hosted Fields, you need the merchant’s processing terminal ID, and you need to generate a Bearer token to initialize our JavaScript library.
Session tokens
To authenticate each instance of Hosted Fields, create a session token each time you load Hosted Fields on a webpage.
To create a session token, see our Authentication with Hosted Fields guide.
Integration steps
Step 1. Add HTML for each payment type.
Step 2. Add and configure JavaScript.
Step 3. Handle the single-use token.
Step 4. Handle error events.
Step 1. Add HTML for each payment type.
Important: You can add only one set of Hosted Fields to a webpage.
- Insert HTML for the type of payment form you want to create.
Note: For the card HTML, we added the col
and col-2
custom CSS attributes to create the structure for the example form.
Step 2. Add and configure JavaScript
We provide you with different JavaScript configurations depending on the payment type and transaction type. The value for the mode parameter depends on whether you want to take a payment, save payment details, or update saved payment details:
payment
- You want to run a sale or to run a sale and tokenize the payment details within the same transaction.tokenization
- You want to save the customer’s payment details to run a sale later, or you want to update payment details that the customer previously saved.
To add and configure JavaScript for Hosted Fields, complete the following steps:
- Insert the JavaScript configuration for the action that you want to use the single-use token for:
- Run a sale.
- Save a customer’s payment details.
- Update payment details.
- In the sessionToken field, include your session token.
To test your integration in our UAT environment, use the following details in the JavaScript configuration:
Run a sale
Save a customer's payment details
Update payment details
Step 3. Handle the single-use token
After the customer submits their payment details, our gateway tokenizes them and returns a single-use token. To access the single-use token, you need to subscribe to the submissionSuccess event. You can then use the single-use token in follow-on actions.
To subscribe to the submissionSuccess event, add an event listener to the form. For example:
Response
The event response contains the following fields:
Example response
Step 4. Handle error events
To help you identify and fix any errors that you might encounter when using Hosted Fields, subscribe to our error event. To subscribe to the error event, add an event listener to the form. For example:
For more information about the error event, go to Error Event.