PayFields - Developer Guide
Example code and detailed, step-by-step instructions for building a payment page using PayFields.
This page includes a Quickstart section, which provides sample code for a basic payment page using all of the available fields provided by PayFields, an Implementation section, which provides details about how to incorporate PayFields into a custom payment page, and definitions of all of the actions supported by PayFields.
Warning: For increased security measures of the platform, only use a Public Key with your Payfields integration in production environments and only use, and regularly change, Transaction Session Keys for sandbox environment testing.
Getting Started
To get started setting up your PayFields integration, you'll need the following:Â
Some experience with basic front-end languages - HTML, JavaScript & CSS
An IDE such as Visual Studio Code or XCode.
A valid API Key or Transaction Session Key
An active, fully boarded Merchant ID
In your IDE, create or open an existing HTML file for the payment webpage.
Tip: If you want to skip the tutorial, scroll to the PayFields Quickstart Code below.
1. Import Library Scripts
Add the PayFields external script to import the core PayFields iframe functionality and set the development environment.Â
PayFields Sandbox (Test) Environment External Script
<script type="text/javascript" src="https://test-api.payrix.com/payFieldsScript"></script>
PayFields Production Environment External Script
<script type="text/javascript" src="https://api.payrix.com/payFieldsScript"></script>
2. Setup Basic Payment Fields
Add the core PayFields form fields with labels inside the <body> element of the file, where the PayFields customer payment entry form will be displayed via iFrame later.
<div>
<label for="number">Number:</label>
<div id="number"></div>
</div>
<div>
<label for="expiration">Expiration:</label>
<div id="expiration"></div>
</div>
<div>
<label for="cvv">CVV:</label>
<div id="cvv"></div>
</div>
<div>
<label for="name">Name:</label>
<div id="name"></div>
</div>
<div>
<label for="address">Address:</label>
<div id="address"></div>
</div>
3. Add the Submit Transaction Button
Add the transaction submission button below the Basic Fields you just added.
4. Add Authentication Script
Add the first PayFields configuration script to authenticate access at the end of your <body>, replacing the placeholders below with your valid Merchant ID and API Key/Transaction Session Key.
5. Add Transaction Settings Script
Add the next PayFields configuration script to set the basic transaction information about the type of transaction, tokenization status, and amount.Â
6. Assign Basic Card Payment Fields to PayFields Inputs
Add the PayFields form field connections to assign your payment form elements from Step 2 to the PayFields inputs to securely iframe them onto the page.Â
7. Assign Submit Button Functionality
Now, add the Submit Button script to assign the PayFields.submit()
function, submitting the transaction to the platform when the customer submits their payment.
8. Add Basic Console Log Responses
Add the scripts below to ensure you can review PayFields responses in your browser console log while testing for basic success or failure responses.
Done! Your basic PayFields integration is complete and you can begin to test submitting card payment transactions.Â
Quickstart Setup
Follow the steps below to open a basic checkout page with PayFields already integrated:
Copy the code below into a text editor.
Add your API Key or Transaction Session Key and Merchant ID on lines 37 and 38.
Save the file with a
.html
extension.Open the file in your web browser. The page will display all of the fields available for use on your custom payment page: card number, expiration date, CVV, and billing address.
PayFields Quickstart Code
PayFields JavaScript Reference
The table below defines all of the actions supported by the PayFields JavaScript library:
External PayFields Script Import Query
Query | Description | Valid Values |
---|---|---|
| A boolean determining whether or not the webpage the PayFields external script is being added to is a single-page application. When this query parameter is set, the following occurs:
| Valid Values:
|
Actions
Action | Description |
---|---|
| Submits the PayFields data to the platform. |
| Opens the card swipe popup for card-present payment terminals. |
| Clears all values from all fields. |
| Moves the specified field to a new |
| Reappends the PayField with all existing values to the |
| Restores the values if the PayField is moved to a new |
| Removes all loaded PayFields iframes and event handlers from the page. Useful for mounting and unmounting PayFields on demand. |
| Mandatory function to call when using the |
| Prevents jQuery from setting any unwanted global variables. |
Callbacks
Action | Description |
---|---|
| Runs when the API responds with a successful transaction and/or token. |
| Runs when invalid or incomplete cardholder and/or payment data is entered. |
| Runs when API Key, Transaction Session Key, or Merchant ID fails validation before creating the API call or when the API responds with a failed transaction or token. |
| Runs when the API responds. |
| Runs when the |
| Runs when |
ConfigurationsÂ
Configuration | Required | Type | Description | |
---|---|---|---|---|
| Required | string | The API Key or Transaction Session Key used to authenticate the associated Merchant. | |
| Required | string | The Merchant ID for the Merchant entity associated with the PayFields-integrated webpage, (e.g. | |
| Required | string | Whether the payment capture mode set for PayFields is:
| |
| Required | string | Whether the transaction mode set for PayFields is:
| |
| Required | numeric string | The total transaction amount charged. Specified in cents. (e.g. | |
| Optional | number | Sets an order number for interchange data submission. | |
| Optional | integer | Sets tax amount for interchange data submission. | |
| Optional | integer | Sets a transaction discount value for interchange data submission. | |
| Optional | integer | Sets a shipping charge amount for interchange data submission. | |
| Optional | integer | Sets a duty amount for interchange data submission. | |
| Optional | object | Sets customer creation information if a customer ID is not provided. | |
 |
| Optional | string | Customer first name |
| Optional | string | Customer middle name | |
| Optional | string | Customer last name | |
| Optional | string | Customer company if applicable. | |
| Optional | string | Custom field for passing CRM data or other associated identifier within the Merchant business. | |
| Optional | string | Customer email address. | |
| Optional | number | Customer phone number. | |
| Optional | number | Customer fax number. | |
| Optional | array of objects | Adds an array of items to the order for interchange data submission. Item array data is only required when submitting item information. | |
 |
| Optional | string | The name of the item. Up to 500 characters long. |
| Optional | string | The item product code such as UPC, catalog number, or inventory number. Up to 100 characters long. | |
| Optional | string | A description of the Item. | |
| Optional | integer | The quantity of the item included in the Transaction. | |
| Optional | number | The "unit of measure" for this item such as each, kilogram, pound, or month. | |
| Optional | integer | The amount charged for this Item. Specified in cents. (e.g. | |
| Optional | integer | The total price for the line item. Specified in cents. (e.g. | |
| Optional | number | The commodity code for this Item. Up to 12 characters long. | |
| Optional | string | A custom identifier for this line item. Up to 500 characters long. | |
| Optional | integer | The discount for the line item. Specified in cents. (e.g. | |
| Optional | array | Sets known values for the cardholder's billing address that remain hidden on the webpage for interchange data submission. | |
 |
| Optional | string | Sets the street address. |
| Optional | string | Sets the unit or suite. | |
| Optional | string | Sets the associated company. | |
| Optional | string | Sets the city for the cardholder. | |
| Optional | string | Sets the state or province, (e.g. | |
| Optional | string | Sets a 5-8 digit postal code. | |
| Optional | string | Automatically sets the country, | |
| Optional | string | Sets email address for contact. | |
| Optional | number | Sets phone number for contact. | |
| Optional | array | Allows additional data to be submitted with the transaction. | |
 |
| Optional | string | Custom description of the payment token. Up to 500 characters long. |
| Optional | string | Custom description of the transaction. Up to 500 characters long. | |
| Optional | array | An associated invoice detailing the shipping details for the cardholder. | |
 |
| Optional | string | The associated Invoice ID, (e.g. |
| Optional | string | Cardholder first name. Up to 100 characters long. | |
| Optional | string | Cardholder middle name. Up to 100 characters long. | |
| Optional | string | Cardholder last name. Up to 100 characters long. | |
| Optional | string | Company name. Up to 100 characters long. | |
| Optional | string | The first line of the shipping address. Up to 500 characters long. | |
| Optional | string | The unit or suite for the shipping address. Up to 500 characters long. | |
| Optional | string | The shipping address city. Up to 500 characters long. | |
| Optional | string | The shipping address state. Up to 500 characters long. | |
| Optional | string | The 5-8 digit shipping address postal code. | |
| Optional | string |
| |
| Optional | string | The associate shipping address phone number. | |
| Optional | string | The associate shipping address fax number. |
Customizations
Customization | Required | Type | Description | |
| Optional | object | Set core CSS design for PayFields through this JavaScript object to maintain full PCI compliance and security while modifying your PayFields design. See PayFields CSS Customizations below. | |
| Optional | object | Sets the placeholder values that appear in each PayFields form field. See Placeholders below. | |
| Optional | array | Can be:Â
|
Fields
| Required | Description |
Required | The cardholder or checking account holder's name. | |
Required | The card or account holder's associated address. | |
Required | Credit/Debit card number. | |
Required | Credit/Debit Card Verification Value (CVV). | |
Required | Credit/Debit card expiration month and year (MM/YY) | |
Optional | The type of eCheck account being used for the transaction. Valid Values:Â
| |
Optional | The account number for the customer's eCheck account. | |
Optional | The routing number for the customer's eCheck account's financial institution. |
CSS Customizations
PayFields CSS customizations utilize a unique combination of JavaScript and specifically formatted CSS selectors, properties, and their associated values. There are 3 categories of CSS customizations available: Input Elements, Error Span Elements, & Action Elements.Â
Note: These options must be set through the PayFields script to ensure full PCI compliance and security.Â
To begin setting CSS stylization options, add the following script to your payment webpage:Â
CSS selectors for class or ID must be enclosed in double quotes, followed by a colon before the standard CSS curly bracket like so:
".class": {}
Adding multiple classes requires a comma after the closing curly bracket for each selector.
CSS properties are formatted as normal with no quotes.
CSS property values must be formatted with double quotes and completed with a comma as normal like so when using multiple properties:
property: "value",
Your PayFields.customizations.style = {}
JavaScript object should match the formatting below:
CSS Input Element CustomizationÂ
CSS Input elements are simply the <div> elements added to the basic PayFields page allowing you to customize the look and feel of your integration to match your branding and payment page.Â
All CSS input customization options are shown below:
| Description |
| Defines the style for all payment info input fields. |
| Defines the style for the card number input field. |
| Defines the style for the expiration date input field. |
| Defines the style for the card verification value (CVV) input field. |
| Defines the style for the cardholder name input field. |
| Defines the style for all address info input fields. |
| Defines the style for the cardholder street address input field. |
| Defines the style for the cardholder city input field. |
| Defines the style for the cardholder state input field. |
| Defines the style for the cardholder postal code input field. |
| Defines the style for the cardholder email address input field. |
| Defines the style for the cardholder phone number input field. |
CSS Error Span Element Customization
You can further update the input fields by modifying the look and feel of the error messages that appear on the PayFields payment form when incorrect data is provided by a cardholder.
All CSS error span customization options are shown below:
| Description |
| Defines the style for the error message shown when incorrect data is submitted for all payment info input fields. |
| Defines the style for the error message shown when incorrect data is submitted for the card number input field. |
| Defines the style for the error message shown when incorrect data is submitted for the expiration date input field. |
| Defines the style for the error message shown when incorrect data is submitted for the card verification value (CVV) input field. |
| Defines the style for the error message shown when incorrect data is submitted for the cardholder name input field. |
| Defines the style for the error message shown when incorrect data is submitted for all address info input fields. |
| Defines the style for the error message shown when incorrect data is submitted for the cardholder street address input field. |
| Defines the style for the error message shown when incorrect data is submitted for the cardholder city input field. |
| Defines the style for the error message shown when incorrect data is submitted for the cardholder state input field. |
| Defines the style for the error message shown when incorrect data is submitted for the cardholder postal code input field. |
| Defines the style for the error message shown when incorrect data is submitted for the cardholder email address input field. |
| Defines the style for the error message shown when incorrect data is submitted for the cardholder phone number input field. |
CSS Popup Element Customization
To allow full customization, the card icon pop-up, and the iframe card swipe popup, are customizable to allow you to rearrange and reformat your form, styling and specifying the locations of each popup as needed.
All CSS popup element customization options are shown below:
| Description |
| Defines how and where the card icon will appear as the cardholder enters their card, confirming the correct card brand. |
| Defines how and where the Swipe Your Card icon is displayed on the screen. |