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
func chilkatTest() {
let rest = CkoRest()
var success: Bool
// URL: https://api.stripe.com/v1/coupons/25OFF
var bTls: Bool = true
var port: Int = 443
var bAutoReconnect: Bool = true
success = rest.Connect("api.stripe.com", port: port, tls: bTls, autoReconnect: bAutoReconnect)
if success != true {
print("ConnectFailReason: \(rest.ConnectFailReason.integerValue)")
print("\(rest.LastErrorText)")
return
}
rest.SetAuthBasic("STRIPE_SECRET_KEY", password: "")
rest.AddQueryParam("metadata[order_id]", value: "6735")
var strResponseBody: String? = rest.FullRequestFormUrlEncoded("POST", uriPath: "/v1/coupons/25OFF")
if rest.LastMethodSuccess != true {
print("\(rest.LastErrorText)")
return
}
let jsonResponse = CkoJsonObject()
jsonResponse.Load(strResponseBody)
var id: String?
var object: String?
var amount_off: Bool
var created: Int
var currency: Bool
var duration: String?
var duration_in_months: Int
var livemode: Bool
var max_redemptions: Bool
var metadataOrder_id: String?
var percent_off: Int
var redeem_by: Bool
var times_redeemed: Int
var valid: Bool
id = jsonResponse.StringOf("id")
object = jsonResponse.StringOf("object")
amount_off = jsonResponse.IsNullOf("amount_off")
created = jsonResponse.IntOf("created").integerValue
currency = jsonResponse.IsNullOf("currency")
duration = jsonResponse.StringOf("duration")
duration_in_months = jsonResponse.IntOf("duration_in_months").integerValue
livemode = jsonResponse.BoolOf("livemode")
max_redemptions = jsonResponse.IsNullOf("max_redemptions")
metadataOrder_id = jsonResponse.StringOf("metadata.order_id")
percent_off = jsonResponse.IntOf("percent_off").integerValue
redeem_by = jsonResponse.IsNullOf("redeem_by")
times_redeemed = jsonResponse.IntOf("times_redeemed").integerValue
valid = jsonResponse.BoolOf("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
}