Skip to content

Commit

Permalink
Merge pull request #67 from mageplaza/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
haitv282 committed Apr 14, 2023
2 parents 343eea8 + 69cc2e6 commit 569d041
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
28 changes: 22 additions & 6 deletions Model/Activate.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@
namespace Mageplaza\Core\Model;

use Exception;
use Laminas\Http\Request;
use Magento\Framework\DataObject;
use Magento\Framework\HTTP\Adapter\CurlFactory;
use Mageplaza\Core\Helper\AbstractData;
use Zend_Http_Client;
use Zend_Http_Response;

/**
* Class Activate
Expand All @@ -36,7 +35,7 @@ class Activate extends DataObject
{
/**
* Localhost maybe not active via https
* @inheritdoc
*
*/
const MAGEPLAZA_ACTIVE_URL = 'https://dashboard.mageplaza.com/license/index/activate/?isAjax=true';

Expand Down Expand Up @@ -71,7 +70,7 @@ public function activate($params = [])

$curl = $this->curlFactory->create();
$curl->write(
Zend_Http_Client::POST,
Request::METHOD_POST,
self::MAGEPLAZA_ACTIVE_URL,
'1.1',
[],
Expand All @@ -83,8 +82,8 @@ public function activate($params = [])
if (empty($resultCurl)) {
$result['message'] = __('Cannot connect to server. Please try again later.');
} else {
$responseBody = Zend_Http_Response::extractBody($resultCurl);
$result += AbstractData::jsonDecode($responseBody);
$responseBody = $this->extractBody($resultCurl);
$result += AbstractData::jsonDecode($responseBody);
if (isset($result['status']) && in_array($result['status'], [200, 201])) {
$result['success'] = true;
}
Expand All @@ -97,4 +96,21 @@ public function activate($params = [])

return $result;
}

/**
* Extract the body from a response string
*
* @param string $response_str
*
* @return string
*/
public function extractBody(string $response_str): string
{
$parts = preg_split('|(?:\r\n){2}|m', $response_str, 2);
if (isset($parts[1])) {
return $parts[1];
}

return '';
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "mageplaza/module-core",
"description": "Mageplaza Core for Magento 2",
"type": "magento2-module",
"version": "1.5.2",
"version": "1.5.3",
"license": "proprietary",
"authors": [
{
Expand Down

0 comments on commit 569d041

Please sign in to comment.