-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bug #296 Always create RefundPayment after CreditMemo (Zales0123)
This PR was merged into the 1.0-dev branch. Discussion ---------- Partially solves #91 With the current implementation, both **CreditMemo** and **RefundPayment** are generated separately, which can results in a situation when one of them exists and the other does not. With the proposed change, we're protected from such a situation. For sure, the solution is not perfect. The whole compensation/rollback functionality is based on the [DoctrineTransactionMiddleware](https://github.com/symfony/doctrine-bridge/blob/5.4/Messenger/DoctrineTransactionMiddleware.php#L37), which works in this case but does not have to be enough for some more complicated processes. A possible improvement of the proposed architecture would be adding the `prev/compensate/rollback` function to the `UnitsRefundedProcessStepInterface` to implement a more mature and reliable saga pattern 🖖 Commits ------- 261e0d3 Change current process manager to process steps 82f42a1 Describe desired post-refund behaviour with scenarios 7cf06b7 Tag services and document the whole process 90db258 PR review fixes
- Loading branch information
Showing
20 changed files
with
366 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
features/not_seeing_refund_payments_and_credit_memos_on_admin_order_view.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
@refunds | ||
Feature: Not seeing refund payments and credit memos on admin order view | ||
In order to have consistent documents and payment in a refunded order | ||
As an Administrator | ||
I don't want to have a credit memo or refund payment generated alone | ||
|
||
Background: | ||
Given the store operates on a single green channel in "United States" | ||
And the store has a product "Mr. Meeseeks T-Shirt" priced at "$10.00" | ||
And the store has a product "Angel T-Shirt" priced at "$5.00" | ||
And the store allows shipping with "Galaxy Post" | ||
And the store allows paying with "Space money" | ||
And there is a customer "[email protected]" that placed an order "#00000023" | ||
And the customer bought 2 "Mr. Meeseeks T-Shirt" products | ||
And the customer chose "Galaxy Post" shipping method to "United States" with "Space money" payment | ||
And the order "#00000023" is already paid | ||
And I am logged in as an administrator | ||
|
||
@ui | ||
Scenario: Not seeing credit memo and refund payment on order view if credit memo generation failed | ||
Given the credit memo generation is broken | ||
And I decided to refund 1st "Mr. Meeseeks T-Shirt" product of the order "00000023" with "Space money" payment | ||
When I view the summary of the order "#00000023" | ||
Then I should not see any refund payments | ||
And I should not see any credit memos | ||
|
||
@ui | ||
Scenario: Not seeing credit memo and refund payment on order view if refund generation failed | ||
Given the refund payment generation is broken | ||
And I decided to refund 1st "Mr. Meeseeks T-Shirt" product of the order "00000023" with "Space money" payment | ||
When I view the summary of the order "#00000023" | ||
Then I should not see any refund payments | ||
And I should not see any credit memos |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\Sylius\RefundPlugin\ProcessManager; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Sylius\RefundPlugin\Event\UnitsRefunded; | ||
use Sylius\RefundPlugin\Model\OrderItemUnitRefund; | ||
use Sylius\RefundPlugin\Model\ShipmentRefund; | ||
use Sylius\RefundPlugin\ProcessManager\UnitsRefundedProcessManagerInterface; | ||
use Sylius\RefundPlugin\ProcessManager\UnitsRefundedProcessStepInterface; | ||
|
||
final class UnitsRefundedProcessManagerSpec extends ObjectBehavior | ||
{ | ||
function let( | ||
UnitsRefundedProcessStepInterface $creditMemoProcessManager, | ||
UnitsRefundedProcessStepInterface $refundPaymentProcessManager | ||
): void { | ||
$this->beConstructedWith([$creditMemoProcessManager, $refundPaymentProcessManager]); | ||
} | ||
|
||
function it_implements_units_refunded_process_manager_interface(): void | ||
{ | ||
$this->shouldImplement(UnitsRefundedProcessManagerInterface::class); | ||
} | ||
|
||
function it_triggers_all_process_steps_if_all_are_successful( | ||
UnitsRefundedProcessStepInterface $creditMemoProcessManager, | ||
UnitsRefundedProcessStepInterface $refundPaymentProcessManager | ||
): void { | ||
$unitRefunds = [new OrderItemUnitRefund(1, 1000), new OrderItemUnitRefund(3, 2000), new OrderItemUnitRefund(5, 3000)]; | ||
$shipmentRefunds = [new ShipmentRefund(1, 500), new ShipmentRefund(2, 1000)]; | ||
$event = new UnitsRefunded('000222', $unitRefunds, $shipmentRefunds, 1, 1500, 'USD', 'Comment'); | ||
|
||
$creditMemoProcessManager->next($event)->shouldBeCalled(); | ||
$refundPaymentProcessManager->next($event)->shouldBeCalled(); | ||
|
||
$this($event); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\RefundPlugin\ProcessManager; | ||
|
||
use Sylius\RefundPlugin\Event\UnitsRefunded; | ||
|
||
final class UnitsRefundedProcessManager implements UnitsRefundedProcessManagerInterface | ||
{ | ||
/** @var iterable|UnitsRefundedProcessStepInterface[] */ | ||
private $steps; | ||
|
||
public function __construct(iterable $steps) | ||
{ | ||
$this->steps = $steps; | ||
} | ||
|
||
public function __invoke(UnitsRefunded $event): void | ||
{ | ||
/** @var UnitsRefundedProcessStepInterface $step */ | ||
foreach ($this->steps as $step) { | ||
$step->next($event); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/ProcessManager/UnitsRefundedProcessManagerInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\RefundPlugin\ProcessManager; | ||
|
||
use Sylius\RefundPlugin\Event\UnitsRefunded; | ||
|
||
interface UnitsRefundedProcessManagerInterface | ||
{ | ||
public function __invoke(UnitsRefunded $event): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\RefundPlugin\ProcessManager; | ||
|
||
use Sylius\RefundPlugin\Event\UnitsRefunded; | ||
|
||
interface UnitsRefundedProcessStepInterface | ||
{ | ||
public function next(UnitsRefunded $unitsRefunded): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
imports: | ||
- { resource: "../../../vendor/sylius/sylius/src/Sylius/Behat/Resources/config/services.xml" } | ||
- { resource: "../../Behat/Resources/services.xml" } | ||
|
||
services: | ||
Tests\Sylius\RefundPlugin\Behat\Services\Generator\FailedCreditMemoGenerator: | ||
decorates: 'Sylius\RefundPlugin\Generator\CreditMemoGenerator' | ||
arguments: | ||
- '@Tests\Sylius\RefundPlugin\Behat\Services\Generator\FailedCreditMemoGenerator.inner' | ||
|
||
Tests\Sylius\RefundPlugin\Behat\Services\Factory\FailedRefundPaymentFactory: | ||
decorates: 'Sylius\RefundPlugin\Factory\RefundPaymentFactory' | ||
arguments: | ||
- '@Tests\Sylius\RefundPlugin\Behat\Services\Factory\FailedRefundPaymentFactory.inner' |
Oops, something went wrong.