Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Perl Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
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
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(Perl) Calculate a X_RISKIFIED_HMAC_SHA256 for riskified.com API Calls

Demonstrates how to calculate the value for the X_RISKIFIED_HMAC_SHA256 header for riskified.com HTTP requests (REST API calls).

Chilkat Perl Downloads

Perl Module for Windows, Linux, Alpine Linux,
MAC OS X, Solaris, FreeBSD, OpenBSD,
Raspberry Pi and other single board computers

use chilkat();

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

#  Create the JSON that is to be the body of the HTTP request.
#  The JSON created by this code is shown at the bottom of this example.
# 
#  The JSON Code Generator at http://tools.chilkat.io/ can be used
#  to generate the following code from sample JSON.

$json = chilkat::CkJsonObject->new();
$json->UpdateNull("order.cancel_reason");
$json->UpdateNull("order.cancelled_at");
$json->UpdateString("order.cart_token","68778783ad298f1c80c3bafcddeea02f");
$json->UpdateNull("order.closed_at");
$json->UpdateString("order.created_at","2008-01-10T11:00:00-05:00");
$json->UpdateString("order.currency","USD");
$json->UpdateString("order.email",'bob.norman@hostmail.com');
$json->UpdateString("order.gateway","authorize_net");
$json->UpdateNumber("order.id","450789469");
$json->UpdateString("order.total_discounts","0.00");
$json->UpdateString("order.total_price","409.94");
$json->UpdateString("order.updated_at","2008-01-10T11:00:00-05:00");
$json->UpdateString("order.note","some note made by the shop’s stuff member");
$json->UpdateNull("order.browser_ip");
$json->UpdateString("order.discount_codes[0].amount","10.00");
$json->UpdateString("order.discount_codes[0].code","TENOFF");
$json->UpdateString("order.line_items[0].title","IPod Nano - 8gb - green");
$json->UpdateNumber("order.line_items[0].price","199.00");
$json->UpdateNumber("order.line_items[0].product_id","632910392");
$json->UpdateNumber("order.line_items[0].quantity","1");
$json->UpdateString("order.line_items[0].sku","IPOD2008GREEN");
$json->UpdateString("order.shipping_lines[0].code","Free Shipping");
$json->UpdateString("order.shipping_lines[0].price","0.00");
$json->UpdateString("order.shipping_lines[0].title","Free Shipping");
$json->UpdateNull("order.payment_details.avs_result_code");
$json->UpdateNull("order.payment_details.credit_card_bin");
$json->UpdateString("order.payment_details.credit_card_company","Visa");
$json->UpdateString("order.payment_details.credit_card_number","XXXX-XXXX-XXXX-4242");
$json->UpdateNull("order.payment_details.cvv_result_code");
$json->UpdateString("order.payment_details.authorization_id","RK346IK124");
$json->UpdateString("order.billing_address.address1","Chestnut Street 92");
$json->UpdateString("order.billing_address.address2","");
$json->UpdateString("order.billing_address.city","Louisville");
$json->UpdateNull("order.billing_address.company");
$json->UpdateString("order.billing_address.country","United States");
$json->UpdateString("order.billing_address.country_code","US");
$json->UpdateString("order.billing_address.first_name","Bob");
$json->UpdateString("order.billing_address.last_name","Norman");
$json->UpdateString("order.billing_address.name","Bob Norman");
$json->UpdateString("order.billing_address.phone","555-625-1199");
$json->UpdateString("order.billing_address.province","Kentucky");
$json->UpdateString("order.billing_address.province_code","KY");
$json->UpdateString("order.billing_address.zip","40202");
$json->UpdateString("order.shipping_address.address1","Chestnut Street 92");
$json->UpdateString("order.shipping_address.address2","");
$json->UpdateString("order.shipping_address.city","Louisville");
$json->UpdateNull("order.shipping_address.company");
$json->UpdateString("order.shipping_address.country","United States");
$json->UpdateString("order.shipping_address.country_code","US");
$json->UpdateString("order.shipping_address.first_name","Bob");
$json->UpdateString("order.shipping_address.last_name","Norman");
$json->UpdateString("order.shipping_address.name","Bob Norman");
$json->UpdateString("order.shipping_address.phone","555-625-1199");
$json->UpdateString("order.shipping_address.province","Kentucky");
$json->UpdateString("order.shipping_address.province_code","KY");
$json->UpdateString("order.shipping_address.zip","40202");
$json->UpdateString("order.customer.created_at","2013-04-23T13:36:50-04:00");
$json->UpdateString("order.customer.email",'bob.norman@hostmail.com');
$json->UpdateString("order.customer.first_name","Bob");
$json->UpdateNumber("order.customer.id","207119551");
$json->UpdateString("order.customer.last_name","Norman");
$json->UpdateNull("order.customer.note");
$json->UpdateNumber("order.customer.orders_count","0");
$json->UpdateBool("order.customer.verified_email",1);

#  Emit the JSON in compact format..
$json->put_EmitCompact(1);
#  Get the JSON that will be HMAC'd and will also be the contents of the HTTP request body.
$jsonBody = $json->emit();

$crypt = chilkat::CkCrypt2->new();
$crypt->put_EncodingMode("hex");
$crypt->put_HashAlgorithm("sha256");
$crypt->put_MacAlgorithm("hmac");

$crypt->SetMacKeyString("55fe0f4d4023bbdfbc124cabd88bf9bb");

$hmacHexStr = $crypt->macStringENC($jsonBody);
if ($crypt->get_LastMethodSuccess() != 1) {
    print $crypt->lastErrorText() . "\r\n";
    exit;
}

#  We need a lowercase hmacHexStr...
$sbHmacHex = chilkat::CkStringBuilder->new();
$sbHmacHex->Append($hmacHexStr);
$sbHmacHex->ToLowercase();

$hmacHexStr = $sbHmacHex->getAsString();

print "The value of the X_RISKIFIED_HMAC_SHA256 should be: " . $hmacHexStr . "\r\n";

#  This example is only to show the HMAC SHA256 calculation.
#  See examples of sending REST requests to riskified.com at http://rest-examples.chilkat.io/riskified/default.cshtml

#  ----------------------------------------------
#  This is the JSON created by the above code..

#  {
#    "order": {
#      "cancel_reason": null,
#      "cancelled_at": null,
#      "cart_token": "68778783ad298f1c80c3bafcddeea02f",
#      "closed_at": null,
#      "created_at": "2008-01-10T11:00:00-05:00",
#      "currency": "USD",
#      "email": "bob.norman@hostmail.com",
#      "gateway": "authorize_net",
#      "id": 450789469,
#      "total_discounts": "0.00",
#      "total_price": "409.94",
#      "updated_at": "2008-01-10T11:00:00-05:00",
#      "note": "some note made by the shop’s stuff member",

#      "browser_ip": null,
#      "discount_codes": [
#          {
#              "amount": "10.00",
#              "code": "TENOFF"
#          }
#      ],
#      "line_items": [
#          {
#              "title": "IPod Nano - 8gb - green",
#              "price": 199.00,
#              "product_id": 632910392,
#              "quantity": 1,
#              "sku": "IPOD2008GREEN"
#          }
#      ],
#      "shipping_lines": [
#          {
#              "code": "Free Shipping",
#              "price": "0.00",
#              "title": "Free Shipping"
#          }
#      ],
#      "payment_details": {
#          "avs_result_code": null,
#          "credit_card_bin": null,
#          "credit_card_company": "Visa",
#          "credit_card_number": "XXXX-XXXX-XXXX-4242",
#          "cvv_result_code": null,
#          "authorization_id": "RK346IK124"
#      },
#      "billing_address": {
#          "address1": "Chestnut Street 92",
#          "address2": "",
#          "city": "Louisville",
#          "company": null,
#          "country": "United States",
#          "country_code": "US",
#          "first_name": "Bob",
#          "last_name": "Norman",
#          "name": "Bob Norman",
#          "phone": "555-625-1199",
#          "province": "Kentucky",
#          "province_code": "KY",
#          "zip": "40202"
#      },
#      "shipping_address": {
#          "address1": "Chestnut Street 92",
#          "address2": "",
#          "city": "Louisville",
#          "company": null,
#          "country": "United States",
#          "country_code": "US",
#          "first_name": "Bob",
#          "last_name": "Norman",
#          "name": "Bob Norman",
#          "phone": "555-625-1199",
#          "province": "Kentucky",
#          "province_code": "KY",
#          "zip": "40202"
#      },
#      "customer": {
#          "created_at": "2013-04-23T13:36:50-04:00",
#          "email": "bob.norman@hostmail.com",
#          "first_name": "Bob",
#          "id": 207119551,
#          "last_name": "Norman",
#          "note": null,
#          "orders_count": 0,
#          "verified_email": true
#      }
#   }
#  }

 

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