C++ Stripe: Retrieve a Coupon

Back to Index

Retrieves the coupon with the given ID.

Documentation: https://stripe.com/docs/api/curl#retrieve_coupon

CURL Command

curl https://api.stripe.com/v1/coupons/25OFF \
   -u STRIPE_SECRET_KEY:

C++ Example

#include <CkRest.h>
#include <CkStringBuilder.h>
#include <CkJsonObject.h>

void ChilkatSample(void)
    {
    CkRest rest;
    bool success;

    //  URL: https://api.stripe.com/v1/coupons/25OFF
    bool bTls = true;
    int port = 443;
    bool bAutoReconnect = true;
    success = rest.Connect("api.stripe.com",port,bTls,bAutoReconnect);
    if (success != true) {
        std::cout << "ConnectFailReason: " << rest.get_ConnectFailReason() << "\r\n";
        std::cout << rest.lastErrorText() << "\r\n";
        return;
    }

    rest.SetAuthBasic("STRIPE_SECRET_KEY","");

    CkStringBuilder sbResponseBody;
    success = rest.FullRequestNoBodySb("GET","/v1/coupons/25OFF",sbResponseBody);
    if (success != true) {
        std::cout << rest.lastErrorText() << "\r\n";
        return;
    }

    CkJsonObject jsonResponse;
    jsonResponse.LoadSb(sbResponseBody);

    const char *id = 0;
    const char *object = 0;
    bool amount_off;
    int created;
    bool currency;
    const char *duration = 0;
    int duration_in_months;
    bool livemode;
    bool max_redemptions;
    int percent_off;
    bool redeem_by;
    int times_redeemed;
    bool valid;

    id = jsonResponse.stringOf("id");
    object = jsonResponse.stringOf("object");
    amount_off = jsonResponse.IsNullOf("amount_off");
    created = jsonResponse.IntOf("created");
    currency = jsonResponse.IsNullOf("currency");
    duration = jsonResponse.stringOf("duration");
    duration_in_months = jsonResponse.IntOf("duration_in_months");
    livemode = jsonResponse.BoolOf("livemode");
    max_redemptions = jsonResponse.IsNullOf("max_redemptions");
    percent_off = jsonResponse.IntOf("percent_off");
    redeem_by = jsonResponse.IsNullOf("redeem_by");
    times_redeemed = jsonResponse.IntOf("times_redeemed");
    valid = jsonResponse.BoolOf("valid");
    }

Sample JSON Response Body

{
  "id": "25OFF",
  "object": "coupon",
  "amount_off": null,
  "created": 1516662783,
  "currency": null,
  "duration": "repeating",
  "duration_in_months": 3,
  "livemode": false,
  "max_redemptions": null,
  "metadata": {},
  "percent_off": 25,
  "redeem_by": null,
  "times_redeemed": 0,
  "valid": true
}