/** * Perform API call to Amazon to validate keys * */ public function _afterSaveCommit() { $data = $this->getFieldsetData(); $isEnabled = $this->getValue(); if ($isEnabled) { $config = array('ServiceURL' => "https://mws.amazonservices.com/Sellers/2011-07-01", 'ProxyHost' => null, 'ProxyPort' => -1, 'ProxyUsername' => null, 'ProxyPassword' => null, 'MaxErrorRetry' => 3); $service = new MarketplaceWebServiceSellers_Client($data['access_key'], $data['access_secret'], 'Login and Pay for Magento', '1.3', $config); $request = new MarketplaceWebServiceSellers_Model_ListMarketplaceParticipationsRequest(); $request->setSellerId($data['seller_id']); try { $service->ListMarketplaceParticipations($request); Mage::getSingleton('core/session')->addSuccess("All of your Amazon API keys are correct!"); } catch (MarketplaceWebServiceSellers_Exception $ex) { if ($ex->getErrorCode() == 'InvalidAccessKeyId') { Mage::getSingleton('core/session')->addError("The Amazon MWS Access Key is incorrect"); } else { if ($ex->getErrorCode() == 'SignatureDoesNotMatch') { Mage::getSingleton('core/session')->addError("The Amazon MWS Secret Key is incorrect"); } else { if ($ex->getErrorCode() == 'InvalidParameterValue') { Mage::getSingleton('core/session')->addError("The Amazon Seller/Merchant ID is incorrect"); } else { if ($ex->getErrorCode() == 'AccessDenied') { Mage::getSingleton('core/session')->addError("The Amazon Seller/Merchant ID does not match the MWS keys provided"); } else { $string = " Error Message: " . $ex->getMessage(); $string .= " Response Status Code: " . $ex->getStatusCode(); $string .= " Error Code: " . $ex->getErrorCode(); Mage::getSingleton('core/session')->addError($string); } } } } } } return parent::_afterSaveCommit(); }
<?php /** * Amazon Login - Login for osCommerce * * @category Amazon * @package Amazon_Login * @copyright Copyright (c) 2015 Amazon.com * @license http://opensource.org/licenses/Apache-2.0 Apache License, Version 2.0 */ require 'includes/modules/payment/paywithamazon/lib/MarketplaceWebServiceSellers/Client.php'; require 'includes/modules/payment/paywithamazon/lib/MarketplaceWebServiceSellers/Model/ListMarketplaceParticipationsRequest.php'; $config = array('ServiceURL' => "https://mws.amazonservices.com/Sellers/2011-07-01", 'ProxyHost' => null, 'ProxyPort' => -1, 'ProxyUsername' => null, 'ProxyPassword' => null, 'MaxErrorRetry' => 3); $service = new MarketplaceWebServiceSellers_Client($_GET['mws_access_key'], $_GET['mws_secret_key'], 'Login and Pay for Zen Cart', '1.0', $config); $request = new MarketplaceWebServiceSellers_Model_ListMarketplaceParticipationsRequest(); $request->setSellerId($_GET['seller_id']); try { $service->ListMarketplaceParticipations($request); echo "Your Amazon Credentials are correct.<br />"; } catch (MarketplaceWebServiceSellers_Exception $ex) { if ($ex->getErrorCode() == 'InvalidAccessKeyId') { echo "Your Amazon MWS Access Key is incorrect.<br />"; } else { if ($ex->getErrorCode() == 'SignatureDoesNotMatch') { echo "Your Amazon MWS Secret Key is incorrect.<br />"; } else { if ($ex->getErrorCode() == 'InvalidParameterValue') { echo "Your Amazon Seller/Merchant ID is incorrect.<br />"; } else { if ($ex->getErrorCode() == 'AccessDenied') { echo "Your Amazon Seller/Merchant ID does not match the MWS keys provided.<br />";
* responses without calling MarketplaceWebServiceSellers service. * * Responses are loaded from local XML files. You can tweak XML files to * experiment with various outputs during development * * XML files available under MarketplaceWebServiceSellers/Mock tree * ***********************************************************************/ // $service = new MarketplaceWebServiceSellers_Mock(); /************************************************************************ * Setup request parameters and uncomment invoke to try out * sample for List Marketplace Participations Action ***********************************************************************/ // @TODO: set request. Action can be passed as MarketplaceWebServiceSellers_Model_ListMarketplaceParticipations $request = new MarketplaceWebServiceSellers_Model_ListMarketplaceParticipationsRequest(); $request->setSellerId(MERCHANT_ID); // object or array of parameters invokeListMarketplaceParticipations($service, $request); /** * Get List Marketplace Participations Action Sample * Gets competitive pricing and related information for a product identified by * the MarketplaceId and ASIN. * * @param MarketplaceWebServiceSellers_Interface $service instance of MarketplaceWebServiceSellers_Interface * @param mixed $request MarketplaceWebServiceSellers_Model_ListMarketplaceParticipations or array of parameters */ function invokeListMarketplaceParticipations(MarketplaceWebServiceSellers_Interface $service, $request) { try { $response = $service->ListMarketplaceParticipations($request); echo "Service Response\n";
public function listMarketplaceParticipations() { $this->initAPI('Sellers'); $request = new MarketplaceWebServiceSellers_Model_ListMarketplaceParticipationsRequest(); $request->setSellerId($this->SellerId); $allowed_markets = array(); // invoke request try { $response = $this->service->listMarketplaceParticipations($request); if ($response->isSetListMarketplaceParticipationsResult()) { $listMarketplaceParticipationsResult = $response->getListMarketplaceParticipationsResult(); // process marketplaces $listMarketplaces = $listMarketplaceParticipationsResult->getListMarketplaces(); $marketplaceList = $listMarketplaces->getMarketplace(); foreach ($marketplaceList as $marketplace) { $key = $marketplace->getMarketplaceId(); $allowed_markets[$key] = new stdClass(); $allowed_markets[$key]->MarketplaceId = $marketplace->getMarketplaceId(); $allowed_markets[$key]->Name = $marketplace->getName(); $allowed_markets[$key]->DefaultLanguageCode = $marketplace->getDefaultLanguageCode(); $allowed_markets[$key]->DefaultCountryCode = $marketplace->getDefaultCountryCode(); $allowed_markets[$key]->DefaultCurrencyCode = $marketplace->getDefaultCurrencyCode(); $allowed_markets[$key]->DomainName = $marketplace->getDomainName(); } // process participations $listParticipations = $listMarketplaceParticipationsResult->getListParticipations(); $participationList = $listParticipations->getParticipation(); foreach ($participationList as $participation) { $key = $marketplace->getMarketplaceId(); $allowed_markets[$key]->MarketplaceId = $participation->getMarketplaceId(); $allowed_markets[$key]->SellerId = $participation->getSellerId(); $allowed_markets[$key]->HasSellerSuspendedListings = $participation->getHasSellerSuspendedListings(); } // echo "<pre>allowed_markets: ";print_r($allowed_markets);echo"</pre>";#die(); $result = new stdClass(); $result->allowed_markets = $allowed_markets; $result->success = true; return $result; } } catch (MarketplaceWebServiceSellers_Exception $ex) { $error = new stdClass(); $error->ErrorMessage = $ex->getMessage(); $error->ErrorCode = $ex->getErrorCode(); $error->StatusCode = $ex->getStatusCode(); return $error; } $result = new stdClass(); $result->success = false; return $result; }