Objective-C Requires Chilkat v11.0.0+
Objective-C
PayPal: Cancel a sent, unpaid invoice
See more PayPal Examples
Cancel an unpaid invoice that has already been sent and notify the customer why. For a draft use delete instead. Cancellation does not return funds.
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];
// This cancels a sent, unpaid invoice. It does not send a refund.
[http SetUrlVar: @"id" value: @"INVOICE_ID"];
CkoJsonObject *body = [[CkoJsonObject alloc] init];
[body UpdateString: @"subject" value: @"Inspection invoice canceled"];
[body UpdateString: @"note" value: @"The inspection was canceled before work began."];
[body UpdateBool: @"send_to_recipient" value: YES];
success = [http HttpJson: @"POST" url: @"https://api-m.sandbox.paypal.com/v2/invoicing/invoices/{$id}/cancel" 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;
}
NSLog(@"%@%d",@"Cancellation accepted; HTTP ",[resp.StatusCode intValue]);