1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace spec\Sylius\Bundle\PayumBundle\Action\Paypal\ExpressCheckout; |
15
|
|
|
|
16
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
17
|
|
|
use Payum\Core\Action\ActionInterface; |
18
|
|
|
use Payum\Core\Exception\RequestNotSupportedException; |
19
|
|
|
use Payum\Core\Request\Convert; |
20
|
|
|
use PhpSpec\ObjectBehavior; |
21
|
|
|
use Sylius\Component\Core\Model\AddressInterface; |
22
|
|
|
use Sylius\Component\Core\Model\AdjustmentInterface; |
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
|
|
|
use Sylius\Component\Core\Model\ProductVariantInterface; |
29
|
|
|
use Sylius\Component\Core\Payment\InvoiceNumberGeneratorInterface; |
30
|
|
|
|
31
|
|
|
final class ConvertPaymentActionSpec extends ObjectBehavior |
32
|
|
|
{ |
33
|
|
|
function let(InvoiceNumberGeneratorInterface $invoiceNumberGenerator): void |
34
|
|
|
{ |
35
|
|
|
$this->beConstructedWith($invoiceNumberGenerator); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
function it_implements_action_interface(): void |
39
|
|
|
{ |
40
|
|
|
$this->shouldImplement(ActionInterface::class); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
function it_executes_request( |
44
|
|
|
InvoiceNumberGeneratorInterface $invoiceNumberGenerator, |
45
|
|
|
Convert $request, |
46
|
|
|
PaymentInterface $payment, |
47
|
|
|
OrderInterface $order, |
48
|
|
|
OrderItemInterface $orderItem, |
49
|
|
|
ProductVariantInterface $productVariant, |
50
|
|
|
ProductInterface $product, |
51
|
|
|
CustomerInterface $customer, |
52
|
|
|
AddressInterface $billingAddress |
53
|
|
|
): void { |
54
|
|
|
$request->getTo()->willReturn('array'); |
55
|
|
|
|
56
|
|
|
$payment->getId()->willReturn(19); |
57
|
|
|
|
58
|
|
|
$order->getId()->willReturn(92); |
59
|
|
|
$order->getId()->willReturn(92); |
60
|
|
|
$order->getCurrencyCode()->willReturn('PLN'); |
61
|
|
|
$order->getTotal()->willReturn(88000); |
62
|
|
|
$order->getItems()->willReturn(new ArrayCollection([$orderItem->getWrappedObject()])); |
63
|
|
|
$order->getAdjustmentsTotalRecursively(AdjustmentInterface::TAX_ADJUSTMENT)->willReturn(0); |
64
|
|
|
$order->getOrderPromotionTotal()->willReturn(0); |
65
|
|
|
$order->getShippingTotal()->willReturn(8000); |
66
|
|
|
|
67
|
|
|
$orderItem->getVariant()->willReturn($productVariant); |
68
|
|
|
$orderItem->getDiscountedUnitPrice()->willReturn(80000); |
69
|
|
|
$orderItem->getQuantity()->willReturn(1); |
70
|
|
|
|
71
|
|
|
$productVariant->getProduct()->willReturn($product); |
72
|
|
|
|
73
|
|
|
$product->getName()->willReturn('Lamborghini Aventador Model'); |
74
|
|
|
|
75
|
|
|
$order->getCustomer()->willReturn($customer); |
76
|
|
|
$customer->getEmail()->willReturn('[email protected]'); |
77
|
|
|
|
78
|
|
|
$order->getBillingAddress()->willReturn($billingAddress); |
79
|
|
|
$billingAddress->getCountryCode()->willReturn('US'); |
80
|
|
|
$billingAddress->getFullName()->willReturn('John Doe'); |
81
|
|
|
$billingAddress->getStreet()->willReturn('Main St. 123'); |
82
|
|
|
$billingAddress->getCity()->willReturn('New York'); |
83
|
|
|
$billingAddress->getPostcode()->willReturn('20500'); |
84
|
|
|
$billingAddress->getPhoneNumber()->willReturn('888222111'); |
85
|
|
|
$billingAddress->getProvinceCode()->willReturn('NY'); |
86
|
|
|
|
87
|
|
|
$request->getSource()->willReturn($payment); |
88
|
|
|
$payment->getOrder()->willReturn($order); |
89
|
|
|
|
90
|
|
|
$invoiceNumberGenerator->generate($order, $payment)->willReturn('19-92'); |
91
|
|
|
$details = [ |
92
|
|
|
'PAYMENTREQUEST_0_INVNUM' => '19-92', |
93
|
|
|
'PAYMENTREQUEST_0_CURRENCYCODE' => 'PLN', |
94
|
|
|
'PAYMENTREQUEST_0_AMT' => 880.00, |
95
|
|
|
'PAYMENTREQUEST_0_ITEMAMT' => 880.00, |
96
|
|
|
'EMAIL' => '[email protected]', |
97
|
|
|
'LOCALECODE' => 'US', |
98
|
|
|
'PAYMENTREQUEST_0_SHIPTONAME' => 'John Doe', |
99
|
|
|
'PAYMENTREQUEST_0_SHIPTOSTREET' => 'Main St. 123', |
100
|
|
|
'PAYMENTREQUEST_0_SHIPTOCITY' => 'New York', |
101
|
|
|
'PAYMENTREQUEST_0_SHIPTOZIP' => '20500', |
102
|
|
|
'PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE' => 'US', |
103
|
|
|
'PAYMENTREQUEST_0_SHIPTOPHONENUM' => '888222111', |
104
|
|
|
'PAYMENTREQUEST_0_SHIPTOSTATE' => 'NY', |
105
|
|
|
'L_PAYMENTREQUEST_0_NAME0' => 'Lamborghini Aventador Model', |
106
|
|
|
'L_PAYMENTREQUEST_0_AMT0' => 800.00, |
107
|
|
|
'L_PAYMENTREQUEST_0_QTY0' => 1, |
108
|
|
|
'L_PAYMENTREQUEST_0_NAME1' => 'Shipping Total', |
109
|
|
|
'L_PAYMENTREQUEST_0_AMT1' => 80.00, |
110
|
|
|
'L_PAYMENTREQUEST_0_QTY1' => 1, |
111
|
|
|
]; |
112
|
|
|
|
113
|
|
|
$request->setResult($details)->shouldBeCalled(); |
114
|
|
|
|
115
|
|
|
$this->execute($request); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
function it_throws_exception_when_source_is_not_a_payment_interface(Convert $request): void |
119
|
|
|
{ |
120
|
|
|
$request->getSource()->willReturn(null); |
121
|
|
|
|
122
|
|
|
$this |
123
|
|
|
->shouldThrow(RequestNotSupportedException::class) |
124
|
|
|
->during('execute', [$request]) |
125
|
|
|
; |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
|