Skip to content

Commit 343fb02

Browse files
Merge pull request #98 from pagarme/develop
Develop
2 parents 4cf4a7a + 7beedbb commit 343fb02

File tree

10 files changed

+86
-23
lines changed

10 files changed

+86
-23
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This is the repository of Pagar.me's payment module core for all supported e-com
1313
- [Pagar.me Magento payment module for Magento 2.3+](https://github.com/pagarme/magento2).
1414

1515
## Dependencies
16-
* ``PHP`` Version 7.1 - 7.4
16+
* ``PHP`` Version 7.1 - 8.1
1717

1818
## Install
1919
Require by composer

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "pagarme/ecommerce-module-core",
33
"description": "Core component for Pagar.me e-commerce platform modules.",
44
"license": "MIT",
5-
"version": "2.2.1",
5+
"version": "2.2.2",
66
"authors": [
77
{
88
"name":"Open Source Team"
@@ -12,7 +12,7 @@
1212
"require": {
1313
"php": ">=7.1",
1414
"monolog/monolog": "<3",
15-
"pagarme/pagarmecoreapi": "5.6.1",
15+
"pagarme/pagarmecoreapi": "5.6.2",
1616
"ext-json": "*"
1717
},
1818
"require-dev": {

src/Hub/Aggregates/InstallToken.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
final class InstallToken extends AbstractEntity
99
{
10-
const LIFE_SPAN = 1800; //time in seconds
10+
const LIFE_SPAN = 43200; //time in seconds
1111

1212
/**
1313
*

src/Hub/Services/HubIntegrationService.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,13 @@ public function endHubIntegration(
5858
$rawToken = $installToken;
5959

6060
$installToken = $tokenRepo->findByPagarmeId(new HubInstallToken($installToken));
61-
61+
62+
if (is_null($installToken)) {
63+
$message = "Received an invalid installToken. NULL: $rawToken";
64+
$exception = new \Exception($message);
65+
$this->logService->exception($exception);
66+
throw $exception;
67+
}
6268
if (empty($installToken)) {
6369
$message = "installToken not found in database. Raw Token: $rawToken";
6470

src/Kernel/Abstractions/AbstractModuleCoreSetup.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,27 +87,21 @@ protected static function setApiBaseUrl()
8787

8888
protected static function updateModuleConfiguration()
8989
{
90-
$configurationRepository = new ConfigurationRepository;
91-
9290
static::loadSavedConfiguration();
93-
9491
$savedConfig = static::$moduleConfig;
9592
static::$instance->loadModuleConfigurationFromPlatform();
9693
static::$moduleConfig->setStoreId(static::getCurrentStoreId());
97-
9894
if (
9995
$savedConfig !== null &&
10096
($savedConfigId = $savedConfig->getId()) !== null
10197
) {
10298
static::$moduleConfig->setid($savedConfigId);
10399
}
104-
105100
if (self::getDefaultConfigSaved() === null) {
106101
static::$moduleConfig->setStoreId(static::getDefaultStoreId());
107-
$configurationRepository->save(static::$moduleConfig);
102+
static::saveModuleConfig();
108103
static::$moduleConfig->setStoreId(static::getCurrentStoreId());
109104
}
110-
111105
if (
112106
static::$moduleConfig->getStoreId() != static::getDefaultStoreId() &&
113107
$savedConfig === null
@@ -116,10 +110,16 @@ protected static function updateModuleConfiguration()
116110
static::$moduleConfig->setInheritAll(true);
117111
static::$moduleConfig->setId(null);
118112
}
119-
120-
$configurationRepository->save(static::$moduleConfig);
113+
static::saveModuleConfig();
121114
}
122115

116+
protected static function saveModuleConfig()
117+
{
118+
if (strpos(static::$instance->getPlatformVersion(), 'Wordpress') === false) {
119+
$configurationRepository = new ConfigurationRepository;
120+
$configurationRepository->save(static::$moduleConfig);
121+
}
122+
}
123123
protected static function loadSavedConfiguration()
124124
{
125125
$store = static::getCurrentStoreId();

src/Kernel/Aggregates/Charge.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,11 @@ public function failed()
339339
$this->status = ChargeStatus::failed();
340340
}
341341

342+
public function chargedback()
343+
{
344+
$this->status = ChargeStatus::chargedback();
345+
}
346+
342347
/**
343348
*
344349
* @param Transaction $newTransaction

src/Kernel/Aggregates/Configuration.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,12 @@ protected function isTestMode()
331331
*/
332332
public function isHubEnabled()
333333
{
334-
if ($this->hubInstallId === null) {
335-
return false;
334+
if ($this->getHubInstallId() && $this->getHubInstallId() instanceof GUID) {
335+
return
336+
$this->getHubInstallId()->getValue() !== null &&
337+
$this->getHubInstallId()->getValue() !== "00000000-0000-0000-0000-000000000000";
336338
}
337-
return $this->hubInstallId->getValue() !== null;
339+
return false;
338340
}
339341

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

582584
if ($minAmount < 0) {
583-
throw new InvalidParamException(
584-
'AntifraudMinAmount should be at least 0!',
585-
$minAmount
586-
);
585+
$minAmount = 0;
587586
}
588587
$this->antifraudMinAmount = $minAmount;
589588
}

src/Kernel/Services/OrderService.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,9 @@ public function createOrderAtPagarme(PlatformOrderInterface $platformOrder)
287287
throw new \Exception($message, 400);
288288
}
289289

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

292294
$orderFactory = new OrderFactory();
293295
$order = $orderFactory->createFromPostData($response);

src/Payment/Aggregates/Payments/AbstractPayment.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public function convertToSDKRequest()
5959
$newPayment->customer = $this->getCustomer()->convertToSDKRequest();
6060
}
6161

62-
if ($this->moduleConfig->getMarketplaceConfig()->isEnabled()) {
62+
$marketplaceConfig = $this->moduleConfig->getMarketplaceConfig();
63+
if ($marketplaceConfig && $marketplaceConfig->isEnabled()) {
6364
$newPayment->split = static::getSplitData();
6465
$newPayment->split = $this->extractRequestsFromArray(
6566
$newPayment->split

src/Webhook/Services/ChargeOrderService.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,52 @@ protected function handlePaymentFailed(Webhook $webhook)
363363
];
364364
}
365365

366+
/**
367+
* @param Webhook $webhook
368+
* @return array
369+
*/
370+
protected function handleChargedback(Webhook $webhook)
371+
{
372+
$order = $this->order;
373+
/**
374+
* @var Charge $charge
375+
*/
376+
$charge = $webhook->getEntity();
377+
378+
$transaction = $charge->getLastTransaction();
379+
380+
$outdatedCharge = $this->chargeRepository->findByPagarmeId(
381+
$charge->getPagarmeId()
382+
);
383+
384+
if ($outdatedCharge !== null) {
385+
$charge = $outdatedCharge;
386+
}
387+
/**
388+
* @var Charge $outdatedCharge
389+
*/
390+
if ($transaction !== null) {
391+
$charge->addTransaction($transaction);
392+
}
393+
394+
$charge->chargedback();
395+
$order->updateCharge($charge);
396+
$this->orderRepository->save($order);
397+
398+
$history = $this->prepareHistoryComment($charge);
399+
$order->getPlatformOrder()->addHistoryComment($history, false);
400+
401+
$this->orderService->syncPlatformWith($order, false);
402+
403+
$returnMessage = $this->prepareReturnMessage($charge);
404+
405+
return [
406+
"code" => 200,
407+
"message" => $returnMessage
408+
];
409+
410+
}
411+
366412
/**
367413
* @return string
368414
*/
@@ -490,6 +536,10 @@ public function prepareHistoryComment(ChargeInterface $charge)
490536
return $this->i18n->getDashboard('Charge failed.');
491537
}
492538

539+
if ($charge->getStatus()->equals(ChargeStatus::chargedback())) {
540+
return $this->i18n->getDashboard('Charge chargedback.');
541+
}
542+
493543
$amountInCurrency = $this->moneyService->centsToFloat($charge->getRefundedAmount());
494544
$history = $this->i18n->getDashboard(
495545
'Charge canceled.'

0 commit comments

Comments
 (0)