Sample code for 30+ languages & platforms
Unicode 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 Unicode C++ Downloads

Unicode C++
#include <CkHttpW.h>
#include <CkHttpResponseW.h>
#include <CkJsonObjectW.h>

void ChilkatSample(void)
    {
    bool success = false;

    //  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.
    CkHttpW http;
    http.put_AuthToken(L"SANDBOX_ACCESS_TOKEN");
    CkHttpResponseW resp;

    http.SetUrlVar(L"id",L"SUBSCRIPTION_ID");

    success = http.HttpNoBody(L"GET",L"https://api-m.sandbox.paypal.com/v1/billing/subscriptions/{$id}",resp);
    if (success != true) {
        wprintf(L"No HTTP response: %s\n",http.lastErrorText());
        return;
    }

    if ((resp.get_StatusCode() < 200) || (resp.get_StatusCode() >= 300)) {
        CkJsonObjectW errorInfo;
        errorInfo.Load(resp.bodyStr());
        wprintf(L"HTTP %d %s %s\n",resp.get_StatusCode(),errorInfo.stringOf(L"name"),errorInfo.stringOf(L"details[0].issue"));
        wprintf(L"PayPal debug ID: %s\n",errorInfo.stringOf(L"debug_id"));
        return;
    }

    CkJsonObjectW result;
    bool parsedResult = result.Load(resp.bodyStr());
    if (parsedResult != true) {
        wprintf(L"Expected a JSON response; HTTP %d\n",resp.get_StatusCode());
        return;
    }

    if (result.StringOfEquals(L"status",L"SUSPENDED",true) != true) {
        wprintf(L"Subscription status is %s. No change made.\n",result.stringOf(L"status"));
        return;
    }

    CkJsonObjectW body;
    body.UpdateString(L"reason",L"Customer requested that billing resume.");
    success = http.HttpJson(L"POST",L"https://api-m.sandbox.paypal.com/v1/billing/subscriptions/{$id}/activate",body,L"application/json",resp);
    if (success != true) {
        wprintf(L"No HTTP response: %s\n",http.lastErrorText());
        return;
    }

    if ((resp.get_StatusCode() < 200) || (resp.get_StatusCode() >= 300)) {
        CkJsonObjectW changeError;
        changeError.Load(resp.bodyStr());
        wprintf(L"HTTP %d %s %s\n",resp.get_StatusCode(),changeError.stringOf(L"name"),changeError.stringOf(L"details[0].issue"));
        wprintf(L"PayPal debug ID: %s\n",changeError.stringOf(L"debug_id"));
        return;
    }

    wprintf(L"PayPal accepted the subscription change.\n");
    }