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) Payeezy Place Temp Authorization Hold on Buyer’s Credit CardDemonstrates how to place a temporary authorization hold for the desired amount on the buyer’s credit card. You can Capture the authorized amount on completion of service or Void/Refund the transaction as required.
Use ChilkatAx-win32.pkg Procedure Test Handle hoCrypt Handle hoPrng Boolean iSuccess String sApiKey String sApiSecret String sToken String sNonce Handle hoDtNow Handle hoSbTimestamp String sTimestamp Handle hoJson Handle hoSbHmacData String sHexHash Handle hoSbBase64Hash Handle hoHttp String sUrl Variant vResp Handle hoResp String sTemp1 Integer iTemp1 Boolean bTemp1 // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. Get Create (RefClass(cComChilkatCrypt2)) To hoCrypt If (Not(IsComObjectCreated(hoCrypt))) Begin Send CreateComObject of hoCrypt End Get Create (RefClass(cComChilkatPrng)) To hoPrng If (Not(IsComObjectCreated(hoPrng))) Begin Send CreateComObject of hoPrng End // An API key such as y6pWAJNyJyjGv66IsVuWnklkKUPFbb0a Move "my_api_key" To sApiKey // An API secret such as 86fbae7030253af3cd15faef2a1f4b67353e41fb6799f576b5093ae52901e6f7 Move "my_api_secret" To sApiSecret // A token such as fdoa-a480ce8951daa73262734cf102641994c1e55e7cdf4c02b6 Move "my_merchant_token" To sToken // The nonce is a random number (bytes), something like "6057786719490086000" Get ComGenRandom Of hoPrng 8 "decimal" To sNonce Showln "nonce = " sNonce Get Create (RefClass(cComCkDateTime)) To hoDtNow If (Not(IsComObjectCreated(hoDtNow))) Begin Send CreateComObject of hoDtNow End Get ComSetFromCurrentSystemTime Of hoDtNow To iSuccess Get Create (RefClass(cComChilkatStringBuilder)) To hoSbTimestamp If (Not(IsComObjectCreated(hoSbTimestamp))) Begin Send CreateComObject of hoSbTimestamp End // Get the epoch timestamp in seconds Get ComGetAsUnixTimeStr Of hoDtNow False To sTemp1 Get ComAppend Of hoSbTimestamp sTemp1 To iSuccess // Change it to milliseconds Get ComAppend Of hoSbTimestamp "000" To iSuccess // The timestamp is a number similar to this: 1546011905000 (which is a timestamp taken on 28-Dec-2018). Get ComGetAsString Of hoSbTimestamp To sTimestamp Showln "timestamp = " sTimestamp // Generate the following JSON request body: // { // "merchant_ref": "Astonishing-Sale", // "transaction_type": "authorize", // "method": "credit_card", // "amount": "1299", // "currency_code": "USD", // "credit_card": { // "type": "visa", // "cardholder_name": "John Smith", // "card_number": "4788250000028291", // "exp_date": "1020", // "cvv": "123" // } // } Get Create (RefClass(cComChilkatJsonObject)) To hoJson If (Not(IsComObjectCreated(hoJson))) Begin Send CreateComObject of hoJson End Get ComUpdateString Of hoJson "merchant_ref" "Astonishing-Sale" To iSuccess Get ComUpdateString Of hoJson "transaction_type" "authorize" To iSuccess Get ComUpdateString Of hoJson "method" "credit_card" To iSuccess Get ComUpdateString Of hoJson "amount" "1299" To iSuccess Get ComUpdateString Of hoJson "currency_code" "USD" To iSuccess Get ComUpdateString Of hoJson "credit_card.type" "visa" To iSuccess Get ComUpdateString Of hoJson "credit_card.cardholder_name" "John Smith" To iSuccess Get ComUpdateString Of hoJson "credit_card.card_number" "4788250000028291" To iSuccess Get ComUpdateString Of hoJson "credit_card.exp_date" "1020" To iSuccess Get ComUpdateString Of hoJson "credit_card.cvv" "123" To iSuccess Set ComEmitCompact Of hoJson To False Get ComEmit Of hoJson To sTemp1 Showln sTemp1 // string hashData = apiKey + nonce + timestamp + token + jsonString; Get Create (RefClass(cComChilkatStringBuilder)) To hoSbHmacData If (Not(IsComObjectCreated(hoSbHmacData))) Begin Send CreateComObject of hoSbHmacData End Get ComAppend Of hoSbHmacData sApiKey To iSuccess Get ComAppend Of hoSbHmacData sNonce To iSuccess Get ComAppend Of hoSbHmacData sTimestamp To iSuccess Get ComAppend Of hoSbHmacData sToken To iSuccess Get ComEmit Of hoJson To sTemp1 Get ComAppend Of hoSbHmacData sTemp1 To iSuccess // HMAC the data to produce a hex string. Set ComEncodingMode Of hoCrypt To "hexlower" Set ComMacAlgorithm Of hoCrypt To "hmac" Get ComSetMacKeyString Of hoCrypt sApiSecret To iSuccess Set ComHashAlgorithm Of hoCrypt To "sha256" Set ComCharset Of hoCrypt To "utf-8" Get ComGetAsString Of hoSbHmacData To sTemp1 Get ComMacStringENC Of hoCrypt sTemp1 To sHexHash Showln "hexHash = " sHexHash // Now base64 encode the hex string: Get Create (RefClass(cComChilkatStringBuilder)) To hoSbBase64Hash If (Not(IsComObjectCreated(hoSbBase64Hash))) Begin Send CreateComObject of hoSbBase64Hash End Get ComAppend Of hoSbBase64Hash sHexHash To iSuccess Get ComEncode Of hoSbBase64Hash "base64" "utf-8" To iSuccess Showln "This is the Authorization header to be sent with the payeezy request:" Get ComGetAsString Of hoSbBase64Hash To sTemp1 Showln "Authorization: " sTemp1 // ----------------------------------------------------------- // Now that we have the value for the Authorization header, send the POST containing the JSON. Get Create (RefClass(cComChilkatHttp)) To hoHttp If (Not(IsComObjectCreated(hoHttp))) Begin Send CreateComObject of hoHttp End Set ComAccept Of hoHttp To "*/*" Set ComUserAgent Of hoHttp To "" Get ComGetAsString Of hoSbBase64Hash To sTemp1 Send ComSetRequestHeader To hoHttp "Authorization" sTemp1 Send ComSetRequestHeader To hoHttp "apikey" sApiKey Send ComSetRequestHeader To hoHttp "nonce" sNonce Send ComSetRequestHeader To hoHttp "timestamp" sTimestamp Send ComSetRequestHeader To hoHttp "token" sToken Set ComSessionLogFilename Of hoHttp To "qa_output/payeezy.txt" Move "https://api-cert.payeezy.com/v1/transactions" To sUrl Get ComEmit Of hoJson To sTemp1 Get ComPostJson2 Of hoHttp sUrl "application/json" sTemp1 To vResp If (IsComObject(vResp)) Begin Get Create (RefClass(cComChilkatHttpResponse)) To hoResp Set pvComObject Of hoResp To vResp End Get ComLastMethodSuccess Of hoHttp To bTemp1 If (bTemp1 <> True) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get ComStatusCode Of hoResp To iTemp1 Showln "response status code = " iTemp1 Get ComBodyStr Of hoResp To sTemp1 Get ComLoad Of hoJson sTemp1 To iSuccess Get ComEmit Of hoJson To sTemp1 Showln sTemp1 Send Destroy of hoResp // Sample JSON response: // { // "correlation_id": "228.4604632998994", // "transaction_status": "approved", // "validation_status": "success", // "transaction_type": "authorize", // "transaction_id": "ET175628", // "transaction_tag": "2313721985", // "method": "credit_card", // "amount": "1299", // "currency": "USD", // "cvv2": "M", // "token": { // "token_type": "FDToken", // "token_data": { // "value": "9732261336638291" // } // }, // "card": { // "type": "visa", // "cardholder_name": "John Smith", // "card_number": "8291", // "exp_date": "1020" // }, // "bank_resp_code": "100", // "bank_message": "Approved", // "gateway_resp_code": "00", // "gateway_message": "Transaction Normal" // } // Get ComStringOf Of hoJson "correlation_id" To sTemp1 Showln sTemp1 Get ComStringOf Of hoJson "transaction_status" To sTemp1 Showln sTemp1 Get ComStringOf Of hoJson "validation_status" To sTemp1 Showln sTemp1 Get ComStringOf Of hoJson "transaction_type" To sTemp1 Showln sTemp1 Get ComStringOf Of hoJson "transaction_id" To sTemp1 Showln sTemp1 Get ComStringOf Of hoJson "transaction_tag" To sTemp1 Showln sTemp1 Get ComStringOf Of hoJson "method" To sTemp1 Showln sTemp1 Get ComStringOf Of hoJson "amount" To sTemp1 Showln sTemp1 Get ComStringOf Of hoJson "currency" To sTemp1 Showln sTemp1 Get ComStringOf Of hoJson "cvv2" To sTemp1 Showln sTemp1 Get ComStringOf Of hoJson "token.token_type" To sTemp1 Showln sTemp1 Get ComStringOf Of hoJson "token.token_data.value" To sTemp1 Showln sTemp1 Get ComStringOf Of hoJson "card.type" To sTemp1 Showln sTemp1 Get ComStringOf Of hoJson "card.cardholder_name" To sTemp1 Showln sTemp1 Get ComStringOf Of hoJson "card.card_number" To sTemp1 Showln sTemp1 Get ComStringOf Of hoJson "card.exp_date" To sTemp1 Showln sTemp1 Get ComStringOf Of hoJson "bank_resp_code" To sTemp1 Showln sTemp1 Get ComStringOf Of hoJson "bank_message" To sTemp1 Showln sTemp1 Get ComStringOf Of hoJson "gateway_resp_code" To sTemp1 Showln sTemp1 Get ComStringOf Of hoJson "gateway_message" To sTemp1 Showln sTemp1 End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.