Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Objective-C) Adyen HMAC Signature Calculation for Hosted Payment PagesDemonstrates 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/
#import <NSString.h> #import <CkoGzip.h> #import <CkoXml.h> #import <CkoStringBuilder.h> #import <CkoCrypt2.h> // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. BOOL success; NSString *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>"; CkoGzip *gzip = [[CkoGzip alloc] init]; NSString *gzOrderData = [gzip CompressStringENC: strHtml charset: @"utf-8" encoding: @"base64"]; CkoXml *xml = [[CkoXml alloc] init]; xml.Tag = @"keyValuePairs"; [xml NewChild2: @"orderData" content: gzOrderData]; // required, The payment deadline; the payment needs to occur within the specified time value. NSString *sessionValidity = @"2019-08-11T10:30:00Z"; [xml NewChild2: @"sessionValidity" content: 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. NSString *countryCode = @"GB"; [xml NewChild2: @"countryCode" content: countryCode]; // optional NSString *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. [xml NewChild2: @"shopperLocale" content: 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. NSString *merchantReference = @"paymentTest1234"; [xml NewChild2: @"merchantReference" content: merchantReference]; // required, The merchant account identifier you want to process the (transaction) request with. NSString *merchantAccount = @"ChilkatSoftwareIncCOM"; [xml NewChild2: @"merchantAccount" content: merchantAccount]; // required. 10000 for $100.00 NSString *paymentAmount = @"10000"; [xml NewChild2: @"paymentAmount" content: paymentAmount]; // required, The three-character ISO currency code NSString *currencyCode = @"GBP"; [xml NewChild2: @"currencyCode" content: currencyCode]; // required. NSString *skinCode = @"S7uWsvfB"; [xml NewChild2: @"skinCode" content: 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. NSString *shopperReference = @"somebody@example.com"; [xml NewChild2: @"shopperReference" content: shopperReference]; // optional NSString *shopperEmail = @"somebody@example.com"; [xml NewChild2: @"shopperEmail" content: shopperEmail]; // optional, An integer value that adds up to the normal fraud score. // The value can be either a positive or negative integer. [xml NewChild2: @"offset" content: @"0"]; // Apparently this is a required field. NSString *shipBeforeDate = @"2019-06-04"; [xml NewChild2: @"shipBeforeDate" content: shipBeforeDate]; [xml SortByTag: YES]; // Encode... // "\" (backslash) as "\\" // ":" (colon) as "\:" CkoStringBuilder *sbTags = [[CkoStringBuilder alloc] init]; CkoStringBuilder *sbValues = [[CkoStringBuilder alloc] init]; CkoStringBuilder *sbContent = [[CkoStringBuilder alloc] init]; int n = [xml.NumChildren intValue]; int i = 0; while (i < n) { if (i > 0) { [sbTags Append: @":"]; [sbValues Append: @":"]; } [xml GetChild2: [NSNumber numberWithInt: i]]; [sbTags Append: xml.Tag]; [sbContent SetString: xml.Content]; int numReplaced = [[sbContent Replace: @"\\" replacement: @"\\\\"] intValue]; numReplaced = [[sbContent Replace: @":" replacement: @"\\:"] intValue]; [sbValues AppendSb: sbContent]; [xml GetParent2]; i = i + 1; } CkoStringBuilder *sbSigningStr = [[CkoStringBuilder alloc] init]; [sbSigningStr AppendSb: sbTags]; [sbSigningStr Append: @":"]; [sbSigningStr AppendSb: sbValues]; CkoCrypt2 *crypt = [[CkoCrypt2 alloc] init]; crypt.HashAlgorithm = @"sha256"; crypt.MacAlgorithm = @"hmac"; NSString *hmacKey = @"934D1E806DDD99595EB430076FD7F8E4D12D0A3F51243A4C0C3897703118E739"; [crypt SetMacKeyEncoded: hmacKey encoding: @"hex"]; crypt.EncodingMode = @"base64"; NSString *merchantSig = [crypt HmacStringENC: [sbSigningStr GetAsString]]; NSLog(@"%@",merchantSig); |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.