Guest User

MWS Test

a guest
Jan 6th, 2018
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.14 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Repositories\Api;
  4.  
  5. require_once app_path() .  '/Libraries/amazon-mws-v20090101-php-2016-09-21/src/MarketplaceWebService/.mws_config.inc.php';
  6.  
  7. require_once app_path() . '/Libraries/amazon-mws-v20090101-php-2016-09-21/src/MarketplaceWebService/Client.php';
  8. require_once app_path() . '/Libraries/amazon-mws-v20090101-php-2016-09-21/src/MarketplaceWebService/Model/RequestReportRequest.php';
  9.  
  10. require_once app_path() . '/Libraries/amazon-mws-v20090101-php-2016-09-21/src/MarketplaceWebService/Interface.php';
  11. require_once app_path() . '/Libraries/amazon-mws-v20090101-php-2016-09-21/src/MarketplaceWebService/Exception.php';
  12. require_once app_path() . '/Libraries/amazon-mws-v20090101-php-2016-09-21/src/MarketplaceWebService/Model.php';
  13.  
  14. use AmazonAdvertisingApi\Client;
  15.  
  16. class TestRepository
  17. {
  18.  
  19.     private $config;
  20.  
  21.     private $client;
  22.  
  23.     private $reportType;
  24.  
  25.     private $parameters;
  26.  
  27.     function __construct()
  28.     {
  29.         /*
  30.          * 1.
  31.          */
  32.         $this->config = [
  33.             'ServiceURL' => config('amazon.mws_marketplace_url.na'),
  34.             'ProxyHost' => null,
  35.             'ProxyPort' => -1,
  36.             'MaxErrorRetry' => 3,
  37.         ];
  38.  
  39.         $this->client = new \MarketplaceWebService_Client(
  40.             config('amazon.aws_access_key_id'),
  41.             config('amazon.aws_secret_access_key'),
  42.             $this->config,
  43.             config('amazon.app_name'),
  44.             config('amazon.app_version')
  45.         );
  46.  
  47.         $this->reportType = '_GET_FBA_ESTIMATED_FBA_FEES_TXT_DATA_';
  48.  
  49.         $this->parameters = [
  50.             'Merchant' => config('amazon.merchant_id'),
  51.             'MarketplaceIdList' => ['Id' => [config('amazon.mws_marketplace_id.us')]],
  52.             'ReportType' => $this->reportType,
  53.             'ReportOptions' => 'ShowSalesChannel=true',
  54.             'MWSAuthToken' => config('amazon.mws_auth_token'), // Optional,
  55.             'StartDate' => '2017-12-21 00:00:00', //Optional
  56.             'EndDate' => '2017-12-21 23:59:59', //Optional
  57.         ];
  58.  
  59.     }
  60.  
  61.     public function getTest()
  62.     {
  63.         return $this->getMwsRequestReport($this->client, $this->parameters);
  64.     }
  65.  
  66.     /*
  67.     * 1. RequestReport
  68.      *
  69.      */
  70.     function getMwsRequestReport(\MarketplaceWebService_Interface $client, $parameters) {
  71.         $reportRequestInfo = null;
  72.         $responseMetadata = null;
  73.  
  74.         return response()->json([get_object_vars($client)]);
  75.         die();
  76.  
  77.         try {
  78.             $request = new \MarketplaceWebService_Model_RequestReportRequest($parameters);
  79.  
  80.             $response = $client->requestReport($request);
  81.  
  82.             if ($response->isSetRequestReportResult()) {
  83.  
  84.                 $requestReportResult = $response->getRequestReportResult();
  85.  
  86.                 if ($requestReportResult->isSetReportRequestInfo()) {
  87.  
  88.                     $reportRequestInfo = $requestReportResult->getReportRequestInfo();
  89.  
  90. //                if ($reportRequestInfo->isSetReportRequestId())
  91. //                {
  92. //                    echo("                        " . $reportRequestInfo->getReportRequestId() . "\n");
  93. //                }
  94.                 }
  95.             }
  96.             if ($response->isSetResponseMetadata()) {
  97.                 $responseMetadata = $response->getResponseMetadata();
  98. //            if ($responseMetadata->isSetRequestId())
  99. //            {
  100. //                echo("                    " . $responseMetadata->getRequestId() . "\n");
  101. //            }
  102.             }
  103.  
  104.         } catch (MarketplaceWebService_Exception $ex) {
  105.             echo("Caught Exception: " . $ex->getMessage() . "\n");
  106.             echo("Response Status Code: " . $ex->getStatusCode() . "\n");
  107.             echo("Error Code: " . $ex->getErrorCode() . "\n");
  108.             echo("Error Type: " . $ex->getErrorType() . "\n");
  109.             echo("Request ID: " . $ex->getRequestId() . "\n");
  110.             echo("XML: " . $ex->getXML() . "\n");
  111.             echo("ResponseHeaderMetadata: " . $ex->getResponseHeaderMetadata() . "\n");
  112.         }
  113.  
  114.         return [
  115.             'ReportRequestInfo' => $reportRequestInfo,
  116.             'ResponseMetadata'  => $responseMetadata
  117.         ];
  118.     }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment