Activate.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Mageplaza
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Mageplaza.com license that is
  8. * available through the world-wide-web at this URL:
  9. * https://www.mageplaza.com/LICENSE.txt
  10. *
  11. * DISCLAIMER
  12. *
  13. * Do not edit or add to this file if you wish to upgrade this extension to newer
  14. * version in the future.
  15. *
  16. * @category Mageplaza
  17. * @package Mageplaza_Core
  18. * @copyright Copyright (c) 2016-2018 Mageplaza (http://www.mageplaza.com/)
  19. * @license https://www.mageplaza.com/LICENSE.txt
  20. */
  21. namespace Mageplaza\Core\Model;
  22. use Mageplaza\Core\Helper\AbstractData;
  23. /**
  24. * Class Activate
  25. * @package Mageplaza\Core\Model
  26. */
  27. class Activate extends \Magento\AdminNotification\Model\Feed
  28. {
  29. /**
  30. * @inheritdoc
  31. */
  32. const MAGEPLAZA_ACTIVE_URL = 'http://store.mageplaza.com/license/index/activate';
  33. /**
  34. * @inheritdoc
  35. */
  36. public function getActiveUrl()
  37. {
  38. return self::MAGEPLAZA_ACTIVE_URL;
  39. // $httpPath = $this->_backendConfig->isSetFlag(self::XML_USE_HTTPS_PATH) ? 'https://' : 'http://';
  40. // if ($this->_feedUrl === null) {
  41. // $this->_feedUrl = $httpPath . self::MAGEPLAZA_ACTIVE_URL;
  42. // }
  43. //
  44. // return $this->_feedUrl;
  45. }
  46. /**
  47. * @param array $params
  48. * @return array
  49. */
  50. public function activate($params = [])
  51. {
  52. $result = ['success' => false];
  53. $curl = $this->curlFactory->create();
  54. $curl->write(\Zend_Http_Client::POST, $this->getActiveUrl(), '1.1', [], http_build_query($params));
  55. try {
  56. $resultCurl = $curl->read();
  57. if (!empty($resultCurl)) {
  58. $responseBody = \Zend_Http_Response::extractBody($resultCurl);
  59. $result += AbstractData::jsonDecode($responseBody);
  60. if (isset($result['status']) && in_array($result['status'], [200, 201])) {
  61. $result['success'] = true;
  62. }
  63. } else {
  64. $result['message'] = __('Cannot connect to server. Please try again later.');
  65. }
  66. } catch (\Exception $e) {
  67. $result['message'] = $e->getMessage();
  68. }
  69. $curl->close();
  70. return $result;
  71. }
  72. }