Sample code for 30+ languages & platforms
PowerBuilder

Calculate a X_RISKIFIED_HMAC_SHA256 for riskified.com API Calls

See more REST Misc Examples

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

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
oleobject loo_Json
string ls_JsonBody
oleobject loo_Crypt
string ls_HmacHexStr
oleobject loo_SbHmacHex

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

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

// Emit the JSON in compact format..
loo_Json.EmitCompact = 1
// Get the JSON that will be HMAC'd and will also be the contents of the HTTP request body.
ls_JsonBody = loo_Json.Emit()

loo_Crypt = create oleobject
li_rc = loo_Crypt.ConnectToNewObject("Chilkat.Crypt2")

loo_Crypt.EncodingMode = "hex"
loo_Crypt.HashAlgorithm = "sha256"
loo_Crypt.MacAlgorithm = "hmac"

loo_Crypt.SetMacKeyString("55fe0f4d4023bbdfbc124cabd88bf9bb")

ls_HmacHexStr = loo_Crypt.MacStringENC(ls_JsonBody)
if loo_Crypt.LastMethodSuccess <> 1 then
    Write-Debug loo_Crypt.LastErrorText
    destroy loo_Json
    destroy loo_Crypt
    return
end if

// We need a lowercase hmacHexStr...
loo_SbHmacHex = create oleobject
li_rc = loo_SbHmacHex.ConnectToNewObject("Chilkat.StringBuilder")

loo_SbHmacHex.Append(ls_HmacHexStr)
loo_SbHmacHex.ToLowercase()

ls_HmacHexStr = loo_SbHmacHex.GetAsString()

Write-Debug "The value of the X_RISKIFIED_HMAC_SHA256 should be: " + ls_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
//     }
//  }
// }


destroy loo_Json
destroy loo_Crypt
destroy loo_SbHmacHex