iFrame Integration Documentation
Basic requirements for integrating with PayHQ iFrame
Enable iFrame from your PayHQ account
Generate your iFrame access token
Use this access token in your iFrame integration code
Request payment token for your transaction
Exchange the payment token to complete the transaction
Before you start
Please make sure you have access to PayHQ Sandbox account
Go to https://www.payfirma.com/signup or call 1 (800) 747-6883 and ask for a Payment Advisor to set up a Demo / Sandbox Account for you.
iFrame in action
You can visit https://payhq-iframe-test-demo.firebaseapp.com/ to see the iFrame in action. You can use the test card data mentioned on this page to complete a test transaction.
Important URL
Sandbox – https://sandbox.payfirma.com
Test – https://test.payfirma.com
Production – https://hq.payfirma.com
Developer portal – https://developers.payfirma.com
Integration Process
The integration process comprises of 3 stages
Stage 1 – Your team works on the integration work by using the Sandbox account
Stage 2 – After you finish your integration we will help you go through a certification process to make sure that your integration satisfies your end goal that you had for this integration.
Stage 3 – Request a production PayHQ account. Make sure you change all the URLs in your code to point to the production environment before you go live with your code.
Enable iFrame and generate access token
Login to your merchant account
Click “Settings” on the top right menu
Select “Hosted Pay Page and iFrame” tab on settings page
At the top of the page that opens you will see the iFrame Settings
Click the create button on the right to generate your iFrame token
You will notice that the iFrame access token has been generated. You have an option to delete or refresh the access token as per your requirements
At this point you are ready to start writing your code to integrate iFrame into your web page.
Write your integration code
Link the PayHQ iFrame Javascript library in the webpage where you will be adding the iFrame. The URL of this library for the test environment is https://test-iframe.payfirma.com/payhq-js/payhq-iframe-lib-test.min.js
Add three placeholder div elements in your webpage to hold the iFrames for card number, expiry date and CVV. At this point it’s important to know that PayHQ iFrame is not a single iFrame that you add to your webpage. It comprises three different iFrames, one each for card number, expiry date and CVV. This gives you more flexibility to design your UI the way you want to.
You may choose to provide any id of your choice to the three placeholder divs you added in step 2
The next step is to write Javascript code to initialize the iFrame in your webpage. (See example below)
At this point you should be ready to run your webpage and see the iFrame in action.
Step 4 - script tag
START SCRIPT TAG
// 4.1 select the payfirma test environment
// LIVE, TEST, SANDBOX
const environment = 'TEST'
// 4.2 set apiKey for authorization token
const apiKey = "iframe access token";
// 4.3 set options
var options = {
fields: {
cardNumber: {
selector: "#cardNumber_container",
placeholder: "Credit Card *",
},
cardExpiry: {
selector: "#cardExpiry_container",
placeholder: "Expires (MM/YY) *"
},
cardCvv: {
selector: "#cardCvv_container",
placeholder: "CVV *"
}
},
// set the CSS styles to apply to the payment fields
// camelCases instead dash-separated CSS attributes
style: {
input: {
"fontFamily": "robotoregular,Helvetica,Arial,sans-serif",
"fontWeight": "700",
"fontSize": "1em",
"color": "#ff0000",
"backgroundColor": "#a2d157",
}
}
};
// 4.4 init payfirma object
const payfirmaObject= Payfirma.payfirmaInit(environment, apiKey,options);
payfirmaObject.NumberField().render(options.fields.cardNumber.selector);
payfirmaObject.ExpiryField().render(options.fields.cardExpiry.selector);
payfirmaObject.CVVField().render(options.fields.cardCvv.selector);
// 4.5 set button event
document.querySelector('button#payNow').addEventListener('click', () => {
// 4.6 Get Form fields data
const formData = {first_name,last_name,email,amount}
// 4.7 get card token
payfirmaObject.tokenize().then((response)=>{
// Set result
document.querySelector('#cardtoken-result').innerText = response.payment_token;
// If you need to check payment token expiry,
// you need to make a logic with response.expires_in
// console.log('payment token will expire in ',response.expires_in + " seconds")
// 4.8 Make a sale transaction with card token.
makeSaleRequest(response.payment_token, formData);
}).catch(error => {
// There was an error tokenizing your card data
console.log('error from server')
console.log(error);
})
});
END SCRIPT TAG
Request payment token
In the code shared above the payfirmaObject.tokenize()
is responsible for submitting the card details to PayHQ backend and receive a payment token.
Complete the sale
The payment token received in the previous step can be used to complete the sale
Finally call the
makeSaleRequest
method to complete the sale. This method will make an API call to PayHQ backend and complete the saleThe response of the final sale method contains the lookup ID of the transaction. This lookup ID should be saved for performing refund operations in future.