Sample code for 30+ languages & platforms
DataFlex 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 DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoHttp
    Variant vResp
    Handle hoResp
    Handle hoDt
    Variant vQuery
    Handle hoQuery
    Integer iPage
    Integer iLastPage
    Handle hoErrorInfo
    Handle hoResult
    Boolean iParsed
    Integer i
    Integer iCount
    String sTemp1
    String sTemp2
    String sTemp3
    Integer iTemp1
    Integer iTemp2

    Move False To iSuccess

    //  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.
    Get Create (RefClass(cComChilkatHttp)) To hoHttp
    If (Not(IsComObjectCreated(hoHttp))) Begin
        Send CreateComObject of hoHttp
    End
    Set ComAuthToken Of hoHttp To "SANDBOX_ACCESS_TOKEN"
    Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
    If (Not(IsComObjectCreated(hoResp))) Begin
        Send CreateComObject of hoResp
    End
    //  Use the UTC window containing the transaction (at most 31 days per request).
    Get Create (RefClass(cComCkDateTime)) To hoDt
    If (Not(IsComObjectCreated(hoDt))) Begin
        Send CreateComObject of hoDt
    End
    Get ComSetFromCurrentSystemTime Of hoDt To iSuccess
    Get Create (RefClass(cComChilkatJsonObject)) To hoQuery
    If (Not(IsComObjectCreated(hoQuery))) Begin
        Send CreateComObject of hoQuery
    End
    Get ComGetAsTimestamp Of hoDt False To sTemp1
    Get ComUpdateString Of hoQuery "end_date" sTemp1 To iSuccess
    Get ComAddDays Of hoDt -1 To iSuccess
    Get ComGetAsTimestamp Of hoDt False To sTemp1
    Get ComUpdateString Of hoQuery "start_date" sTemp1 To iSuccess
    Get ComUpdateString Of hoQuery "fields" "transaction_info" To iSuccess
    Get ComUpdateInt Of hoQuery "page_size" 100 To iSuccess
    Get ComUpdateString Of hoQuery "transaction_id" "REPORT_TRANSACTION_ID" To iSuccess
    Get ComUpdateString Of hoQuery "balance_affecting_records_only" "N" To iSuccess
    Move 1 To iPage
    Move 1 To iLastPage
    While (iPage <= iLastPage)
        Get ComUpdateInt Of hoQuery "page" iPage To iSuccess
        Get pvComObject of hoQuery to vQuery
        Get pvComObject of hoResp to vResp
        Get ComHttpParams Of hoHttp "GET" "https://api-m.sandbox.paypal.com/v1/reporting/transactions" vQuery vResp To iSuccess
        If (iSuccess <> True) Begin
            Get ComLastErrorText Of hoHttp To sTemp1
            Showln "No HTTP response: " sTemp1
            Procedure_Return
        End

        Get ComStatusCode Of hoResp To iTemp1
        Get ComStatusCode Of hoResp To iTemp2
        If ((iTemp1 < 200) Or (iTemp2 >= 300)) Begin
            Get Create (RefClass(cComChilkatJsonObject)) To hoErrorInfo
            If (Not(IsComObjectCreated(hoErrorInfo))) Begin
                Send CreateComObject of hoErrorInfo
            End
            Get ComBodyStr Of hoResp To sTemp1
            Get ComLoad Of hoErrorInfo sTemp1 To iSuccess
            Get ComStatusCode Of hoResp To iTemp1
            Get ComStringOf Of hoErrorInfo "name" To sTemp1
            Get ComStringOf Of hoErrorInfo "details[0].issue" To sTemp2
            Showln "HTTP " iTemp1 " " sTemp1 " " sTemp2
            Get ComStringOf Of hoErrorInfo "debug_id" To sTemp1
            Showln "PayPal debug ID: " sTemp1
            Procedure_Return
        End

        Get Create (RefClass(cComChilkatJsonObject)) To hoResult
        If (Not(IsComObjectCreated(hoResult))) Begin
            Send CreateComObject of hoResult
        End
        Get ComBodyStr Of hoResp To sTemp1
        Get ComLoad Of hoResult sTemp1 To iParsed
        If (iParsed <> True) Begin
            Get ComStatusCode Of hoResp To iTemp1
            Showln "Expected a JSON response; HTTP " iTemp1
            Procedure_Return
        End

        Move 0 To i
        Get ComSizeOfArray Of hoResult "transaction_details" To iCount
        While (i < iCount)
            Set ComI Of hoResult To i
            Get ComStringOf Of hoResult "transaction_details[i].transaction_info.transaction_id" To sTemp1
            Get ComStringOf Of hoResult "transaction_details[i].transaction_info.transaction_event_code" To sTemp2
            Get ComStringOf Of hoResult "transaction_details[i].transaction_info.transaction_status" To sTemp3
            Showln sTemp1 "  " sTemp2 "  " sTemp3
            Get ComStringOf Of hoResult "transaction_details[i].transaction_info.transaction_amount.value" To sTemp1
            Get ComStringOf Of hoResult "transaction_details[i].transaction_info.transaction_amount.currency_code" To sTemp2
            Showln "  " sTemp1 " " sTemp2
            Move (i + 1) To i
        Loop

        Get ComIntOf Of hoResult "total_pages" To iLastPage
        Move (iPage + 1) To iPage
    Loop



End_Procedure