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
Cloud Signature CSC
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
uncategorized

 

 

 

(PowerBuilder) Payeezy Place Temp Authorization Hold on Buyer’s Credit Card

Demonstrates 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.

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
oleobject loo_Http
string ls_Url
oleobject loo_Resp

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

loo_Crypt = create oleobject
// Use "Chilkat_9_5_0.Crypt2" for versions of Chilkat < 10.0.0
li_rc = loo_Crypt.ConnectToNewObject("Chilkat.Crypt2")
if li_rc < 0 then
    destroy loo_Crypt
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Prng = create oleobject
// Use "Chilkat_9_5_0.Prng" for versions of Chilkat < 10.0.0
li_rc = loo_Prng.ConnectToNewObject("Chilkat.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
// Use "Chilkat_9_5_0.CkDateTime" for versions of Chilkat < 10.0.0
li_rc = loo_DtNow.ConnectToNewObject("Chilkat.CkDateTime")

loo_DtNow.SetFromCurrentSystemTime()
loo_SbTimestamp = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbTimestamp.ConnectToNewObject("Chilkat.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": "credit_card",
//   "amount": "1299",
//   "currency_code": "USD",
//   "credit_card": {
//     "type": "visa",
//     "cardholder_name": "John Smith",
//     "card_number": "4788250000028291",
//     "exp_date": "1020",
//     "cvv": "123"
//   }
// }

loo_Json = create oleobject
// Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

loo_Json.UpdateString("merchant_ref","Astonishing-Sale")
loo_Json.UpdateString("transaction_type","authorize")
loo_Json.UpdateString("method","credit_card")
loo_Json.UpdateString("amount","1299")
loo_Json.UpdateString("currency_code","USD")
loo_Json.UpdateString("credit_card.type","visa")
loo_Json.UpdateString("credit_card.cardholder_name","John Smith")
loo_Json.UpdateString("credit_card.card_number","4788250000028291")
loo_Json.UpdateString("credit_card.exp_date","1020")
loo_Json.UpdateString("credit_card.cvv","123")
loo_Json.EmitCompact = 0
Write-Debug loo_Json.Emit()

// string hashData = apiKey + nonce + timestamp + token + jsonString;
loo_SbHmacData = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbHmacData.ConnectToNewObject("Chilkat.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())
Write-Debug "hexHash = " + ls_HexHash

// Now base64 encode the hex string:
loo_SbBase64Hash = create oleobject
// Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
li_rc = loo_SbBase64Hash.ConnectToNewObject("Chilkat.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()

// -----------------------------------------------------------
// Now that we have the value for the Authorization header, send the POST containing the JSON.

loo_Http = create oleobject
// Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")

loo_Http.Accept = "*/*"
loo_Http.UserAgent = ""
loo_Http.SetRequestHeader("Authorization",loo_SbBase64Hash.GetAsString())
loo_Http.SetRequestHeader("apikey",ls_ApiKey)
loo_Http.SetRequestHeader("nonce",ls_Nonce)
loo_Http.SetRequestHeader("timestamp",ls_Timestamp)
loo_Http.SetRequestHeader("token",ls_Token)

loo_Http.SessionLogFilename = "qa_output/payeezy.txt"

ls_Url = "https://api-cert.payeezy.com/v1/transactions"
loo_Resp = loo_Http.PostJson2(ls_Url,"application/json",loo_Json.Emit())
if loo_Http.LastMethodSuccess <> 1 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Crypt
    destroy loo_Prng
    destroy loo_DtNow
    destroy loo_SbTimestamp
    destroy loo_Json
    destroy loo_SbHmacData
    destroy loo_SbBase64Hash
    destroy loo_Http
    return
end if

Write-Debug "response status code = " + string(loo_Resp.StatusCode)
loo_Json.Load(loo_Resp.BodyStr)
Write-Debug loo_Json.Emit()
destroy loo_Resp

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

Write-Debug loo_Json.StringOf("correlation_id")
Write-Debug loo_Json.StringOf("transaction_status")
Write-Debug loo_Json.StringOf("validation_status")
Write-Debug loo_Json.StringOf("transaction_type")
Write-Debug loo_Json.StringOf("transaction_id")
Write-Debug loo_Json.StringOf("transaction_tag")
Write-Debug loo_Json.StringOf("method")
Write-Debug loo_Json.StringOf("amount")
Write-Debug loo_Json.StringOf("currency")
Write-Debug loo_Json.StringOf("cvv2")
Write-Debug loo_Json.StringOf("token.token_type")
Write-Debug loo_Json.StringOf("token.token_data.value")
Write-Debug loo_Json.StringOf("card.type")
Write-Debug loo_Json.StringOf("card.cardholder_name")
Write-Debug loo_Json.StringOf("card.card_number")
Write-Debug loo_Json.StringOf("card.exp_date")
Write-Debug loo_Json.StringOf("bank_resp_code")
Write-Debug loo_Json.StringOf("bank_message")
Write-Debug loo_Json.StringOf("gateway_resp_code")
Write-Debug loo_Json.StringOf("gateway_message")


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

 

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