Objective-C Requires Chilkat v11.0.0+
Objective-C
PayPal: Get the next invoice number
See more PayPal Examples
Read invoice_number for use as the customer-facing number on a draft. It is distinct from the PayPal invoice ID used in API paths. If you do not need to choose a number, omit it when creating the invoice.
Chilkat Objective-C Downloads
#import <CkoHttp.h>
#import <CkoHttpResponse.h>
#import <CkoJsonObject.h>
BOOL success = NO;
// See Unlock Chilkat before making requests.
// For the merchant's internal backoffice application. Load the sandbox token
// from the merchant's credential store. Keep it out of publicly distributed apps.
// See Get a PayPal access token.
CkoHttp *http = [[CkoHttp alloc] init];
http.AuthToken = @"SANDBOX_ACCESS_TOKEN";
CkoHttpResponse *resp = [[CkoHttpResponse alloc] init];
// The customer sees the invoice number. Subsequent REST calls need the invoice ID
// instead.
CkoJsonObject *body = [[CkoJsonObject alloc] init];
success = [http HttpJson: @"POST" url: @"https://api-m.sandbox.paypal.com/v2/invoicing/generate-next-invoice-number" json: body contentType: @"application/json" response: resp];
if (success != YES) {
NSLog(@"%@%@",@"No HTTP response: ",http.LastErrorText);
return;
}
if (([resp.StatusCode intValue] < 200) || ([resp.StatusCode intValue] >= 300)) {
CkoJsonObject *errorInfo = [[CkoJsonObject alloc] init];
[errorInfo Load: resp.BodyStr];
NSLog(@"%@%d%@%@%@%@",@"HTTP ",[resp.StatusCode intValue],@" ",[errorInfo StringOf: @"name"],@" ",[errorInfo StringOf: @"details[0].issue"]);
NSLog(@"%@%@",@"PayPal debug ID: ",[errorInfo StringOf: @"debug_id"]);
return;
}
CkoJsonObject *result = [[CkoJsonObject alloc] init];
BOOL parsed = [result Load: resp.BodyStr];
if (parsed != YES) {
NSLog(@"%@%d",@"Expected a JSON response; HTTP ",[resp.StatusCode intValue]);
return;
}
NSLog(@"%@%@",@"Next number: ",[result StringOf: @"invoice_number"]);