Creates a coupon object.
curl https://api.stripe.com/v1/coupons \
-u STRIPE_SECRET_KEY: \
-d percent_off=25 \
-d duration=repeating \
-d duration_in_months=3 \
-d id=25OFF \
-X POST
#include <CkRestW.h>
#include <CkJsonObjectW.h>
void ChilkatSample(void)
{
CkRestW rest;
bool success;
// URL: https://api.stripe.com/v1/coupons
bool bTls = true;
int port = 443;
bool bAutoReconnect = true;
success = rest.Connect(L"api.stripe.com",port,bTls,bAutoReconnect);
if (success != true) {
wprintf(L"ConnectFailReason: %d\n",rest.get_ConnectFailReason());
wprintf(L"%s\n",rest.lastErrorText());
return;
}
rest.SetAuthBasic(L"STRIPE_SECRET_KEY",L"");
rest.AddQueryParam(L"percent_off",L"25");
rest.AddQueryParam(L"duration",L"repeating");
rest.AddQueryParam(L"duration_in_months",L"3");
rest.AddQueryParam(L"id",L"25OFF");
const wchar_t *strResponseBody = rest.fullRequestFormUrlEncoded(L"POST",L"/v1/coupons");
if (rest.get_LastMethodSuccess() != true) {
wprintf(L"%s\n",rest.lastErrorText());
return;
}
CkJsonObjectW jsonResponse;
jsonResponse.Load(strResponseBody);
const wchar_t *id = 0;
const wchar_t *object = 0;
bool amount_off;
int created;
bool currency;
const wchar_t *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(L"id");
object = jsonResponse.stringOf(L"object");
amount_off = jsonResponse.IsNullOf(L"amount_off");
created = jsonResponse.IntOf(L"created");
currency = jsonResponse.IsNullOf(L"currency");
duration = jsonResponse.stringOf(L"duration");
duration_in_months = jsonResponse.IntOf(L"duration_in_months");
livemode = jsonResponse.BoolOf(L"livemode");
max_redemptions = jsonResponse.IsNullOf(L"max_redemptions");
percent_off = jsonResponse.IntOf(L"percent_off");
redeem_by = jsonResponse.IsNullOf(L"redeem_by");
times_redeemed = jsonResponse.IntOf(L"times_redeemed");
valid = jsonResponse.BoolOf(L"valid");
}
{
"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
}