Unicode C++ Requires Chilkat v11.0.0+
Unicode C++
PayPal: Find invoices for a recipient
See more PayPal Examples
Filter by a sandbox recipient email address in the JSON body. Pagination belongs in the URL. Read every matching invoice ID; several invoices can share the same recipient.
Chilkat Unicode C++ Downloads
#include <CkHttpW.h>
#include <CkHttpResponseW.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.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;
// Use a JSON search body on every page; the recipient email does not belong in the
// URL.
CkJsonObjectW body;
body.UpdateString(L"recipient_email",L"buyer@example.com");
int page = 1;
int lastPage = 1;
while ((page <= lastPage)) {
CkStringBuilderW url;
url.Append(L"https://api-m.sandbox.paypal.com/v2/invoicing/search-invoices?total_required=true&page_size=20&page=");
url.AppendInt(page);
success = http.HttpJson(L"POST",url.getAsString(),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;
}
CkJsonObjectW result;
bool parsed = result.Load(resp.bodyStr());
if (parsed != true) {
wprintf(L"Expected a JSON response; HTTP %d\n",resp.get_StatusCode());
return;
}
int i = 0;
int count = result.SizeOfArray(L"items");
while ((i < count)) {
result.put_I(i);
wprintf(L"%s %s %s\n",result.stringOf(L"items[i].id"),result.stringOf(L"items[i].detail.invoice_number"),result.stringOf(L"items[i].status"));
i = i + 1;
}
lastPage = result.IntOf(L"total_pages");
page = page + 1;
}
}