Unicode C++ Requires Chilkat v11.0.0+
Unicode C++
PayPal: Read an invoice and its outstanding balance
See more PayPal Examples
Use the PayPal invoice ID to retrieve its number, status, total and balance due. A partial external payment can reduce the balance without settling the whole invoice.
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;
// The original total and the balance still due may differ after a payment.
http.SetUrlVar(L"id",L"INVOICE_ID");
success = http.HttpNoBody(L"GET",L"https://api-m.sandbox.paypal.com/v2/invoicing/invoices/{$id}",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;
}
CkJsonObjectW result;
bool parsed = result.Load(resp.bodyStr());
if (parsed != true) {
wprintf(L"Expected a JSON response; HTTP %d\n",resp.get_StatusCode());
return;
}
wprintf(L"ID: %s\n",result.stringOf(L"id"));
wprintf(L"Status: %s\n",result.stringOf(L"status"));
wprintf(L"Number: %s\n",result.stringOf(L"detail.invoice_number"));
wprintf(L"Total: %s\n",result.stringOf(L"amount.value"));
wprintf(L"Currency: %s\n",result.stringOf(L"amount.currency_code"));
wprintf(L"Balance due: %s\n",result.stringOf(L"due_amount.value"));
}