Objective-C Stripe: Retrieve a Coupon

Back to Index

Retrieves the coupon with the given ID.

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

CURL Command

curl https://api.stripe.com/v1/coupons/25OFF \
   -u STRIPE_SECRET_KEY:

Objective-C Example

#import <CkoRest.h>
#import <CkoStringBuilder.h>
#import <CkoJsonObject.h>
#import <NSString.h>

CkoRest *rest = [[CkoRest alloc] init];
BOOL success;

//  URL: https://api.stripe.com/v1/coupons/25OFF
BOOL bTls = YES;
int port = 443;
BOOL bAutoReconnect = YES;
success = [rest Connect: @"api.stripe.com" port: [NSNumber numberWithInt: port] tls: bTls autoReconnect: bAutoReconnect];
if (success != YES) {
    NSLog(@"%@%d",@"ConnectFailReason: ",[rest.ConnectFailReason intValue]);
    NSLog(@"%@",rest.LastErrorText);
    return;
}

[rest SetAuthBasic: @"STRIPE_SECRET_KEY" password: @""];

CkoStringBuilder *sbResponseBody = [[CkoStringBuilder alloc] init];
success = [rest FullRequestNoBodySb: @"GET" uriPath: @"/v1/coupons/25OFF" sb: sbResponseBody];
if (success != YES) {
    NSLog(@"%@",rest.LastErrorText);
    return;
}

CkoJsonObject *jsonResponse = [[CkoJsonObject alloc] init];
[jsonResponse LoadSb: sbResponseBody];

NSString *id = 0;
NSString *object = 0;
BOOL amount_off;
int created;
BOOL currency;
NSString *duration = 0;
int duration_in_months;
BOOL livemode;
BOOL max_redemptions;
int percent_off;
BOOL redeem_by;
int times_redeemed;
BOOL valid;

id = [jsonResponse StringOf: @"id"];
object = [jsonResponse StringOf: @"object"];
amount_off = [jsonResponse IsNullOf: @"amount_off"];
created = [[jsonResponse IntOf: @"created"] intValue];
currency = [jsonResponse IsNullOf: @"currency"];
duration = [jsonResponse StringOf: @"duration"];
duration_in_months = [[jsonResponse IntOf: @"duration_in_months"] intValue];
livemode = [jsonResponse BoolOf: @"livemode"];
max_redemptions = [jsonResponse IsNullOf: @"max_redemptions"];
percent_off = [[jsonResponse IntOf: @"percent_off"] intValue];
redeem_by = [jsonResponse IsNullOf: @"redeem_by"];
times_redeemed = [[jsonResponse IntOf: @"times_redeemed"] intValue];
valid = [jsonResponse BoolOf: @"valid"];

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
}