Sample code for 30+ languages & platforms
Objective-C Requires Chilkat v11.0.0+

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.

PayPal documentation

Chilkat Objective-C Downloads

Objective-C
#import <CkoHttp.h>
#import <CkoHttpResponse.h>
#import <CkoJsonObject.h>

BOOL success = NO;

//  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.
CkoHttp *http = [[CkoHttp alloc] init];
http.AuthToken = @"SANDBOX_ACCESS_TOKEN";
CkoHttpResponse *resp = [[CkoHttpResponse alloc] init];

[http SetUrlVar: @"id" value: @"SUBSCRIPTION_ID"];

success = [http HttpNoBody: @"GET" url: @"https://api-m.sandbox.paypal.com/v1/billing/subscriptions/{$id}" response: resp];
if (success != YES) {
    NSLog(@"%@%@",@"No HTTP response: ",http.LastErrorText);
    return;
}

if (([resp.StatusCode intValue] < 200) || ([resp.StatusCode intValue] >= 300)) {
    CkoJsonObject *errorInfo = [[CkoJsonObject alloc] init];
    [errorInfo Load: resp.BodyStr];
    NSLog(@"%@%d%@%@%@%@",@"HTTP ",[resp.StatusCode intValue],@" ",[errorInfo StringOf: @"name"],@" ",[errorInfo StringOf: @"details[0].issue"]);
    NSLog(@"%@%@",@"PayPal debug ID: ",[errorInfo StringOf: @"debug_id"]);
    return;
}

CkoJsonObject *result = [[CkoJsonObject alloc] init];
BOOL parsedResult = [result Load: resp.BodyStr];
if (parsedResult != YES) {
    NSLog(@"%@%d",@"Expected a JSON response; HTTP ",[resp.StatusCode intValue]);
    return;
}

if ([result StringOfEquals: @"status" value: @"SUSPENDED" caseSensitive: YES] != YES) {
    NSLog(@"%@%@%@",@"Subscription status is ",[result StringOf: @"status"],@". No change made.");
    return;
}

CkoJsonObject *body = [[CkoJsonObject alloc] init];
[body UpdateString: @"reason" value: @"Customer requested that billing resume."];
success = [http HttpJson: @"POST" url: @"https://api-m.sandbox.paypal.com/v1/billing/subscriptions/{$id}/activate" json: body contentType: @"application/json" response: resp];
if (success != YES) {
    NSLog(@"%@%@",@"No HTTP response: ",http.LastErrorText);
    return;
}

if (([resp.StatusCode intValue] < 200) || ([resp.StatusCode intValue] >= 300)) {
    CkoJsonObject *changeError = [[CkoJsonObject alloc] init];
    [changeError Load: resp.BodyStr];
    NSLog(@"%@%d%@%@%@%@",@"HTTP ",[resp.StatusCode intValue],@" ",[changeError StringOf: @"name"],@" ",[changeError StringOf: @"details[0].issue"]);
    NSLog(@"%@%@",@"PayPal debug ID: ",[changeError StringOf: @"debug_id"]);
    return;
}

NSLog(@"%@",@"PayPal accepted the subscription change.");