Generate Payment Link From API Using TruBuy App

Generate, Share, and Get Paid — All Through the API

Generate Payment Link From API

The TruBuy App Payment Link Generator API allows external systems to programmatically create secure payment links that customers can use to complete payments through the TruBuy payment gateway.

1. Create Webstore or Install Plugin

Generate Payment Link using API requires one of the following TruBuy App options:

Payment links can be generated from:

  • external platforms
  • SaaS systems
  • CRM applications
  • eCommerce websites
  • billing platforms

Once generated, the payment link can be sent to a customer via:

  • email
  • SMS
  • WhatsApp
  • invoice systems
  • checkout systems

The API returns a fully hosted payment page URL where the customer completes the payment securely.


2. API Settings Configuration

Before using the API, the integration must be configured in the Custom API Settings panel, located in your webstore or website with TruBuy App plugin.

Configuration Fields

FieldDescription
API Allowed IPsWhitelisted IP addresses allowed to call the API
API KeyAuthentication key sent in request headers
HTTPS OnlyForces API calls over HTTPS

3. API Endpoint

POST /wp-json/tba/v1/payment-link/

Example:

https://yourdomain.com/wp-json/tba/v1/payment-link/

The request must include:

  • JSON payload
  • authentication headers
  • hashed verification

4. Example JSON Response

When a payment link is successfully created, the API returns a response similar to:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
{
  "Status": "Success",
  "FormID": "paymentForm",
  "ButtonClass": "button atl",
  "originpoint": "https://test.ipg-online.com",
  "endpoint": "https://test.ipg-online.com/connect/gateway/processing",
  "ButtonLabel": "Make Payment",
  "hashExtended": "D/uSHy8o/AxoZ4jRxoomMts8TTnluOiejBsjfMjQ2aQ=",
  "link": "https://[your-webstore-domain]/my-payment-link/KYFZGZZ7HP1"
}

The link field is the generated payment page.

5. Request Parameters

ParameterDescription
merchant_idMerchant account ID
platform_nameName of the calling platform
chargtotalPayment amount
cnameCustomer name
emailCustomer email
product_infoName of the product/service
product_descriptionDescription
currency_codeISO currency code
platform_transaction_idExternal transaction ID
platform_checkout_idExternal checkout reference
hashExtendedSecurity hash

6. Security: Hash Generation

To ensure request integrity, TruBuy requires a HMAC SHA256 hash.

The hash is generated by:

  1. Sorting all parameters alphabetically
  2. Concatenating values separated by |
  3. Hashing using HMAC SHA256
  4. Encoding result using Base64

This ensures:

  • request authenticity
  • payload integrity
  • secure API calls

7. Hash Generation Example

String Format

value1|value2|value3|value4

Hash Algorithm

HMAC SHA256

Encoded Output

Base64

8. PHP Implementation

The following PHP function generates a TruBuy App payment link.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
<?php
/*
This function is used to generate a TruBuy App Payment Link.
*/
function _generate_payment_link(){
	//Replace API credentials below located on the Gateway and Integration Settings page
	//in Custom API setting section of your webstore
	$url = "[your domain]/wp-json/tba/v1/payment-link/"; 	// URL endpoint 	
	$merchant_id = "SCD......"; 	// Merchant Id
	$shared_secret = "SSC......."; 	// Shared Secret
	$api_key = "your-api-key"; 		// API Key.
	
	$error_msg = "";
	$arrPosts = [];
	$arrPosts['merchant_id'] = $merchant_id;
	$arrPosts['hash_algorithm'] = "HMACSHA256";
	
	//General options
	$arrPosts['platform_method'] = "My Platform"; 	//Give the API platform a name. This will be generated on 
													//the client's reciept as the payment platform used to create the link.
	$arrPosts['cname'] = "John Doe"; 						//The name of the client
	$arrPosts['email'] = "[email protected]"; 		//The client's email address and / or phone number
	$arrPosts['phonenumber'] = "1555-555-5555"; 			//The client's email address or phone number
	$arrPosts['product_info'] = "Name of payment link"; 	//Product or service information for the client
	$arrPosts['product_description'] = "Payment link info"; //Information about the payment link
	$arrPosts['currency_code'] = "840"; 					//Currency code for the payment link. Example USD
	$arrPosts['chargetotal'] = "23.46"; 					//The charge total of the link
	$arrPosts['platform_checkout_id'] = "2001"; 			//Optionally identifies or map to the platform's order in the checkout page. 
															//Helps to update an existing order instead of creating a new order
	$arrPosts['platform_transaction_id'] = "1001"; 			//Optionally identifies or map to the platform's transaction id 
	$arrPosts['order_id'] = ""; 							//Blank order number will be generated automatically 
	
	//Optional billing information for client
	$arrPosts['baddr1'] = "";
	$arrPosts['baddr2'] = "";
	$arrPosts['bcity'] = "";
	$arrPosts['bcountry'] = "";
	$arrPosts['bzip'] = "";
	
	//Optional shipping information for client
	$arrPosts['saddr1'] = "";
	$arrPosts['saddr2'] = "";
	$arrPosts['scity'] = "";
	$arrPosts['scountry'] = "";
	$arrPosts['szip'] = "";
	
	//Optional return url after success, cancel or declined transaction 
	$arrPosts['platform_site_url'] = "";
	$arrPosts['success_url'] = "";
	$arrPosts['error_url'] = "";
	$arrPosts['cancel_url'] = "";
	
	//Optional booking information
	$arrPosts['booking_name'] = "";
	$arrPosts['booking_timezone'] = "";
	$arrPosts['start_time'] = "";
	$arrPosts['end_time'] = "";
	$arrPosts['booking_memo'] = "";

	ksort($arrPosts);
	$stringToHash = "";
	foreach($arrPosts as $keyname => $val){ 
		if((string)$val !== ""){
			if($stringToHash != ""){
				$stringToHash = $stringToHash ."|";
			}
			$stringToHash = $stringToHash . $val;
		}
	}
	$hashSHA = hash_hmac('sha256', $stringToHash, $shared_secret, true);
	$hashSHA = base64_encode($hashSHA);
	$arrPosts['hashExtended'] = $hashSHA;

	$ch = curl_init($url);

	$headers = [
		'Content-Type: application/json',
		'X-Timestamp: '.time(),
		'X-API-Key: '.$api_key
	];

	$payload = json_encode($arrPosts);

	curl_setopt_array($ch, [
		CURLOPT_RETURNTRANSFER => true,
		CURLOPT_POST => true,
		CURLOPT_POSTFIELDS => $payload,
		CURLOPT_HTTPHEADER => $headers,
		CURLOPT_CONNECTTIMEOUT => 15,
		CURLOPT_TIMEOUT => 30
	]);

	$response = curl_exec($ch);

	if ($response === false) {
		$error_msg = curl_error($ch);
	}
	$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
	curl_close($ch);

	if($error_msg !== ""){
		$res = ['Status' => 'Error', 'Message' => $error_msg, 'Code' => $http_code];
	}else{
		$res = json_decode($response, true);
		//$res['link'] is available once payment link is created
	}
	
	return $res;
}
?>

Get In Touch

Want to know more about the product? Please get in touch with us!