Sample code for 30+ languages & platforms
C

ClickBank Parse Instant Notification JSON

See more ClickBank Examples

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

Chilkat C Downloads

C
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    HCkJsonObject json;
    const char *transactionTime;
    const char *receipt;
    const char *transactionType;
    const char *vendor;
    const char *affiliate;
    const char *role;
    const char *totalAccountAmount;
    const char *paymentMethod;
    const char *totalOrderAmount;
    const char *totalTaxAmount;
    const char *totalShippingAmount;
    const char *currency;
    const char *orderLanguage;
    const char *customerShippingFirstName;
    const char *customerShippingLastName;
    const char *customerShippingFullName;
    const char *customerShippingPhoneNumber;
    const char *customerShippingEmail;
    const char *customerShippingAddressAddress1;
    const char *customerShippingAddressAddress2;
    const char *customerShippingAddressCity;
    const char *customerShippingAddressCounty;
    const char *customerShippingAddressState;
    const char *customerShippingAddressPostalCode;
    const char *customerShippingAddressCountry;
    const char *customerBillingFirstName;
    const char *customerBillingLastName;
    const char *customerBillingFullName;
    const char *customerBillingPhoneNumber;
    const char *customerBillingEmail;
    const char *customerBillingAddressState;
    const char *customerBillingAddressPostalCode;
    const char *customerBillingAddressCountry;
    const char *upsellUpsellOriginalReceipt;
    int upsellUpsellFlowId;
    const char *upsellUpsellSession;
    const char *upsellUpsellPath;
    const char *hopfeedHopfeedClickId;
    int hopfeedHopfeedApplicationId;
    int hopfeedHopfeedCreativeId;
    const char *hopfeedHopfeedApplicationPayout;
    const char *hopfeedHopfeedVendorPayout;
    const char *version;
    int attemptCount;
    const char *vendorVariablesV1;
    const char *vendorVariablesV2;
    int i;
    int count_i;
    const char *strVal;
    const char *itemNo;
    const char *productTitle;
    BOOL shippable;
    BOOL recurring;
    const char *accountAmount;
    int quantity;
    const char *downloadUrl;
    const char *lineItemType;

    json = CkJsonObject_Create();

    CkJsonObject_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" 
    //     }
    //  }
    // 
    // 

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

    i = 0;
    count_i = CkJsonObject_SizeOfArray(json,"lineItems");
    while (i < count_i) {
        CkJsonObject_putI(json,i);
        itemNo = CkJsonObject_stringOf(json,"lineItems[i].itemNo");
        productTitle = CkJsonObject_stringOf(json,"lineItems[i].productTitle");
        shippable = CkJsonObject_BoolOf(json,"lineItems[i].shippable");
        recurring = CkJsonObject_BoolOf(json,"lineItems[i].recurring");
        accountAmount = CkJsonObject_stringOf(json,"lineItems[i].accountAmount");
        quantity = CkJsonObject_IntOf(json,"lineItems[i].quantity");
        downloadUrl = CkJsonObject_stringOf(json,"lineItems[i].downloadUrl");
        lineItemType = CkJsonObject_stringOf(json,"lineItems[i].lineItemType");
        i = i + 1;
    }



    CkJsonObject_Dispose(json);

    }