Perl Requires Chilkat v11.0.0+
Perl
PayPal: Resume a suspended subscription
See more PayPal Examples
Resume billing on a separate operator request after verifying the subscription is suspended. Save the reason with the customer support record.
Chilkat Perl Downloads
use strict;
use warnings;
use Chilkat2;
# See Unlock Chilkat before making requests.
# For the merchant's internal backoffice application. Load the sandbox token
# from the merchant's credential store. Keep it out of publicly distributed apps.
# See Get a PayPal access token.
my $http = Chilkat2::Http->new;
$http->AuthToken('SANDBOX_ACCESS_TOKEN');
my $resp = Chilkat2::HttpResponse->new;
$http->SetUrlVar('id', 'SUBSCRIPTION_ID');
my $success = $http->HttpNoBody('GET', 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions/{$id}', $resp);
if (!$success) {
print 'No HTTP response: ', $http->LastErrorText, "\n";
exit;
}
if (($resp->StatusCode < 200) || ($resp->StatusCode >= 300)) {
my $errorInfo = Chilkat2::JsonObject->new;
$errorInfo->Load($resp->BodyStr);
print 'HTTP ', $resp->StatusCode, ' ', $errorInfo->StringOf('name'), ' ', $errorInfo->StringOf('details[0].issue'), "\n";
print 'PayPal debug ID: ', $errorInfo->StringOf('debug_id'), "\n";
exit;
}
my $result = Chilkat2::JsonObject->new;
my $parsedResult = $result->Load($resp->BodyStr);
if (!$parsedResult) {
print 'Expected a JSON response; HTTP ', $resp->StatusCode, "\n";
exit;
}
if (!$result->StringOfEquals('status', 'SUSPENDED', 1)) {
print 'Subscription status is ', $result->StringOf('status'), ". No change made.\n";
exit;
}
my $body = Chilkat2::JsonObject->new;
$body->UpdateString('reason', 'Customer requested that billing resume.');
$success = $http->HttpJson('POST', 'https://api-m.sandbox.paypal.com/v1/billing/subscriptions/{$id}/activate', $body, 'application/json', $resp);
if (!$success) {
print 'No HTTP response: ', $http->LastErrorText, "\n";
exit;
}
if (($resp->StatusCode < 200) || ($resp->StatusCode >= 300)) {
my $changeError = Chilkat2::JsonObject->new;
$changeError->Load($resp->BodyStr);
print 'HTTP ', $resp->StatusCode, ' ', $changeError->StringOf('name'), ' ', $changeError->StringOf('details[0].issue'), "\n";
print 'PayPal debug ID: ', $changeError->StringOf('debug_id'), "\n";
exit;
}
print "PayPal accepted the subscription change.\n";