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
(PureBasic) 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
IncludeFile "CkHttpResponse.pb" IncludeFile "CkHttp.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkJsonObject.pb" Procedure ChilkatExample() ; 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.i = CkJsonObject::ckCreate() If jsonToken.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckLoadFile(jsonToken,"qa_data/tokens/ecwid.json") sbUrl.i = CkStringBuilder::ckCreate() If sbUrl.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkStringBuilder::ckAppend(sbUrl,"https://app.ecwid.com/api/v3/4870020/orders?token=") CkStringBuilder::ckAppend(sbUrl,CkJsonObject::ckStringOf(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.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkHttp::ckSetRequestHeader(http,"Cache-Control","no-cache") json.i = CkJsonObject::ckCreate() If json.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckUpdateInt(json,"subtotal",30) CkJsonObject::ckUpdateInt(json,"total",40) CkJsonObject::ckUpdateString(json,"email","example@example.com") CkJsonObject::ckUpdateString(json,"paymentMethod","Phone order") CkJsonObject::ckUpdateInt(json,"tax",0) CkJsonObject::ckUpdateString(json,"paymentStatus","PAID") CkJsonObject::ckUpdateBool(json,"customerTaxExempt",0) CkJsonObject::ckUpdateString(json,"customerTaxId","") CkJsonObject::ckUpdateBool(json,"customerTaxIdValid",0) CkJsonObject::ckUpdateBool(json,"reversedTaxApplied",0) CkJsonObject::ckUpdateString(json,"fulfillmentStatus","AWAITING_PROCESSING") CkJsonObject::ckUpdateString(json,"createDate","2015-09-20 19:59:43 +0000") CkJsonObject::ckUpdateInt(json,"items[0].price",15) CkJsonObject::ckUpdateNumber(json,"items[0].weight","0.32") CkJsonObject::ckUpdateString(json,"items[0].sku","00004") CkJsonObject::ckUpdateInt(json,"items[0].quantity",2) CkJsonObject::ckUpdateString(json,"items[0].name","Cherry") CkJsonObject::ckUpdateString(json,"billingPerson.name","Eugene K") CkJsonObject::ckUpdateString(json,"billingPerson.companyName","Hedgehog and Bucket") CkJsonObject::ckUpdateString(json,"billingPerson.street","My Street") CkJsonObject::ckUpdateString(json,"billingPerson.city","San Diego") CkJsonObject::ckUpdateString(json,"billingPerson.countryCode","US") CkJsonObject::ckUpdateString(json,"billingPerson.postalCode","90002") CkJsonObject::ckUpdateString(json,"billingPerson.stateOrProvinceCode","CA") CkJsonObject::ckUpdateString(json,"billingPerson.phone","123141321") CkJsonObject::ckUpdateString(json,"shippingPerson.name","Eugene K") CkJsonObject::ckUpdateString(json,"shippingPerson.companyName","Hedgehog and Bucket") CkJsonObject::ckUpdateString(json,"shippingPerson.street","My Street") CkJsonObject::ckUpdateString(json,"shippingPerson.city","San Diego") CkJsonObject::ckUpdateString(json,"shippingPerson.countryCode","US") CkJsonObject::ckUpdateString(json,"shippingPerson.postalCode","90002") CkJsonObject::ckUpdateString(json,"shippingPerson.stateOrProvinceCode","CA") CkJsonObject::ckUpdateString(json,"shippingPerson.phone","123141321") CkJsonObject::ckUpdateString(json,"shippingOption.shippingMethodName","Fast Delivery") CkJsonObject::ckUpdateInt(json,"shippingOption.shippingRate",10) CkJsonObject::ckUpdateBool(json,"shippingOption.isPickup",0) CkJsonObject::ckUpdateString(json,"shippingOption.fulfilmentType","DELIVERY") CkJsonObject::ckUpdateBool(json,"hidden",0) CkJsonObject::ckUpdateString(json,"privateAdminNotes","Must be delivered till Sunday.") CkJsonObject::ckUpdateBool(json,"acceptMarketing",0) CkJsonObject::ckUpdateBool(json,"disableAllCustomerNotifications",1) CkJsonObject::ckUpdateBool(json,"externalFulfillment",1) CkJsonObject::ckUpdateString(json,"externalOrderId","2") CkJsonObject::ckUpdateBool(json,"pricesIncludeTax",0) resp.i = CkHttp::ckPostJson3(http,CkStringBuilder::ckGetAsString(sbUrl),"application/json",json) If CkHttp::ckLastMethodSuccess(http) <> 1 Debug CkHttp::ckLastErrorText(http) CkJsonObject::ckDispose(jsonToken) CkStringBuilder::ckDispose(sbUrl) CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) ProcedureReturn EndIf Debug "Response status code = " + Str(CkHttpResponse::ckStatusCode(resp)) sbResponseBody.i = CkStringBuilder::ckCreate() If sbResponseBody.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkHttpResponse::ckGetBodySb(resp,sbResponseBody) jResp.i = CkJsonObject::ckCreate() If jResp.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckLoadSb(jResp,sbResponseBody) CkJsonObject::setCkEmitCompact(jResp, 0) Debug "Response Body:" Debug CkJsonObject::ckEmit(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.i = CkJsonObject::ckIntOf(jResp,"id") orderid.s = CkJsonObject::ckStringOf(jResp,"orderid") CkHttpResponse::ckDispose(resp) CkJsonObject::ckDispose(jsonToken) CkStringBuilder::ckDispose(sbUrl) CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.