Skip to content

Instantly share code, notes, and snippets.

@IbrahimS2
Forked from Hailong/Index.php
Created February 5, 2020 22:32
Show Gist options
  • Save IbrahimS2/13d0276dfda99b86dd4cea8ecd602056 to your computer and use it in GitHub Desktop.
Save IbrahimS2/13d0276dfda99b86dd4cea8ecd602056 to your computer and use it in GitHub Desktop.

Revisions

  1. @Hailong Hailong revised this gist Apr 15, 2019. 1 changed file with 86 additions and 0 deletions.
    86 changes: 86 additions & 0 deletions Index.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,86 @@
    <?php
    namespace Auctane\Api\Controller\Auctane;

    use Exception;
    use Magento\Framework\App\CsrfAwareActionInterface;
    use Magento\Framework\App\Request\InvalidRequestException;
    use Magento\Framework\App\RequestInterface;

    class Index extends \Magento\Framework\App\Action\Action implements CsrfAwareActionInterface
    {
    /**
    * @inheritDoc
    */
    public function createCsrfValidationException(
    RequestInterface $request
    ): ?InvalidRequestException {
    return null;
    }

    /**
    * @inheritDoc
    */
    public function validateForCsrf(RequestInterface $request): ?bool
    {
    return true;
    }

    /**
    * Default function
    *
    * @return void
    */
    public function execute()
    {
    $authUser = $this->getRequest()->getParam('SS-UserName');
    $authPassword = $this->getRequest()->getParam('SS-Password');

    // \Magento\Store\Model\StoreManagerInterface $storeManager
    $storeManager = $this->_objectManager->get(
    'Magento\Store\Model\StoreManagerInterface'
    );
    $storeId = $storeManager->getStore()->getId();

    $storageInterface = $this->_objectManager->get(
    '\Magento\Backend\Model\Auth\Credential\StorageInterface'
    );
    $userAuthentication = $storageInterface->authenticate(
    $authUser,
    $authPassword
    );

    $dataHelper = $this->_objectManager->get('Auctane\Api\Helper\Data');
    if (!$userAuthentication) {
    header(sprintf('WWW-Authenticate: Basic realm=ShipStation'));
    $result = $dataHelper->fault(401, 'Authentication failed');
    header('Content-Type: text/xml; charset=UTF-8');
    $this->getResponse()->setBody($result);
    return false;
    }

    //Get the requested action
    $action = $this->getRequest()->getParam('action');
    try {
    switch ($action) {
    case 'export':
    $export = $this->_objectManager->get(
    'Auctane\Api\Model\Action\Export'
    );
    $result = $export->process($this->getRequest(), $storeId);
    break;

    case 'shipnotify':
    $shipNotify = $this->_objectManager->get(
    'Auctane\Api\Model\Action\ShipNotify'
    );
    $result = $shipNotify->process($this->getRequest());
    // if there hasn't been an error then "200 OK" is given
    break;
    }
    } catch (Exception $fault) {
    $result = $dataHelper->fault($fault->getCode(), $fault->getMessage());
    }

    $this->getResponse()->setBody($result);
    }
    }
  2. @Hailong Hailong created this gist Apr 14, 2019.
    47 changes: 47 additions & 0 deletions fix-shipstation-plugin-for-magento-2.3.patch
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    From 15db78fd75a7fc473d72157cb952f36739b125c7 Mon Sep 17 00:00:00 2001
    From: Hailong Zhao <[email protected]>
    Date: Sat, 13 Apr 2019 23:13:58 -0400
    Subject: [PATCH] Fix ShipStation plugin.

    ---
    .../Auctane/Api/Controller/Auctane/Index.php | 22 ++++++++++++++++++-
    1 file changed, 21 insertions(+), 1 deletion(-)

    diff --git a/app/code/Auctane/Api/Controller/Auctane/Index.php b/app/code/Auctane/Api/Controller/Auctane/Index.php
    index 53f9664f..a3319f17 100644
    --- a/app/code/Auctane/Api/Controller/Auctane/Index.php
    +++ b/app/code/Auctane/Api/Controller/Auctane/Index.php
    @@ -2,9 +2,29 @@
    namespace Auctane\Api\Controller\Auctane;

    use Exception;
    +use Magento\Framework\App\CsrfAwareActionInterface;
    +use Magento\Framework\App\Request\InvalidRequestException;
    +use Magento\Framework\App\RequestInterface;

    -class Index extends \Magento\Framework\App\Action\Action
    +class Index extends \Magento\Framework\App\Action\Action implements CsrfAwareActionInterface
    {
    + /**
    + * @inheritDoc
    + */
    + public function createCsrfValidationException(
    + RequestInterface $request
    + ): ?InvalidRequestException {
    + return null;
    + }
    +
    + /**
    + * @inheritDoc
    + */
    + public function validateForCsrf(RequestInterface $request): ?bool
    + {
    + return true;
    + }
    +
    /**
    * Default function
    *
    --
    2.20.1 (Apple Git-117)