C Requires Chilkat v11.0.0+
C
PayPal: Reconcile a transaction ID in a reporting window
See more PayPal Examples
Supply the reporting transaction ID and a window containing the activity. Return all matches: transaction IDs are not necessarily unique in the report. Include non-balance-affecting records when reconciling an event.
Chilkat C Downloads
#include <C_CkHttp.h>
#include <C_CkHttpResponse.h>
#include <C_CkDateTime.h>
#include <C_CkJsonObject.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttp http;
HCkHttpResponse resp;
HCkDateTime dt;
HCkJsonObject query;
int page;
int lastPage;
HCkJsonObject errorInfo;
HCkJsonObject result;
BOOL parsed;
int i;
int count;
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.
http = CkHttp_Create();
CkHttp_putAuthToken(http,"SANDBOX_ACCESS_TOKEN");
resp = CkHttpResponse_Create();
// Use the UTC window containing the transaction (at most 31 days per request).
dt = CkDateTime_Create();
CkDateTime_SetFromCurrentSystemTime(dt);
query = CkJsonObject_Create();
CkJsonObject_UpdateString(query,"end_date",CkDateTime_getAsTimestamp(dt,FALSE));
CkDateTime_AddDays(dt,-1);
CkJsonObject_UpdateString(query,"start_date",CkDateTime_getAsTimestamp(dt,FALSE));
CkJsonObject_UpdateString(query,"fields","transaction_info");
CkJsonObject_UpdateInt(query,"page_size",100);
CkJsonObject_UpdateString(query,"transaction_id","REPORT_TRANSACTION_ID");
CkJsonObject_UpdateString(query,"balance_affecting_records_only","N");
page = 1;
lastPage = 1;
while ((page <= lastPage)) {
CkJsonObject_UpdateInt(query,"page",page);
success = CkHttp_HttpParams(http,"GET","https://api-m.sandbox.paypal.com/v1/reporting/transactions",query,resp);
if (success != TRUE) {
printf("No HTTP response: %s\n",CkHttp_lastErrorText(http));
CkHttp_Dispose(http);
CkHttpResponse_Dispose(resp);
CkDateTime_Dispose(dt);
CkJsonObject_Dispose(query);
return;
}
if ((CkHttpResponse_getStatusCode(resp) < 200) || (CkHttpResponse_getStatusCode(resp) >= 300)) {
errorInfo = CkJsonObject_Create();
CkJsonObject_Load(errorInfo,CkHttpResponse_bodyStr(resp));
printf("HTTP %d %s %s\n",CkHttpResponse_getStatusCode(resp),CkJsonObject_stringOf(errorInfo,"name"),CkJsonObject_stringOf(errorInfo,"details[0].issue"));
printf("PayPal debug ID: %s\n",CkJsonObject_stringOf(errorInfo,"debug_id"));
CkHttp_Dispose(http);
CkHttpResponse_Dispose(resp);
CkDateTime_Dispose(dt);
CkJsonObject_Dispose(query);
CkJsonObject_Dispose(errorInfo);
return;
}
result = CkJsonObject_Create();
parsed = CkJsonObject_Load(result,CkHttpResponse_bodyStr(resp));
if (parsed != TRUE) {
printf("Expected a JSON response; HTTP %d\n",CkHttpResponse_getStatusCode(resp));
CkHttp_Dispose(http);
CkHttpResponse_Dispose(resp);
CkDateTime_Dispose(dt);
CkJsonObject_Dispose(query);
CkJsonObject_Dispose(errorInfo);
CkJsonObject_Dispose(result);
return;
}
i = 0;
count = CkJsonObject_SizeOfArray(result,"transaction_details");
while ((i < count)) {
CkJsonObject_putI(result,i);
printf("%s %s %s\n",CkJsonObject_stringOf(result,"transaction_details[i].transaction_info.transaction_id"),CkJsonObject_stringOf(result,"transaction_details[i].transaction_info.transaction_event_code")
,CkJsonObject_stringOf(result,"transaction_details[i].transaction_info.transaction_status"));
printf(" %s %s\n",CkJsonObject_stringOf(result,"transaction_details[i].transaction_info.transaction_amount.value"),CkJsonObject_stringOf(result,"transaction_details[i].transaction_info.transaction_amount.currency_code"));
i = i + 1;
}
lastPage = CkJsonObject_IntOf(result,"total_pages");
page = page + 1;
}
CkHttp_Dispose(http);
CkHttpResponse_Dispose(resp);
CkDateTime_Dispose(dt);
CkJsonObject_Dispose(query);
CkJsonObject_Dispose(errorInfo);
CkJsonObject_Dispose(result);
}