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
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:
The X-Login is your login API Key, it can be retrieved from the Tupay Panel by going to Settings -> API Access -> Deposit credentials -> API Key.
The X-Date is the date in ISO8601 Datetime with Timezone. Format expected: ISO8601 Datetime with Timezone: yyyy-MM-dd'T'HH:mm:ssZ. E.g.: 2020-06-21T12:33:20Z.
The Authorization value is case sensitive and must include all the above mentioned values.
The JSONPayload is the exact same JSON you sent in the body of the request.
In case the JSONPayload value is empty (for example in the status or payment methods endpoints), use an empty string ("") instead.
The JSONPayload should be converted to UTF-8 before hashing it to prevent Invalid Signature error when sending characters with different encodings.
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
For security purposes, you need to whitelist the IPs from where you will call our API.
In order to whitelist your IPs and make the process as smoother as possible, you should go to Settings -> API Access and add the list of IPs you will possibly use under the Deposit IP Address section.
Best Practices
We recommend you follow this list of technical and security practices to maximize the security of the information end-to-end.
Always make sure to verify the Signatures control string sent in the notifications to validate the veracity.
All information we receive is converted to UTF-8. Be sure to convert it to UTF-8 as well to ensure that both parties have the same details.
Always validate that a deposit is not released more than once based on the deposit_id (Notifications can be sent multiple times). Make sure that a deposit is not released more than once based on the deposit_id, as the notification may be sent more than once.
Examples
Check the examples in the different languages on how to properly calculate the Signature.
<?phpclassDirecta24Example {const D24_AUTHORIZATION_SCHEME ="D24 ";const HMAC_SHA256 ='sha256';publicstaticfunctionbuild_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 hashreturnself::D24_AUTHORIZATION_SCHEME .hash_hmac(self::HMAC_SHA256, $string, $api_signature); }}