Sample code for 30+ languages & platforms
Xbase++ Requires Chilkat v11.0.0+

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.

PayPal documentation

Chilkat Xbase++ Downloads

Xbase++
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)
oQuery:UpdateString("transaction_id", "REPORT_TRANSACTION_ID")
oQuery:UpdateString("balance_affecting_records_only", "N")
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()