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 <C_CkRest.h>
#include <C_CkJsonObject.h>
void ChilkatSample(void)
{
HCkRest rest;
BOOL success;
BOOL bTls;
int port;
BOOL bAutoReconnect;
const char *strResponseBody;
HCkJsonObject jsonResponse;
const char *id;
const char *object;
BOOL amount_off;
int created;
BOOL currency;
const char *duration;
int duration_in_months;
BOOL livemode;
BOOL max_redemptions;
const char *metadataOrder_id;
int percent_off;
BOOL redeem_by;
int times_redeemed;
BOOL valid;
rest = CkRest_Create();
// URL: https://api.stripe.com/v1/coupons/25OFF
bTls = TRUE;
port = 443;
bAutoReconnect = TRUE;
success = CkRest_Connect(rest,"api.stripe.com",port,bTls,bAutoReconnect);
if (success != TRUE) {
printf("ConnectFailReason: %d\n",CkRest_getConnectFailReason(rest));
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
return;
}
CkRest_SetAuthBasic(rest,"STRIPE_SECRET_KEY","");
CkRest_AddQueryParam(rest,"metadata[order_id]","6735");
strResponseBody = CkRest_fullRequestFormUrlEncoded(rest,"POST","/v1/coupons/25OFF");
if (CkRest_getLastMethodSuccess(rest) != TRUE) {
printf("%s\n",CkRest_lastErrorText(rest));
CkRest_Dispose(rest);
return;
}
jsonResponse = CkJsonObject_Create();
CkJsonObject_Load(jsonResponse,strResponseBody);
id = CkJsonObject_stringOf(jsonResponse,"id");
object = CkJsonObject_stringOf(jsonResponse,"object");
amount_off = CkJsonObject_IsNullOf(jsonResponse,"amount_off");
created = CkJsonObject_IntOf(jsonResponse,"created");
currency = CkJsonObject_IsNullOf(jsonResponse,"currency");
duration = CkJsonObject_stringOf(jsonResponse,"duration");
duration_in_months = CkJsonObject_IntOf(jsonResponse,"duration_in_months");
livemode = CkJsonObject_BoolOf(jsonResponse,"livemode");
max_redemptions = CkJsonObject_IsNullOf(jsonResponse,"max_redemptions");
metadataOrder_id = CkJsonObject_stringOf(jsonResponse,"metadata.order_id");
percent_off = CkJsonObject_IntOf(jsonResponse,"percent_off");
redeem_by = CkJsonObject_IsNullOf(jsonResponse,"redeem_by");
times_redeemed = CkJsonObject_IntOf(jsonResponse,"times_redeemed");
valid = CkJsonObject_BoolOf(jsonResponse,"valid");
CkRest_Dispose(rest);
CkJsonObject_Dispose(jsonResponse);
}
{
"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
}