ProductsiFrame JavaScript SDK Integration Guide
Environment | Base URL |
---|---|
Sandbox | https://proxy.payanywhere.dev |
Production | https://proxy.payanywhere.com |
How To Start
- Sign up for a free North Developer account.
- Contact us for Sandbox credentials that can be used to try out this product in a test environment. We will ask that you provide us with the Domain Names (DNS) for the website which will be used to develop and test the integration.
- Use the guide below or the Postman Collection to build your app. Resources to assist with development are provided here.
- When logged in, you can use the Integration Tracker to view the status of your integration, notes from meetings with Integration Engineers, resources related to your solution, and more by clicking the User profile icon in the top right corner of the screen and selecting Integrations.
- When development is complete, contact us to certify your integration. Once certified, the merchant or an authorized contact will be able to retrieve Production credentials from the API Access page of your Production Payments Hub account. For more information about using Payments Hub, visit the Help Center.
Server Requirements
Any connections must be made over TLS v1.2 or higher. The following are the supported ciphers:
- ECDHE-ECDSA-AES128-GCM-SHA256
- ECDHE-RSA-AES128-GCM-SHA256
- ECDHE-ECDSA-AES256-GCM-SHA384
- ECDHE-RSA-AES256-GCM-SHA384
iFrame JavaScript SDK Setup
1. Place the following JavaScript in a file named "ph.js" (or your preferred name):
- addressFieldId: This field is required if zip or zip+4 are present.
- zipFieldId: This field is required if address or zip+4 are present.
- zipPlusFourFieldId: If this field is set, the data in it will be added to the zip value to send the 9-digit zip.
2. Add references to the JavaScript SDK file, https://sdk.paymentshub.dev/pay-now.min.js, and your local JavaScript file from Step 1, ph.js, on your checkout page. For example:
HTML
3. Add code to initialize the SDK when the checkout page loads, and be sure to replace the placeholders with your credentials. For example:
HTML
4. Build your form to collect payment data, including any fields necessary for the way that your business wants to process payments. For example, you might include fields for customer name, address, and the card expiration date. A few fields need to be created in a special way to work with the SDK. See below for how to create these fields:
HTML
The SDK will turn these divs into iFrames when the page loads. The hidden card-token field will be populated by the SDK when the user clicks the button to "Submit Payment."
Either set your form's id to "pay", or adjust the JavaScript at the very bottom of the file from Step 1 to use your desired form id.
5. If you would like to customize the appearance of the iFrame fields, place CSS similar to the following in a file named "ph.css" (or your preferred name):
6. When the user clicks the button to "Submit Payment," the browser will make a call to the getToken() JavaScript function defined in the ph.js file. This function uses the SDK to run validation checks and tries to tokenize the card. If either the validation or tokenization step fails, the payment form is not submitted. In these cases, you should notify the user so they can correct the card information on the current page or try another card. When card tokenization is successful, the getToken() function will populate the "card-token" field in your form, right before programmatically submitting the payment form.
7. When the POSTed form is received by your server, you will need to make two calls to API endpoints.
The first call is to authenticate. You can make this call using a variety of server-side languages or libraries of your choice. Here are the details for this request:
Method: POST
Request URL: https://proxy.payanywhere.com/auth
Headers:
Name | Value | Description |
---|---|---|
Content-Type | application/json | Required. Content type of message. For most messages, this will be the default. |
Content-Length | 1234 | Required. This value should be set to the exact length of the message body you are sending. |
x-nabwss-appsource | pa_isv_1234567890abc | Required. This value is specific to each individual API account. For example, ISVs selling an application to multiple companies would use a different value for each company. Similarly, if a user has multiple accounts (MIDs) with us, the value for the x-nabwss-appsource header would be different for each MID. |
Request body:
JSON response:
When authentication is successful, you will receive a JSON response which includes a "token" field. The value in this field will be used in the next step.
8. The second API call is to submit the payment. Pass in the information from your payment form including the hidden card-token field. Include the token (JWT) received in the previous call.
Method: POST
Request URL: https://proxy.payanywhere.com/mids/YourMID/gateways/payment
Headers:
Name | Value | Description |
---|---|---|
Content-Type | application/json | Required. Content type of message. For most messages, this will be the default. |
Content-Length | 1234 | Required. This value should be set to the exact length of the message body you are sending. |
Authorization | Bearer | Required. |
x-nabwss-appsource | pa_isv_1234567890abc | Required. This value is specific to each individual API account. For example, ISVs selling an application to multiple companies would use a different value for each company. Similarly, if a user has multiple accounts (MIDs) with us, the value for the x-nabwss-appsource header would be different for each MID. |
Body:
9. Your site will receive a response with details of the attempted payment. Below is a sample response:
Based on the response (approval, decline, partial auth, etc.), your site can present any relevant information to the user and continue your desired user experience. The uniq_id field can be parsed to get a transaction identifier which can be used for a void or refund of that same transaction. For more details, see the Server Functions page.