Skip to content

Commit 3a34086

Browse files
authored
Merge pull request #49 from pplotka/configurable-transaction-description
Make transaction description configurable.
2 parents 6b8be8a + d9d2ce1 commit 3a34086

File tree

5 files changed

+57
-9
lines changed

5 files changed

+57
-9
lines changed

src/Action/CaptureAction.php

+16-6
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,11 @@
2525
use Payum\Core\Security\GenericTokenFactoryAwareInterface;
2626
use Payum\Core\Security\GenericTokenFactoryInterface;
2727
use Payum\Core\Security\TokenInterface;
28+
use Sylius\Bundle\PayumBundle\Provider\PaymentDescriptionProviderInterface;
2829
use Sylius\Component\Core\Model\CustomerInterface;
2930
use Sylius\Component\Core\Model\OrderInterface;
3031
use Sylius\Component\Core\Model\OrderItemInterface;
32+
use Sylius\Component\Core\Model\PaymentInterface;
3133
use Webmozart\Assert\Assert;
3234

3335
final class CaptureAction implements ActionInterface, ApiAwareInterface, GenericTokenFactoryAwareInterface, GatewayAwareInterface
@@ -37,12 +39,18 @@ final class CaptureAction implements ActionInterface, ApiAwareInterface, Generic
3739
/** @var OpenPayUBridgeInterface */
3840
private $openPayUBridge;
3941

42+
/** @var PaymentDescriptionProviderInterface */
43+
private $paymentDescriptionProvider;
44+
4045
/** @var GenericTokenFactoryInterface */
4146
private $tokenFactory;
4247

43-
public function __construct(OpenPayUBridgeInterface $openPayUBridge)
44-
{
48+
public function __construct(
49+
OpenPayUBridgeInterface $openPayUBridge,
50+
PaymentDescriptionProviderInterface $paymentDescriptionProvider
51+
) {
4552
$this->openPayUBridge = $openPayUBridge;
53+
$this->paymentDescriptionProvider = $paymentDescriptionProvider;
4654
}
4755

4856
/**
@@ -67,12 +75,14 @@ public function execute($request): void
6775
{
6876
RequestNotSupportedException::assertSupports($this, $request);
6977
$model = $request->getModel();
78+
/** @var PaymentInterface $payment */
79+
$payment = $request->getFirstModel();
7080
/** @var OrderInterface $orderData */
71-
$order = $request->getFirstModel()->getOrder();
81+
$order = $payment->getOrder();
7282

7383
/** @var TokenInterface $token */
7484
$token = $request->getToken();
75-
$payUdata = $this->prepareOrder($token, $order);
85+
$payUdata = $this->prepareOrder($token, $order, $payment);
7686

7787
$result = $this->openPayUBridge->create($payUdata);
7888

@@ -116,7 +126,7 @@ public function supports($request): bool
116126
&& $request->getModel() instanceof ArrayObject;
117127
}
118128

119-
private function prepareOrder(TokenInterface $token, OrderInterface $order): array
129+
private function prepareOrder(TokenInterface $token, OrderInterface $order, PaymentInterface $payment): array
120130
{
121131
$notifyToken = $this->tokenFactory->createNotifyToken($token->getGatewayName(), $token->getDetails());
122132
$payUdata = [];
@@ -125,7 +135,7 @@ private function prepareOrder(TokenInterface $token, OrderInterface $order): arr
125135
$payUdata['notifyUrl'] = $notifyToken->getTargetUrl();
126136
$payUdata['customerIp'] = $order->getCustomerIp();
127137
$payUdata['merchantPosId'] = OpenPayU_Configuration::getMerchantPosId();
128-
$payUdata['description'] = $order->getNumber();
138+
$payUdata['description'] = $this->paymentDescriptionProvider->getPaymentDescription($payment);
129139
$payUdata['currencyCode'] = $order->getCurrencyCode();
130140
$payUdata['totalAmount'] = $order->getTotal();
131141
/** @var CustomerInterface $customer */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file was created by developers working at BitBag
5+
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
6+
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
7+
*/
8+
9+
declare(strict_types=1);
10+
11+
namespace BitBag\SyliusPayUPlugin\Provider;
12+
13+
use Sylius\Bundle\PayumBundle\Provider\PaymentDescriptionProviderInterface;
14+
use Sylius\Component\Core\Model\PaymentInterface;
15+
16+
final class PaymentDescriptionProvider implements PaymentDescriptionProviderInterface
17+
{
18+
public function getPaymentDescription(PaymentInterface $payment): string
19+
{
20+
$order = $payment->getOrder();
21+
22+
return $order->getNumber();
23+
}
24+
}

src/Resources/config/services/action.xml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
<service id="bitbag.payu_plugin.action.capture" class="BitBag\SyliusPayUPlugin\Action\CaptureAction">
88
<argument type="service" id="bitbag.payu_plugin.bridge.open_payu"/>
9+
<argument type="service" id="bitbag.payu_plugin.provider.payment_description_provider"/>
910
<tag name="payum.action" factory="payu" alias="payum.action.capture"/>
1011
</service>
1112

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
3+
<services>
4+
5+
<defaults public="true" autoconfigure="false" autowire="false"/>
6+
7+
<service id="bitbag.payu_plugin.provider.payment_description_provider" class="BitBag\SyliusPayUPlugin\Provider\PaymentDescriptionProvider">
8+
</service>
9+
</services>
10+
</container>

tests/spec/Action/CaptureActionSpec.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,18 @@
2121
use Payum\Core\Request\Capture;
2222
use Payum\Core\Security\TokenInterface;
2323
use PhpSpec\ObjectBehavior;
24+
use Sylius\Bundle\PayumBundle\Provider\PaymentDescriptionProviderInterface;
2425
use Sylius\Component\Core\Model\CustomerInterface;
2526
use Sylius\Component\Core\Model\OrderInterface;
2627
use Sylius\Component\Core\Model\OrderItemInterface;
2728

2829
final class CaptureActionSpec extends ObjectBehavior
2930
{
30-
function let(OpenPayUBridgeInterface $openPayUBridge): void
31-
{
32-
$this->beConstructedWith($openPayUBridge);
31+
function let(
32+
OpenPayUBridgeInterface $openPayUBridge,
33+
PaymentDescriptionProviderInterface $paymentDescriptionProvider
34+
): void {
35+
$this->beConstructedWith($openPayUBridge, $paymentDescriptionProvider);
3336
}
3437

3538
function it_is_initializable(): void

0 commit comments

Comments
 (0)