Objective-C Requires Chilkat v11.0.0+
Objective-C
PayPal: Revise a draft invoice from its full billing record
See more PayPal Examples
PUT replaces the invoice. This example revises the quantity on the simple two-inspection draft to three. Rebuild the complete editable document from your billing record; omitted items, terms or recipients can be lost. Do not use this body for an unrelated 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];
// Use only the ID of the matching draft from the create example, while it is still a
// draft. Preserve all of your real draft fields, including any custom invoice number.
[http SetUrlVar: @"id" value: @"INVOICE_ID"];
[http SetRequestHeader: @"Prefer" value: @"return=representation"];
CkoJsonObject *body = [[CkoJsonObject alloc] init];
[body UpdateString: @"detail.currency_code" value: @"USD"];
[body UpdateString: @"detail.payment_term.term_type" value: @"NET_30"];
[body UpdateString: @"primary_recipients[0].billing_info.email_address" value: @"buyer@example.com"];
[body UpdateString: @"items[0].name" value: @"Equipment inspection"];
[body UpdateString: @"items[0].quantity" value: @"3"];
[body UpdateString: @"items[0].unit_amount.currency_code" value: @"USD"];
[body UpdateString: @"items[0].unit_amount.value" value: @"45.00"];
success = [http HttpJson: @"PUT" url: @"https://api-m.sandbox.paypal.com/v2/invoicing/invoices/{$id}" 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(@"%@%@",@"ID: ",[result StringOf: @"id"]);
NSLog(@"%@%@",@"Status: ",[result StringOf: @"status"]);
NSLog(@"%@%@",@"New total: ",[result StringOf: @"amount.value"]);
NSLog(@"%@%@",@"Currency: ",[result StringOf: @"amount.currency_code"]);