Skip to content

Commit

Permalink
Merge pull request #11 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 1b0d028 + 397902e commit 8f59e30
Show file tree
Hide file tree
Showing 33 changed files with 729 additions and 137 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This is the repository of Pagar.me's payment module core for all supported e-com
- [Pagar.me Magento payment module for Magento 2.3+](https://github.com/pagarme/magento2).

## Dependencies
* ``PHP`` Version 5.6+
* ``PHP`` Version 7.1+

## Install
Require by composer
Expand Down
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ stages:
sudo update-alternatives --set phpdbg /usr/bin/phpdbg$(phpCurrentVersion)
sudo update-alternatives --set php-cgi /usr/bin/php-cgi$(phpCurrentVersion)
sudo update-alternatives --set phar.phar /usr/bin/phar.phar$(phpCurrentVersion)
sudo apt-get install php-xdebug
sudo apt-get install php7.2-xdebug
php -version
displayName: Build PHP Version $(phpCurrentVersion)
- script: |
sudo apt-get install php-xdebug
sudo apt-get install php7.2-xdebug
php -version
displayName: Install PHP extensions
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"name": "pagarme/ecommerce-module-core",
"description": "Core component for Pagar.me e-commerce platform modules.",
"license": "MIT",
"version": "1.0.0",
"version": "1.1.0",
"authors": [
{
"name":"Open Source Team"
}
],
"type": "library",
"require": {
"php": ">=5.6",
"php": ">=7.1",
"monolog/monolog": "~1.6",
"mundipagg/mundiapi": "^3.0",
"ext-json": "*"
Expand Down
2 changes: 2 additions & 0 deletions src/Hub/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public function execute()

$moduleConfig->setHubInstallId($this->getInstallId());

$moduleConfig->setHubEnvironment($this->getType());

$moduleConfig->setPublicKey(
$this->getAccountPublicKey()
);
Expand Down
9 changes: 6 additions & 3 deletions src/Hub/Factories/HubCommandFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function createFromStdClass($object)

/**
*
* @var AbstractCommand $command
*/
* @var AbstractCommand $command
*/
$command = new $commandClass();

$command->setAccessToken(
Expand All @@ -48,7 +48,10 @@ public function createFromStdClass($object)
);

$publicKeyClass = PublicKey::class;
if ($command->getType()->equals(CommandType::Sandbox())) {
if (
$command->getType()->equals(CommandType::Sandbox())
|| $command->getType()->equals(CommandType::Development())
) {
$publicKeyClass = TestPublicKey::class;
}

Expand Down
7 changes: 4 additions & 3 deletions src/Hub/Services/HubIntegrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ public function endHubIntegration(

$installToken = $tokenRepo->findByPagarmeId(new HubInstallToken($installToken));

if (is_a($installToken, InstallToken::class)
&& !$installToken->isExpired()
if (
is_a($installToken, InstallToken::class)
&& !$installToken->isExpired()
&& !$installToken->isUsed()
) {
$body = [
Expand Down Expand Up @@ -100,4 +101,4 @@ public function executeCommandFromPost($body)
$command = $commandFactory->createFromStdClass($body);
$command->execute();
}
}
}
15 changes: 12 additions & 3 deletions src/Kernel/Abstractions/AbstractModuleCoreSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Pagarme\Core\Kernel\Aggregates\Configuration;
use Pagarme\Core\Kernel\Repositories\ConfigurationRepository;
use MundiAPILib\Configuration as MundiAPIConfiguration;
use ReflectionClass;

abstract class AbstractModuleCoreSetup
Expand Down Expand Up @@ -72,6 +73,15 @@ public static function bootstrap($platformRoot = null)
static::$platformRoot = $platformRoot;

static::updateModuleConfiguration();

static::$instance->setApiBaseUrl();
}
}

protected static function setApiBaseUrl()
{
if (static::$moduleConfig->isHubEnabled()) {
MundiAPIConfiguration::$BASEURI = 'https://hubapi.mundipagg.com/core/v1';
}
}

Expand All @@ -98,7 +108,7 @@ protected static function updateModuleConfiguration()
static::$moduleConfig->setStoreId(static::getCurrentStoreId());
}

if(
if (
static::$moduleConfig->getStoreId() != static::getDefaultStoreId() &&
$savedConfig === null
) {
Expand Down Expand Up @@ -241,7 +251,7 @@ public static function getModuleConcreteDir()

public static function setModuleConcreteDir($concreteModuleDir)
{
if(!isset(self::$moduleConcreteDir)) {
if (!isset(self::$moduleConcreteDir)) {
self::$moduleConcreteDir = $concreteModuleDir;
}
}
Expand Down Expand Up @@ -288,4 +298,3 @@ public static function getStoreTimezone()
*/
abstract protected function getPlatformStoreTimezone();
}

17 changes: 17 additions & 0 deletions src/Kernel/Aggregates/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ final class Configuration extends AbstractEntity
*/
private $hubInstallId;

/**
*
* @var string
*/
private $hubEnvironment;

/** @var string */
private $cardOperation;

Expand Down Expand Up @@ -315,6 +321,16 @@ public function getHubInstallId()
return $this->hubInstallId;
}

public function setHubEnvironment($hubEnvironment)
{
$this->hubEnvironment = $hubEnvironment;
}

public function getHubEnvironment()
{
return $this->hubEnvironment;
}

/**
*
* @param bool $boletoEnabled
Expand Down Expand Up @@ -711,6 +727,7 @@ public function jsonSerialize()
"boletoCreditCardEnabled" => $this->boletoCreditCardEnabled,
"testMode" => $this->testMode,
"hubInstallId" => $this->isHubEnabled() ? $this->hubInstallId->getValue() : null,
"hubEnvironment" => $this->hubEnvironment,
"addressAttributes" => $this->getAddressAttributes(),
"keys" => $this->keys,
"cardOperation" => $this->cardOperation,
Expand Down
4 changes: 4 additions & 0 deletions src/Kernel/Factories/ConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ public function createFromJsonData($json)
);
}

if (!empty($data->hubEnvironment)) {
$config->setHubEnvironment($data->hubEnvironment);
}

if (!empty($data->keys) ) {
if (!isset($data->publicKey)) {
$index = Configuration::KEY_PUBLIC;
Expand Down
11 changes: 11 additions & 0 deletions src/Kernel/Factories/Configurations/PixConfigFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ public function createFromDbData($data)
$pixConfig->setExpirationQrCode($data->expirationQrCode);
}

if (!empty($data->additionalInformation)) {
$additionalInformationArray = json_decode(
json_encode($data->additionalInformation),
true
);

$pixConfig->setAdditionalInformation(
$additionalInformationArray
);
}

if (!empty($data->bankType)) {
$pixConfig->setBankType(
$data->bankType
Expand Down
11 changes: 10 additions & 1 deletion src/Kernel/I18N/ENUS.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,18 @@ protected function getTable()
"The card '%s' couldn't be deleted." => null,
"Different paid amount for this invoice. Paid value: %.2f" => null,
"The %s should not be empty!" => null,
"The %s is invalid!" => null,
"street" => null,
"number" => null,
"neighborhood" => null,
"zipCode" => null,
"city" => null,
"country" => null,
"state" => null,
"phone" => null,
"document" => null,
"Can't create order." => null,
"Can't create payment. Please review the information and try again." => null,
'Invalid address configuration. Please fill the address configuration on admin panel.' => null,
'week' => null,
'weeks' => null,
Expand Down Expand Up @@ -85,6 +89,11 @@ protected function getTable()
'Antifraud reproved' => null,
'Antifraud pending' => null,
'Waiting manual analise in antifraud' => null,
"Can't connect to the payment service. Please contact the store administrator." => null,
"The sum of payments is different than the order amount! Review the information and try again." => null,
"The sum of payments is greater than the order amount! Review the information and try again." => null,
"The card brand '%s' or the amount %.2f doesn't allow %d installment(s)! Please review the information and try again." => null,
"Passed value:" => null,
];
}
}
}
17 changes: 13 additions & 4 deletions src/Kernel/I18N/PTBR.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,19 @@ protected function getTable()
"The card '%s' was deleted." => "O cartão '%s' foi deletado.",
"The card '%s' couldn't be deleted." => "O cartão '%s' não pôde ser deletado.",
"Different paid amount for this invoice. Paid value: %.2f" => "Esta Invoice foi paga com um valor diferente do Grand Total do pedido. Valor pago: %.2f",
"The %s should not be empty!" => "O campo %s não deve estar vazio",
"The %s should not be empty!" => "O campo %s é obrigatório!",
"The %s is invalid!" => "Campo %s inválido!",
"street" => "rua",
"number" => "número",
"neighborhood" => "bairro",
"zipCode" => "CEP",
"city" => "cidade",
"country" => "país",
"state" => "estado",
"document" => "CPF",
"Can't create order." => "Não foi possível criar o pedido",
"phone" => "telefone",
"document" => "CPF/CNPJ",
"Can't create order." => "Não foi possível criar o pedido.",
"Can't create payment. Please review the information and try again." => "Não foi possível realizar o pagamento. Por favor revise os dados e tente novamente.",
'Invalid address configuration. Please fill the address configuration on admin panel.' => 'Configurações de endereço inválidas. Preencha as configurações de endereço no painel de administração',
'week' => "semana",
'weeks' => "semanas",
Expand Down Expand Up @@ -86,6 +90,11 @@ protected function getTable()
'Antifraud reproved' => 'Reprovado no antifraude',
'Antifraud pending' => 'Analise pendente no antifraude',
'Waiting manual analise in antifraud' => 'Aguardando análise manual em antifraude',
"Can't connect to the payment service. Please contact the store administrator." => "Não foi possivel conectar com o serviço de pagamento. Por favor contate o administrador da loja.",
"The sum of payments is different than the order amount! Review the information and try again." => "A soma dos pagamentos é diferente do valor do pedido! Verifique as informações de sua compra e tente novamente.",
"The sum of payments is greater than the order amount! Review the information and try again." => "A soma dos pagamentos é maior do que o valor do pedido! Verifique as informações de sua compra e tente novamente.",
"The card brand '%s' or the amount %.2f doesn't allow %d installment(s)! Please review the information and try again." => "A bandeira do cartão '%s' ou o valor %.2f não permite %d parcela(s)! Por favor revise os dados e tente novamente.",
"Passed value:" => "Valor informado:",
];
}
}
}
10 changes: 10 additions & 0 deletions src/Kernel/Services/APIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ private function getCustomerController()

private function getMundiPaggApiClient()
{
$i18n = new LocalizationService();
$config = MPSetup::getModuleConfiguration();

$secretKey = null;
Expand All @@ -231,6 +232,15 @@ private function getMundiPaggApiClient()
}
$password = '';

if (empty($secretKey)) {
$message = $i18n->getDashboard(
"Can't connect to the payment service. " .
"Please contact the store administrator."
);

throw new \Exception($message, 400);
}

Configuration::$basicAuthPassword = '';

return new MundiAPIClient($secretKey, $password);
Expand Down
34 changes: 17 additions & 17 deletions src/Kernel/Services/ChargeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ public function capture(Charge $charge, $amount = 0)

$orderHandlerService = new OrderHandler();

$order->setCustomer($charge->getCustomer());
if (!empty($charge->getCustomer())) {
$order->setCustomer($charge->getCustomer());
}

$orderHandlerService->handle($order);

Expand Down Expand Up @@ -215,21 +217,19 @@ public function getNotFailedOrCanceledCharges(array $listCharge)
$listCharge,
function (Charge $charge) {
return (
($charge->getStatus()->getStatus() == 'failed')
);
($charge->getStatus()->getStatus() == 'failed'));
}
);

if ($existStatusFailed != null) {
$listChargesPaid = array_filter(
$listCharge,
function (Charge $charge) {
return (
$charge->getStatus()->getStatus() == 'paid' ||
return ($charge->getStatus()->getStatus() == 'paid' ||
$charge->getStatus()->getStatus() == 'underpaid' ||
$charge->getStatus()->getStatus() == 'pending'
);
});
$charge->getStatus()->getStatus() == 'pending');
}
);
}

return $listChargesPaid;
Expand All @@ -255,16 +255,16 @@ public function prepareHistoryComment(ChargeInterface $charge)
$extraValue = $charge->getPaidAmount() - $charge->getAmount();
if ($extraValue > 0) {
$history .= ". " . $i18n->getDashboard(
"Extra amount paid: %.2f",
$moneyService->centsToFloat($extraValue)
);
"Extra amount paid: %.2f",
$moneyService->centsToFloat($extraValue)
);
}

if ($extraValue < 0) {
$history .= ". " . $i18n->getDashboard(
"Remaining amount: %.2f",
$moneyService->centsToFloat(abs($extraValue))
);
"Remaining amount: %.2f",
$moneyService->centsToFloat(abs($extraValue))
);
}

$refundedAmount = $charge->getRefundedAmount();
Expand Down Expand Up @@ -297,9 +297,9 @@ public function prepareHistoryComment(ChargeInterface $charge)
);

$history .= ' ' . $i18n->getDashboard(
'Refunded amount: %.2f',
$amountInCurrency
);
'Refunded amount: %.2f',
$amountInCurrency
);

$history .= " (" . $i18n->getDashboard('until now') . ")";

Expand Down
Loading

0 comments on commit 8f59e30

Please sign in to comment.