Signature Authorization and Calculation
API credentials
Our Deposits APIs uses API Keys in all of the requests to authenticate. Your API Keys can be retrieved from the Tupay Panel by going to Settings -> API Access.
The API Keys on the STG and PROD environments are different.
There are basically two set of credentials:
One API Key and one API Signature for POST operations.
One API Key key for read-only endpoints.
Authentication to the API is performed via HTTP Basic Auth. You must provide your API Key in all the requests as the basic auth username value. You do not need to provide a password.
Your API Key must be sent in all the API calls using the X-Login field on the header of the request.
Your API Keys, along with your IP Addresses are your way to authenticate yourself, therefore, do not share your secret API keys in publicly accessible areas such as GitHub, client-side code and so forth.
Headers
Header
Format
Mandatory
Description
Authorization
String
Yes
"TUPAY"
plus a hash HMAC256 to verify request integrity
X-Login
String
Yes
Merchant API Key
X-Date
String
Yes
ISO8601 Datetime: yyyy-MM-dd'T'HH:mm:ssZ
. E.g.: 2020-06-21T12:33:20Z
Content-Type
String
Yes
application/json
X-Idempotency-Key
String
No
Unique value generated by the client which the server uses to recognize subsequent retries of the same request
Calculating the Signature
All the calls to our Deposits APIs will contain an Authorization
field on the header used to ensure request integrity and to authenticate yourself since you will use your own secret key (API Signature) to generate and encrypt a hash.
It has to be created using HMAC-SHA-256 (RFC 2104) encoding and the payload must include the following details:
Use your API Signature to generate the Authorization value
The Authorization
field on the header of the requests will contain the string "TUPAY " plus the hash generated, in the following format:
Authorization: "TUPAY " + HMAC256(X-Date + X-Login + JSONPayload)
Example:
Authorization: TUPAY 223a9dd4784726f1536c926da7dc69155a57612c5c3c1e1b429c367a5eee67cf
Our API supports idempotency for safely retrying requests without accidentally performing the same operation twice. This is useful when an API call is disrupted in transit and you do not receive a response. For example, if a request to the Deposit Creation Endpoint does not respond due to a network connection error, you can retry the request with the same idempotency key to guarantee that no more than one deposit is created.
In order to perform an idempotent request you need to send the X-Idempotency-Key: <key>
header with a random and unique string.
Idempotency works by saving the resulting status code and body of the first request made for any given idempotency key, regardless of whether it succeeded or failed. Subsequent requests with the same key return the same result, including 500
errors.
An idempotency key is a unique value generated by the client which the server uses to recognize subsequent retries of the same request. How you create unique keys is up to you, but we suggest using V4 UUIDs, or another random string with enough entropy to avoid collisions.
All POST
requests accept idempotency keys. Sending idempotency keys in GET
and DELETE
requests has no effect and should be avoided as these requests are idempotent by definition.
Content-Type
All of our Deposits APIs are designed to receive and respond the information in JSON format.
This header won't change across the requests, and shall always be: application/json
Examples
Check the examples in the different languages on how to properly calculate the Signature.
<?php
class Directa24Example {
const TUPAY_AUTHORIZATION_SCHEME = "TUPAY ";
const HMAC_SHA256 = 'sha256';
public static function build_deposit_key_signature($api_signature, $x_date, $deposits_api_key, $json_payload)
{
// Concatenate the content of the header X-Date, your deposits API Key (X-Login) and
// the whole JSON payload of the body of the request
$string = $x_date . $deposits_api_key . $json_payload;
// Generate the HASH by using yur own deposits API Signature and
// concatenate "D24 " in front of the hash
return self::TUPAY_AUTHORIZATION_SCHEME . hash_hmac(self::HMAC_SHA256, $string, $api_signature);
}
}
Última actualización
¿Te fue útil?