Skip to content

Commit

Permalink
Merge pull request #98 from pagarme/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mateus-picoloto authored Jul 4, 2023
2 parents 4cf4a7a + 7beedbb commit 343fb02
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 23 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 7.1 - 7.4
* ``PHP`` Version 7.1 - 8.1

## Install
Require by composer
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "pagarme/ecommerce-module-core",
"description": "Core component for Pagar.me e-commerce platform modules.",
"license": "MIT",
"version": "2.2.1",
"version": "2.2.2",
"authors": [
{
"name":"Open Source Team"
Expand All @@ -12,7 +12,7 @@
"require": {
"php": ">=7.1",
"monolog/monolog": "<3",
"pagarme/pagarmecoreapi": "5.6.1",
"pagarme/pagarmecoreapi": "5.6.2",
"ext-json": "*"
},
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion src/Hub/Aggregates/InstallToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

final class InstallToken extends AbstractEntity
{
const LIFE_SPAN = 1800; //time in seconds
const LIFE_SPAN = 43200; //time in seconds

/**
*
Expand Down
8 changes: 7 additions & 1 deletion src/Hub/Services/HubIntegrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ public function endHubIntegration(
$rawToken = $installToken;

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


if (is_null($installToken)) {
$message = "Received an invalid installToken. NULL: $rawToken";
$exception = new \Exception($message);
$this->logService->exception($exception);
throw $exception;
}
if (empty($installToken)) {
$message = "installToken not found in database. Raw Token: $rawToken";

Expand Down
18 changes: 9 additions & 9 deletions src/Kernel/Abstractions/AbstractModuleCoreSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,27 +87,21 @@ protected static function setApiBaseUrl()

protected static function updateModuleConfiguration()
{
$configurationRepository = new ConfigurationRepository;

static::loadSavedConfiguration();

$savedConfig = static::$moduleConfig;
static::$instance->loadModuleConfigurationFromPlatform();
static::$moduleConfig->setStoreId(static::getCurrentStoreId());

if (
$savedConfig !== null &&
($savedConfigId = $savedConfig->getId()) !== null
) {
static::$moduleConfig->setid($savedConfigId);
}

if (self::getDefaultConfigSaved() === null) {
static::$moduleConfig->setStoreId(static::getDefaultStoreId());
$configurationRepository->save(static::$moduleConfig);
static::saveModuleConfig();
static::$moduleConfig->setStoreId(static::getCurrentStoreId());
}

if (
static::$moduleConfig->getStoreId() != static::getDefaultStoreId() &&
$savedConfig === null
Expand All @@ -116,10 +110,16 @@ protected static function updateModuleConfiguration()
static::$moduleConfig->setInheritAll(true);
static::$moduleConfig->setId(null);
}

$configurationRepository->save(static::$moduleConfig);
static::saveModuleConfig();
}

protected static function saveModuleConfig()
{
if (strpos(static::$instance->getPlatformVersion(), 'Wordpress') === false) {
$configurationRepository = new ConfigurationRepository;
$configurationRepository->save(static::$moduleConfig);
}
}
protected static function loadSavedConfiguration()
{
$store = static::getCurrentStoreId();
Expand Down
5 changes: 5 additions & 0 deletions src/Kernel/Aggregates/Charge.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,11 @@ public function failed()
$this->status = ChargeStatus::failed();
}

public function chargedback()
{
$this->status = ChargeStatus::chargedback();
}

/**
*
* @param Transaction $newTransaction
Expand Down
13 changes: 6 additions & 7 deletions src/Kernel/Aggregates/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,12 @@ protected function isTestMode()
*/
public function isHubEnabled()
{
if ($this->hubInstallId === null) {
return false;
if ($this->getHubInstallId() && $this->getHubInstallId() instanceof GUID) {
return
$this->getHubInstallId()->getValue() !== null &&
$this->getHubInstallId()->getValue() !== "00000000-0000-0000-0000-000000000000";
}
return $this->hubInstallId->getValue() !== null;
return false;
}

public function setHubInstallId(GUID $hubInstallId)
Expand Down Expand Up @@ -580,10 +582,7 @@ public function setAntifraudMinAmount($antifraudMinAmount)
$minAmount = preg_replace($numbers, $replace, $antifraudMinAmount ?? '');

if ($minAmount < 0) {
throw new InvalidParamException(
'AntifraudMinAmount should be at least 0!',
$minAmount
);
$minAmount = 0;
}
$this->antifraudMinAmount = $minAmount;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Kernel/Services/OrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@ public function createOrderAtPagarme(PlatformOrderInterface $platformOrder)
throw new \Exception($message, 400);
}

$platformOrder->save();
if (strpos(MPSetup::getPlatformVersion(), 'Wordpress') === false) {
$platformOrder->save();
}

$orderFactory = new OrderFactory();
$order = $orderFactory->createFromPostData($response);
Expand Down
3 changes: 2 additions & 1 deletion src/Payment/Aggregates/Payments/AbstractPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ public function convertToSDKRequest()
$newPayment->customer = $this->getCustomer()->convertToSDKRequest();
}

if ($this->moduleConfig->getMarketplaceConfig()->isEnabled()) {
$marketplaceConfig = $this->moduleConfig->getMarketplaceConfig();
if ($marketplaceConfig && $marketplaceConfig->isEnabled()) {
$newPayment->split = static::getSplitData();
$newPayment->split = $this->extractRequestsFromArray(
$newPayment->split
Expand Down
50 changes: 50 additions & 0 deletions src/Webhook/Services/ChargeOrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,52 @@ protected function handlePaymentFailed(Webhook $webhook)
];
}

/**
* @param Webhook $webhook
* @return array
*/
protected function handleChargedback(Webhook $webhook)
{
$order = $this->order;
/**
* @var Charge $charge
*/
$charge = $webhook->getEntity();

$transaction = $charge->getLastTransaction();

$outdatedCharge = $this->chargeRepository->findByPagarmeId(
$charge->getPagarmeId()
);

if ($outdatedCharge !== null) {
$charge = $outdatedCharge;
}
/**
* @var Charge $outdatedCharge
*/
if ($transaction !== null) {
$charge->addTransaction($transaction);
}

$charge->chargedback();
$order->updateCharge($charge);
$this->orderRepository->save($order);

$history = $this->prepareHistoryComment($charge);
$order->getPlatformOrder()->addHistoryComment($history, false);

$this->orderService->syncPlatformWith($order, false);

$returnMessage = $this->prepareReturnMessage($charge);

return [
"code" => 200,
"message" => $returnMessage
];

}

/**
* @return string
*/
Expand Down Expand Up @@ -490,6 +536,10 @@ public function prepareHistoryComment(ChargeInterface $charge)
return $this->i18n->getDashboard('Charge failed.');
}

if ($charge->getStatus()->equals(ChargeStatus::chargedback())) {
return $this->i18n->getDashboard('Charge chargedback.');
}

$amountInCurrency = $this->moneyService->centsToFloat($charge->getRefundedAmount());
$history = $this->i18n->getDashboard(
'Charge canceled.'
Expand Down

0 comments on commit 343fb02

Please sign in to comment.