Pause subscription
Last updated: 18-Oct-2022
Rate this article:
Overview
Use the pauseSubscription method to suspend all automatic charges for a predefined time period for a subscription.
Request Parameters
Parameters | Required | Type/Description |
---|---|---|
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 Example
<?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
The pauseSubscription call returns the above TRUE/FALSE parameters.
Parameters | Type/Description |
---|---|
SubscriptionRef |
Boolean
|
ResumeDate |
Boolean
|
Rate this article: