Pause subscription
Use the pauseSubscription method to suspend all automatic charges for a predefined time period for a subscription.
Request parameters
SubscriptionRef
Required (string)
The system-generated reference code of the subscription.
ResumeDate
Required (number)
Date when the subscription should be resumed. Format "YYYY-MM-DD". The resume date needs to be set within 3 years starting from the day the subscription expires. The timezone used is the one on the server.
PauseReason
Optional (string)
Freeform text filled in by the merchant. Text is limited to 100 characters.
Request sample
<?php
$host = 'https://api.2checkout.com/rpc/6.0/';
$merchantCode = "666999";
$key = "%y~8|m]T84p[W4+O1]_?";
$string = strlen($merchantCode) . $merchantCode . strlen(gmdate('Y-m-d H:i:s')) . gmdate('Y-m-d H:i:s');
$hash = hash_hmac('md5', $string, $key);
$i = 1; // counter for api calls
// call login
$jsonRpcRequest = new stdClass();
$jsonRpcRequest->jsonrpc = '2.0';
$jsonRpcRequest->method = 'login';
$jsonRpcRequest->params = array($merchantCode, gmdate('Y-m-d H:i:s'), $hash);
$jsonRpcRequest->id = $i++;
$sessionID = callRPC($jsonRpcRequest, $host);
var_dump("session id:" . $sessionID);
// call api methods below
$SubscriptionRef = 'B7D8E72224';
$jsonRpcRequest = array (
'jsonrpc' => '2.0',
'method' => 'setRenewalPause',
'params' => array($sessionID, $SubscriptionRef, "2020-09-30 17:00:00", "vacation leave"),
'id' => $i++
);
var_dump ("setRenewalPause", callRPC((Object)$jsonRpcRequest, $host));
$jsonRpcRequest = array (
'jsonrpc' => '2.0',
'method' => 'getRenewalPause',
'params' => array($sessionID, $SubscriptionRef),
'id' => $i++
);
var_dump ("getRenewalPause", callRPC((Object)$jsonRpcRequest, $host));
function callRPC($Request, $hostUrl, $Debug = false) {
$curl = curl_init($hostUrl);
curl_setopt( $curl, CURLOPT_POST, 1);
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Accept: application/json'));
$RequestString = json_encode($Request);
curl_setopt( $curl, CURLOPT_POSTFIELDS, $RequestString);
curl_setopt( $curl, CURLOPT_COOKIE, "XDEBUG_SESSION=PHPSTORM");
if (stristr($hostUrl, 'sandboxdev') || stristr($hostUrl, 'git-sb')) {
curl_setopt( $curl, CURLOPT_PROXY, 'localhost:3128');
// curl_setopt( $curl, CURLOPT_PROXY, 'proxy.avangate.local:8080');
// curl_setopt( $curl, CURLOPT_PROXYUSERPWD, 'andrei.avramica:pw'); // for authenticated proxies
}
$ResponseString = curl_exec ($curl);
if (!empty($ResponseString)) {
$Response = json_decode ($ResponseString,false);
if (isset($Response->error) && !is_null($Response->error)) {
var_dump($Response->error) ;
return null;
}
return $Response->result;
} else {
return null;
}
}
exit;Response parameters
The pauseSubscription call returns TRUE/FALSE parameters.
SubscriptionRef
Boolean
TRUE — if the call was successful and a pause was scheduled.
FALSE — if the pause mechanism is not enabled for the merchant OR any of the eligibility conditions were not met OR pause is not enabled for the product OR the maximum pause duration for the product was exceeded. In this case, the system also throws the following message: "The subscription is not eligible for pause."
ResumeDate
Boolean
TRUE — if the call was successful and a pause was scheduled.
FALSE — if the pause mechanism is not enabled for the merchant OR any of the eligibility conditions were not met OR pause is not enabled for the product OR the maximum pause duration for the product was exceeded. In this case, the system also throws the following message: "The subscription is not eligible for pause."
Last updated
Was this helpful?