Visual FoxPro Requires Chilkat v11.0.0+
Visual FoxPro
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 Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loHttp
LOCAL loResp
LOCAL loDt
LOCAL loQuery
LOCAL lnPage
LOCAL lnLastPage
LOCAL loErrorInfo
LOCAL loResult
LOCAL lnParsed
LOCAL i
LOCAL lnCount
lnSuccess = 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.
loHttp = CreateObject('Chilkat.Http')
loHttp.AuthToken = "SANDBOX_ACCESS_TOKEN"
loResp = CreateObject('Chilkat.HttpResponse')
* Use the UTC window containing the transaction (at most 31 days per request).
loDt = CreateObject('Chilkat.CkDateTime')
loDt.SetFromCurrentSystemTime()
loQuery = CreateObject('Chilkat.JsonObject')
loQuery.UpdateString("end_date",loDt.GetAsTimestamp(0))
loDt.AddDays(-1)
loQuery.UpdateString("start_date",loDt.GetAsTimestamp(0))
loQuery.UpdateString("fields","transaction_info")
loQuery.UpdateInt("page_size",100)
lnPage = 1
lnLastPage = 1
DO WHILE (lnPage <= lnLastPage)
loQuery.UpdateInt("page",lnPage)
lnSuccess = loHttp.HttpParams("GET","https://api-m.sandbox.paypal.com/v1/reporting/transactions",loQuery,loResp)
IF (lnSuccess <> 1) THEN
? "No HTTP response: " + loHttp.LastErrorText
RELEASE loHttp
RELEASE loResp
RELEASE loDt
RELEASE loQuery
CANCEL
ENDIF
IF ((loResp.StatusCode < 200) OR (loResp.StatusCode >= 300)) THEN
loErrorInfo = CreateObject('Chilkat.JsonObject')
loErrorInfo.Load(loResp.BodyStr)
? "HTTP " + STR(loResp.StatusCode) + " " + loErrorInfo.StringOf("name") + " " + loErrorInfo.StringOf("details[0].issue")
? "PayPal debug ID: " + loErrorInfo.StringOf("debug_id")
RELEASE loHttp
RELEASE loResp
RELEASE loDt
RELEASE loQuery
RELEASE loErrorInfo
CANCEL
ENDIF
loResult = CreateObject('Chilkat.JsonObject')
lnParsed = loResult.Load(loResp.BodyStr)
IF (lnParsed <> 1) THEN
? "Expected a JSON response; HTTP " + STR(loResp.StatusCode)
RELEASE loHttp
RELEASE loResp
RELEASE loDt
RELEASE loQuery
RELEASE loErrorInfo
RELEASE loResult
CANCEL
ENDIF
i = 0
lnCount = loResult.SizeOfArray("transaction_details")
DO WHILE (i < lnCount)
loResult.I = i
? loResult.StringOf("transaction_details[i].transaction_info.transaction_id") + " " + loResult.StringOf("transaction_details[i].transaction_info.transaction_event_code") + " " + loResult.StringOf("transaction_details[i].transaction_info.transaction_status")
? " " + loResult.StringOf("transaction_details[i].transaction_info.transaction_amount.value") + " " + loResult.StringOf("transaction_details[i].transaction_info.transaction_amount.currency_code")
i = i + 1
ENDDO
lnLastPage = loResult.IntOf("total_pages")
lnPage = lnPage + 1
ENDDO
RELEASE loHttp
RELEASE loResp
RELEASE loDt
RELEASE loQuery
RELEASE loErrorInfo
RELEASE loResult