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.
<button type="button" id="submitBtn" class="btn">Submit Payment</button>
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.
<script> // Authentication PayFields.config.apiKey = '01a2bc34de5fg678h90ijk123m456789'; PayFields.config.merchant = 't1_mer_123abc4d567890efg1h2i34'; </script>
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.
<script> // Transaction Settings PayFields.config.mode = ''; PayFields.config.txnType = ''; PayFields.config.amount = 1000; </script>
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.
<script> // Form Field Connections PayFields.fields = [ { type: "number", element: "#number", }, { type: "name", element: "#name", }, { type: "cvv", element: "#cvv", }, { type: "expiration", element: "#expiration", }, { type: "address", element: "#address", } ]; </script>
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.
<script> // Submit Button Function document.querySelector('#submitBtn').addEventListener('click', function() { PayFields.submit() }); </script>
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.
<script> // Success Callback PayFields.onSuccess = function(response) { console.log(response) alert('Payment Successful!') } </script> <script> // Failure Callback PayFields.onFailure = function(err) { console.log(err) alert('Payment failed. Verify your payment method.') } </script>
Done! Your basic PayFields integration is complete and you can begin to test submitting card payment transactions.
To further customize and enhance your integration, a PayFields JavaScript Reference is provided below containing detailed information about the available actions, functions, and callbacks offered by PayFields. Individual setup steps are outlined below. You can also find more details about specific setups for functions like tokenization or auth-only options offered through PayFields on our PayFields - Additional Features guide.
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
Important Info for Canadian 🇨🇦 Merchants:
province
fields replace thestate
fields (see valid values here).postal
fields replacezip
fields (see valid values here).currency
will be in CAD.
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
Warning: The customizations
object checks for iFrame configuration before any customization attributes are enabled.
To prevent potential rendering or functional issues, ensure that iframes are fully initialized before applying any customization attribute
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 |
{ type: 'name', element: '#name', }, | Required | The cardholder or checking account holder's name. |
{ type: 'address', element: '#address', }, | Required | The card or account holder's associated address. |
{ type: 'number', element: '#number', }, | Required | Credit/Debit card number. |
{ type: 'cvv', element: '#cvv', }, | Required | Credit/Debit Card Verification Value (CVV). |
{ type: 'expiration', element: '#expiration', }, | Required | Credit/Debit card expiration month and year (MM/YY) |
{ type: 'account_type', element: '#account_type', }, | Optional | The type of eCheck account being used for the transaction. Valid Values:
|
{ type: 'account_number', element: '#account_number', }, | Optional | The account number for the customer's eCheck account. |
{ type: 'routing', element: '#routing', }, | Optional | The routing number for the customer's eCheck account's financial institution. |
Note: Adding values: {}
to any of the PayFields.fields
JavaScript object payment form field connections will automatically prefill the information. You can choose to display or hide this prepopulated information. See the Prefill & Display or Hide Fields section below for more details.
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:
PayFields.customizations.style = {}
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:
PayFields.customizations.style = { ".number": { borderStyle: "solid", border-radius: "5px" }, ".address-input": { borderStyle: "dashed", border-radius: "5px" }, ... }
Warning: CSS pseudo-classes are not supported by PayFields CSS customizations. Example: #name::hover
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. |