Zig
Zig
ClickBank Parse Instant Notification JSON
See more ClickBank Examples
Demonstrates how to parse the JSON of a ClickBank instant notification.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.load("{ ... }") catch {};
// 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 i: i32 = 0;
var count_i: i32 = 0;
var str_val: [:0]const u8 = "";
var item_no: [:0]const u8 = "";
var product_title: [:0]const u8 = "";
var shippable: bool = false;
var recurring: bool = false;
var account_amount: [:0]const u8 = "";
var quantity: i32 = 0;
var download_url: [:0]const u8 = "";
var line_item_type: [:0]const u8 = "";
_ = try json.stringOf(alloc, "transactionTime");
_ = try json.stringOf(alloc, "receipt");
_ = try json.stringOf(alloc, "transactionType");
_ = try json.stringOf(alloc, "vendor");
_ = try json.stringOf(alloc, "affiliate");
_ = try json.stringOf(alloc, "role");
_ = try json.stringOf(alloc, "totalAccountAmount");
_ = try json.stringOf(alloc, "paymentMethod");
_ = try json.stringOf(alloc, "totalOrderAmount");
_ = try json.stringOf(alloc, "totalTaxAmount");
_ = try json.stringOf(alloc, "totalShippingAmount");
_ = try json.stringOf(alloc, "currency");
_ = try json.stringOf(alloc, "orderLanguage");
_ = try json.stringOf(alloc, "customer.shipping.firstName");
_ = try json.stringOf(alloc, "customer.shipping.lastName");
_ = try json.stringOf(alloc, "customer.shipping.fullName");
_ = try json.stringOf(alloc, "customer.shipping.phoneNumber");
_ = try json.stringOf(alloc, "customer.shipping.email");
_ = try json.stringOf(alloc, "customer.shipping.address.address1");
_ = try json.stringOf(alloc, "customer.shipping.address.address2");
_ = try json.stringOf(alloc, "customer.shipping.address.city");
_ = try json.stringOf(alloc, "customer.shipping.address.county");
_ = try json.stringOf(alloc, "customer.shipping.address.state");
_ = try json.stringOf(alloc, "customer.shipping.address.postalCode");
_ = try json.stringOf(alloc, "customer.shipping.address.country");
_ = try json.stringOf(alloc, "customer.billing.firstName");
_ = try json.stringOf(alloc, "customer.billing.lastName");
_ = try json.stringOf(alloc, "customer.billing.fullName");
_ = try json.stringOf(alloc, "customer.billing.phoneNumber");
_ = try json.stringOf(alloc, "customer.billing.email");
_ = try json.stringOf(alloc, "customer.billing.address.state");
_ = try json.stringOf(alloc, "customer.billing.address.postalCode");
_ = try json.stringOf(alloc, "customer.billing.address.country");
_ = try json.stringOf(alloc, "upsell.upsellOriginalReceipt");
_ = json.intOf("upsell.upsellFlowId");
_ = try json.stringOf(alloc, "upsell.upsellSession");
_ = try json.stringOf(alloc, "upsell.upsellPath");
_ = try json.stringOf(alloc, "hopfeed.hopfeedClickId");
_ = json.intOf("hopfeed.hopfeedApplicationId");
_ = json.intOf("hopfeed.hopfeedCreativeId");
_ = try json.stringOf(alloc, "hopfeed.hopfeedApplicationPayout");
_ = try json.stringOf(alloc, "hopfeed.hopfeedVendorPayout");
_ = try json.stringOf(alloc, "version");
_ = json.intOf("attemptCount");
_ = try json.stringOf(alloc, "vendorVariables.v1");
_ = try json.stringOf(alloc, "vendorVariables.v2");
i = 0;
count_i = json.sizeOfArray("trackingCodes");
while (i < count_i) {
json.setI(i);
str_val = try json.stringOf(alloc, "trackingCodes[i]");
i = i + 1;
}
i = 0;
count_i = json.sizeOfArray("lineItems");
while (i < count_i) {
json.setI(i);
item_no = try json.stringOf(alloc, "lineItems[i].itemNo");
product_title = try json.stringOf(alloc, "lineItems[i].productTitle");
shippable = json.boolOf("lineItems[i].shippable");
recurring = json.boolOf("lineItems[i].recurring");
account_amount = try json.stringOf(alloc, "lineItems[i].accountAmount");
quantity = json.intOf("lineItems[i].quantity");
download_url = try json.stringOf(alloc, "lineItems[i].downloadUrl");
line_item_type = try json.stringOf(alloc, "lineItems[i].lineItemType");
i = i + 1;
}
}