Sample code for 30+ languages & platforms
Objective-C Requires Chilkat v11.0.0+

PayPal: Send a draft invoice

See more PayPal Examples

Send a draft to its sandbox recipient. PayPal can accept delivery for later when the issue date is in the future. After an uncertain response, look up the invoice before trying again.

PayPal documentation

Chilkat Objective-C Downloads

Objective-C
#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 invoice already exists as a draft. Sending is the separate step that notifies
//  the recipient.

[http SetUrlVar: @"id" value: @"INVOICE_ID"];
CkoJsonObject *body = [[CkoJsonObject alloc] init];
[body UpdateBool: @"send_to_recipient" value: YES];
[body UpdateBool: @"send_to_invoicer" value: NO];

success = [http HttpJson: @"POST" url: @"https://api-m.sandbox.paypal.com/v2/invoicing/invoices/{$id}/send" 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",@"Send request accepted; HTTP ",[resp.StatusCode intValue]);