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
IncludeFile "CkRest.pb"
IncludeFile "CkJsonObject.pb"
Procedure ChilkatExample()
rest.i = CkRest::ckCreate()
If rest.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success.i
; URL: https://api.stripe.com/v1/coupons
bTls.i = 1
port.i = 443
bAutoReconnect.i = 1
success = CkRest::ckConnect(rest,"api.stripe.com",port,bTls,bAutoReconnect)
If success <> 1
Debug "ConnectFailReason: " + Str(CkRest::ckConnectFailReason(rest))
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
ProcedureReturn
EndIf
CkRest::ckSetAuthBasic(rest,"STRIPE_SECRET_KEY","")
CkRest::ckAddQueryParam(rest,"percent_off","25")
CkRest::ckAddQueryParam(rest,"duration","repeating")
CkRest::ckAddQueryParam(rest,"duration_in_months","3")
CkRest::ckAddQueryParam(rest,"id","25OFF")
strResponseBody.s = CkRest::ckFullRequestFormUrlEncoded(rest,"POST","/v1/coupons")
If CkRest::ckLastMethodSuccess(rest) <> 1
Debug CkRest::ckLastErrorText(rest)
CkRest::ckDispose(rest)
ProcedureReturn
EndIf
jsonResponse.i = CkJsonObject::ckCreate()
If jsonResponse.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckLoad(jsonResponse,strResponseBody)
id.s
object.s
amount_off.i
created.i
currency.i
duration.s
duration_in_months.i
livemode.i
max_redemptions.i
percent_off.i
redeem_by.i
times_redeemed.i
valid.i
id = CkJsonObject::ckStringOf(jsonResponse,"id")
object = CkJsonObject::ckStringOf(jsonResponse,"object")
amount_off = CkJsonObject::ckIsNullOf(jsonResponse,"amount_off")
created = CkJsonObject::ckIntOf(jsonResponse,"created")
currency = CkJsonObject::ckIsNullOf(jsonResponse,"currency")
duration = CkJsonObject::ckStringOf(jsonResponse,"duration")
duration_in_months = CkJsonObject::ckIntOf(jsonResponse,"duration_in_months")
livemode = CkJsonObject::ckBoolOf(jsonResponse,"livemode")
max_redemptions = CkJsonObject::ckIsNullOf(jsonResponse,"max_redemptions")
percent_off = CkJsonObject::ckIntOf(jsonResponse,"percent_off")
redeem_by = CkJsonObject::ckIsNullOf(jsonResponse,"redeem_by")
times_redeemed = CkJsonObject::ckIntOf(jsonResponse,"times_redeemed")
valid = CkJsonObject::ckBoolOf(jsonResponse,"valid")
CkRest::ckDispose(rest)
CkJsonObject::ckDispose(jsonResponse)
ProcedureReturn
EndProcedure
{
"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
}