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

PowerBuilder 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

 

 

 

(PowerBuilder) 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

integer li_rc
oleobject loo_Crypt
oleobject loo_Prng
integer li_Success
string ls_ApiKey
string ls_ApiSecret
string ls_Token
string ls_Nonce
oleobject loo_DtNow
oleobject loo_SbTimestamp
string ls_Timestamp
oleobject loo_Json
oleobject loo_SbHmacData
string ls_HexHash
oleobject loo_SbBase64Hash

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

loo_Crypt = create oleobject
li_rc = loo_Crypt.ConnectToNewObject("Chilkat_9_5_0.Crypt2")
if li_rc < 0 then
    destroy loo_Crypt
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Prng = create oleobject
li_rc = loo_Prng.ConnectToNewObject("Chilkat_9_5_0.Prng")

// An API key such as y6pWAJNyJyjGv66IsVuWnklkKUPFbb0a
ls_ApiKey = "my_api_key"
// An API secret such as 86fbae7030253af3cd15faef2a1f4b67353e41fb6799f576b5093ae52901e6f7
ls_ApiSecret = "my_api_secret"
// A token such as fdoa-a480ce8951daa73262734cf102641994c1e55e7cdf4c02b6
ls_Token = "my_merchant_token"

// The nonce is a random number (bytes), something like "6057786719490086000"
ls_Nonce = loo_Prng.GenRandom(8,"decimal")
Write-Debug "nonce = " + ls_Nonce

loo_DtNow = create oleobject
li_rc = loo_DtNow.ConnectToNewObject("Chilkat_9_5_0.CkDateTime")

loo_DtNow.SetFromCurrentSystemTime()
loo_SbTimestamp = create oleobject
li_rc = loo_SbTimestamp.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

// Get the epoch timestamp in seconds
loo_SbTimestamp.Append(loo_DtNow.GetAsUnixTimeStr(0))
// Change it to milliseconds
loo_SbTimestamp.Append("000")
// The timestamp is a number similar to this: 1546011905000 (which is a timestamp taken on 28-Dec-2018).
ls_Timestamp = loo_SbTimestamp.GetAsString()
Write-Debug "timestamp = " + ls_Timestamp

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

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_Json.UpdateString("merchant_ref","Astonishing-Sale")
loo_Json.UpdateString("transaction_type","authorize")
loo_Json.UpdateString("method","token")
loo_Json.UpdateString("amount","200")
loo_Json.UpdateString("currency_code","USD")
loo_Json.UpdateString("token.token_type","FDToken")
loo_Json.UpdateString("token.token_data.type","visa")
loo_Json.UpdateString("token.token_data.value","2537446225198291")
loo_Json.UpdateString("token.token_data.cardholder_name","JohnSmith")
loo_Json.UpdateString("token.token_data.exp_date","1030")
loo_Json.UpdateString("token.token_data.special_payment","B")

// string hashData = apiKey + nonce + timestamp + token + jsonString;
loo_SbHmacData = create oleobject
li_rc = loo_SbHmacData.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

loo_SbHmacData.Append(ls_ApiKey)
loo_SbHmacData.Append(ls_Nonce)
loo_SbHmacData.Append(ls_Timestamp)
loo_SbHmacData.Append(ls_Token)
loo_SbHmacData.Append(loo_Json.Emit())

// HMAC the data to produce a hex string.
loo_Crypt.EncodingMode = "hexlower"
loo_Crypt.MacAlgorithm = "hmac"
loo_Crypt.SetMacKeyString(ls_ApiSecret)
loo_Crypt.HashAlgorithm = "sha256"
loo_Crypt.Charset = "utf-8"
ls_HexHash = loo_Crypt.MacStringENC(loo_SbHmacData.GetAsString())

// Now base64 encode the hex string:
loo_SbBase64Hash = create oleobject
li_rc = loo_SbBase64Hash.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

loo_SbBase64Hash.Append(ls_HexHash)
loo_SbBase64Hash.Encode("base64","utf-8")

Write-Debug "This is the Authorization header to be sent with the payeezy request:"
Write-Debug "Authorization: " + loo_SbBase64Hash.GetAsString()


destroy loo_Crypt
destroy loo_Prng
destroy loo_DtNow
destroy loo_SbTimestamp
destroy loo_Json
destroy loo_SbHmacData
destroy loo_SbBase64Hash

 

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