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
(Swift 3,4,5...) 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
func chilkatTest() { // 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 let jsonToken = CkoJsonObject()! jsonToken.loadFile("qa_data/tokens/ecwid.json") let sbUrl = CkoStringBuilder()! sbUrl.append("https://app.ecwid.com/api/v3/4870020/orders?token=") sbUrl.append(jsonToken.string(of: "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 // } let http = CkoHttp()! http.setRequestHeader("Cache-Control", value: "no-cache") let json = CkoJsonObject()! json.updateInt("subtotal", value: 30) json.updateInt("total", value: 40) json.update("email", value: "example@example.com") json.update("paymentMethod", value: "Phone order") json.updateInt("tax", value: 0) json.update("paymentStatus", value: "PAID") json.updateBool("customerTaxExempt", value: false) json.update("customerTaxId", value: "") json.updateBool("customerTaxIdValid", value: false) json.updateBool("reversedTaxApplied", value: false) json.update("fulfillmentStatus", value: "AWAITING_PROCESSING") json.update("createDate", value: "2015-09-20 19:59:43 +0000") json.updateInt("items[0].price", value: 15) json.updateNumber("items[0].weight", numericStr: "0.32") json.update("items[0].sku", value: "00004") json.updateInt("items[0].quantity", value: 2) json.update("items[0].name", value: "Cherry") json.update("billingPerson.name", value: "Eugene K") json.update("billingPerson.companyName", value: "Hedgehog and Bucket") json.update("billingPerson.street", value: "My Street") json.update("billingPerson.city", value: "San Diego") json.update("billingPerson.countryCode", value: "US") json.update("billingPerson.postalCode", value: "90002") json.update("billingPerson.stateOrProvinceCode", value: "CA") json.update("billingPerson.phone", value: "123141321") json.update("shippingPerson.name", value: "Eugene K") json.update("shippingPerson.companyName", value: "Hedgehog and Bucket") json.update("shippingPerson.street", value: "My Street") json.update("shippingPerson.city", value: "San Diego") json.update("shippingPerson.countryCode", value: "US") json.update("shippingPerson.postalCode", value: "90002") json.update("shippingPerson.stateOrProvinceCode", value: "CA") json.update("shippingPerson.phone", value: "123141321") json.update("shippingOption.shippingMethodName", value: "Fast Delivery") json.updateInt("shippingOption.shippingRate", value: 10) json.updateBool("shippingOption.isPickup", value: false) json.update("shippingOption.fulfilmentType", value: "DELIVERY") json.updateBool("hidden", value: false) json.update("privateAdminNotes", value: "Must be delivered till Sunday.") json.updateBool("acceptMarketing", value: false) json.updateBool("disableAllCustomerNotifications", value: true) json.updateBool("externalFulfillment", value: true) json.update("externalOrderId", value: "2") json.updateBool("pricesIncludeTax", value: false) var resp: CkoHttpResponse? = http.postJson3(sbUrl.getAsString(), contentType: "application/json", json: json) if http.lastMethodSuccess != true { print("\(http.lastErrorText!)") return } print("Response status code = \(resp!.statusCode.intValue)") let sbResponseBody = CkoStringBuilder()! resp!.getBodySb(sbResponseBody) let jResp = CkoJsonObject()! jResp.loadSb(sbResponseBody) jResp.emitCompact = false print("Response Body:") print("\(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 var id: Int = jResp.int(of: "id").intValue var orderid: String? = jResp.string(of: "orderid") resp = nil } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.