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
(Unicode C++) Walmart - Acknowledge OrderSee Acknowledge Orders for more information about this call. Acknowledges an entire order, including all of its order lines. Walmart requires a seller to acknowledge orders within four hours of receipt of the order, except in extenuating circumstances. The response to a successful call contains the acknowledged order. In general, only orders that are in a “Created” state should be acknowledged. As a good practice, acknowledge your orders to avoid underselling. Orders that are in an “Acknowledged” state can be re-acknowledged, possibly in response to an error response from an earlier call to acknowledge order. Orders with line items that are shipped or canceled should not be re-acknowledged.
#include <CkStringBuilderW.h> #include <CkAuthUtilW.h> #include <CkJsonObjectW.h> #include <CkHttpW.h> #include <CkHttpResponseW.h> void ChilkatSample(void) { // --------------------------------------------------------------------------------------------------------- // Note: This example is deprecated. The Walmart API no longer uses the Signature method of authenticating. // Walmart now uses OAuth2. // --------------------------------------------------------------------------------------------------------- // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // Sends the following POST request: // POST https://marketplace.walmartapis.com/v3/orders/{purchaseOrderId}/acknowledge CkStringBuilderW sbUrl; bool success = sbUrl.Append(L"https://marketplace.walmartapis.com/v3/orders/{purchaseOrderId}/acknowledge"); int numReplaced = sbUrl.Replace(L"{purchaseOrderId}",L"1111691995111"); const wchar_t *requestMethod = L"POST"; // First we need to generate a signature for our request. // The signature needs to be re-generated for each new Walmart HTTP request. CkAuthUtilW authUtil; const wchar_t *wmConsumerId = L"WALMART_CONSUMER_ID"; const wchar_t *wmPrivateKey = L"WALMART_PRIVATE_KEY"; const wchar_t *jsonStr = authUtil.walmartSignature(sbUrl.getAsString(),wmConsumerId,wmPrivateKey,requestMethod); if (authUtil.get_LastMethodSuccess() != true) { wprintf(L"%s\n",authUtil.lastErrorText()); return; } // The JSON returned by WalmartSignature contains the values to be used in the following // header fields: WM_SEC.AUTH_SIGNATURE, WM_SEC.TIMESTAMP, and WM_QOS.CORRELATION_ID CkJsonObjectW json; json.Load(jsonStr); CkHttpW http; http.SetRequestHeader(L"WM_SVC.NAME",L"Walmart Marketplace"); http.SetRequestHeader(L"WM_QOS.CORRELATION_ID",json.stringOf(L"correlation_id")); http.SetRequestHeader(L"WM_SEC.TIMESTAMP",json.stringOf(L"timestamp")); http.SetRequestHeader(L"WM_SEC.AUTH_SIGNATURE",json.stringOf(L"signature")); http.SetRequestHeader(L"WM_CONSUMER.ID",wmConsumerId); // Note: Make sure to replace "WALMART_CHANNEL_TYPE" with the actual value for your seller account... http.SetRequestHeader(L"WM_CONSUMER.CHANNEL.TYPE",L"WALMART_CHANNEL_TYPE"); http.put_Accept(L"application/xml"); // Note: Do not explicitly set the "Host" header. Chilkat will set it automatically. // Walmart provides the option to send/receive JSON or XML. This example will use JSON. // Note: Please see the online JSON/XML code generation tools at https://tools.chilkat.io/ // The online tools generate code to create/parse XML or JSON. (You copy sample JSON/XML into the online format, // and generate code in your selected programming language. It's a big time saver.) http.SetRequestHeader(L"Accept",L"application/json"); // The body of this particular POST request contains just "{}". (The order ID is already in the URL path.) CkHttpResponseW *resp = http.PostJson2(sbUrl.getAsString(),L"application/json",L"{}"); if (http.get_LastMethodSuccess() != true) { wprintf(L"%s\n",http.lastErrorText()); return; } // Get the JSON response body, which could contain an error, or if successful contains // the acknowledged order. CkStringBuilderW sbBody; resp->GetBodySb(sbBody); // A successful response should have a 200 response status if (resp->get_StatusCode() != 200) { wprintf(L"%s\n",sbBody.getAsString()); wprintf(L"Response Status Code: %d\n",resp->get_StatusCode()); wprintf(L"Failed.\n"); delete resp; return; } delete resp; // Parse the JSON response. // A sample response is shown below this code. (The online tools at https://tools.chilkat.io were used to generate the // fragment of code below using the sample response data at // https://developer.walmart.com/#/apicenter/marketPlace/latest?country=us#acknowledgingOrders json.LoadSb(sbBody); const wchar_t *orderPurchaseOrderId = 0; const wchar_t *orderCustomerOrderId = 0; const wchar_t *orderCustomerEmailId = 0; int orderOrderDate; const wchar_t *orderShippingInfoPhone = 0; int orderShippingInfoEstimatedDeliveryDate; int orderShippingInfoEstimatedShipDate; const wchar_t *orderShippingInfoMethodCode = 0; const wchar_t *orderShippingInfoPostalAddressName = 0; const wchar_t *orderShippingInfoPostalAddressAddress1 = 0; const wchar_t *orderShippingInfoPostalAddressAddress2 = 0; const wchar_t *orderShippingInfoPostalAddressCity = 0; const wchar_t *orderShippingInfoPostalAddressState = 0; const wchar_t *orderShippingInfoPostalAddressPostalCode = 0; const wchar_t *orderShippingInfoPostalAddressCountry = 0; const wchar_t *orderShippingInfoPostalAddressAddressType = 0; int i; int count_i; const wchar_t *lineNumber = 0; const wchar_t *itemProductName = 0; const wchar_t *itemSku = 0; const wchar_t *orderLineQuantityUnitOfMeasurement = 0; const wchar_t *orderLineQuantityAmount = 0; int statusDate; bool refundRefundId; bool refundRefundComments; int j; int count_j; const wchar_t *chargeType = 0; const wchar_t *chargeName = 0; const wchar_t *chargeAmountCurrency = 0; int chargeAmountAmount; const wchar_t *taxTaxName = 0; const wchar_t *taxTaxAmountCurrency = 0; int taxTaxAmountAmount; const wchar_t *status = 0; const wchar_t *statusQuantityUnitOfMeasurement = 0; const wchar_t *statusQuantityAmount = 0; bool cancellationReason; int trackingInfoShipDateTime; bool trackingInfoCarrierNameOtherCarrier; const wchar_t *trackingInfoCarrierNameCarrier = 0; const wchar_t *trackingInfoMethodCode = 0; const wchar_t *trackingInfoTrackingNumber = 0; const wchar_t *trackingInfoTrackingURL = 0; const wchar_t *refundReason = 0; const wchar_t *chargeChargeType = 0; const wchar_t *chargeChargeName = 0; const wchar_t *chargeChargeAmountCurrency = 0; int chargeChargeAmountAmount; bool chargeTax; orderPurchaseOrderId = json.stringOf(L"order.purchaseOrderId"); orderCustomerOrderId = json.stringOf(L"order.customerOrderId"); orderCustomerEmailId = json.stringOf(L"order.customerEmailId"); orderOrderDate = json.IntOf(L"order.orderDate"); orderShippingInfoPhone = json.stringOf(L"order.shippingInfo.phone"); orderShippingInfoEstimatedDeliveryDate = json.IntOf(L"order.shippingInfo.estimatedDeliveryDate"); orderShippingInfoEstimatedShipDate = json.IntOf(L"order.shippingInfo.estimatedShipDate"); orderShippingInfoMethodCode = json.stringOf(L"order.shippingInfo.methodCode"); orderShippingInfoPostalAddressName = json.stringOf(L"order.shippingInfo.postalAddress.name"); orderShippingInfoPostalAddressAddress1 = json.stringOf(L"order.shippingInfo.postalAddress.address1"); orderShippingInfoPostalAddressAddress2 = json.stringOf(L"order.shippingInfo.postalAddress.address2"); orderShippingInfoPostalAddressCity = json.stringOf(L"order.shippingInfo.postalAddress.city"); orderShippingInfoPostalAddressState = json.stringOf(L"order.shippingInfo.postalAddress.state"); orderShippingInfoPostalAddressPostalCode = json.stringOf(L"order.shippingInfo.postalAddress.postalCode"); orderShippingInfoPostalAddressCountry = json.stringOf(L"order.shippingInfo.postalAddress.country"); orderShippingInfoPostalAddressAddressType = json.stringOf(L"order.shippingInfo.postalAddress.addressType"); i = 0; count_i = json.SizeOfArray(L"order.orderLines.orderLine"); while (i < count_i) { json.put_I(i); lineNumber = json.stringOf(L"order.orderLines.orderLine[i].lineNumber"); itemProductName = json.stringOf(L"order.orderLines.orderLine[i].item.productName"); itemSku = json.stringOf(L"order.orderLines.orderLine[i].item.sku"); orderLineQuantityUnitOfMeasurement = json.stringOf(L"order.orderLines.orderLine[i].orderLineQuantity.unitOfMeasurement"); orderLineQuantityAmount = json.stringOf(L"order.orderLines.orderLine[i].orderLineQuantity.amount"); statusDate = json.IntOf(L"order.orderLines.orderLine[i].statusDate"); refundRefundId = json.IsNullOf(L"order.orderLines.orderLine[i].refund.refundId"); refundRefundComments = json.IsNullOf(L"order.orderLines.orderLine[i].refund.refundComments"); j = 0; count_j = json.SizeOfArray(L"order.orderLines.orderLine[i].charges.charge"); while (j < count_j) { json.put_J(j); chargeType = json.stringOf(L"order.orderLines.orderLine[i].charges.charge[j].chargeType"); chargeName = json.stringOf(L"order.orderLines.orderLine[i].charges.charge[j].chargeName"); chargeAmountCurrency = json.stringOf(L"order.orderLines.orderLine[i].charges.charge[j].chargeAmount.currency"); chargeAmountAmount = json.IntOf(L"order.orderLines.orderLine[i].charges.charge[j].chargeAmount.amount"); taxTaxName = json.stringOf(L"order.orderLines.orderLine[i].charges.charge[j].tax.taxName"); taxTaxAmountCurrency = json.stringOf(L"order.orderLines.orderLine[i].charges.charge[j].tax.taxAmount.currency"); taxTaxAmountAmount = json.IntOf(L"order.orderLines.orderLine[i].charges.charge[j].tax.taxAmount.amount"); j = j + 1; } j = 0; count_j = json.SizeOfArray(L"order.orderLines.orderLine[i].orderLineStatuses.orderLineStatus"); while (j < count_j) { json.put_J(j); status = json.stringOf(L"order.orderLines.orderLine[i].orderLineStatuses.orderLineStatus[j].status"); statusQuantityUnitOfMeasurement = json.stringOf(L"order.orderLines.orderLine[i].orderLineStatuses.orderLineStatus[j].statusQuantity.unitOfMeasurement"); statusQuantityAmount = json.stringOf(L"order.orderLines.orderLine[i].orderLineStatuses.orderLineStatus[j].statusQuantity.amount"); cancellationReason = json.IsNullOf(L"order.orderLines.orderLine[i].orderLineStatuses.orderLineStatus[j].cancellationReason"); trackingInfoShipDateTime = json.IntOf(L"order.orderLines.orderLine[i].orderLineStatuses.orderLineStatus[j].trackingInfo.shipDateTime"); trackingInfoCarrierNameOtherCarrier = json.IsNullOf(L"order.orderLines.orderLine[i].orderLineStatuses.orderLineStatus[j].trackingInfo.carrierName.otherCarrier"); trackingInfoCarrierNameCarrier = json.stringOf(L"order.orderLines.orderLine[i].orderLineStatuses.orderLineStatus[j].trackingInfo.carrierName.carrier"); trackingInfoMethodCode = json.stringOf(L"order.orderLines.orderLine[i].orderLineStatuses.orderLineStatus[j].trackingInfo.methodCode"); trackingInfoTrackingNumber = json.stringOf(L"order.orderLines.orderLine[i].orderLineStatuses.orderLineStatus[j].trackingInfo.trackingNumber"); trackingInfoTrackingURL = json.stringOf(L"order.orderLines.orderLine[i].orderLineStatuses.orderLineStatus[j].trackingInfo.trackingURL"); j = j + 1; } j = 0; count_j = json.SizeOfArray(L"order.orderLines.orderLine[i].refund.refundCharges.refundCharge"); while (j < count_j) { json.put_J(j); refundReason = json.stringOf(L"order.orderLines.orderLine[i].refund.refundCharges.refundCharge[j].refundReason"); chargeChargeType = json.stringOf(L"order.orderLines.orderLine[i].refund.refundCharges.refundCharge[j].charge.chargeType"); chargeChargeName = json.stringOf(L"order.orderLines.orderLine[i].refund.refundCharges.refundCharge[j].charge.chargeName"); chargeChargeAmountCurrency = json.stringOf(L"order.orderLines.orderLine[i].refund.refundCharges.refundCharge[j].charge.chargeAmount.currency"); chargeChargeAmountAmount = json.IntOf(L"order.orderLines.orderLine[i].refund.refundCharges.refundCharge[j].charge.chargeAmount.amount"); chargeTax = json.IsNullOf(L"order.orderLines.orderLine[i].refund.refundCharges.refundCharge[j].charge.tax"); j = j + 1; } i = i + 1; } wprintf(L"Success!\n"); // Sample Walmart Order Acknowledge Response: // { // "order": { // "purchaseOrderId": "1577684050862", // "customerOrderId": "2861700797280", // "customerEmailId": "jsanthanam@walmartlabs.com", // "orderDate": 1484458949000, // "shippingInfo": { // "phone": "4151234567", // "estimatedDeliveryDate": 1485586800000, // "estimatedShipDate": 1484636400000, // "methodCode": "Value", // "postalAddress": { // "name": "Asha Chakre", // "address1": "860 W California ave", // "address2": null, // "city": "Sunnyvale", // "state": "CA", // "postalCode": "94086", // "country": "USA", // "addressType": "RESIDENTIAL" // } // }, // "orderLines": { // "orderLine": [ // { // "lineNumber": "1", // "item": { // "productName": "Kellogg's Rice Krispies Cereal, 24 oz", // "sku": "MGR_07_21_00100123" // }, // "charges": { // "charge": [ // { // "chargeType": "PRODUCT", // "chargeName": "ItemPrice", // "chargeAmount": { // "currency": "USD", // "amount": 19.99 // }, // "tax": { // "taxName": "Tax1", // "taxAmount": { // "currency": "USD", // "amount": 1.7 // } // } // } // ] // }, // "orderLineQuantity": { // "unitOfMeasurement": "EACH", // "amount": "1" // }, // "statusDate": 1487888747000, // "orderLineStatuses": { // "orderLineStatus": [ // { // "status": "Shipped", // "statusQuantity": { // "unitOfMeasurement": "EACH", // "amount": "1" // }, // "cancellationReason": null, // "trackingInfo": { // "shipDateTime": 1485549015000, // "carrierName": { // "otherCarrier": null, // "carrier": "FedEx" // }, // "methodCode": "Value", // "trackingNumber": "3445435443441221", // "trackingURL": "http://walmart.narvar.com/walmart/tracking/Fedex?&type=MP&seller_id=801&promise_date=01/28/2017&dzip=94086&tracking_numbers=3445435443441221" // } // } // ] // }, // "refund": { // "refundId": null, // "refundComments": null, // "refundCharges": { // "refundCharge": [ // { // "refundReason": "ItemNotReceivedByCustomer", // "charge": { // "chargeType": "PRODUCT", // "chargeName": "Lost in Transit", // "chargeAmount": { // "currency": "USD", // "amount": -0.01 // }, // "tax": null // } // } // ] // } // } // } // ] // } // } // } } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.