Unicode C++ Requires Chilkat v11.0.0+
Unicode C++
PayPal: Find disputes awaiting a seller response
See more PayPal Examples
Scan cases updated in the past 30 days and page through the results. Show each case waiting on the seller and its response deadline when PayPal includes one in the summary.
Chilkat Unicode C++ Downloads
#include <CkHttpW.h>
#include <CkHttpResponseW.h>
#include <CkDateTimeW.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;
CkDateTimeW since;
since.SetFromCurrentSystemTime();
since.AddDays(-30);
CkJsonObjectW query;
query.UpdateString(L"update_time_after",since.getAsTimestamp(false));
query.UpdateInt(L"page_size",50);
int page = 1;
bool more = true;
while ((more == true)) {
query.UpdateInt(L"page",page);
success = http.HttpParams(L"GET",L"https://api-m.sandbox.paypal.com/v1/customer/disputes",query,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 parsedResult = result.Load(resp.bodyStr());
if (parsedResult != true) {
wprintf(L"Expected a JSON response; HTTP %d\n",resp.get_StatusCode());
return;
}
int i = 0;
while ((i < result.SizeOfArray(L"items"))) {
result.put_I(i);
if (result.StringOfEquals(L"items[i].status",L"WAITING_FOR_SELLER_RESPONSE",true) == true) {
wprintf(L"%s %s\n",result.stringOf(L"items[i].dispute_id"),result.stringOf(L"items[i].reason"));
if (result.HasMember(L"items[i].seller_response_due_date") == true) {
wprintf(L"Respond by %s\n",result.stringOf(L"items[i].seller_response_due_date"));
}
}
i = i + 1;
}
bool hasNext = false;
int linkIndex = 0;
while ((linkIndex < result.SizeOfArray(L"links"))) {
result.put_I(linkIndex);
if (result.StringOfEquals(L"links[i].rel",L"next",true) == true) {
hasNext = true;
}
linkIndex = linkIndex + 1;
}
more = hasNext;
page = page + 1;
}
}