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

Swift 3,4,5... 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
Google Vision
Hungary NAV Invoicing
IBM Text to Speech
Ibanity
IntakeQ
Jira
Lightspeed
MYOB
Magento
Mailgun
Malaysia MyInvois
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
Salesforce
SendGrid
Shippo
Shopify
Shopware
Shopware 6
SimpleTexting
Square
Stripe
SugarCRM
TicketBAI
TikTok Shop
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

 

 

 

(Swift 3,4,5...) 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 Downloads for the Swift Programming Language

MAC OS X (Cocoa) Objective-C/Swift Libs

iOS Objective-C/Swift Libs

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

    var success: Bool

    var strHtml: String? = "<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>"

    let gzip = CkoGzip()!
    var gzOrderData: String? = gzip.compressStringENC(strHtml, charset: "utf-8", encoding: "base64")

    let xml = CkoXml()!
    xml.tag = "keyValuePairs"

    xml.newChild2("orderData", content: gzOrderData)

    // required, The payment deadline; the payment needs to occur within the specified time value.
    var sessionValidity: String? = "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.
    var countryCode: String? = "GB"
    xml.newChild2("countryCode", content: countryCode)

    // optional
    var shopperLocale: String? = "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.
    var merchantReference: String? = "paymentTest1234"
    xml.newChild2("merchantReference", content: merchantReference)

    // required, The merchant account identifier you want to process the (transaction) request with.
    var merchantAccount: String? = "ChilkatSoftwareIncCOM"
    xml.newChild2("merchantAccount", content: merchantAccount)

    // required.  10000 for $100.00
    var paymentAmount: String? = "10000"
    xml.newChild2("paymentAmount", content: paymentAmount)

    // required, The three-character ISO currency code
    var currencyCode: String? = "GBP"
    xml.newChild2("currencyCode", content: currencyCode)

    // required.
    var skinCode: String? = "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.  
    var shopperReference: String? = "somebody@example.com"
    xml.newChild2("shopperReference", content: shopperReference)

    // optional
    var shopperEmail: String? = "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.
    var shipBeforeDate: String? = "2019-06-04"
    xml.newChild2("shipBeforeDate", content: shipBeforeDate)

    xml.sort(byTag: true)

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

    let sbTags = CkoStringBuilder()!
    let sbValues = CkoStringBuilder()!

    let sbContent = CkoStringBuilder()!
    var n: Int = xml.numChildren.intValue
    var i: Int = 0
    while i < n {
        if i > 0 {
            sbTags.append(":")
            sbValues.append(":")
        }

        xml.getChild2(i)
        sbTags.append(xml.tag)

        sbContent.setString(xml.content)
        var numReplaced: Int = sbContent.replace("\\", replacement: "\\\\").intValue
        numReplaced = sbContent.replace(":", replacement: "\\:").intValue
        sbValues.appendSb(sbContent)
        xml.getParent2()

        i = i + 1
    }

    let sbSigningStr = CkoStringBuilder()!
    sbSigningStr.appendSb(sbTags)
    sbSigningStr.append(":")
    sbSigningStr.appendSb(sbValues)

    let crypt = CkoCrypt2()!
    crypt.hashAlgorithm = "sha256"
    crypt.macAlgorithm = "hmac"

    var hmacKey: String? = "934D1E806DDD99595EB430076FD7F8E4D12D0A3F51243A4C0C3897703118E739"
    crypt.setMacKeyEncoded(hmacKey, encoding: "hex")

    crypt.encodingMode = "base64"
    var merchantSig: String? = crypt.hmacStringENC(sbSigningStr.getAsString())

    print("\(merchantSig!)")

}

 

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