Sample code for 30+ languages & platforms
Swift

ClickBank Parse Instant Notification JSON

See more ClickBank Examples

Demonstrates how to parse the JSON of a ClickBank instant notification.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    let json = CkoJsonObject()!

    json.load(json: "{  ...  }")

    // Use this online tool to generate parsing code from sample JSON: 
    // Generate Parsing Code from JSON

    // See the parsing code below..

    // Sample notification JSON: 

    // {
    //     "transactionTime": "2016-06-05T13:47:51-06:00",
    //     "receipt": "CWOGBZLN",
    //     "transactionType": "SALE",
    //     "vendor": "testacct",
    //     "affiliate": "affiliate1",
    //     "role": "VENDOR",
    //     "totalAccountAmount": 0.00,
    //     "paymentMethod": "VISA",
    //     "totalOrderAmount": 0.00,
    //     "totalTaxAmount": 0.00,
    //     "totalShippingAmount": 0.00,
    //     "currency": "USD",
    //     "orderLanguage": "EN",
    //     "trackingCodes": [
    //         "tracking_code"
    //     ],
    //     "lineItems": [
    //         {
    //             "itemNo": "1",
    //             "productTitle": "Product Title",
    //             "shippable": false,
    //             "recurring": false,
    //             "accountAmount": 5.00,
    //             "quantity": 1,
    //             "downloadUrl": "<download_url>"
    //             "lineItemType": "CART"
    //        }
    //         {
    //             "itemNo": "2",
    //             "productTitle": "Second Product",
    //             "shippable": false,
    //             "recurring": true,
    //             "accountAmount": 2.99,
    //             "quantity": 1,
    //             "downloadUrl": "<download_url>"
    //             "lineItemType": "CART"
    //        }
    // 
    //     ],
    //      "customer": {
    //         "shipping": {
    //             "firstName": "TEST",
    //             "lastName": "GUY",
    //             "fullName": "Test Guy",
    //             "phoneNumber": "",
    //             "email": "test@example.net",
    //             "address": {
    //                 "address1": "12 Test Lane",
    //                 "address2": "Suite 100",
    //                 "city": "LAS VEGAS",
    //                 "county": "LAS VEGAS",
    //                 "state": "NV",
    //                 "postalCode": "89101",
    //                 "country": "US"
    //             }
    //         },
    //         "billing": {
    //             "firstName": "TEST",
    //             "lastName": "GUY",
    //             "fullName": "Test Guy",
    //             "phoneNumber": "",
    //             "email": "test@example.net",
    //             "address": {
    //                 "state": "NV",
    //                 "postalCode": "89101",
    //                 "country": "US"
    //             }
    //         }
    //     },
    //      "upsell": {
    //         "upsellOriginalReceipt": "XXXXXXXX",
    //         "upsellFlowId": 55,
    //         "upsellSession": "VVVVVVVVVV",
    //         "upsellPath": "upsell_path"
    //     },
    //      "hopfeed": {
    //         "hopfeedClickId": "hopfeed_click",
    //         "hopfeedApplicationId": 0000,
    //         "hopfeedCreativeId": 0000,
    //         "hopfeedApplicationPayout": 0.00,
    //         "hopfeedVendorPayout": 0.00
    //     },
    //      "version": 6.0,
    //     "attemptCount": 1,
    //      "vendorVariables": {
    //        "v1": "variable1", 
    //        "v2": "variable2" 
    //     }
    //  }
    // 
    // 

    var transactionTime: String?
    var receipt: String?
    var transactionType: String?
    var vendor: String?
    var affiliate: String?
    var role: String?
    var totalAccountAmount: String?
    var paymentMethod: String?
    var totalOrderAmount: String?
    var totalTaxAmount: String?
    var totalShippingAmount: String?
    var currency: String?
    var orderLanguage: String?
    var customerShippingFirstName: String?
    var customerShippingLastName: String?
    var customerShippingFullName: String?
    var customerShippingPhoneNumber: String?
    var customerShippingEmail: String?
    var customerShippingAddressAddress1: String?
    var customerShippingAddressAddress2: String?
    var customerShippingAddressCity: String?
    var customerShippingAddressCounty: String?
    var customerShippingAddressState: String?
    var customerShippingAddressPostalCode: String?
    var customerShippingAddressCountry: String?
    var customerBillingFirstName: String?
    var customerBillingLastName: String?
    var customerBillingFullName: String?
    var customerBillingPhoneNumber: String?
    var customerBillingEmail: String?
    var customerBillingAddressState: String?
    var customerBillingAddressPostalCode: String?
    var customerBillingAddressCountry: String?
    var upsellUpsellOriginalReceipt: String?
    var upsellUpsellFlowId: Int
    var upsellUpsellSession: String?
    var upsellUpsellPath: String?
    var hopfeedHopfeedClickId: String?
    var hopfeedHopfeedApplicationId: Int
    var hopfeedHopfeedCreativeId: Int
    var hopfeedHopfeedApplicationPayout: String?
    var hopfeedHopfeedVendorPayout: String?
    var version: String?
    var attemptCount: Int
    var vendorVariablesV1: String?
    var vendorVariablesV2: String?
    var i: Int
    var count_i: Int
    var strVal: String?
    var itemNo: String?
    var productTitle: String?
    var shippable: Bool
    var recurring: Bool
    var accountAmount: String?
    var quantity: Int
    var downloadUrl: String?
    var lineItemType: String?

    transactionTime = json.string(of: "transactionTime")
    receipt = json.string(of: "receipt")
    transactionType = json.string(of: "transactionType")
    vendor = json.string(of: "vendor")
    affiliate = json.string(of: "affiliate")
    role = json.string(of: "role")
    totalAccountAmount = json.string(of: "totalAccountAmount")
    paymentMethod = json.string(of: "paymentMethod")
    totalOrderAmount = json.string(of: "totalOrderAmount")
    totalTaxAmount = json.string(of: "totalTaxAmount")
    totalShippingAmount = json.string(of: "totalShippingAmount")
    currency = json.string(of: "currency")
    orderLanguage = json.string(of: "orderLanguage")
    customerShippingFirstName = json.string(of: "customer.shipping.firstName")
    customerShippingLastName = json.string(of: "customer.shipping.lastName")
    customerShippingFullName = json.string(of: "customer.shipping.fullName")
    customerShippingPhoneNumber = json.string(of: "customer.shipping.phoneNumber")
    customerShippingEmail = json.string(of: "customer.shipping.email")
    customerShippingAddressAddress1 = json.string(of: "customer.shipping.address.address1")
    customerShippingAddressAddress2 = json.string(of: "customer.shipping.address.address2")
    customerShippingAddressCity = json.string(of: "customer.shipping.address.city")
    customerShippingAddressCounty = json.string(of: "customer.shipping.address.county")
    customerShippingAddressState = json.string(of: "customer.shipping.address.state")
    customerShippingAddressPostalCode = json.string(of: "customer.shipping.address.postalCode")
    customerShippingAddressCountry = json.string(of: "customer.shipping.address.country")
    customerBillingFirstName = json.string(of: "customer.billing.firstName")
    customerBillingLastName = json.string(of: "customer.billing.lastName")
    customerBillingFullName = json.string(of: "customer.billing.fullName")
    customerBillingPhoneNumber = json.string(of: "customer.billing.phoneNumber")
    customerBillingEmail = json.string(of: "customer.billing.email")
    customerBillingAddressState = json.string(of: "customer.billing.address.state")
    customerBillingAddressPostalCode = json.string(of: "customer.billing.address.postalCode")
    customerBillingAddressCountry = json.string(of: "customer.billing.address.country")
    upsellUpsellOriginalReceipt = json.string(of: "upsell.upsellOriginalReceipt")
    upsellUpsellFlowId = json.int(of: "upsell.upsellFlowId").intValue
    upsellUpsellSession = json.string(of: "upsell.upsellSession")
    upsellUpsellPath = json.string(of: "upsell.upsellPath")
    hopfeedHopfeedClickId = json.string(of: "hopfeed.hopfeedClickId")
    hopfeedHopfeedApplicationId = json.int(of: "hopfeed.hopfeedApplicationId").intValue
    hopfeedHopfeedCreativeId = json.int(of: "hopfeed.hopfeedCreativeId").intValue
    hopfeedHopfeedApplicationPayout = json.string(of: "hopfeed.hopfeedApplicationPayout")
    hopfeedHopfeedVendorPayout = json.string(of: "hopfeed.hopfeedVendorPayout")
    version = json.string(of: "version")
    attemptCount = json.int(of: "attemptCount").intValue
    vendorVariablesV1 = json.string(of: "vendorVariables.v1")
    vendorVariablesV2 = json.string(of: "vendorVariables.v2")
    i = 0
    count_i = json.size(ofArray: "trackingCodes").intValue
    while i < count_i {
        json.i = i
        strVal = json.string(of: "trackingCodes[i]")
        i = i + 1
    }

    i = 0
    count_i = json.size(ofArray: "lineItems").intValue
    while i < count_i {
        json.i = i
        itemNo = json.string(of: "lineItems[i].itemNo")
        productTitle = json.string(of: "lineItems[i].productTitle")
        shippable = json.bool(of: "lineItems[i].shippable")
        recurring = json.bool(of: "lineItems[i].recurring")
        accountAmount = json.string(of: "lineItems[i].accountAmount")
        quantity = json.int(of: "lineItems[i].quantity").intValue
        downloadUrl = json.string(of: "lineItems[i].downloadUrl")
        lineItemType = json.string(of: "lineItems[i].lineItemType")
        i = i + 1
    }


}