|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file has been created by developers from BitBag. |
|
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
|
6
|
|
|
* another great project. |
|
7
|
|
|
* You can find more information about us on https://bitbag.shop and write us |
|
8
|
|
|
* an email on [email protected]. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
declare(strict_types=1); |
|
12
|
|
|
|
|
13
|
|
|
namespace spec\BitBag\SyliusQuadPayPlugin\Action; |
|
14
|
|
|
|
|
15
|
|
|
use BitBag\SyliusQuadPayPlugin\Action\ConvertPaymentAction; |
|
16
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
17
|
|
|
use Payum\Core\Action\ActionInterface; |
|
18
|
|
|
use Payum\Core\GatewayInterface; |
|
19
|
|
|
use Payum\Core\Request\Convert; |
|
20
|
|
|
use PhpSpec\ObjectBehavior; |
|
21
|
|
|
use Sylius\Bundle\PayumBundle\Provider\PaymentDescriptionProviderInterface; |
|
22
|
|
|
use Sylius\Component\Core\Model\AddressInterface; |
|
23
|
|
|
use Sylius\Component\Core\Model\CustomerInterface; |
|
24
|
|
|
use Sylius\Component\Core\Model\OrderInterface; |
|
25
|
|
|
use Sylius\Component\Core\Model\OrderItemInterface; |
|
26
|
|
|
use Sylius\Component\Core\Model\PaymentInterface; |
|
27
|
|
|
use Sylius\Component\Core\Model\ProductInterface; |
|
28
|
|
|
|
|
29
|
|
|
final class ConvertPaymentActionSpec extends ObjectBehavior |
|
30
|
|
|
{ |
|
31
|
|
|
function let(PaymentDescriptionProviderInterface $paymentDescriptionProvider): void |
|
|
|
|
|
|
32
|
|
|
{ |
|
33
|
|
|
$this->beConstructedWith($paymentDescriptionProvider); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
function it_is_initializable(): void |
|
|
|
|
|
|
37
|
|
|
{ |
|
38
|
|
|
$this->shouldHaveType(ConvertPaymentAction::class); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
function it_implements_action_interface(): void |
|
42
|
|
|
{ |
|
43
|
|
|
$this->shouldHaveType(ActionInterface::class); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
function it_executes( |
|
47
|
|
|
Convert $request, |
|
48
|
|
|
PaymentInterface $payment, |
|
49
|
|
|
OrderInterface $order, |
|
50
|
|
|
CustomerInterface $customer, |
|
51
|
|
|
GatewayInterface $gateway, |
|
52
|
|
|
PaymentDescriptionProviderInterface $paymentDescriptionProvider, |
|
53
|
|
|
AddressInterface $address, |
|
54
|
|
|
OrderItemInterface $orderItem, |
|
55
|
|
|
ProductInterface $product |
|
56
|
|
|
): void { |
|
57
|
|
|
$this->setGateway($gateway); |
|
|
|
|
|
|
58
|
|
|
$customer->getFullName()->willReturn('Jan Kowalski'); |
|
59
|
|
|
$customer->getEmail()->willReturn('[email protected]'); |
|
60
|
|
|
$customer->getId()->willReturn(1); |
|
61
|
|
|
$address->getPhoneNumber()->willReturn(353464674); |
|
62
|
|
|
$address->getCity()->willReturn('test'); |
|
63
|
|
|
$address->getStreet()->willReturn('test'); |
|
64
|
|
|
$address->getPostcode()->willReturn('353664'); |
|
65
|
|
|
$address->getLastName()->willReturn('test'); |
|
66
|
|
|
$address->getFirstName()->willReturn('test'); |
|
67
|
|
|
$address->getProvinceCode()->willReturn(null); |
|
68
|
|
|
$product->getShortDescription()->willReturn('description'); |
|
69
|
|
|
$product->getName()->willReturn('name'); |
|
70
|
|
|
$product->getCode()->willReturn('code'); |
|
71
|
|
|
$orderItem->getProduct()->willReturn($product); |
|
|
|
|
|
|
72
|
|
|
$orderItem->getQuantity()->willReturn(1); |
|
|
|
|
|
|
73
|
|
|
$orderItem->getUnitPrice()->willReturn(20); |
|
|
|
|
|
|
74
|
|
|
$order->getId()->willReturn(1); |
|
75
|
|
|
$order->getLocaleCode()->willReturn('pl_PL'); |
|
76
|
|
|
$order->getCustomer()->willReturn($customer); |
|
|
|
|
|
|
77
|
|
|
$order->getShippingAddress()->willReturn($address); |
|
|
|
|
|
|
78
|
|
|
$order->getBillingAddress()->willReturn($address); |
|
79
|
|
|
$order->getItems()->willReturn(new ArrayCollection([$orderItem->getWrappedObject()])); |
|
|
|
|
|
|
80
|
|
|
$order->getNumber()->willReturn('0000001'); |
|
81
|
|
|
$order->getTaxTotal()->willReturn(100); |
|
|
|
|
|
|
82
|
|
|
$order->getShippingTotal()->willReturn(100); |
|
|
|
|
|
|
83
|
|
|
$payment->getOrder()->willReturn($order); |
|
|
|
|
|
|
84
|
|
|
$payment->getAmount()->willReturn(445535); |
|
85
|
|
|
$payment->getCurrencyCode()->willReturn('EUR'); |
|
86
|
|
|
$paymentDescriptionProvider->getPaymentDescription($payment)->willReturn('description'); |
|
87
|
|
|
$request->getSource()->willReturn($payment); |
|
88
|
|
|
$request->getTo()->willReturn('array'); |
|
89
|
|
|
|
|
90
|
|
|
$request->setResult([ |
|
|
|
|
|
|
91
|
|
|
'amount' => '445535.00', |
|
92
|
|
|
'consumer' => [ |
|
93
|
|
|
'phoneNumber' => '353464674', |
|
94
|
|
|
'givenNames' => 'test', |
|
95
|
|
|
'surname' => 'test', |
|
96
|
|
|
'email' => '[email protected]', |
|
97
|
|
|
], |
|
98
|
|
|
'billing' => [ |
|
99
|
|
|
'addressLine1' => 'test', |
|
100
|
|
|
'addressLine2' => '', |
|
101
|
|
|
'city' => 'test', |
|
102
|
|
|
'postcode' => '353664', |
|
103
|
|
|
'state' => '', |
|
104
|
|
|
], |
|
105
|
|
|
'shipping' => [ |
|
106
|
|
|
'addressLine1' => 'test', |
|
107
|
|
|
'addressLine2' => '', |
|
108
|
|
|
'city' => 'test', |
|
109
|
|
|
'postcode' => '353664', |
|
110
|
|
|
'state' => '', |
|
111
|
|
|
], |
|
112
|
|
|
'description' => 'description', |
|
113
|
|
|
'items' => [ |
|
114
|
|
|
[ |
|
115
|
|
|
'description' => 'description', |
|
116
|
|
|
'name' => 'name', |
|
117
|
|
|
'sku' => 'code', |
|
118
|
|
|
'quantity' => 1, |
|
119
|
|
|
'price' => '20.00', |
|
120
|
|
|
], |
|
121
|
|
|
], |
|
122
|
|
|
'merchantReference' => '0000001', |
|
123
|
|
|
'taxAmount' => '100.00', |
|
124
|
|
|
'shippingAmount' => '100.00', |
|
125
|
|
|
] |
|
126
|
|
|
)->shouldBeCalled(); |
|
127
|
|
|
|
|
128
|
|
|
$this->execute($request); |
|
|
|
|
|
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
function it_supports_only_convert_request_payment_source_and_array_to( |
|
132
|
|
|
Convert $request, |
|
133
|
|
|
PaymentInterface $payment |
|
134
|
|
|
): void { |
|
135
|
|
|
$request->getSource()->willReturn($payment); |
|
136
|
|
|
$request->getTo()->willReturn('array'); |
|
137
|
|
|
|
|
138
|
|
|
$this->supports($request)->shouldReturn(true); |
|
|
|
|
|
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.