Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

DataFlex Web API Examples

Primary Categories

AWS Translate
Activix CRM
Adyen
Amazon MWS
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Bluzone
CardConnect
ClickBank
Clickatell
Cloudfare
DocuSign
ETrade
Etsy
Facebook
GeoOp
GetHarvest
Jira
MYOB

Magento
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Okta OAuth/OIDC
OneLogin OIDC
PayPal
Peoplevox
Populi
QuickBooks
SOAP finkok.com
Shippo
Shopify
Stripe
SugarCRM
Trello
Twitter
VoiceBase
Vonage
Walmart
Walmart v3
Xero
eBay
effectconnect

 

 

 

(DataFlex) PayPal - Show Payment Details

Shows details for a payment by ID.

Note: This example requires Chilkat v9.5.0.65 or greater.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoJsonToken
    Handle hoSbAuth
    Handle hoRest
    Boolean iBAutoReconnect
    Boolean iSuccess
    Handle hoSbPath
    Integer iNumReplaced
    Variant vSbJsonResponse
    Handle hoSbJsonResponse
    Handle hoJson
    Handle hoDateTime
    Variant vDtUtc
    Handle hoDtUtc
    String sTemp1
    Integer iTemp1
    Integer iTemp2
    Integer iTemp3

    // Note: Requires Chilkat v9.5.0.65 or greater.

    // This requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    // Load our previously obtained access token. (see PayPal OAuth2 Access Token)
    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonToken
    If (Not(IsComObjectCreated(hoJsonToken))) Begin
        Send CreateComObject of hoJsonToken
    End
    Get ComLoadFile Of hoJsonToken "qa_data/tokens/paypal.json" To iSuccess

    // Build the Authorization request header field value.
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbAuth
    If (Not(IsComObjectCreated(hoSbAuth))) Begin
        Send CreateComObject of hoSbAuth
    End
    // token_type should be "Bearer"
    Get ComStringOf Of hoJsonToken "token_type" To sTemp1
    Get ComAppend Of hoSbAuth sTemp1 To iSuccess
    Get ComAppend Of hoSbAuth " " To iSuccess
    Get ComStringOf Of hoJsonToken "access_token" To sTemp1
    Get ComAppend Of hoSbAuth sTemp1 To iSuccess

    // Make the initial connection.
    // A single REST object, once connected, can be used for many PayPal REST API calls.
    // The auto-reconnect indicates that if the already-established HTTPS connection is closed,
    // then it will be automatically re-established as needed.
    Get Create (RefClass(cComChilkatRest)) To hoRest
    If (Not(IsComObjectCreated(hoRest))) Begin
        Send CreateComObject of hoRest
    End
    Move True To iBAutoReconnect
    Get ComConnect Of hoRest "api.sandbox.paypal.com" 443 True iBAutoReconnect To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // ----------------------------------------------------------------------------------------------
    // The code above this comment could be placed inside a function/subroutine within the application
    // because the connection does not need to be made for every request.  Once the connection is made
    // the app may send many requests..
    // ----------------------------------------------------------------------------------------------

    // Clear the REST object of any headers or query params from previous requests.
    Get ComClearAllHeaders Of hoRest To iSuccess
    Get ComClearAllQueryParams Of hoRest To iSuccess

    Get ComGetAsString Of hoSbAuth To sTemp1
    Get ComAddHeader Of hoRest "Authorization" sTemp1 To iSuccess

    // The payment ID is added to the path.
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbPath
    If (Not(IsComObjectCreated(hoSbPath))) Begin
        Send CreateComObject of hoSbPath
    End
    Get ComAppend Of hoSbPath "/v1/payments/payment/payment_id" To iSuccess
    Get ComReplace Of hoSbPath "payment_id" "PAY-2CY489250W145633HLA3DK3Y" To iNumReplaced

    // Send the GET request and get the JSON response.
    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbJsonResponse
    If (Not(IsComObjectCreated(hoSbJsonResponse))) Begin
        Send CreateComObject of hoSbJsonResponse
    End
    Get ComGetAsString Of hoSbPath To sTemp1
    Get pvComObject of hoSbJsonResponse to vSbJsonResponse
    Get ComFullRequestNoBodySb Of hoRest "GET" sTemp1 vSbJsonResponse To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Set ComEmitCompact Of hoJson To False
    Get pvComObject of hoSbJsonResponse to vSbJsonResponse
    Get ComLoadSb Of hoJson vSbJsonResponse To iSuccess

    Get ComResponseStatusCode Of hoRest To iTemp1
    Showln "Response Status Code = " iTemp1

    // Did we get a 200 success response?
    Get ComResponseStatusCode Of hoRest To iTemp1
    If (iTemp1 <> 200) Begin
        Get ComEmit Of hoJson To sTemp1
        Showln sTemp1
        Showln "Failed."
        Procedure_Return
    End

    // Sample JSON response is shown below.
    Get ComEmit Of hoJson To sTemp1
    Showln sTemp1
    Showln "----------------------"

    // Show how to get a timestamp, such as update_time.
    Get Create (RefClass(cComCkDateTime)) To hoDateTime
    If (Not(IsComObjectCreated(hoDateTime))) Begin
        Send CreateComObject of hoDateTime
    End
    Get ComStringOf Of hoJson "update_time" To sTemp1
    Get ComSetFromTimestamp Of hoDateTime sTemp1 To iSuccess
    Get ComGetAsTimestamp Of hoDateTime False To sTemp1
    Showln "utc update_time: " sTemp1
    Get ComGetAsTimestamp Of hoDateTime True To sTemp1
    Showln "local update_time: " sTemp1
    Get ComGetAsRfc822 Of hoDateTime False To sTemp1
    Showln "utc rfc822: " sTemp1
    Get ComGetAsRfc822 Of hoDateTime True To sTemp1
    Showln "local rfc822: " sTemp1

    Get ComGetDtObj Of hoDateTime False To vDtUtc
    If (IsComObject(vDtUtc)) Begin
        Get Create (RefClass(cComChilkatDtObj)) To hoDtUtc
        Set pvComObject Of hoDtUtc To vDtUtc
    End
    Get ComMonth Of hoDtUtc To iTemp1
    Get ComDay Of hoDtUtc To iTemp2
    Get ComYear Of hoDtUtc To iTemp3
    Showln iTemp1 "/" iTemp2 "/" iTemp3
    Send Destroy of hoDtUtc

    Showln "success"

    // ------------------------------------------------
    // A sample JSON response:

    // 	{ 
    // 	  "id": "PAY-2CY489250W145633HLA3DK3Y",
    // 	  "create_time": "2016-11-24T00:33:51Z",
    // 	  "update_time": "2016-11-24T00:40:54Z",
    // 	  "state": "approved",
    // 	  "intent": "authorize",
    // 	  "payer": { 
    // 	    "payment_method": "credit_card",
    // 	    "funding_instruments": [
    // 	      { 
    // 	        "credit_card_token": { 
    // 	          "credit_card_id": "CARD-52W84623JH8043102LA3CLGA",
    // 	          "payer_id": "user12345",
    // 	          "last4": "9974",
    // 	          "type": "visa",
    // 	          "expire_month": "9",
    // 	          "expire_year": "2021"
    // 	        }
    // 	      }
    // 	    ]
    // 	  },
    // 	  "transactions": [
    // 	    { 
    // 	      "amount": { 
    // 	        "total": "6.70",
    // 	        "currency": "USD",
    // 	        "details": { 
    // 	          "subtotal": "6.70"
    // 	        }
    // 	      },
    // 	      "description": "This is the payment transaction description.",
    // 	      "related_resources": [
    // 	        { 
    // 	          "authorization": { 
    // 	            "id": "7X8332687A4929542",
    // 	            "create_time": "2016-11-24T00:33:51Z",
    // 	            "update_time": "2016-11-24T00:33:58Z",
    // 	            "amount": { 
    // 	              "total": "6.70",
    // 	              "currency": "USD",
    // 	              "details": { 
    // 	                "subtotal": "6.70"
    // 	              }
    // 	            },
    // 	            "state": "captured",
    // 	            "parent_payment": "PAY-2CY489250W145633HLA3DK3Y",
    // 	            "valid_until": "2016-12-23T00:33:51Z",
    // 	            "links": [
    // 	              { 
    // 	                "href": "https://api.sandbox.paypal.com/v1/payments/authorization/7X8332687A4929542",
    // 	                "rel": "self",
    // 	                "method": "GET"
    // 	              },
    // 	              { 
    // 	                "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-2CY489250W145633HLA3DK3Y",
    // 	                "rel": "parent_payment",
    // 	                "method": "GET"
    // 	              }
    // 	            ]
    // 	          }
    // 	        },
    // 	        { 
    // 	          "capture": { 
    // 	            "id": "1LY5310469661362J",
    // 	            "create_time": "2016-11-24T00:40:50Z",
    // 	            "update_time": "2016-11-24T00:40:54Z",
    // 	            "amount": { 
    // 	              "total": "4.54",
    // 	              "currency": "USD"
    // 	            },
    // 	            "state": "completed",
    // 	            "parent_payment": "PAY-2CY489250W145633HLA3DK3Y",
    // 	            "transaction_fee": { 
    // 	              "value": "0.43",
    // 	              "currency": "USD"
    // 	            },
    // 	            "links": [
    // 	              { 
    // 	                "href": "https://api.sandbox.paypal.com/v1/payments/capture/1LY5310469661362J",
    // 	                "rel": "self",
    // 	                "method": "GET"
    // 	              },
    // 	              { 
    // 	                "href": "https://api.sandbox.paypal.com/v1/payments/capture/1LY5310469661362J/refund",
    // 	                "rel": "refund",
    // 	                "method": "POST"
    // 	              },
    // 	              { 
    // 	                "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-2CY489250W145633HLA3DK3Y",
    // 	                "rel": "parent_payment",
    // 	                "method": "GET"
    // 	              }
    // 	            ]
    // 	          }
    // 	        }
    // 	      ]
    // 	    }
    // 	  ],
    // 	  "links": [
    // 	    { 
    // 	      "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-2CY489250W145633HLA3DK3Y",
    // 	      "rel": "self",
    // 	      "method": "GET"
    // 	    }
    // 	  ]
    // 	}


End_Procedure

 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.