Xbase++
Xbase++
Adyen HMAC Signature Calculation for Hosted Payment Pages
See more Adyen Examples
Demonstrates how to do the HMAC Signature Calculation for a hosted payment page (HPP) in Adyen.For a C# ASP.NET Razor Pages example showing the HTML Form with HMAC signature code, see Adyen HMAC Signature Calculation in C#
Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL cStrHtml
LOCAL oGzip
LOCAL cGzOrderData
LOCAL oXml
LOCAL cSessionValidity
LOCAL cCountryCode
LOCAL cShopperLocale
LOCAL cMerchantReference
LOCAL cMerchantAccount
LOCAL cPaymentAmount
LOCAL cCurrencyCode
LOCAL cSkinCode
LOCAL cShopperReference
LOCAL cShopperEmail
LOCAL cShipBeforeDate
LOCAL oSbTags
LOCAL oSbValues
LOCAL oSbContent
LOCAL n
LOCAL i
LOCAL nNumReplaced
LOCAL oSbSigningStr
LOCAL oCrypt
LOCAL cHmacKey
LOCAL cMerchantSig
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
cStrHtml := '<table class="od"><tr><th>Description</th><th>Quantity</th><th>Amount</th></tr><tr><td>1 Digital Camera</td><td class="r">1</td><td class="r">100 GBP</td></tr><tr><td class="b">Total</td><td class="r"></td><td class="b r">100.00 GBP</td></tr></table>'
oGzip := CreateObject("Chilkat.Gzip")
cGzOrderData := oGzip:CompressStringENC(cStrHtml, "utf-8", "base64")
oXml := CreateObject("Chilkat.Xml")
oXml:Tag := "keyValuePairs"
oXml:NewChild2("orderData", cGzOrderData)
// required, The payment deadline; the payment needs to occur within the specified time value.
cSessionValidity := "2019-08-11T10:30:00Z"
oXml:NewChild2("sessionValidity", cSessionValidity)
// optional. Normally we'll let Adyen automatically know the country based on the IP address.
// By default, the payment methods offered to a shopper are filtered based on the country the shopper's IP address is mapped to.
// In this way, shoppers are not offered payment methods that are not available in the country they are carrying out the transaction from.
// This IP-to-country mapping is not 100% accurate, so if you have already established the country of the shopper, you can set it explicitly
// in the countryCode parameter.
cCountryCode := "GB"
oXml:NewChild2("countryCode", cCountryCode)
// optional
cShopperLocale := "en_GB"
// If not specified, the locale preference is set to en_GB by default.
// When it is not necessary to include the country-specific part, use only the language code.
// For example: it instead of it_IT to set the locale preferences to Italian.
oXml:NewChild2("shopperLocale", cShopperLocale)
// required, A reference to uniquely identify the payment. This reference is used in all communication with you about the payment status.
// We recommend using a unique value per payment; however, it is not a requirement. If you need to provide multiple references for a transaction,
// you can enter them in this field. Separate each reference value with a hyphen character ("-"). This field has a length restriction:
// you can enter max. 80 characters.
cMerchantReference := "paymentTest1234"
oXml:NewChild2("merchantReference", cMerchantReference)
// required, The merchant account identifier you want to process the (transaction) request with.
cMerchantAccount := "ChilkatSoftwareIncCOM"
oXml:NewChild2("merchantAccount", cMerchantAccount)
// required. 10000 for $100.00
cPaymentAmount := "10000"
oXml:NewChild2("paymentAmount", cPaymentAmount)
// required, The three-character ISO currency code
cCurrencyCode := "GBP"
oXml:NewChild2("currencyCode", cCurrencyCode)
// required.
cSkinCode := "S7uWsvfB"
oXml:NewChild2("skinCode", cSkinCode)
// optional, A unique identifier for the shopper, for example, a customer ID.
// We recommend providing this information, as it is used in velocity fraud checks. It is also the key in recurring payments.
// This field is mandatory in recurring payments.
cShopperReference := "somebody@example.com"
oXml:NewChild2("shopperReference", cShopperReference)
// optional
cShopperEmail := "somebody@example.com"
oXml:NewChild2("shopperEmail", cShopperEmail)
// optional, An integer value that adds up to the normal fraud score.
// The value can be either a positive or negative integer.
oXml:NewChild2("offset", "0")
// Apparently this is a required field.
cShipBeforeDate := "2019-06-04"
oXml:NewChild2("shipBeforeDate", cShipBeforeDate)
oXml:SortByTag(1)
// Encode...
// "\" (backslash) as "\\"
// ":" (colon) as "\:"
oSbTags := CreateObject("Chilkat.StringBuilder")
oSbValues := CreateObject("Chilkat.StringBuilder")
oSbContent := CreateObject("Chilkat.StringBuilder")
n := oXml:NumChildren
i := 0
DO WHILE i < n
IF (i > 0)
oSbTags:Append(":")
oSbValues:Append(":")
ENDIF
oXml:GetChild2(i)
oSbTags:Append(oXml:Tag)
oSbContent:SetString(oXml:Content)
nNumReplaced := oSbContent:Replace("\", "\\")
nNumReplaced := oSbContent:Replace(":", "\:")
oSbValues:AppendSb(oSbContent)
oXml:GetParent2()
i := i + 1
ENDDO
oSbSigningStr := CreateObject("Chilkat.StringBuilder")
oSbSigningStr:AppendSb(oSbTags)
oSbSigningStr:Append(":")
oSbSigningStr:AppendSb(oSbValues)
oCrypt := CreateObject("Chilkat.Crypt2")
oCrypt:HashAlgorithm := "sha256"
oCrypt:MacAlgorithm := "hmac"
cHmacKey := "934D1E806DDD99595EB430076FD7F8E4D12D0A3F51243A4C0C3897703118E739"
oCrypt:SetMacKeyEncoded(cHmacKey, "hex")
oCrypt:EncodingMode := "base64"
cMerchantSig := oCrypt:MacStringENC(oSbSigningStr:GetAsString())
? cMerchantSig
oGzip:destroy()
oXml:destroy()
oSbTags:destroy()
oSbValues:destroy()
oSbContent:destroy()
oSbSigningStr:destroy()
oCrypt:destroy()