Send POST /payment-request with the appropriate parameters.
Properties secret_key and payment_page_id must be pre-configured by the hiqdev/Merchant team.
As a response, you'll get an URL where you can either redirect a user, embed it as an Iframe inside your application.
In order to notify the POS of success payments, we use Cross-Window JS communication.
After embedding the Iframe, you can subscribe to the messages from it:
const frame_url = 'https://url.to.the.payment.page.retured.from.the.API/pay/#pr_naNzb914a'
window.addEventListener('message', (event) => {
if (frame_url && frame_url.startsWith(event.origin)) { // Make sure event is not a fake
const data = JSON.parse(event.data);
if (data.isSuccess) {
alert('Success payment!');
}
}
});
You should also always check the Payment Request status to make sure the received message is real. See bellow.
Send GET /payment-request/:pr_id to get status and all the details.
notify_urlAs soon as the Customer pays a Payment Request, we will send a notification at the URL, you've passed during the Payment Request creation.
Sample request:
POST /merchantPayTransaction HTTP/1.1
Host: hiapi.blazingcdn.com
X-Notification-Id: pnot_GR8Oykh1EqM
Content-Type: application/x-www-form-urlencoded
payment_request_id=preq_z6XJVys8YYr&reference_id=z0xy7yqkt&transaction_id=txn_jY8m79iwjo&state=paid&external_transaction_id=ch_1HFHbcLb0dkY3ky52KC5IhKZ&payment_method=payment_card_token&payment_service=payment_card_token_eur_hpp&payment_provider=stripe&amount=199.00¤cy=USD&pay_time=2020-08-12T10%3A54%3A53%2B00%3A00&payer=cus_HovQqlZAHML6ew&description=blazingcdn.com%3A+deposit+test123%40example.com+for+199.00USD&commission=0.00&signature=0932197ff7bcdf2a7103b538d00bf18afaca5e3668fe784f34859fde4ab9da0a
The body parameters are the following:
| name | description |
|---|---|
| payment_request_id | The Payment Request ID, as received after creation |
| reference_id | ID of the Payment Request in the POS database, as passed during Payment Request creation |
| transaction_id | ID of the Payment Transaction. May be stored at the POS side to identify the resulting transaction |
| state | MUST be paid |
| external_transaction_id | ID of the Payment Confirmation at the Service Provider side |
| payment_method | The effective Payment Method name |
| payment_service | The effective Payment Service name |
| payment_provider | The effective Payment Provider code |
| amount | How much money have the user paid, as requested in the Payment Request |
| currency | The currency of that amount, as requested in the Payment Request |
| pay_time | RFC8601 date time in UTC, when the payment actually happened |
| payer | Name, email, account number or any other information that identifies a Payer, provided by the Payment Provider with the confirmation |
| description | A payment description, as requested in the Payment Request |
| commission | Amount of money set by the merchant for the payment processing. May be used to compensate operational spending for a specific payment provider. |
| signature | A hash, that is calculated based on a secret_key to verify authority of this confirmation |
Before accepting this Payment Confirmation Notification you MUST always verify the signature. You can use the following PHP code as an example:
function validate_signature(string $secret_key, array $notification): void
{
$hash = hash('sha256', json_encode([
$notification['payment_request_id'],
$notification['transaction_id'],
$notification['state'],
$notification['amount'],
$secret_key,
]));
if (! hash_equals($notification['signature'], $hash)) {
throw new Exception('Invalid signature');
}
}