Xbase++ Requires Chilkat v11.0.0+
Xbase++
PayPal: Page through merchant transactions
See more PayPal Examples
Read yesterday-to-now account activity one page at a time. Enable Transaction Search for the REST app and obtain a token with reporting access. Data can lag by up to three hours; use order or capture lookup for a checkout in progress.
Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oResp
LOCAL oDt
LOCAL oQuery
LOCAL nPage
LOCAL nLastPage
LOCAL oErrorInfo
LOCAL oResult
LOCAL nParsed
LOCAL i
LOCAL nCount
nSuccess := 0
// 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.
oHttp := CreateObject("Chilkat.Http")
oHttp:AuthToken := "SANDBOX_ACCESS_TOKEN"
oResp := CreateObject("Chilkat.HttpResponse")
// Use the UTC window containing the transaction (at most 31 days per request).
oDt := CreateObject("Chilkat.CkDateTime")
oDt:SetFromCurrentSystemTime()
oQuery := CreateObject("Chilkat.JsonObject")
oQuery:UpdateString("end_date", oDt:GetAsTimestamp(0))
oDt:AddDays(-1)
oQuery:UpdateString("start_date", oDt:GetAsTimestamp(0))
oQuery:UpdateString("fields", "transaction_info")
oQuery:UpdateInt("page_size", 100)
nPage := 1
nLastPage := 1
DO WHILE (nPage <= nLastPage)
oQuery:UpdateInt("page", nPage)
nSuccess := oHttp:HttpParams("GET", "https://api-m.sandbox.paypal.com/v1/reporting/transactions", oQuery, oResp)
IF (nSuccess != 1)
? "No HTTP response: " + oHttp:LastErrorText
oHttp:destroy()
oResp:destroy()
oDt:destroy()
oQuery:destroy()
RETURN
ENDIF
IF ((oResp:StatusCode < 200) .OR. (oResp:StatusCode >= 300))
oErrorInfo := CreateObject("Chilkat.JsonObject")
oErrorInfo:Load(oResp:BodyStr)
? "HTTP " + Str(oResp:StatusCode) + " " + oErrorInfo:StringOf("name") + " " + oErrorInfo:StringOf("details[0].issue")
? "PayPal debug ID: " + oErrorInfo:StringOf("debug_id")
oHttp:destroy()
oResp:destroy()
oDt:destroy()
oQuery:destroy()
oErrorInfo:destroy()
RETURN
ENDIF
oResult := CreateObject("Chilkat.JsonObject")
nParsed := oResult:Load(oResp:BodyStr)
IF (nParsed != 1)
? "Expected a JSON response; HTTP " + Str(oResp:StatusCode)
oHttp:destroy()
oResp:destroy()
oDt:destroy()
oQuery:destroy()
oErrorInfo:destroy()
oResult:destroy()
RETURN
ENDIF
i := 0
nCount := oResult:SizeOfArray("transaction_details")
DO WHILE (i < nCount)
oResult:I := i
? oResult:StringOf("transaction_details[i].transaction_info.transaction_id") + " " + oResult:StringOf("transaction_details[i].transaction_info.transaction_event_code") + " " + oResult:StringOf("transaction_details[i].transaction_info.transaction_status")
? " " + oResult:StringOf("transaction_details[i].transaction_info.transaction_amount.value") + " " + oResult:StringOf("transaction_details[i].transaction_info.transaction_amount.currency_code")
i := i + 1
ENDDO
nLastPage := oResult:IntOf("total_pages")
nPage := nPage + 1
ENDDO
oHttp:destroy()
oResp:destroy()
oDt:destroy()
oQuery:destroy()
oErrorInfo:destroy()
oResult:destroy()