Trying to upload PDF invoice to Amazon MWS results in Error: “Please provide only one valid marketplace while uploading an invoice”

本秂侑毒 提交于 2019-12-24 06:49:42

问题


I am currently trying to figure out how to upload my own invoice pdf files to Amazon MWS with php/curl: 1.) Upload pdf to Amazon MWS using Action: SubmitFeed and FeedType: _UPLOAD_VAT_INVOICE_ This is giving a positive response with a FeedSubmissionId

2.) Get Feed Submission Result with that FeedSubmissionId is reporting an Error 79523 "Please provide only one valid marketplace while uploading an invoice."

So I assume that my upload is not working properly, but I can not find the mistake.

The Error Code is described on Page 21 in this PDF File from Amazon: VAT Calculation Service (VCS) Developer Guide

I have spent 2 days so far, trying to solve this, and I was not able to find anything about it on google. Hope someone here can help me. Thanks!

Here is the code:

 <?php 
$param = array();
$param['AWSAccessKeyId']   = 'XXXXX'; 
$param['Action']           = 'SubmitFeed';
$param['Merchant']         = 'XXXXX';
$param['FeedType']         = '_UPLOAD_VAT_INVOICE_';//'_POST_ORDER_FULFILLMENT_DATA_';
$param['FeedOptions']      = 'metadata:OrderId='.$amz_order_id.';metadata:TotalAmount='.$TotalAmount.';metadata:TotalVATAmount='.$TotalVATAmount.';metadata:InvoiceNumber='.$InvoiceNumber.';metadata:documenttype=Invoice';
$param['SignatureMethod']  = 'HmacSHA256';
$param['SignatureVersion'] = '2';
$param['Timestamp']        = gmdate("Y-m-d\TH:i:s.\\0\\0\\0\\Z", time());
$param['Version']          = '2009-01-01';
$param['MarketplaceIdList.Id.1']    = 'A1PA6795UKMFR9';
$param['PurgeAndReplace']   = 'false'; 

$secret = 'XXXXX';

$url = array();
foreach ($param as $key => $val) {
    $key = str_replace("%7E", "~", rawurlencode($key));
    $val = str_replace("%7E", "~", rawurlencode($val));
    $url[] = "{$key}={$val}";
}

$file = fopen($link_to_pdf_file,"r");
$pdf_feed=fread($file,filesize($FileName));
fclose($file);
    sort($url);

    $arr   = implode('&', $url);
    $sign  = 'POST' . "\n";
    $sign .= 'mws.amazonservices.de' . "\n";
    $sign .= '/Feeds/'.$param['Version'].'' . "\n";
    $sign .= $arr;
    $signature = hash_hmac("sha256", $sign, $secret, true);
    $httpHeader     =   array();
    $httpHeader[]   =   'Transfer-Encoding: chunked';
    $httpHeader[]   =   'Content-Type: application/octet-stream';//application/pdf
    $httpHeader[]   =   'Content-MD5: ' . base64_encode(md5($pdf_feed, true));
    $httpHeader[]   =   'Expect:';
    $httpHeader[]   =   'Accept:';
    $signature = urlencode(base64_encode($signature));
    $link  = "https://mws.amazonservices.de/Feeds/".$param['Version']."?";
    $link .= $arr . "&Signature=" . $signature;
    $ch = curl_init($link);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $amazon_feed);
    $response['reply'] = curl_exec($ch);
    $response['info'] = curl_getinfo($ch);      
    curl_close($ch);
  ?>

来源:https://stackoverflow.com/questions/59178671/trying-to-upload-pdf-invoice-to-amazon-mws-results-in-error-please-provide-onl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!