-
Notifications
You must be signed in to change notification settings - Fork 4
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 #41 from pagarme/develop
Develop
- Loading branch information
Showing
41 changed files
with
1,184 additions
and
92 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
FROM thiagobarradas/magento2:2.2.0-php7.1 | ||
MAINTAINER Open Source Team | ||
|
||
COPY . /app/app/code/Pagarme/Pagarme | ||
WORKDIR /app |
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,15 @@ | ||
<?php | ||
|
||
namespace Pagarme\Pagarme\Api; | ||
|
||
interface BulkApiInterface | ||
{ | ||
const HTTP_OK = 200; | ||
const HTTP_BAD_REQUEST = 400; | ||
const HTTP_INTERNAL_SERVER_ERROR = 500; | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function execute(); | ||
} |
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,13 @@ | ||
<?php | ||
|
||
namespace Pagarme\Pagarme\Api; | ||
|
||
use Pagarme\Pagarme\Model\Api\BulkSingleResponse; | ||
|
||
interface BulkSingleResponseInterface | ||
{ | ||
public function setStatus(int $status): BulkSingleResponse; | ||
public function getStatus(): int; | ||
public function setBody(array $body): BulkSingleResponse; | ||
public function getBody(): array; | ||
} |
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,12 @@ | ||
<?php | ||
|
||
namespace Pagarme\Pagarme\Api; | ||
|
||
interface ChargeApiInterface | ||
{ | ||
/** | ||
* @param string $id | ||
* @return Pagarme\Pagarme\Model\Api\ResponseMessage | ||
*/ | ||
public function cancel($id); | ||
} |
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,11 @@ | ||
<?php | ||
|
||
namespace Pagarme\Pagarme\Api; | ||
|
||
interface HubCommandInterface | ||
{ | ||
/** | ||
* @return mixed | ||
*/ | ||
public function execute(); | ||
} |
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,24 @@ | ||
<?php | ||
|
||
namespace Pagarme\Pagarme\Block\Adminhtml\Form\Field; | ||
|
||
use Magento\Config\Block\System\Config\Form\Field; | ||
use Magento\Framework\Data\Form\Element\AbstractElement; | ||
use Pagarme\Pagarme\Concrete\Magento2CoreSetup; | ||
|
||
class HubEnvironment extends Field | ||
{ | ||
/** | ||
* @param AbstractElement $element | ||
* @return string | ||
*/ | ||
protected function _renderValue(AbstractElement $element) | ||
{ | ||
Magento2CoreSetup::bootstrap(); | ||
$config = Magento2CoreSetup::getModuleConfiguration(); | ||
$environment = $config->getHubEnvironment(); | ||
|
||
return '<td class="value">' . $environment . '</td>'; | ||
} | ||
|
||
} |
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,103 @@ | ||
<?php | ||
|
||
namespace Pagarme\Pagarme\Block\Adminhtml\Form\Field; | ||
|
||
use Magento\Config\Block\System\Config\Form\Field; | ||
use Magento\Framework\Data\Form\Element\AbstractElement; | ||
use Pagarme\Core\Hub\Services\HubIntegrationService; | ||
use Pagarme\Pagarme\Concrete\Magento2CoreSetup; | ||
|
||
class HubIntegration extends Field | ||
{ | ||
/** | ||
* @param AbstractElement $element | ||
* @return string | ||
* @throws \Exception | ||
*/ | ||
protected function _renderValue(AbstractElement $element) | ||
{ | ||
Magento2CoreSetup::bootstrap(); | ||
|
||
$installId = Magento2CoreSetup::getModuleConfiguration() | ||
->getHubInstallId(); | ||
|
||
$hubUrl = $this->getHubUrl($installId); | ||
$buttonText = $this->getButtonText($installId); | ||
|
||
$html = '<td class="value">'; | ||
$html .= $this->_getElementHtml($element); | ||
|
||
$html .= sprintf( | ||
'<p | ||
id="botao-hub" | ||
hub-url="%s" | ||
button-text="%s"></p>', | ||
$hubUrl, | ||
$buttonText | ||
); | ||
|
||
$html .= '</td>'; | ||
|
||
return $html; | ||
} | ||
|
||
private function getButtonText($installId) | ||
{ | ||
return $installId | ||
? __("View Integration") : __("Integrate With Pagar.me"); | ||
} | ||
|
||
private function getHubUrl($installId) | ||
{ | ||
return $installId | ||
? $this->getBaseViewIntegrationUrl($installId->getValue()) | ||
: $this->getBaseIntegrateUrl(); | ||
} | ||
|
||
private function getBaseIntegrateUrl() | ||
{ | ||
$baseUrl = sprintf( | ||
'https://hub.pagar.me/apps/%s/authorize', | ||
$this->getPublicAppKey() | ||
); | ||
|
||
$params = sprintf( | ||
'?redirect=%swebsite/%s/&install_token/%s', | ||
$this->getRedirectUrl(), | ||
Magento2CoreSetup::getCurrentStoreId(), | ||
$this->getInstallToken() | ||
); | ||
|
||
return $baseUrl . $params; | ||
} | ||
|
||
private function getBaseViewIntegrationUrl($installId) | ||
{ | ||
return sprintf( | ||
'https://hub.pagar.me/apps/%s/edit/%s', | ||
$this->getPublicAppKey(), | ||
$installId | ||
); | ||
} | ||
|
||
private function getPublicAppKey() | ||
{ | ||
return Magento2CoreSetup::getHubAppPublicAppKey(); | ||
} | ||
|
||
private function getRedirectUrl() | ||
{ | ||
return $this->getUrl('pagarme_pagarme/hub/index'); | ||
} | ||
|
||
private function getInstallToken() | ||
{ | ||
$installSeed = uniqid(); | ||
$hubIntegrationService = new HubIntegrationService(); | ||
$installToken = $hubIntegrationService | ||
->startHubIntegration($installSeed); | ||
|
||
return $installToken->getValue(); | ||
} | ||
|
||
} |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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.