Skip to content

Commit

Permalink
Merge pull request #195 from mundipagg/develop-recurrence
Browse files Browse the repository at this point in the history
Merge develop recurrence into relase
  • Loading branch information
GabrielDeveloper authored Sep 22, 2020
2 parents 20a5120 + 6a8e023 commit c48c09d
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "mundipagg/ecommerce-module-core",
"description": "Core component for Mundipagg e-commerce platform modules.",
"license": "MIT",
"version": "2.4.7",
"version": "2.4.8",
"authors": [
{
"name": "MundiPagg Embeddables Team",
Expand Down
6 changes: 3 additions & 3 deletions src/Kernel/Services/ChargeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function capture(Charge $charge, $amount = 0)
$platformOrder->addHistoryComment($history);

$this->logService->info("Synchronizing with platform Order");
$orderService->syncPlatformWith($order);
$orderService->syncPlatformWith($order, false);

$this->logService->info("Change Order status");
$order->setStatus(OrderStatus::paid());
Expand Down Expand Up @@ -187,7 +187,7 @@ public function cancel(Charge $charge, $amount = 0)
$order->getPlatformOrder()->addHistoryComment($history);

$this->logService->info("Synchronizing with platform Order");
$orderService->syncPlatformWith($order);
$orderService->syncPlatformWith($order, false);

$platformOrderGrandTotal = $moneyService->floatToCents(
$platformOrder->getGrandTotal()
Expand All @@ -213,7 +213,7 @@ public function cancel(Charge $charge, $amount = 0)
$order->getPlatformOrder()->save();

$orderRepository->save($order);
$orderService->syncPlatformWith($order);
$orderService->syncPlatformWith($order, false);

$statusOrderLabel = $platformOrder->getStatusLabel(
$order->getStatus()
Expand Down
16 changes: 12 additions & 4 deletions src/Kernel/Services/OrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ public function __construct()
/**
*
* @param Order $order
* @param bool $changeStatus
*/
public function syncPlatformWith(Order $order)
public function syncPlatformWith(Order $order, $changeStatus = true)
{
$moneyService = new MoneyService();

Expand All @@ -65,6 +66,16 @@ public function syncPlatformWith(Order $order)
$platformOrder->setTotalRefunded($refundedAmount);
$platformOrder->setBaseTotalRefunded($refundedAmount);

if ($changeStatus) {
$this->changeOrderStatus($order);
}

$platformOrder->save();
}

public function changeOrderStatus(Order $order)
{
$platformOrder = $order->getPlatformOrder();
$orderStatus = $order->getStatus();
if ($orderStatus->equals(OrderStatus::paid())) {
$orderStatus = OrderStatus::processing();
Expand All @@ -74,10 +85,7 @@ public function syncPlatformWith(Order $order)
if (!$order->getPlatformOrder()->getState()->equals(OrderState::closed())) {
$platformOrder->setStatus($orderStatus);
}

$platformOrder->save();
}

public function updateAcquirerData(Order $order)
{
$dataServiceClass =
Expand Down
2 changes: 1 addition & 1 deletion src/Maintenance/Assets/integrityData

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Recurrence/Services/ResponseHandlers/ChargeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private function handleChargeStatusPaid(Charge $charge, $order)
$history = $this->prepareHistoryComment($charge);
$order->addHistoryComment($history);

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

$order->save();
}
Expand Down
8 changes: 4 additions & 4 deletions src/Webhook/Services/ChargeOrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ protected function handlePaid(Webhook $webhook)
$history = $this->prepareHistoryComment($charge);
$this->order->getPlatformOrder()->addHistoryComment($history);

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

$this->addWebHookReceivedHistory($webhook);
$platformOrder->save();
Expand Down Expand Up @@ -143,7 +143,7 @@ protected function handlePartialCanceled(Webhook $webhook)
$orderRepository->save($order);
$history = $this->prepareHistoryComment($charge);
$order->getPlatformOrder()->addHistoryComment($history);
$orderService->syncPlatformWith($order);
$orderService->syncPlatformWith($order, false);

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

Expand Down Expand Up @@ -214,7 +214,7 @@ protected function handleRefunded(Webhook $webhook)
$orderRepository->save($order);
$history = $this->prepareHistoryComment($charge);
$order->getPlatformOrder()->addHistoryComment($history);
$orderService->syncPlatformWith($order);
$orderService->syncPlatformWith($order, false);

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

Expand Down Expand Up @@ -275,7 +275,7 @@ protected function handlePaymentFailed(Webhook $webhook)
$orderRepository->save($order);
$history = $this->prepareHistoryComment($charge);
$order->getPlatformOrder()->addHistoryComment($history, false);
$orderService->syncPlatformWith($order);
$orderService->syncPlatformWith($order, false);

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

Expand Down
8 changes: 4 additions & 4 deletions src/Webhook/Services/ChargeRecurrenceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function handlePaid(Webhook $webhook)
);
$realOrder->addCharge($charge);

$orderService->syncPlatformWith($realOrder);
$orderService->syncPlatformWith($realOrder, false);

$platformOrder->save();

Expand Down Expand Up @@ -177,7 +177,7 @@ protected function handlePartialCanceled(Webhook $webhook)
);
$realOrder->addCharge($charge);

$orderService->syncPlatformWith($realOrder);
$orderService->syncPlatformWith($realOrder, false);

$returnMessage = $this->prepareReturnMessage($charge);
$result = [
Expand Down Expand Up @@ -252,7 +252,7 @@ protected function handleRefunded(Webhook $webhook)
);
$realOrder->addCharge($charge);

$orderService->syncPlatformWith($realOrder);
$orderService->syncPlatformWith($realOrder, false);

$returnMessage = $this->prepareReturnMessage($charge);
$result = [
Expand Down Expand Up @@ -353,7 +353,7 @@ protected function handleCreated(Webhook $webhook)
);

$realOrder->addCharge($charge);
$this->orderService->syncPlatformWith($realOrder);
$this->orderService->syncPlatformWith($realOrder, false);

$sender = $this->sendBoletoEmail($charge, $realOrder->getCode(), $platformOrder);

Expand Down

0 comments on commit c48c09d

Please sign in to comment.