### Generate SHA-512 Signature in Python Source: https://docs.transactbridge.com/ A Python example for generating a SHA-512 hash, essential for creating API signatures. It utilizes the 'hashlib' module. ```python import hashlib text = 'tb_test_q47Wqf04e1sIZu22kVwWBrDncigOkIPN:tb_test_CT5u9ZeNMBEL884g6gP3' m = hashlib.sha512(text.encode('UTF-8')) print(m.hexdigest()) # will print below signature ``` -------------------------------- ### Request and Response Structure Source: https://docs.transactbridge.com/ Details common parameters for request bodies and the standard structure of API responses. ```APIDOC ## Request Body Parameters ### Description Following are some of the common parameters that the request body accepts. ### Parameters #### Request Body - **filter** (Object) - Optional - In getting a list of Objects API `filter` parameter allows us to narrow down the results. Each API can have a different `filter` parameters. - **page** (Number) - Optional - Used to paginate if the API is of Get a list of Objects. - **sort** (Object) - Optional - In getting a list of Objects API `sort` parameter allows us to get a sorted result. Each API can have a different `sort` parameters. - **fromDate** (Date) - Optional - The date format used is `yyyy-MM-dd HH:mm:ss`. For Ex. 2023-10-19 18:30:00 ## Response Body Structure ### Description All the responses will contain these 4 parameters `status`, `sub_status`, `msg`, `data`. Other parameters are on a need basis. ### Response #### Success Response (200) - **status** (String) - Enum: `success`, `error` - This is the final status of the API, if the status is not successful then consider that the API did not run successfully. You can check `msg` parameter to understand what went wrong. - **sub_status** (String) - Used for internal purposes only. - **msg** (String) - To understand the error if the request was not successful. - **data** (Array or Object) - Contains the response data of the request. - **maxPageSize** (Number) - The maximum number of data objects that are returned in the Get All requests. - **hasMore** (Boolean) - If the Get All request has more data objects then the value is `true`. Use `page` parameter in the request to get the next data objects. #### Error Response - **status** (String) - Enum: `success`, `error` - This is the final status of the API, if the status is not successful then consider that the API did not run successfully. You can check `msg` parameter to understand what went wrong. - **sub_status** (String) - Used for internal purposes only. - **error_code** (String) - This parameter is only available when `status` in the response body is `error`. - **msg** (String) - To understand the error if the request was not successful. ``` -------------------------------- ### Generate Extended API Signature in Python Source: https://docs.transactbridge.com/ Use this Python function to generate an extended API signature for authorization. It requires a payload dictionary and a secret key. Ensure correct encoding and hashing for security. ```python import json import hmac import hashlib import base64 def base64url_encode(data: bytes) -> str: """Encodes bytes into base64url without padding.""" return base64.urlsafe_b64encode(data).rstrip(b'=').decode('utf-8') def get_api_extended_signature(payload: dict, secret: str) -> str: try: # Header auth_headers_json = { "alg": "HS512", "typ": "JWT" } encoded_header = base64url_encode(json.dumps(auth_headers_json).encode("utf-8")) encoded_payload = base64url_encode(json.dumps(payload).encode("utf-8")) token = f"{encoded_header}.{encoded_payload}" # Signature using HMAC SHA-512 signature = hmac.new( secret.encode("utf-8"), token.encode("utf-8"), hashlib.sha512 ).digest() encoded_signature = base64url_encode(signature) return f"{token}.{encoded_signature}" except Exception as e: raise e # Example usage payload = {"returnUrl":"https://www.transactbridge.com/demo","quoteCurrCode":"USD"} secret = "tb_test_CT5u9ZeNMBEL884g6gP3" signed_token = get_api_extended_signature(payload, secret) print(signed_token) # will print below signature # eyJhbGciOiAiSFM1MTIiLCAidHlwIjogIkpXVCJ9.eyJyZXR1cm5VcmwiOiAiaHR0cHM6Ly93d3cudHJhbnNhY3RicmlkZ2UuY29tL2RlbW8iLCAicXVvdGVDdXJyQ29kZSI6ICJVU0QifQ.ipnnEhwj0kzUhkGvcXD_maWFt17IVxdmR68ETrruku3WSif-NDMOMH-DrAu78tV-T9TxR2coO8lLM9A2EZSlfw ``` -------------------------------- ### Billing Session Statuses Source: https://docs.transactbridge.com/ Describes the various statuses a billing session can have. ```APIDOC ## Billing Session Statuses ### Description These billing session statuses represent the state the session is currently in. ### Types - **CREATED** - A session has been created but the link has not been used by the customer to initiate the payment window. - **STARTED** - When the customer opens the payment link and proceeds with accepting TnC. - **CLOSED** - Payment has been successfully done by the customer and an invoice has been created. - **EXPIRED** - In case of non-payment, the link will be expired after a configured interval. Partners can pass the expiry date at the time of session creation. The default expiry date is 24 hours from the time of the creation of the session. - **REJECTED** - This status needs to be enabled by the Admin Team, once done, if a customer clicks on "Back to Shopping" on the payment page then the billing session will be marked `REJECTED` and no further attempts will be allowed. ``` -------------------------------- ### Encrypt Data using RSA PKCS1 OAEP Padding Source: https://docs.transactbridge.com/ Use this function to encrypt sensitive data strings with a public key using RSA PKCS1 OAEP padding. Ensure the crypto module is imported and the publicKey is obtained from Transact Bridge. This is typically used for sensitive data like payment details. ```javascript const crypto = require('crypto'); // data is the payload string that needs to be encrypted // publicKey is provided to the partner by Transact Bridge function encryptRsa(publicKey, data) { try { const encryptMe = crypto.publicEncrypt( { key: publicKey, padding: crypto.constants.RSA_PKCS1_OAEP_PADDING, }, Buffer.from(data), ); let hash = encryptMe.toString('base64'); return hash; } catch (error) { throw error; } } ``` -------------------------------- ### Generate SHA-512 Signature in PHP Source: https://docs.transactbridge.com/ This PHP code snippet demonstrates how to generate a SHA-512 hash for API signature generation. It uses the built-in 'hash' function. ```php $shatest = ("tb_test_q47Wqf04e1sIZu22kVwWBrDncigOkIPN:tb_test_CT5u9ZeNMBEL884g6gP3"); $sha512test = hash("sha512",$shatest); echo $sha512test; // will print below signature // 7ae85bcc8d0af6ceacd271da52d22d1fa091733b891ff133169ef959647f5d23232c6b6709150f1cbbabc5d2a815cb05b91448c3c3eabc9447343b689eba7606 ``` -------------------------------- ### Generate API Signature in Ruby Source: https://docs.transactbridge.com/ Use this Ruby function to generate a SHA-512 hash for API authentication. It concatenates the API key and secret key with a colon before hashing. Ensure you have the 'digest' library available. ```ruby def generate_signature(api_key, secret_key) require 'digest' # Concatenate API key and secret key with colon signature_string = "#{api_key}:#{secret_key}" puts "\nSignature String:" puts signature_string # Generate SHA-512 hash signature = Digest::SHA512.hexdigest(signature_string) puts "\nFinal Signature:" puts signature signature end # --------- INVOCATION ---------- api_key = "tb_test_q47Wqf04e1sIZu22kVwWBrDncigOkIPN" secret_key = "tb_test_CT5u9ZeNMBEL884g6gP3" signature = generate_signature(api_key, secret_key) ``` -------------------------------- ### Generate SHA-512 Signature in JavaScript Source: https://docs.transactbridge.com/ Use this JavaScript code to generate a SHA-512 hash for API authentication. Ensure you have the 'crypto' module available. ```javascript const crypto = require('crypto'); function generateChecksumString(str) { return crypto.createHash('sha512').update(str).digest('hex'); } let signature = generateChecksumString("tb_test_q47Wqf04e1sIZu22kVwWBrDncigOkIPN:tb_test_CT5u9ZeNMBEL884g6gP3") console.log(signature); // will print below signature // 7ae85bcc8d0af6ceacd271da52d22d1fa091733b891ff133169ef959647f5d23232c6b6709150f1cbbabc5d2a815cb05b91448c3c3eabc9447343b689eba7606 ``` -------------------------------- ### RSA Encryption Module Source: https://docs.transactbridge.com/ Provides a JavaScript function for encrypting sensitive data using RSA with OAEP padding. ```javascript ## RSA Encryption ### Description Encryption is used to send sensitive data like credit card and debit card details in the S2S API. We use "RSA (Padding: RSA_PKCS1_OAEP_PADDING)" algorithm to encrypt the data string using a key. To use this module the partner must be PCI-certified. There is no need to integrate this if the partner is not using Create Payment Request. ### Code Example ```javascript // Crypto module is used to encrypt a data string const crypto = require('crypto'); // data is the payload string that needs to be encrypted // publicKey is provided to the partner by Transact Bridge function encryptRsa(publicKey, data) { try { const encryptMe = crypto.publicEncrypt( { key: publicKey, padding: crypto.constants.RSA_PKCS1_OAEP_PADDING, }, Buffer.from(data), ); let hash = encryptMe.toString('base64'); return hash; } catch (error) { throw error; } } ``` ``` -------------------------------- ### Generate Extended API Signature in JavaScript Source: https://docs.transactbridge.com/ Use this JavaScript function to generate an extended API signature by encoding the authentication header and payload, then creating an HMAC-SHA512 signature. Requires the 'crypto' module. ```javascript const crypto = require('crypto'); function getApiExtendedSignature(payload, secret) { try { const authHeadersJson = { alg: 'HS512', typ: 'JWT', }; const authHeadersStr = JSON.stringify(authHeadersJson); const encodedAuthHeader = Buffer.from(authHeadersStr, 'utf8').toString('base64url'); const payloadStr = JSON.stringify(payload); const encodedPayload = Buffer.from(payloadStr, 'utf8').toString('base64url'); let token = `${encodedAuthHeader}.${encodedPayload}`; const signature = crypto.createHmac('sha512', secret).update(token, 'utf8').digest('base64url'); return `${token}.${signature}`; } catch (error) { throw error; } } let signature = getApiExtendedSignature({ returnUrl: 'https://www.transactbridge.com/demo', quoteCurrCode: 'USD' }, "tb_test_CT5u9ZeNMBEL884g6gP3") console.log(signature); // will print below signature // eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJyZXR1cm5VcmwiOiJodHRwczovL3d3dy50cmFuc2FjdGJyaWRnZS5jb20vZGVtbyIsInF1b3RlQ3VyckNvZGUiOiJVU0QifQ.LQKyKPK9Sw_cXyuBxr7gnaUICYY-zASOcKezCr5ed5Vly0E1DXR1-8TZSVfPc9AGymTCjt3kvg48Z93es3slew ``` -------------------------------- ### Generate Extended API Signature in PHP Source: https://docs.transactbridge.com/ This PHP function generates an extended API signature using base64url encoding for the header and payload, and HMAC-SHA512 for the signature. Ensure JSON_UNESCAPED_SLASHES is used for correct encoding. ```php function base64url_encode($data) { // Base64 encode, then convert to URL-safe format and remove padding return rtrim(strtr(base64_encode($data), '+/', '-_'), '='); } function getApiExtendedSignature($payload, $secret) { try { // Header $authHeadersJson = [ "alg" => "HS512", "typ" => "JWT" ]; $encodedHeader = base64url_encode(json_encode($authHeadersJson, JSON_UNESCAPED_SLASHES)); $encodedPayload = base64url_encode(json_encode($payload, JSON_UNESCAPED_SLASHES)); $token = $encodedHeader . "." . $encodedPayload; // HMAC-SHA512 Signature $signature = hash_hmac("sha512", $token, $secret, true); $encodedSignature = base64url_encode($signature); return $token . "." . $encodedSignature; } catch (Exception $e) { throw $e; } } // Example usage: $payload = [ "returnUrl" => "https://www.transactbridge.com/demo", "quoteCurrCode" => "USD" ]; $secret = "tb_test_CT5u9ZeNMBEL884g6gP3"; $token = getApiExtendedSignature($payload, $secret); ``` -------------------------------- ### Transaction Types Source: https://docs.transactbridge.com/ Defines the different types of transactions supported by the API. ```APIDOC ## Transaction Types ### Description Different types of transactions represent different use cases. ### Types - **DEPOSIT** - This is a credit transaction and will be credited only when the transaction is in status `SUCCESS`. - **REFUND** - This is a debit transaction for the refund raised by the partner. - **CHARGEBACK** - This is a debit transaction for the refund raised by the bank against dissatisfaction. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.