Objective-C Stripe: Delete a Customer

Back to Index

Permanently deletes a customer. It cannot be undone. Also immediately cancels any active subscriptions on the customer.

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

CURL Command

curl https://api.stripe.com/v1/customers/cus_CBbgVLJqv487Oq \
   -u STRIPE_SECRET_KEY: \
   -X DELETE

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/customers/cus_CBbgVLJqv487Oq
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: @"DELETE" uriPath: @"/v1/customers/cus_CBbgVLJqv487Oq" sb: sbResponseBody];
if (success != YES) {
    NSLog(@"%@",rest.LastErrorText);
    return;
}

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

BOOL deleted;
NSString *id = 0;

deleted = [jsonResponse BoolOf: @"deleted"];
id = [jsonResponse StringOf: @"id"];

Sample JSON Response Body

{
  "deleted": true,
  "id": "cus_CBbgVLJqv487Oq"
}