Updates the metadata of a coupon. Other coupon details (currency, duration, amount_off) are, by design, not editable.
curl https://api.stripe.com/v1/coupons/25OFF \
-u STRIPE_SECRET_KEY: \
-d metadata[order_id]=6735 \
-X POST
#include <CkRestW.h>
#include <CkJsonObjectW.h>
void ChilkatSample(void)
{
CkRestW rest;
bool success;
// URL: https://api.stripe.com/v1/coupons/25OFF
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"metadata[order_id]",L"6735");
const wchar_t *strResponseBody = rest.fullRequestFormUrlEncoded(L"POST",L"/v1/coupons/25OFF");
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;
const wchar_t *metadataOrder_id = 0;
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");
metadataOrder_id = jsonResponse.stringOf(L"metadata.order_id");
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": {
"order_id": "6735"
},
"percent_off": 25,
"redeem_by": null,
"times_redeemed": 0,
"valid": true
}