In today's world, security and PCI compliance play important roles in protecting cardholders and delivering cash flow for businesses.
Protect.js uses an iframe to create PayTrace hosted fields when collecting sensitive-payment information. This allows you to control the UI and UX of your checkout process so that cardholder data never touches your servers.
You can quickly start accepting secure payments and storing cardholders' payment information by embedding a few lines of code within your existing checkout flow. While achieving the highest level of PCI-Compliance, SAQ-A.
The benefits of using PayTrace Protect.js
- It will allow your customers to process transactions on your website.
- It will allow your customers to safely and securely store their credit card information for future use.
- Your customers are not required to be redirected to another payment page.
- It provides your customers the comfort and security of processing payments on your website.
- Using Protect.js reduces your PCI scope and can help you qualify for PCI SAQ-A.
The PayTrace Protect.js Workflow

Protect.js Details
Protect.js places PayTrace Hosted Payment fields, within an iframe, on your webform. This will allow your customers to enter their sensitive credit card information directly into PayTrace while ensuring your server does not handle any sensitive data. Once this information has been captured, Protect.js will then return a one time use hpf_token (nonce) and enc_key. The nonce and enc_key can then be submitted via an API request in order to process transactions or create customer profiles.
How to incorporate Protect.js in a web form
The following steps are required to utilize The PayTrace Protect.js Library in a web form.
1. Setup: Include JS library and div container tag for iframe on your website.
This step allows the PTPayment object to become available when the Protect library script is sourced in the web application. See available PTPayment methods below:
Method | Description |
process | Validates and tokenizes Hosted Payment Field Data |
setup | Initializes the Protect.js Hosted Payment Fields within iframe using the
clientkey in step 3.
Styling options can be statically applied during the setup call. For more information regarding our styling options, see Styling Options. |
validate | Validates Hosted Payment Field input prior to tokenizing data.
Takes function as an argument. See example 5.1 |
reset | Clears Hosted Payment Fields and resets Protect.js to its beginning state. |
2. Get authorization for application to use JSON API
Make OAuth authorization call to the JSON API to get an API AUTH TOKEN. This token will be used as the authorization bearer access token to authorize the application to use PayTrace's API. The token should be kept secret and should never be added to client side code. This token is valid for 2 hours.
3. Use the JSON API Authorization token to get authorization to use Protect
Using the API AUTH TOKEN from step two as the authorization header, make a JSON API POST request to: https://api.paytrace.com/v3/payment-fields/token to get a PROTECT AUTH TOKEN (clientKey).
The clientkey will be used to authorize the application to use Protect.js. This key is valid for 20 minutes.
4. Use the Protect authorization token to setup the payment form.
Ensure you have the following setup code:
By this point, you should be able to see the Protect.js iframe rendered on your webpage. See example below:

To improve the look and feel of Protect.js, styling options can be statically applied during the setup call. For more information regarding our Styling option, see Protect.js Styling.
5. Bind submit event to event handler for tokenization of sensitive data
The process method will tokenize the sensitive data in the payment fields. The method returns a http promise that will either be fulfilled (resolved) or rejected. If it is rejected, the possible reasons are: network error, internal error, or the fields did not pass validation.
5.1 Validate fields before tokenizing sensitive data.
Step 5.1: Bind Submit event and validate fields before tokenizing sensitive data.
PTPayment.validate will validate the payment fields and allow you to re-prompt your customers to enter valid information.
Dynamic styling can then be used to better control your customer experience when invalid input is entered. For more information regarding our Styling options, see Styling Options.
For a list of potential validation errors, see Validation Error Responses below.
OR
5.2 Directly Tokenize sensitive data
OR
Step 5.2: Bind Submit event and directly tokenize sensitive data.
The tokenization process also validates the sensitive data payment fields.
Dynamic styling can then be used within the error handling to better control your customer experience when invalid input is entered. For more information regarding our Styling options, see Styling Options.
For a list of potential validation errors, see Validation Error Responses below.
Validation Error Responses
If for any reason the users input fails the Protect.js validation, the appropriate Response code will be returned in the error response.
Response Code | Description | Reason |
35 | Please provide a valid Credit Card Number. | The Credit card Number was invalid or not provided. |
43 | Please provide a valid Expiration Month. | The expiration Month was invalid or not provided. |
44 | Please provide a valid Expiration Year. | The expiration Year was invalid or not provided. |
148 | Please provide a valid CSC. Must be 3 to 4 digits. | The CSC/CVV value was invalid. |
400 | Varies based on validation error. | In the case that an error occurs in which a general use case is not covered, this response code will be thrown with a description indicating the field that it detected a problem with. |
How to submit Protect.js Tokens through the API
Once you have received the hpf_token (nonce) and enc_key, you will then submit these values using an API Request and the Oauth token from Step 2. API methods that are meant to be used with the Protect.js UI are listed within their appropriate request categories and begin with the keyword Protect.