Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5d94f8f

Browse files
committed
refund from PayPlug portal
1 parent 8f0fabe commit 5d94f8f

18 files changed

Lines changed: 438 additions & 62 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ jobs:
134134
- name: Composer - Install plugin
135135
working-directory: ./sylius
136136
run: |
137-
cp ../plugin/tests/Application/config/packages/framework.yaml config/packages/framework.yaml
138-
composer req "${{ env.package-name }}:*" --prefer-source
137+
cp ../plugin/tests/Application/config/packages/framework.yaml config/packages/framework.yaml
138+
composer req "${{ env.package-name }}:*" --prefer-source
139139
140140
- name: Sylius - Get test services from Plugin
141141
working-directory: ./sylius

features/admin/refunding_payplug_payment.feature

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,43 @@ Feature: Refunding order's PayPlug payment
1919
And I am viewing the summary of this order
2020

2121
@ui
22-
Scenario: Marking order's payment as refunded
23-
When I mark this order's payplug payment as refunded
24-
Then I should be notified that the order's payment has been successfully refunded
25-
And it should have payment with state refunded
22+
Scenario: Total refund order from PayPlug portal
23+
When I refund totally this order's from payplug portal
24+
And I want to refund some units of order "00000001"
25+
Then this order refunded total should be "$340.00"
26+
27+
@ui
28+
Scenario: Partial refund of one product from PayPlug portal
29+
When I refund partially this order's from payplug portal with 3.00
30+
And I want to refund some units of order "00000001"
31+
Then 1st "Green Arrow" product should have "$3.00" refunded
32+
And this order refunded total should be "$3.00"
33+
34+
@ui
35+
Scenario: Two Partial refund of one product from PayPlug portal
36+
When I refund partially this order's from payplug portal with 3.00
37+
When I refund partially this order's from payplug portal with 7.00
38+
And I want to refund some units of order "00000001"
39+
Then 1st "Green Arrow" product should have "$10.00" refunded
40+
And this order refunded total should be "$10.00"
41+
42+
@ui
43+
Scenario: Two Partial refund from PayPlug portal
44+
When I refund partially this order's from payplug portal with 13.00
45+
When I refund partially this order's from payplug portal with 17.00
46+
And I want to refund some units of order "00000001"
47+
Then 1st "Green Arrow" product should have "$10.00" refunded
48+
Then 1st "Red Arrow" product should have "$20.00" refunded
49+
And this order refunded total should be "$30.00"
2650

2751
@ui
28-
Scenario: Marking an order as refunded after refunding all its payments
29-
When I mark this order's payplug payment as refunded
30-
Then it should have payment with state refunded
31-
And it's payment state should be refunded
52+
Scenario: Two Partial refund with total amount from PayPlug portal
53+
When I refund partially this order's from payplug portal with 10.00
54+
When I refund partially this order's from payplug portal with 330.00
55+
And I want to refund some units of order "00000001"
56+
Then 1st "Green Arrow" product should have "$10.00" refunded
57+
Then 1st "Red Arrow" product should have "$330.00" refunded
58+
And this order refunded total should be "$340.00"
3259

3360
@ui
3461
Scenario: Should be able to refund using payplug payment

rulesets/phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ parameters:
22
level: max
33
reportUnmatchedIgnoredErrors: false
44
checkMissingIterableValueType: false
5+
checkGenericClassInNonGenericObjectType: false
56
excludes_analyse:
67
# Makes PHPStan crash
78
- ../src/DependencyInjection/Configuration.php

spec/Action/NotifyActionSpec.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Payplug\Resource\Payment;
88
use PayPlug\SyliusPayPlugPlugin\Action\NotifyAction;
99
use PayPlug\SyliusPayPlugPlugin\ApiClient\PayPlugApiClient;
10+
use PayPlug\SyliusPayPlugPlugin\PaymentProcessing\RefundPaymentHandlerInterface;
1011
use Payum\Core\Action\ActionInterface;
1112
use Payum\Core\ApiAwareInterface;
1213
use Payum\Core\GatewayAwareInterface;
@@ -17,9 +18,9 @@
1718

1819
final class NotifyActionSpec extends ObjectBehavior
1920
{
20-
function let(LoggerInterface $logger): void
21+
function let(LoggerInterface $logger, RefundPaymentHandlerInterface $refundPaymentHandler): void
2122
{
22-
$this->beConstructedWith($logger);
23+
$this->beConstructedWith($logger, $refundPaymentHandler);
2324
}
2425

2526
function it_is_initializable(): void

spec/Action/StatusActionSpec.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace spec\PayPlug\SyliusPayPlugPlugin\Action;
66

77
use PayPlug\SyliusPayPlugPlugin\Action\StatusAction;
8+
use PayPlug\SyliusPayPlugPlugin\PaymentProcessing\RefundPaymentHandlerInterface;
89
use Payum\Core\Action\ActionInterface;
910
use Payum\Core\GatewayAwareInterface;
1011
use Payum\Core\GatewayInterface;
@@ -15,9 +16,11 @@
1516

1617
final class StatusActionSpec extends ObjectBehavior
1718
{
18-
function let(FactoryInterface $stateMachineFactory): void
19-
{
20-
$this->beConstructedWith($stateMachineFactory);
19+
function let(
20+
FactoryInterface $stateMachineFactory,
21+
RefundPaymentHandlerInterface $refundPaymentHandler
22+
): void {
23+
$this->beConstructedWith($stateMachineFactory, $refundPaymentHandler);
2124
}
2225

2326
function it_is_initializable(): void

src/Action/NotifyAction.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PayPlug\SyliusPayPlugPlugin\Action\Api\ApiAwareTrait;
88
use PayPlug\SyliusPayPlugPlugin\ApiClient\PayPlugApiClientInterface;
9+
use PayPlug\SyliusPayPlugPlugin\PaymentProcessing\RefundPaymentHandlerInterface;
910
use Payum\Core\Action\ActionInterface;
1011
use Payum\Core\ApiAwareInterface;
1112
use Payum\Core\Bridge\Spl\ArrayObject;
@@ -18,12 +19,18 @@ final class NotifyAction implements ActionInterface, ApiAwareInterface, GatewayA
1819
{
1920
use GatewayAwareTrait, ApiAwareTrait;
2021

22+
/** @var RefundPaymentHandlerInterface */
23+
private $refundPaymentHandler;
24+
2125
/** @var LoggerInterface */
2226
private $logger;
2327

24-
public function __construct(LoggerInterface $logger)
25-
{
28+
public function __construct(
29+
LoggerInterface $logger,
30+
RefundPaymentHandlerInterface $refundPaymentHandler
31+
) {
2632
$this->logger = $logger;
33+
$this->refundPaymentHandler = $refundPaymentHandler;
2734
}
2835

2936
public function execute($request): void
@@ -44,8 +51,9 @@ public function execute($request): void
4451
return;
4552
}
4653

47-
if ($resource instanceof \Payplug\Resource\Refund && $resource->is_refunded) {
54+
if ($resource instanceof \Payplug\Resource\Refund) {
4855
$details['status'] = PayPlugApiClientInterface::REFUNDED;
56+
$this->refundPaymentHandler->handle($resource, $request->getFirstModel());
4957

5058
return;
5159
}

src/Action/StatusAction.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace PayPlug\SyliusPayPlugPlugin\Action;
66

77
use PayPlug\SyliusPayPlugPlugin\ApiClient\PayPlugApiClientInterface;
8+
use PayPlug\SyliusPayPlugPlugin\PaymentProcessing\RefundPaymentHandlerInterface;
89
use Payum\Core\Action\ActionInterface;
910
use Payum\Core\Exception\RequestNotSupportedException;
1011
use Payum\Core\GatewayAwareInterface;
@@ -22,9 +23,15 @@ final class StatusAction implements ActionInterface, GatewayAwareInterface
2223
/** @var \SM\Factory\FactoryInterface */
2324
private $stateMachineFactory;
2425

25-
public function __construct(FactoryInterface $stateMachineFactory)
26-
{
26+
/** @var RefundPaymentHandlerInterface */
27+
private $refundPaymentHandler;
28+
29+
public function __construct(
30+
FactoryInterface $stateMachineFactory,
31+
RefundPaymentHandlerInterface $refundPaymentHandler
32+
) {
2733
$this->stateMachineFactory = $stateMachineFactory;
34+
$this->refundPaymentHandler = $refundPaymentHandler;
2835
}
2936

3037
public function execute($request): void
@@ -85,7 +92,7 @@ private function markRequestAs(string $status, $request): void
8592

8693
break;
8794
case PayPlugApiClientInterface::REFUNDED:
88-
$request->markRefunded();
95+
$this->refundPaymentHandler->updatePaymentStatus($request->getModel());
8996

9097
break;
9198
default:

0 commit comments

Comments
 (0)