Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Delphi DLL) Ecwid - Create OrderSee more Ecwid ExamplesCreate 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. For more information, see https://api-docs.ecwid.com/reference/orders#create-an-order
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, StringBuilder, HttpResponse, JsonObject; ... procedure TForm1.Button1Click(Sender: TObject); var jsonToken: HCkJsonObject; sbUrl: HCkStringBuilder; http: HCkHttp; json: HCkJsonObject; resp: HCkHttpResponse; sbResponseBody: HCkStringBuilder; jResp: HCkJsonObject; id: Integer; orderid: PWideChar; begin // 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 jsonToken := CkJsonObject_Create(); CkJsonObject_LoadFile(jsonToken,'qa_data/tokens/ecwid.json'); sbUrl := CkStringBuilder_Create(); CkStringBuilder_Append(sbUrl,'https://app.ecwid.com/api/v3/4870020/orders?token='); CkStringBuilder_Append(sbUrl,CkJsonObject__stringOf(jsonToken,'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 // } http := CkHttp_Create(); CkHttp_SetRequestHeader(http,'Cache-Control','no-cache'); json := CkJsonObject_Create(); CkJsonObject_UpdateInt(json,'subtotal',30); CkJsonObject_UpdateInt(json,'total',40); CkJsonObject_UpdateString(json,'email','example@example.com'); CkJsonObject_UpdateString(json,'paymentMethod','Phone order'); CkJsonObject_UpdateInt(json,'tax',0); CkJsonObject_UpdateString(json,'paymentStatus','PAID'); CkJsonObject_UpdateBool(json,'customerTaxExempt',False); CkJsonObject_UpdateString(json,'customerTaxId',''); CkJsonObject_UpdateBool(json,'customerTaxIdValid',False); CkJsonObject_UpdateBool(json,'reversedTaxApplied',False); CkJsonObject_UpdateString(json,'fulfillmentStatus','AWAITING_PROCESSING'); CkJsonObject_UpdateString(json,'createDate','2015-09-20 19:59:43 +0000'); CkJsonObject_UpdateInt(json,'items[0].price',15); CkJsonObject_UpdateNumber(json,'items[0].weight','0.32'); CkJsonObject_UpdateString(json,'items[0].sku','00004'); CkJsonObject_UpdateInt(json,'items[0].quantity',2); CkJsonObject_UpdateString(json,'items[0].name','Cherry'); CkJsonObject_UpdateString(json,'billingPerson.name','Eugene K'); CkJsonObject_UpdateString(json,'billingPerson.companyName','Hedgehog and Bucket'); CkJsonObject_UpdateString(json,'billingPerson.street','My Street'); CkJsonObject_UpdateString(json,'billingPerson.city','San Diego'); CkJsonObject_UpdateString(json,'billingPerson.countryCode','US'); CkJsonObject_UpdateString(json,'billingPerson.postalCode','90002'); CkJsonObject_UpdateString(json,'billingPerson.stateOrProvinceCode','CA'); CkJsonObject_UpdateString(json,'billingPerson.phone','123141321'); CkJsonObject_UpdateString(json,'shippingPerson.name','Eugene K'); CkJsonObject_UpdateString(json,'shippingPerson.companyName','Hedgehog and Bucket'); CkJsonObject_UpdateString(json,'shippingPerson.street','My Street'); CkJsonObject_UpdateString(json,'shippingPerson.city','San Diego'); CkJsonObject_UpdateString(json,'shippingPerson.countryCode','US'); CkJsonObject_UpdateString(json,'shippingPerson.postalCode','90002'); CkJsonObject_UpdateString(json,'shippingPerson.stateOrProvinceCode','CA'); CkJsonObject_UpdateString(json,'shippingPerson.phone','123141321'); CkJsonObject_UpdateString(json,'shippingOption.shippingMethodName','Fast Delivery'); CkJsonObject_UpdateInt(json,'shippingOption.shippingRate',10); CkJsonObject_UpdateBool(json,'shippingOption.isPickup',False); CkJsonObject_UpdateString(json,'shippingOption.fulfilmentType','DELIVERY'); CkJsonObject_UpdateBool(json,'hidden',False); CkJsonObject_UpdateString(json,'privateAdminNotes','Must be delivered till Sunday.'); CkJsonObject_UpdateBool(json,'acceptMarketing',False); CkJsonObject_UpdateBool(json,'disableAllCustomerNotifications',True); CkJsonObject_UpdateBool(json,'externalFulfillment',True); CkJsonObject_UpdateString(json,'externalOrderId','2'); CkJsonObject_UpdateBool(json,'pricesIncludeTax',False); resp := CkHttp_PostJson3(http,CkStringBuilder__getAsString(sbUrl),'application/json',json); if (CkHttp_getLastMethodSuccess(http) <> True) then begin Memo1.Lines.Add(CkHttp__lastErrorText(http)); Exit; end; Memo1.Lines.Add('Response status code = ' + IntToStr(CkHttpResponse_getStatusCode(resp))); sbResponseBody := CkStringBuilder_Create(); CkHttpResponse_GetBodySb(resp,sbResponseBody); jResp := CkJsonObject_Create(); CkJsonObject_LoadSb(jResp,sbResponseBody); CkJsonObject_putEmitCompact(jResp,False); Memo1.Lines.Add('Response Body:'); Memo1.Lines.Add(CkJsonObject__emit(jResp)); // 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 id := CkJsonObject_IntOf(jResp,'id'); orderid := CkJsonObject__stringOf(jResp,'orderid'); CkHttpResponse_Dispose(resp); CkJsonObject_Dispose(jsonToken); CkStringBuilder_Dispose(sbUrl); CkHttp_Dispose(http); CkJsonObject_Dispose(json); CkStringBuilder_Dispose(sbResponseBody); CkJsonObject_Dispose(jResp); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.