Set up Hosted Fields

Use Hosted Fields to create a form on a webpage that customers can use 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 and configure JavaScript.
Step 2. Add HTML for each payment type.
Step 3. Handle the single-use token.
Step 4. Handle error events.

Step 1. Add and configure JavaScript

Important: You can add only one set of Hosted Fields to a webpage.
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:
  1. Insert the JavaScript configuration for the action that you want to complete:
  • Run a sale.
  • Save a customer's payment details.
  • Update payment details.
  1. In the sessionToken field, include your session token.

Step 2. Add HTML for each payment type.

  • Insert HTML for the type of payment form you want to create.
Card
ACH
PAD
<div class="card-container payroc-form">
<label for="card-holder-name">Cardholder Name</label>
<div class="card-holder-name"></div>
<div class="card-holder-name-error error-message"></div>
<label for="card-number">Card Number</label>
<div class="card-number"></div>
<div class="card-number-error error-message"></div>
<div class="cols-2">
<div class="col">
<label for="card-expiry">Expires (MM/YY)</label>
<div class="card-expiry"></div>
<div class="card-expiry-error error-message"></div>
</div>
<div class="cvv-wrapper">
<div class="col">
<label for="card-cvv">CVV</label>
<div class="card-cvv"></div>
<div class="card-cvv-error error-message"></div>
</div>
</div>
</div>
<div class="card-submit submit-button"></div>
</div>

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:
cardForm.on("submissionSuccess", ({ token, expiresAt }) => {
});

Response

The event response contains the following fields:
FieldDescription
tokenSingle-use token that represents the customer's payment details.
expiresAtExpiry date and time of the single-use token.
Example response
{
"token": "c96cb928e39c34bd05022cd821d2cbba2349f047ce0cef4f77cd2b5762be7608fb7c23e673bf014d58c64672928eb8256e38aa26911a22853143d22dd48ac9aa",
"expiresAt": "2024-05-18T23:17:34.844Z"
}

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:
cardForm.on("error", ({ type, field, message }) => {
});
For more information about the error event, go to Error Event.