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

C Web API Examples

Primary Categories

ABN AMRO
AWS Secrets Manager
AWS Security Token Service
AWS Translate
Activix CRM
Adyen
Alibaba Cloud OSS
Amazon Cognito
Amazon DynamoDB
Amazon MWS
Amazon Pay
Amazon Rekognition
Amazon SP-API
Amazon Voice ID
Aruba Fatturazione
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Backblaze S3
Banco Inter
Belgian eHealth Platform
Bitfinex v2 REST
Bluzone
BrickLink
Bunny CDN
CallRail
CardConnect
Cerved
ClickBank
Clickatell
Cloudfare
Constant Contact
DocuSign
Duo Auth MFA
ETrade
Ecwid
Egypt ITIDA
Egypt eReceipt
Etsy
Facebook
Faire
Frame.io
GeoOp
GetHarvest
Global Payments
Google People
Google Search Console
Google Translate
Hungary NAV Invoicing
IBM Text to Speech
Ibanity
IntakeQ
Jira
Lightspeed
MYOB
Magento
Mailgun
Mastercard

MedTunnel
MercadoLibre
MessageMedia
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Microsoft Teams
Moody's
Okta OAuth/OIDC
OneLogin OIDC
OneNote
OpenAI ChatGPT
PRODA
PayPal
Paynow.pl
Peoplevox
Populi
QuickBooks
Rabobank
Refinitiv
Royal Mail OBA
SCiS Schools Catalogue
SII Chile
SMSAPI
SOAP finkok.com
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
Trello
Twilio
Twitter API v2
Twitter v1
UPS
UniPin
VoiceBase
Vonage
WaTrend
Walmart v3
Wasabi
WhatsApp
WiX
WooCommerce
WordPress
Xero
Yahoo Mail
Yapily
Yousign
ZATCA
Zendesk
Zoom
_Miscellaneous_
eBay
effectconnect
hacienda.go.cr

 

 

 

(C) Adyen HMAC Signature Calculation for Hosted Payment Pages

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#

For more information, see https://docs.adyen.com/classic-integration/hosted-payment-pages/hmac-signature-calculation/

Chilkat C/C++ Library Downloads

MS Visual C/C++

Linux/CentOS C/C++

Alpine Linux C/C++

MAC OS X C/C++

armhf/aarch64 C/C++

C++ Builder

iOS C/C++

Android C/C++

Solaris C/C++

MinGW C/C++

#include <C_CkGzip.h>
#include <C_CkXml.h>
#include <C_CkStringBuilder.h>
#include <C_CkCrypt2.h>

void ChilkatSample(void)
    {
    BOOL success;
    const char *strHtml;
    HCkGzip gzip;
    const char *gzOrderData;
    HCkXml xml;
    const char *sessionValidity;
    const char *countryCode;
    const char *shopperLocale;
    const char *merchantReference;
    const char *merchantAccount;
    const char *paymentAmount;
    const char *currencyCode;
    const char *skinCode;
    const char *shopperReference;
    const char *shopperEmail;
    const char *shipBeforeDate;
    HCkStringBuilder sbTags;
    HCkStringBuilder sbValues;
    HCkStringBuilder sbContent;
    int n;
    int i;
    int numReplaced;
    HCkStringBuilder sbSigningStr;
    HCkCrypt2 crypt;
    const char *hmacKey;
    const char *merchantSig;

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

    strHtml = "<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>";

    gzip = CkGzip_Create();
    gzOrderData = CkGzip_compressStringENC(gzip,strHtml,"utf-8","base64");

    xml = CkXml_Create();
    CkXml_putTag(xml,"keyValuePairs");

    CkXml_NewChild2(xml,"orderData",gzOrderData);

    // required, The payment deadline; the payment needs to occur within the specified time value.
    sessionValidity = "2019-08-11T10:30:00Z";
    CkXml_NewChild2(xml,"sessionValidity",sessionValidity);

    // 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.
    countryCode = "GB";
    CkXml_NewChild2(xml,"countryCode",countryCode);

    // optional
    shopperLocale = "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.
    CkXml_NewChild2(xml,"shopperLocale",shopperLocale);

    // 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.
    merchantReference = "paymentTest1234";
    CkXml_NewChild2(xml,"merchantReference",merchantReference);

    // required, The merchant account identifier you want to process the (transaction) request with.
    merchantAccount = "ChilkatSoftwareIncCOM";
    CkXml_NewChild2(xml,"merchantAccount",merchantAccount);

    // required.  10000 for $100.00
    paymentAmount = "10000";
    CkXml_NewChild2(xml,"paymentAmount",paymentAmount);

    // required, The three-character ISO currency code
    currencyCode = "GBP";
    CkXml_NewChild2(xml,"currencyCode",currencyCode);

    // required.
    skinCode = "S7uWsvfB";
    CkXml_NewChild2(xml,"skinCode",skinCode);

    // 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.  
    shopperReference = "somebody@example.com";
    CkXml_NewChild2(xml,"shopperReference",shopperReference);

    // optional
    shopperEmail = "somebody@example.com";
    CkXml_NewChild2(xml,"shopperEmail",shopperEmail);

    // optional, An integer value that adds up to the normal fraud score.
    // The value can be either a positive or negative integer.
    CkXml_NewChild2(xml,"offset","0");

    // Apparently this is a required field.
    shipBeforeDate = "2019-06-04";
    CkXml_NewChild2(xml,"shipBeforeDate",shipBeforeDate);

    CkXml_SortByTag(xml,TRUE);

    // Encode...
    //  "\" (backslash) as "\\"
    //  ":" (colon) as "\:"

    sbTags = CkStringBuilder_Create();
    sbValues = CkStringBuilder_Create();

    sbContent = CkStringBuilder_Create();
    n = CkXml_getNumChildren(xml);
    i = 0;
    while (i < n) {
        if (i > 0) {
            CkStringBuilder_Append(sbTags,":");
            CkStringBuilder_Append(sbValues,":");
        }

        CkXml_GetChild2(xml,i);
        CkStringBuilder_Append(sbTags,CkXml_tag(xml));

        CkStringBuilder_SetString(sbContent,CkXml_content(xml));
        numReplaced = CkStringBuilder_Replace(sbContent,"\\","\\\\");
        numReplaced = CkStringBuilder_Replace(sbContent,":","\\:");
        CkStringBuilder_AppendSb(sbValues,sbContent);
        CkXml_GetParent2(xml);

        i = i + 1;
    }

    sbSigningStr = CkStringBuilder_Create();
    CkStringBuilder_AppendSb(sbSigningStr,sbTags);
    CkStringBuilder_Append(sbSigningStr,":");
    CkStringBuilder_AppendSb(sbSigningStr,sbValues);

    crypt = CkCrypt2_Create();
    CkCrypt2_putHashAlgorithm(crypt,"sha256");
    CkCrypt2_putMacAlgorithm(crypt,"hmac");

    hmacKey = "934D1E806DDD99595EB430076FD7F8E4D12D0A3F51243A4C0C3897703118E739";
    CkCrypt2_SetMacKeyEncoded(crypt,hmacKey,"hex");

    CkCrypt2_putEncodingMode(crypt,"base64");
    merchantSig = CkCrypt2_hmacStringENC(crypt,CkStringBuilder_getAsString(sbSigningStr));

    printf("%s\n",merchantSig);


    CkGzip_Dispose(gzip);
    CkXml_Dispose(xml);
    CkStringBuilder_Dispose(sbTags);
    CkStringBuilder_Dispose(sbValues);
    CkStringBuilder_Dispose(sbContent);
    CkStringBuilder_Dispose(sbSigningStr);
    CkCrypt2_Dispose(crypt);

    }

 

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