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

SQL Server 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
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

 

 

 

(SQL Server) 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 ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    -- Important: Do not use nvarchar(max).  See the warning about using nvarchar(max).
    DECLARE @sTmp0 nvarchar(4000)
    -- 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.

    DECLARE @json int
    -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

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

    -- Emit the JSON in compact format..
    EXEC sp_OASetProperty @json, 'EmitCompact', 1
    -- Get the JSON that will be HMAC'd and will also be the contents of the HTTP request body.
    DECLARE @jsonBody nvarchar(4000)
    EXEC sp_OAMethod @json, 'Emit', @jsonBody OUT

    DECLARE @crypt int
    -- Use "Chilkat_9_5_0.Crypt2" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.Crypt2', @crypt OUT

    EXEC sp_OASetProperty @crypt, 'EncodingMode', 'hex'
    EXEC sp_OASetProperty @crypt, 'HashAlgorithm', 'sha256'
    EXEC sp_OASetProperty @crypt, 'MacAlgorithm', 'hmac'

    EXEC sp_OAMethod @crypt, 'SetMacKeyString', @success OUT, '55fe0f4d4023bbdfbc124cabd88bf9bb'

    DECLARE @hmacHexStr nvarchar(4000)
    EXEC sp_OAMethod @crypt, 'MacStringENC', @hmacHexStr OUT, @jsonBody
    EXEC sp_OAGetProperty @crypt, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 <> 1
      BEGIN
        EXEC sp_OAGetProperty @crypt, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @crypt
        RETURN
      END

    -- We need a lowercase hmacHexStr...
    DECLARE @sbHmacHex int
    -- Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0
    EXEC @hr = sp_OACreate 'Chilkat.StringBuilder', @sbHmacHex OUT

    EXEC sp_OAMethod @sbHmacHex, 'Append', @success OUT, @hmacHexStr
    EXEC sp_OAMethod @sbHmacHex, 'ToLowercase', @success OUT

    EXEC sp_OAMethod @sbHmacHex, 'GetAsString', @hmacHexStr OUT


    PRINT 'The value of the X_RISKIFIED_HMAC_SHA256 should be: ' + @hmacHexStr

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

    EXEC @hr = sp_OADestroy @json
    EXEC @hr = sp_OADestroy @crypt
    EXEC @hr = sp_OADestroy @sbHmacHex


END
GO

 

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