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++) Amazon MWS Upload InvoiceDemonstrates how to upload an invoice using _UPLOAD_VAT_INVOICE_FeedType to submit an invoice for an order. For more information, see https://m.media-amazon.com/images/G/03/B2B/invoice-uploader-developer-documentation.pdf
#include <CkRestW.h> #include <CkBinDataW.h> #include <CkCrypt2W.h> #include <CkStringBuilderW.h> void ChilkatSample(void) { // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. bool success; CkRestW rest; // Connect to the Amazon MWS REST server. // // Make sure to connect to the correct Amazon MWS Endpoint, otherwise // you'll get an HTTP 401 response code. // // See Amazon MWS endpoints and MarketplaceId values bool bTls = true; int port = 443; bool bAutoReconnect = true; success = rest.Connect(L"mws.amazonservices.com",port,bTls,bAutoReconnect); rest.put_Host(L"mws.amazonservices.com"); // MarketplaceList.Id parameter This should be the marketplace in which the order was placed. Only one marketplace must be used per order.T // Here are the marketplace ID's // Spain: A1RKKUPIHCS9HS // UK: A1F83G8C2ARO7P // France: A13V1IB3VIYZZH // Germany: A1PA6795UKMFR9 // Italy: APJ6JRA9NG5V4 // ... // (See https://docs.developer.amazonservices.com/en_US/dev_guide/DG_Endpoints.html) // FeedOptions parameter Seller can input key value pairs to give important metadata along with the PDF invoice. rest.AddQueryParam(L"FeedOptions",L"metadata:orderid=206-2341234-3455465;metadata:invoicenumber=INT-3431-XJE3;metadata:documenttype=Invoice"); // Load the PDF invoice file that is to be the body of the HTTP POST request. CkBinDataW pdfData; success = pdfData.LoadFile(L"qa_data/pdf/sample.pdf"); // Get the MD5 hash of the PDF data. CkCrypt2W crypt; crypt.put_HashAlgorithm(L"md5"); crypt.put_EncodingMode(L"base64"); const wchar_t *md5Hash = crypt.hashBdENC(pdfData); rest.AddQueryParam(L"AWSAccessKeyId",L"0PB842ExampleN4ZTR2"); rest.AddQueryParam(L"Action",L"SubmitFeed"); rest.AddQueryParam(L"FeedType",L"_UPLOAD_VAT_INVOICE_"); rest.AddQueryParam(L"MWSAuthToken",L"EXAMPLE-amzn.mws.4ea38b7b-f563-7709-4bae-87aea-EXAMPLE"); rest.AddQueryParam(L"MarketplaceIdList.Id.1",L"ATVExampleDER"); rest.AddQueryParam(L"SellerId",L"A1XExample5E6"); rest.AddQueryParam(L"ContentMD5Value",md5Hash); rest.AddQueryParam(L"SignatureMethod",L"HmacSHA256"); rest.AddQueryParam(L"SignatureVersion",L"2"); rest.AddQueryParam(L"Version",L"2009-01-01"); // Add the MWS Signature param. (Also adds the Timestamp parameter using the curent system date/time.) rest.AddMwsSignature(L"POST",L"/Feeds/2009-01-01",L"mws.amazonservices.com",L"YOUR_MWS_SECRET_ACCESS_KEY_ID"); rest.AddHeader(L"Content-Type",L"application/octet-stream"); CkStringBuilderW sbResponseBody; success = rest.FullRequestBd(L"POST",L"/Feeds/2009-01-01",pdfData,sbResponseBody); if (rest.get_LastMethodSuccess() != true) { wprintf(L"%s\n",rest.lastErrorText()); return; } if (rest.get_ResponseStatusCode() != 200) { // Examine the request/response to see what happened. wprintf(L"response status code = %d\n",rest.get_ResponseStatusCode()); wprintf(L"response status text = %s\n",rest.responseStatusText()); wprintf(L"response header: %s\n",rest.responseHeader()); wprintf(L"response body: %s\n",sbResponseBody.getAsString()); wprintf(L"---\n"); wprintf(L"LastRequestStartLine: %s\n",rest.lastRequestStartLine()); wprintf(L"LastRequestHeader: %s\n",rest.lastRequestHeader()); } // Examine the XML returned in the response body. wprintf(L"%s\n",sbResponseBody.getAsString()); wprintf(L"----\n"); wprintf(L"Success.\n"); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.