Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(DataFlex) PayPal - Get Sale DetailsShows details for a sale transaction, by ID. Note: This example requires Chilkat v9.5.0.65 or greater.
Use ChilkatAx-win32.pkg Procedure Test Handle hoJsonToken Boolean iSuccess 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 sale ID is added to the path. // The sale ID is obtained from payment records as shown here: Find Completed Sales Get Create (RefClass(cComChilkatStringBuilder)) To hoSbPath If (Not(IsComObjectCreated(hoSbPath))) Begin Send CreateComObject of hoSbPath End Get ComAppend Of hoSbPath "/v1/payments/sale/sale_id" To iSuccess Get ComReplace Of hoSbPath "sale_id" "1XC17935MN507400J" 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": "1XC17935MN507400J", // "create_time": "2016-11-25T15:42:50Z", // "update_time": "2016-11-25T15:42:56Z", // "amount": { // "total": "289.00", // "currency": "USD" // }, // "payment_mode": "INSTANT_TRANSFER", // "state": "completed", // "protection_eligibility": "ELIGIBLE", // "protection_eligibility_type": "ITEM_NOT_RECEIVED_ELIGIBLE,UNAUTHORIZED_PAYMENT_ELIGIBLE", // "parent_payment": "PAY-2AA764602T410180HLA4FX6Q", // "transaction_fee": { // "value": "8.68", // "currency": "USD" // }, // "links": [ // { // "href": "https://api.sandbox.paypal.com/v1/payments/sale/1XC17935MN507400J", // "rel": "self", // "method": "GET" // }, // { // "href": "https://api.sandbox.paypal.com/v1/payments/sale/1XC17935MN507400J/refund", // "rel": "refund", // "method": "POST" // }, // { // "href": "https://api.sandbox.paypal.com/v1/payments/payment/PAY-2AA764602T410180HLA4FX6Q", // "rel": "parent_payment", // "method": "GET" // } // ] // } End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.