Classic ASP Stripe: Create a Coupon

Back to Index

Creates a coupon object.

Documentation: https://stripe.com/docs/api/curl#create_coupon

CURL Command

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

Classic ASP Example

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
set rest = Server.CreateObject("Chilkat_9_5_0.Rest")

'  URL: https://api.stripe.com/v1/coupons
bTls = 1
port = 443
bAutoReconnect = 1
success = rest.Connect("api.stripe.com",port,bTls,bAutoReconnect)
If (success <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( "ConnectFailReason: " & rest.ConnectFailReason) & "</pre>"
    Response.Write "<pre>" & Server.HTMLEncode( rest.LastErrorText) & "</pre>"

End If

success = rest.SetAuthBasic("STRIPE_SECRET_KEY","")

success = rest.AddQueryParam("percent_off","25")
success = rest.AddQueryParam("duration","repeating")
success = rest.AddQueryParam("duration_in_months","3")
success = rest.AddQueryParam("id","25OFF")

strResponseBody = rest.FullRequestFormUrlEncoded("POST","/v1/coupons")
If (rest.LastMethodSuccess <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( rest.LastErrorText) & "</pre>"

End If

set jsonResponse = Server.CreateObject("Chilkat_9_5_0.JsonObject")
success = jsonResponse.Load(strResponseBody)

id = jsonResponse.StringOf("id")
object = jsonResponse.StringOf("object")
amount_off = jsonResponse.IsNullOf("amount_off")
created = jsonResponse.IntOf("created")
currency = jsonResponse.IsNullOf("currency")
duration = jsonResponse.StringOf("duration")
duration_in_months = jsonResponse.IntOf("duration_in_months")
livemode = jsonResponse.BoolOf("livemode")
max_redemptions = jsonResponse.IsNullOf("max_redemptions")
percent_off = jsonResponse.IntOf("percent_off")
redeem_by = jsonResponse.IsNullOf("redeem_by")
times_redeemed = jsonResponse.IntOf("times_redeemed")
valid = jsonResponse.BoolOf("valid")

%>
</body>
</html>

Sample JSON Response Body

{
  "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
}