Skip to content

Commit

Permalink
Merge pull request #41 from pagarme/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
netorodrigues authored Jun 28, 2021
2 parents 82b88a3 + d72c40c commit 65faa96
Show file tree
Hide file tree
Showing 41 changed files with 1,184 additions and 92 deletions.
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ jobs:
docker exec -it newimage sh -c "ls"
docker exec -it newimage sh -c "ls /app"
docker exec -it newimage sh -c "cd /var/www/html && rm composer.lock"
docker exec -it newimage sh -c "cd /var/www/html && composer require pagarme/ecommerce-module-core:dev-master -vvv"
docker exec -it newimage sh -c "cd /var/www/html && composer selfupdate 1.10.22"
docker exec -it newimage sh -c "cd /var/www/html && composer require pagarme/pagarme-magento2-module:dev-develop -vvv"
docker exec -it newimage sh -c "cd /var/www/html && composer update -vvv"
docker exec -it newimage sh -c "cd /var/www/ && find html/ -type d -exec chmod 775 {} \;"
docker exec -it newimage sh -c "cd /var/www/ && find html/ -type f -exec chmod 664 {} \;"
Expand Down
1 change: 0 additions & 1 deletion .circleci/data/Dockerfile
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
15 changes: 15 additions & 0 deletions Api/BulkApiInterface.php
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();
}
13 changes: 13 additions & 0 deletions Api/BulkSingleResponseInterface.php
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;
}
12 changes: 12 additions & 0 deletions Api/ChargeApiInterface.php
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);
}
11 changes: 11 additions & 0 deletions Api/HubCommandInterface.php
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();
}
24 changes: 24 additions & 0 deletions Block/Adminhtml/Form/Field/HubEnvironment.php
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>';
}

}
103 changes: 103 additions & 0 deletions Block/Adminhtml/Form/Field/HubIntegration.php
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();
}

}
50 changes: 32 additions & 18 deletions Concrete/Magento2CoreSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,19 @@ protected function setConfig()
{
self::$config = [
AbstractModuleCoreSetup::CONCRETE_DATABASE_DECORATOR_CLASS =>
Magento2DatabaseDecorator::class,
Magento2DatabaseDecorator::class,
AbstractModuleCoreSetup::CONCRETE_PLATFORM_ORDER_DECORATOR_CLASS =>
Magento2PlatformOrderDecorator::class,
Magento2PlatformOrderDecorator::class,
AbstractModuleCoreSetup::CONCRETE_PLATFORM_INVOICE_DECORATOR_CLASS =>
Magento2PlatformInvoiceDecorator::class,
Magento2PlatformInvoiceDecorator::class,
AbstractModuleCoreSetup::CONCRETE_PLATFORM_CREDITMEMO_DECORATOR_CLASS =>
Magento2PlatformCreditmemoDecorator::class,
Magento2PlatformCreditmemoDecorator::class,
AbstractModuleCoreSetup::CONCRETE_DATA_SERVICE =>
Magento2DataService::class,
Magento2DataService::class,
AbstractModuleCoreSetup::CONCRETE_PLATFORM_PAYMENT_METHOD_DECORATOR_CLASS =>
Magento2PlatformPaymentMethodDecorator::class,
Magento2PlatformPaymentMethodDecorator::class,
AbstractModuleCoreSetup::CONCRETE_PRODUCT_DECORATOR_CLASS =>
Magento2PlatformProductDecorator::class
Magento2PlatformProductDecorator::class
];
}

Expand All @@ -98,8 +98,7 @@ static public function getDatabaseAccessObject()

static protected function getPlatformHubAppPublicAppKey()
{
/** @todo get the correct key for magento2 */
return "2d2db409-fed0-4bd8-ac1e-43eeff33458d";
return '3470c63b-a233-4be0-9d2a-9ff56e349556';
}

public function _getDashboardLanguage()
Expand Down Expand Up @@ -154,14 +153,15 @@ public function loadModuleConfigurationFromPlatform($storeConfig = null)
self::fillWithAddressConfig($configData, $storeConfig);
self::fillWithMultiBuyerConfig($configData, $storeConfig);
self::fillWithRecurrenceConfig($configData, $storeConfig);
$configData->hubInstallId = null;
self::fillWithHubConfig($configData, $storeConfig);

$configurationFactory = new ConfigurationFactory();
$config = $configurationFactory->createFromJsonData(
json_encode($configData)
);

self::$moduleConfig = $config;
self::$instance->setApiBaseUrl();
}

/**
Expand Down Expand Up @@ -321,6 +321,22 @@ static private function fillWithMultiBuyerConfig(&$dataObj, $storeConfig)
$dataObj = self::fillDataObj($storeConfig, $options, $dataObj, $section);
}

static private function fillWithHubConfig(&$dataObj, $storeConfig)
{
$options = [
'hubInstallId' => 'install_id',
'hubEnvironment' => 'environment'
];

$section = 'pagarme_pagarme/hub/';

$dataObj = self::fillDataObj($storeConfig, $options, $dataObj, $section);
if (!$dataObj->hubInstallId) {
$dataObj->hubInstallId = null;
$dataObj->hubEnvironment = null;
}
}

static private function fillWithPagarmeKeys(&$dataObj, $storeConfig)
{
$options = [
Expand Down Expand Up @@ -411,24 +427,22 @@ static private function getBrandConfig($storeConfig, $section)
$scope = ScopeInterface::SCOPE_WEBSITES;
$storeId = self::getCurrentStoreId();

$brands = array_merge([''],explode(
$brands = array_merge([''], explode(
',',
$storeConfig->getValue($section . 'cctypes', $scope, $storeId)
));

$cardConfigs = [];
foreach ($brands as $brand)
{
foreach ($brands as $brand) {
$brand = "_" . strtolower($brand);
$brandMethod = str_replace('_','', $brand);
$brandMethod = str_replace('_', '', $brand);
$adapted = self::getBrandAdapter(strtoupper($brandMethod));
if ($adapted !== false) {
$brand = "_" . strtolower($adapted);
$brandMethod = str_replace('_','', $brand);
$brandMethod = str_replace('_', '', $brand);
}

if ($brandMethod == '')
{
if ($brandMethod == '') {
$brand = '';
$brandMethod = 'nobrand';
}
Expand All @@ -441,7 +455,7 @@ static private function getBrandConfig($storeConfig, $section)

$minValue = $storeConfig->getValue($section . 'installment_min_amount' . $brand, $scope, $storeId);
$initial = $storeConfig->getValue($section . 'installments_interest_rate_initial' . $brand, $scope, $storeId);
$incremental = $storeConfig->getValue($section . 'installments_interest_rate_incremental'. $brand, $scope, $storeId);
$incremental = $storeConfig->getValue($section . 'installments_interest_rate_incremental' . $brand, $scope, $storeId);
$maxWithout = $storeConfig->getValue($section . 'installments_max_without_interest' . $brand, $scope, $storeId);

$interestByBrand = $storeConfig->getValue($section . 'installments_interest_by_issuer' . $brand, $scope, $storeId);
Expand Down
33 changes: 18 additions & 15 deletions Concrete/Magento2DatabaseDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,49 @@ protected function setTableArray()
{
$this->tableArray = [
AbstractDatabaseDecorator::TABLE_MODULE_CONFIGURATION =>
$this->db->getTableName('pagarme_module_core_configuration'),
$this->db->getTableName('pagarme_module_core_configuration'),

AbstractDatabaseDecorator::TABLE_WEBHOOK =>
$this->db->getTableName('pagarme_module_core_webhook'),
$this->db->getTableName('pagarme_module_core_webhook'),

AbstractDatabaseDecorator::TABLE_ORDER =>
$this->db->getTableName('pagarme_module_core_order'),
$this->db->getTableName('pagarme_module_core_order'),

AbstractDatabaseDecorator::TABLE_CHARGE =>
$this->db->getTableName('pagarme_module_core_charge'),
$this->db->getTableName('pagarme_module_core_charge'),

AbstractDatabaseDecorator::TABLE_TRANSACTION =>
$this->db->getTableName('pagarme_module_core_transaction'),
$this->db->getTableName('pagarme_module_core_transaction'),

AbstractDatabaseDecorator::TABLE_SAVED_CARD =>
$this->db->getTableName('pagarme_module_core_saved_card'),
$this->db->getTableName('pagarme_module_core_saved_card'),

AbstractDatabaseDecorator::TABLE_CUSTOMER =>
$this->db->getTableName('pagarme_module_core_customer'),
$this->db->getTableName('pagarme_module_core_customer'),

AbstractDatabaseDecorator::TABLE_RECURRENCE_PRODUCTS_PLAN =>
$this->db->getTableName('pagarme_module_core_recurrence_products_plan'),
$this->db->getTableName('pagarme_module_core_recurrence_products_plan'),

AbstractDatabaseDecorator::TABLE_RECURRENCE_PRODUCTS_SUBSCRIPTION =>
$this->db->getTableName('pagarme_module_core_recurrence_products_subscription'),
$this->db->getTableName('pagarme_module_core_recurrence_products_subscription'),

AbstractDatabaseDecorator::TABLE_RECURRENCE_SUB_PRODUCTS=>
$this->db->getTableName('pagarme_module_core_recurrence_sub_products'),
AbstractDatabaseDecorator::TABLE_RECURRENCE_SUB_PRODUCTS =>
$this->db->getTableName('pagarme_module_core_recurrence_sub_products'),

AbstractDatabaseDecorator::TABLE_RECURRENCE_CHARGE =>
$this->db->getTableName('pagarme_module_core_recurrence_charge'),
$this->db->getTableName('pagarme_module_core_recurrence_charge'),

AbstractDatabaseDecorator::TABLE_RECURRENCE_SUBSCRIPTION =>
$this->db->getTableName('pagarme_module_core_recurrence_subscription'),
$this->db->getTableName('pagarme_module_core_recurrence_subscription'),

AbstractDatabaseDecorator::TABLE_RECURRENCE_SUBSCRIPTION_REPETITIONS =>
$this->db->getTableName('pagarme_module_core_recurrence_subscription_repetitions'),
$this->db->getTableName('pagarme_module_core_recurrence_subscription_repetitions'),

AbstractDatabaseDecorator::TABLE_RECURRENCE_SUBSCRIPTION_ITEM =>
$this->db->getTableName('pagarme_module_core_recurrence_subscription_items')
$this->db->getTableName('pagarme_module_core_recurrence_subscription_items'),

AbstractDatabaseDecorator::TABLE_HUB_INSTALL_TOKEN =>
$this->db->getTableName('pagarme_module_core_hub_install_token')
];
}

Expand Down
2 changes: 1 addition & 1 deletion Concrete/integrityData

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Controller/Adminhtml/Charges/Cancel.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public function execute()
return $this->responseFail($error);
}

$this->setWebsiteConfiguration($params['chargeId']);

$amount = str_replace([',', '.'], "", $params['amount']);
$chargeId = $params['chargeId'];

Expand Down
Loading

0 comments on commit 65faa96

Please sign in to comment.