This repository has been archived by the owner on Jun 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from pmclain/feature/webhooks
Add Webhook Support
- Loading branch information
Showing
16 changed files
with
328 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace Pmclain\Twilio\Controller\Webhook; | ||
|
||
use Magento\Framework\App\Action\Action; | ||
use Magento\Framework\App\Action\Context; | ||
use Pmclain\Twilio\Api\LogRepositoryInterface; | ||
use Magento\Framework\Stdlib\DateTime\DateTimeFactory; | ||
use Magento\Framework\Controller\ResultFactory; | ||
|
||
class Index extends Action | ||
{ | ||
/** | ||
* @var LogRepositoryInterface | ||
*/ | ||
protected $logRepository; | ||
|
||
/** | ||
* @var DateTimeFactory | ||
*/ | ||
protected $dateTimeFactory; | ||
|
||
/** | ||
* Index constructor. | ||
* @param Context $context | ||
* @param LogRepositoryInterface $logRepository | ||
* @param DateTimeFactory $dateTimeFactory | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
LogRepositoryInterface $logRepository, | ||
DateTimeFactory $dateTimeFactory | ||
) { | ||
parent::__construct($context); | ||
$this->logRepository = $logRepository; | ||
$this->dateTimeFactory = $dateTimeFactory; | ||
} | ||
|
||
/** | ||
* @return \Magento\Framework\Controller\ResultInterface | ||
*/ | ||
public function execute() | ||
{ | ||
if (!$this->getRequest()->isPost()) { | ||
$resultRedirect = $this->resultRedirectFactory->create(); | ||
|
||
return $resultRedirect->setUrl($this->_redirect->getRefererUrl()); | ||
} | ||
|
||
$resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON); | ||
|
||
try { | ||
$log = $this->logRepository->getBySid($this->getRequest()->getParam('SmsSid')); | ||
$log->setResult($this->getRequest()->getParam('SmsStatus')); | ||
$log->setUpdatedAt($this->dateTimeFactory->create()->timestamp()); | ||
$this->logRepository->save($log); | ||
|
||
$resultJson->setData(['message' => 'success']); | ||
} catch (\Exception $e) { | ||
$resultJson->setData(['message' => $e->getMessage()]); | ||
} | ||
|
||
return $resultJson; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.