Walkthrough
Traffic Authentication
The Authorization Service requires the Basic Token in the header while the Transaction, Customer and Plan Services require a Bearer Token. All requests to the Authorization Service will need to point to the root endpoint or url https://auth.payfirma.com and requests to the other services will be addressed to https://apigateway.payfirma.com.
Get your Bearer Token
Step 1. Get your Client ID & Client Secret from your PayHQ account by going to Settings – eCommerce.
Step 2. Using Base64 encoding, combine the Client ID & Client Secret together with a colon in between to acquire your Basic Token for your header.
Step 3. Use your Basic Token with your Client ID and Client Secret to get your Bearer Token from the Client Credentials Grant.
Step 4. Set up a recurring request to get your Bearer Token based on the validity timeframe that you set for your Client ID & Client Secret. The default validity that we recommend is 12 hours. This can be changed in Settings - eCommerce when you create or edit a Client ID and Client Secret.
Get your Merchants Bearer Token
Step 1. Set up your Partner OAuth flow with PayHQ by sending us your selected business name, an image url for your business with a square format, and the callback URI to your Merrco or Payfirma point of contact.
Step 2. Set up an invokable Authorization function in your application to get the short-lived authorization code when your Merchants complete the sign-in and authorization process.
Step 3. Make an Authorization Code Grant request with the Authorization code from Step 2
Step 4. Store the Bearer and Refresh Tokens for each Merchant
Step 5. Use the Token Refresh Grant to request a new Access Token either based of receiving a 401 error for an invalid token, or based off the time validity of the Bearer Token. Please note that Bearer Tokens are valid for 12 hours and the Refresh Token can only be used to refresh the Bearer token once with a new Refresh token provided with a successful Refresh Token Grant request.
Simple Transactions
Sales and Authorizations can be completed on their own, while a Capture transaction requires an Authorization transaction and a Refund requires either a Sale or Capture.
Charge a card
Step 1. Use the Bearer Token as your Authorization header and make sure to provide all the card parameters required for a regular sale transaction along with the different request URL.
Authorize a hold and then capture the payment
Step 1. Use the Bearer Token as your Authorization header and make sure to provide all the card parameters required for a regular sale transaction along with the different request URL. The hold will stay on the card for between 5-30 business days depending on the policy of the cardholder’s bank.
Step 2. Use the ID field from the transaction response to finalize the payment and request funds. You will still be able to request a payment even if the hold has expired, but you run the risk of the funds not being available for the payment.
Refund a payment
Option 1. Log into PayHQ and select My Transactions to view the complete list of transaction available for review. With each transaction, you have the control to refund the transaction and send a receipt for the refund to the email of your preference.
Option 2. Build the API request to ask for a refund by using the ID from the original sale or capture transaction. Authorization transactions cannot be refunded because no funds have been requested or transferred.
Encrypt credit card as a token
The Payfirma Card Encryption Javascript library generates a secure and encrypted card token to be used with any of our transaction methods.
How to use this library
This library was developed specifically for client use.
Within your HTML page, include the following inside the head tab. Alternatively, you can import/require the script from your code base.
You can access and reference the library from inside your Javascript file.
Your public encryption key requires to be sent as an alphanumeric string.
Make sure all your card parameters are sent as numeric strings. Numbers or objects will not be accepted.
Generate an encoded token using the the encode function. It requires Public Encryption Key, Card Number, Card Month, Card Year, CVV2 as parameters.
Use the encoded token within the body of your transaction request.
Post your first transaction!
Example:
Future Payments
The Customer and Transaction Services can be used together to store cards and make payments on those stored cards.The Customer and Plan Services can be used together to set up recurring payment plans called subscriptions.
Storing a credit card
Step 1. Create a customer with all the key details that you want to store in the PayHQ database.
Step 2. Use the Customer_Lookup_ID for the customer you just created to save a card to that customer.
Making a payment on a stored card
Step 1. Use the Customer_Lookup_ID to make a payment with the default card.
Step 2. Use the Customer_Lookup_ID and the Card_Lookup_ID to make a payment with a card other than the default card stored for that customer.
Subscribe a customer with a stored card
Step 1. Create a plan with the key payment details.
Step 2. Make sure that you have a saved customer with a stored card.
Step 3. Create a subscription based on a plan for customer with a stored card.
Reporting
Transaction reporting can be accessed through the PayHQ web application or through the PayHQ API.
Get your transactions
Option 1. Log into PayHQ and select "My Transactions" to view the complete list of transaction available for review. There is also the option to export the transaction list to a .csv file.
Option 2. Build the API call to request the full list of transactions according to whatever parameters you specify.
Get your merchant's transactions
Request the full list of transactions according to whatever parameters you specify and please note that the account data will be based off the Bearer token.
Glossary
Authorization is a financial transaction that places a hold on the credit or debit card for the amount you specify. This hold will last 10-20 business days depending on the cardholder’s bank policy. Please see Capture for how to receive money from this hold. This term can also refer to the class of token for the Basic and Bearer Tokens.
Authorization Service the part of the API that grants access tokens to the Transaction Service.
Basic Token is an encoded version of your Client ID & Client Secret in Base64 format using UTF-8 encoding that you’ll use for most requests to the Authorization service. Use the tool of your choice and encode the Client ID & Client Secret together with a colon in between both values to get your Basic Token.
Here is an example in bash:
Bearer Token is a token that you’ll receive from the authorization service to use in the header for all requests to the Customer, Plan, and Transaction services. The Bearer Token lasts for 20 minutes.
Capture is a financial transaction that collects the payment after a hold has been placed on a credit or debit card. This transfer of funds is entirely dependent on a successful Authorization transaction.
Cards refer to the unique object that is created when you store a credit or debit card in our tokenized card vault.
Client ID & Client Secret are a set of unique account credentials that you generate in your PayHQ account to begin working with our API and should only be shared with team members or colleagues who are going to be working directly with your code base.
Customer is an object in our Customer Service that you create to be able to store customer information, store the Cards of that customer, and create Subscriptions on those cards.
Customer Service the group of API operations that allows developers to create customer objects, store sensitive card data by creating tokens and create subscription payments
Password is the secure, private key that you established with your PayHQ login. This field is only used for the Password Grant Operation and should be managed as privately as possible; only you or people accessing your code should have access to it.
Plans are payment templates that you can create with the Plan Service and are the base object needed for a Subscription payment.
Plan Service the set of operations used for creating recurring payment plans used to create subscription objects.
Refund is a reverse of a Sale or Capture transaction that will send the money from the merchant account back to the account of the cardholder.
Sale is the straightforward purchase transaction to charge a credit or debit card.
Subscription payments are created when a Plan is used to bill the stored Card of a Customer. Subscriptions do not have to be an exact copy of a Plan and can be updated at the time of creation as needed.
Transaction Service the set of transaction and reporting functions, other than subscription payments, for the API.
Username is the email address associated with your PayHQ login. This field is only used for the Password Grant Operation.
Last updated