Visual FoxPro Requires Chilkat v11.0.0+
Visual FoxPro
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 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)
loQuery.UpdateString("transaction_id","REPORT_TRANSACTION_ID")
loQuery.UpdateString("balance_affecting_records_only","N")
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