Chilkat Examples

ChilkatHOME.NET Core C#Android™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi ActiveXDelphi DLLGoJavaLianjaMono C#Node.jsObjective-CPHP ActiveXPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

DataFlex Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(DataFlex) Payeezy HMAC Computation

Demonstrates how to calculate the HMAC for a Payeezy REST request.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Use ChilkatAx-9.5.0-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
    String sTemp1

    // 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": "token",
    // 	  "amount": "200",
    // 	  "currency_code": "USD",
    // 	  "token": {
    // 	    "token_type": "FDToken",
    // 	    "token_data": {
    // 	      "type": "visa",
    // 	      "value": "2537446225198291",
    // 	      "cardholder_name": "JohnSmith",
    // 	      "exp_date": "1030",
    // 	      "special_payment": "B"
    // 	    }
    // 	  }
    // 	}

    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" "token" To iSuccess
    Get ComUpdateString Of hoJson "amount" "200" To iSuccess
    Get ComUpdateString Of hoJson "currency_code" "USD" To iSuccess
    Get ComUpdateString Of hoJson "token.token_type" "FDToken" To iSuccess
    Get ComUpdateString Of hoJson "token.token_data.type" "visa" To iSuccess
    Get ComUpdateString Of hoJson "token.token_data.value" "2537446225198291" To iSuccess
    Get ComUpdateString Of hoJson "token.token_data.cardholder_name" "JohnSmith" To iSuccess
    Get ComUpdateString Of hoJson "token.token_data.exp_date" "1030" To iSuccess
    Get ComUpdateString Of hoJson "token.token_data.special_payment" "B" To iSuccess

    // 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

    // 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


End_Procedure

 

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