Sample code for 30+ languages & platforms
Unicode C++

Ecwid - Create Order

See more Ecwid Examples

Create a new order in an Ecwid store. This can be useful for storefronts with a custom checkout process or manually creating orders for sales made earlier.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>
#include <CkHttpW.h>
#include <CkHttpResponseW.h>

void ChilkatSample(void)
    {
    bool success = false;

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    // Create and send the following HTTP request:

    // Load the access token previously obtained in Ecwid Get Access Token
    CkJsonObjectW jsonToken;
    jsonToken.LoadFile(L"qa_data/tokens/ecwid.json");

    CkStringBuilderW sbUrl;
    sbUrl.Append(L"https://app.ecwid.com/api/v3/4870020/orders?token=");
    sbUrl.Append(jsonToken.stringOf(L"access_token"));

    // POST /api/v3/4870020/orders?token=1234567890qwqeertt HTTP/1.1
    // Host: app.ecwid.com
    // Content-Type: application/json;charset=utf-8
    // Cache-Control: no-cache
    // 
    // {
    //         "subtotal": 30,
    //         "total": 40,
    //         "email": "example@example.com",
    //         "paymentMethod": "Phone order",
    //         "tax": 0,
    //         "paymentStatus": "PAID",
    //         "customerTaxExempt": false,
    //         "customerTaxId": "",
    //         "customerTaxIdValid": false,
    //         "reversedTaxApplied": false,
    //         "fulfillmentStatus": "AWAITING_PROCESSING",
    //         "createDate": "2015-09-20 19:59:43 +0000",
    //         "items": [
    //             {
    //                 "price": 15,
    //                 "weight": 0.32,
    //                 "sku": "00004",
    //                 "quantity": 2,
    //                 "name": "Cherry"
    //             }
    //         ],
    //         "billingPerson": {
    //             "name": "Eugene K",
    //             "companyName": "Hedgehog and Bucket",
    //             "street": "My Street",
    //             "city": "San Diego",
    //             "countryCode": "US",
    //             "postalCode": "90002",
    //             "stateOrProvinceCode": "CA",
    //             "phone": "123141321"
    //         },
    //         "shippingPerson": {
    //             "name": "Eugene K",
    //             "companyName": "Hedgehog and Bucket",
    //             "street": "My Street",
    //             "city": "San Diego",
    //             "countryCode": "US",
    //             "postalCode": "90002",
    //             "stateOrProvinceCode": "CA",
    //             "phone": "123141321"
    //         },
    //         "shippingOption": {
    //             "shippingMethodName": "Fast Delivery",
    //             "shippingRate": 10,
    //             "isPickup": false,
    //             "fulfilmentType": "DELIVERY"
    //         },
    //         "hidden": false,
    //         "privateAdminNotes": "Must be delivered till Sunday.",
    //         "acceptMarketing": false,
    //         "disableAllCustomerNotifications": true,
    //         "externalFulfillment": true,
    //         "externalOrderId": "2",
    //         "pricesIncludeTax": false  
    //     }

    CkHttpW http;
    http.SetRequestHeader(L"Cache-Control",L"no-cache");

    CkJsonObjectW json;
    json.UpdateInt(L"subtotal",30);
    json.UpdateInt(L"total",40);
    json.UpdateString(L"email",L"example@example.com");
    json.UpdateString(L"paymentMethod",L"Phone order");
    json.UpdateInt(L"tax",0);
    json.UpdateString(L"paymentStatus",L"PAID");
    json.UpdateBool(L"customerTaxExempt",false);
    json.UpdateString(L"customerTaxId",L"");
    json.UpdateBool(L"customerTaxIdValid",false);
    json.UpdateBool(L"reversedTaxApplied",false);
    json.UpdateString(L"fulfillmentStatus",L"AWAITING_PROCESSING");
    json.UpdateString(L"createDate",L"2015-09-20 19:59:43 +0000");
    json.UpdateInt(L"items[0].price",15);
    json.UpdateNumber(L"items[0].weight",L"0.32");
    json.UpdateString(L"items[0].sku",L"00004");
    json.UpdateInt(L"items[0].quantity",2);
    json.UpdateString(L"items[0].name",L"Cherry");
    json.UpdateString(L"billingPerson.name",L"Eugene K");
    json.UpdateString(L"billingPerson.companyName",L"Hedgehog and Bucket");
    json.UpdateString(L"billingPerson.street",L"My Street");
    json.UpdateString(L"billingPerson.city",L"San Diego");
    json.UpdateString(L"billingPerson.countryCode",L"US");
    json.UpdateString(L"billingPerson.postalCode",L"90002");
    json.UpdateString(L"billingPerson.stateOrProvinceCode",L"CA");
    json.UpdateString(L"billingPerson.phone",L"123141321");
    json.UpdateString(L"shippingPerson.name",L"Eugene K");
    json.UpdateString(L"shippingPerson.companyName",L"Hedgehog and Bucket");
    json.UpdateString(L"shippingPerson.street",L"My Street");
    json.UpdateString(L"shippingPerson.city",L"San Diego");
    json.UpdateString(L"shippingPerson.countryCode",L"US");
    json.UpdateString(L"shippingPerson.postalCode",L"90002");
    json.UpdateString(L"shippingPerson.stateOrProvinceCode",L"CA");
    json.UpdateString(L"shippingPerson.phone",L"123141321");
    json.UpdateString(L"shippingOption.shippingMethodName",L"Fast Delivery");
    json.UpdateInt(L"shippingOption.shippingRate",10);
    json.UpdateBool(L"shippingOption.isPickup",false);
    json.UpdateString(L"shippingOption.fulfilmentType",L"DELIVERY");
    json.UpdateBool(L"hidden",false);
    json.UpdateString(L"privateAdminNotes",L"Must be delivered till Sunday.");
    json.UpdateBool(L"acceptMarketing",false);
    json.UpdateBool(L"disableAllCustomerNotifications",true);
    json.UpdateBool(L"externalFulfillment",true);
    json.UpdateString(L"externalOrderId",L"2");
    json.UpdateBool(L"pricesIncludeTax",false);

    const wchar_t *url = sbUrl.getAsString();
    CkHttpResponseW resp;
    success = http.HttpJson(L"POST",url,json,L"application/json",resp);
    if (success == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    wprintf(L"Response status code = %d\n",resp.get_StatusCode());

    CkStringBuilderW sbResponseBody;
    resp.GetBodySb(sbResponseBody);
    CkJsonObjectW jResp;
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",jResp.emit());

    // Sample JSON response:
    // (Sample code for parsing the JSON response is shown below)

    // {
    //   "id": 20,
    //   "orderid": "XJ12H"
    // }

    // Sample code for parsing the JSON response...
    // Use the following online tool to generate parsing code from sample JSON:
    // Generate Parsing Code from JSON

    int id = jResp.IntOf(L"id");
    const wchar_t *orderid = jResp.stringOf(L"orderid");
    }