Unicode C++ Requires Chilkat v11.0.0+
Unicode 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 Unicode C++ Downloads
#include <CkHttpW.h>
#include <CkHttpResponseW.h>
#include <CkJsonObjectW.h>
void ChilkatSample(void)
{
bool success = false;
// 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.
CkHttpW http;
http.put_AuthToken(L"SANDBOX_ACCESS_TOKEN");
CkHttpResponseW resp;
// This cancels a sent, unpaid invoice. It does not send a refund.
http.SetUrlVar(L"id",L"INVOICE_ID");
CkJsonObjectW body;
body.UpdateString(L"subject",L"Inspection invoice canceled");
body.UpdateString(L"note",L"The inspection was canceled before work began.");
body.UpdateBool(L"send_to_recipient",true);
success = http.HttpJson(L"POST",L"https://api-m.sandbox.paypal.com/v2/invoicing/invoices/{$id}/cancel",body,L"application/json",resp);
if (success != true) {
wprintf(L"No HTTP response: %s\n",http.lastErrorText());
return;
}
if ((resp.get_StatusCode() < 200) || (resp.get_StatusCode() >= 300)) {
CkJsonObjectW errorInfo;
errorInfo.Load(resp.bodyStr());
wprintf(L"HTTP %d %s %s\n",resp.get_StatusCode(),errorInfo.stringOf(L"name"),errorInfo.stringOf(L"details[0].issue"));
wprintf(L"PayPal debug ID: %s\n",errorInfo.stringOf(L"debug_id"));
return;
}
wprintf(L"Cancellation accepted; HTTP %d\n",resp.get_StatusCode());
}