Create recurring payment

PHP code sample for creating a recurring payment.


The following PHP code sample includes comments explaining the different elements and parameters involved in the Create transaction API call, specifically when being used to make a recurring payment.

Please also see also our tutorial on the same subject

Code sample

The below example uses Basic Auth authentication


// The POST URL and parameters
$request =  '';	// demo environment URL
//$request =  '';	// production environment URL

// Your merchant ID and API Key can be found in the 'Security' settings on your profile.
$merchant_id = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
$api_key = 'xxxxxxxxxxxxx';

//Set the ID of the Initial Transaction
$request .= 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';

//Set the Payment Amount
$amount = 100;	// Amount in cents

$postargs = 'Amount='.$amount;

// Get the curl session object
$session = curl_init($request);

// Set query data here with the URL
curl_setopt($session, CURLOPT_POST, true);
curl_setopt($session, CURLOPT_POSTFIELDS, $postargs);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($session, CURLOPT_USERPWD, $merchant_id.':'.$api_key);

$response = curl_exec($session);

// Parse the JSON response
try {
} catch( Exception $e ) {
	echo $e->getMessage();


if ($resultObj->ErrorCode==0){
	// print JSON output
echo json_encode($resultObj);
	echo $resultObj->ErrorText;


Get Support

If you would like to integrate with Viva, or if you have any queries about our products and solutions, please see our Contact & Support page to see how we can help!