|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Loevgaard\DandomainAltapayBundle\Tests\PayloadGenerator; |
|
4
|
|
|
|
|
5
|
|
|
use Loevgaard\AltaPay\Payload\OrderLine as OrderLinePayload; |
|
6
|
|
|
use Loevgaard\AltaPay\Payload\PaymentRequest\Config as ConfigPayload; |
|
7
|
|
|
use Loevgaard\AltaPay\Payload\PaymentRequest\CustomerInfo as CustomerInfoPayload; |
|
8
|
|
|
use Loevgaard\Dandomain\Pay\Helper\ChecksumHelper; |
|
9
|
|
|
use Loevgaard\Dandomain\Pay\Model\Payment as DandomainPayment; |
|
10
|
|
|
use Loevgaard\DandomainAltapayBundle\Entity\Payment; |
|
11
|
|
|
use Loevgaard\DandomainAltapayBundle\Entity\Terminal; |
|
12
|
|
|
use Loevgaard\DandomainAltapayBundle\Tests\PayloadGenerator\Fixture\Gateway; |
|
13
|
|
|
use Money\Currency; |
|
14
|
|
|
use Money\Money; |
|
15
|
|
|
use PHPUnit\Framework\TestCase; |
|
16
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
17
|
|
|
use Symfony\Component\Routing\RouterInterface; |
|
18
|
|
|
|
|
19
|
|
|
final class PaymentRequestPayloadGeneratorTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
public function testCreateOrderLine() |
|
22
|
|
|
{ |
|
23
|
|
|
$generator = $this->getGenerator(); |
|
24
|
|
|
|
|
25
|
|
|
$description = 'description'; |
|
26
|
|
|
$itemId = 'itemid'; |
|
27
|
|
|
$quantity = 1.0; |
|
28
|
|
|
$unitPrice = new Money(9995, new Currency('DKK')); |
|
29
|
|
|
|
|
30
|
|
|
// without optional parameters |
|
31
|
|
|
$payload = $generator->createOrderLine($description, $itemId, $quantity, $unitPrice); |
|
32
|
|
|
$this->assertInstanceOf(OrderLinePayload::class, $payload); |
|
33
|
|
|
$this->assertSame($description, $payload->getDescription()); |
|
34
|
|
|
$this->assertSame($itemId, $payload->getItemId()); |
|
35
|
|
|
$this->assertSame($quantity, $payload->getQuantity()); |
|
36
|
|
|
$this->assertEquals($unitPrice, $payload->getUnitPrice()); |
|
37
|
|
|
|
|
38
|
|
|
// with tax percent |
|
39
|
|
|
$taxPercent = 25.0; |
|
40
|
|
|
$payload = $generator->createOrderLine($description, $itemId, $quantity, $unitPrice, $taxPercent); |
|
41
|
|
|
$this->assertInstanceOf(OrderLinePayload::class, $payload); |
|
42
|
|
|
$this->assertSame($description, $payload->getDescription()); |
|
43
|
|
|
$this->assertSame($itemId, $payload->getItemId()); |
|
44
|
|
|
$this->assertSame($quantity, $payload->getQuantity()); |
|
45
|
|
|
$this->assertEquals($unitPrice, $payload->getUnitPrice()); |
|
46
|
|
|
$this->assertSame($taxPercent, $payload->getTaxPercent()); |
|
47
|
|
|
|
|
48
|
|
|
// with goods type |
|
49
|
|
|
$goodsType = OrderLinePayload::GOODS_TYPE_ITEM; |
|
50
|
|
|
$payload = $generator->createOrderLine($description, $itemId, $quantity, $unitPrice, null, $goodsType); |
|
51
|
|
|
$this->assertInstanceOf(OrderLinePayload::class, $payload); |
|
52
|
|
|
$this->assertSame($description, $payload->getDescription()); |
|
53
|
|
|
$this->assertSame($itemId, $payload->getItemId()); |
|
54
|
|
|
$this->assertSame($quantity, $payload->getQuantity()); |
|
55
|
|
|
$this->assertEquals($unitPrice, $payload->getUnitPrice()); |
|
56
|
|
|
$this->assertSame($goodsType, $payload->getGoodsType()); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testCreateCustomerInfo() |
|
60
|
|
|
{ |
|
61
|
|
|
$generator = $this->getGenerator(); |
|
62
|
|
|
|
|
63
|
|
|
$billingFirstName = 'billingfirstname'; |
|
64
|
|
|
$billingLastName = 'billinglastname'; |
|
65
|
|
|
$billingAddress = 'billingaddress'; |
|
66
|
|
|
$billingPostal = 'billingpostal'; |
|
67
|
|
|
$billingCity = 'billingcity'; |
|
68
|
|
|
$billingCountry = 'billingcountry'; |
|
69
|
|
|
$shippingFirstName = 'shippingfirstname'; |
|
70
|
|
|
$shippingLastName = 'shippinglastname'; |
|
71
|
|
|
$shippingAddress = 'shippingaddress'; |
|
72
|
|
|
$shippingPostal = 'shippingpostal'; |
|
73
|
|
|
$shippingCity = 'shippingcity'; |
|
74
|
|
|
$shippingCountry = 'shippingcountry'; |
|
75
|
|
|
|
|
76
|
|
|
// without optional parameters |
|
77
|
|
|
$payload = $generator->createCustomerInfo($billingFirstName, $billingLastName, $billingAddress, $billingPostal, $billingCity, $billingCountry, $shippingFirstName, $shippingLastName, $shippingAddress, $shippingPostal, $shippingCity, $shippingCountry); |
|
78
|
|
|
$this->assertInstanceOf(CustomerInfoPayload::class, $payload); |
|
79
|
|
|
$this->assertSame($billingFirstName, $payload->getBillingFirstName()); |
|
80
|
|
|
$this->assertSame($billingLastName, $payload->getBillingLastName()); |
|
81
|
|
|
$this->assertSame($billingAddress, $payload->getBillingAddress()); |
|
82
|
|
|
$this->assertSame($billingPostal, $payload->getBillingPostal()); |
|
83
|
|
|
$this->assertSame($billingCity, $payload->getBillingCity()); |
|
84
|
|
|
$this->assertSame($billingCountry, $payload->getBillingCountry()); |
|
85
|
|
|
$this->assertSame($shippingFirstName, $payload->getShippingFirstName()); |
|
86
|
|
|
$this->assertSame($shippingLastName, $payload->getShippingLastName()); |
|
87
|
|
|
$this->assertSame($shippingAddress, $payload->getShippingAddress()); |
|
88
|
|
|
$this->assertSame($shippingPostal, $payload->getShippingPostal()); |
|
89
|
|
|
$this->assertSame($shippingCity, $payload->getShippingCity()); |
|
90
|
|
|
$this->assertSame($shippingCountry, $payload->getShippingCountry()); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function testCreateConfig() |
|
94
|
|
|
{ |
|
95
|
|
|
$generator = $this->getGenerator(); |
|
96
|
|
|
|
|
97
|
|
|
$callbackForm = 'form'; |
|
98
|
|
|
$callbackOk = 'ok'; |
|
99
|
|
|
$callbackFail = 'fail'; |
|
100
|
|
|
$callbackRedirect = 'redirect'; |
|
101
|
|
|
$callbackOpen = 'open'; |
|
102
|
|
|
$callbackNotification = 'notification'; |
|
103
|
|
|
|
|
104
|
|
|
// without optional parameters |
|
105
|
|
|
$payload = $generator->createConfig($callbackForm, $callbackOk, $callbackFail, $callbackRedirect, $callbackOpen, $callbackNotification); |
|
106
|
|
|
$this->assertInstanceOf(ConfigPayload::class, $payload); |
|
107
|
|
|
$this->assertSame($callbackForm, $payload->getCallbackForm()); |
|
108
|
|
|
$this->assertSame($callbackOk, $payload->getCallbackOk()); |
|
109
|
|
|
$this->assertSame($callbackFail, $payload->getCallbackFail()); |
|
110
|
|
|
$this->assertSame($callbackRedirect, $payload->getCallbackRedirect()); |
|
111
|
|
|
$this->assertSame($callbackOpen, $payload->getCallbackOpen()); |
|
112
|
|
|
$this->assertSame($callbackNotification, $payload->getCallbackNotification()); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
private function getGenerator() |
|
116
|
|
|
{ |
|
117
|
|
|
$container = $this->getContainer(); |
|
118
|
|
|
$router = $this->getRouter(); |
|
119
|
|
|
$dandomainPayment = $this->getDandomainPayment(); |
|
120
|
|
|
$terminal = $this->getTerminal(); |
|
121
|
|
|
$payment = $this->getPayment(); |
|
122
|
|
|
$handler = $this->getChecksumHelper($dandomainPayment); |
|
123
|
|
|
|
|
124
|
|
|
$generator = new Gateway($container, $router, $dandomainPayment, $terminal, $payment, $handler); |
|
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
return $generator; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|ContainerInterface |
|
131
|
|
|
*/ |
|
132
|
|
|
private function getContainer() |
|
133
|
|
|
{ |
|
134
|
|
|
$container = $this->getMockForAbstractClass(ContainerInterface::class); |
|
135
|
|
|
|
|
136
|
|
|
return $container; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|RouterInterface |
|
141
|
|
|
*/ |
|
142
|
|
|
private function getRouter() |
|
143
|
|
|
{ |
|
144
|
|
|
$router = $this->createMock(RouterInterface::class); |
|
145
|
|
|
|
|
146
|
|
|
return $router; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
private function getDandomainPayment() |
|
150
|
|
|
{ |
|
151
|
|
|
$paymentRequest = new DandomainPayment(); |
|
152
|
|
|
|
|
153
|
|
|
return $paymentRequest; |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* @return Terminal |
|
158
|
|
|
*/ |
|
159
|
|
|
private function getTerminal() |
|
160
|
|
|
{ |
|
161
|
|
|
return new Terminal(); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
|
|
/** |
|
165
|
|
|
* @return Payment|\PHPUnit_Framework_MockObject_MockObject |
|
166
|
|
|
*/ |
|
167
|
|
|
private function getPayment() |
|
168
|
|
|
{ |
|
169
|
|
|
$payment = $this->getMockForAbstractClass(Payment::class); |
|
170
|
|
|
|
|
171
|
|
|
return $payment; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
private function getChecksumHelper(DandomainPayment $payment) |
|
175
|
|
|
{ |
|
176
|
|
|
$checksumHelper = new ChecksumHelper($payment, 'sharedkey1', 'sharedkey2'); |
|
177
|
|
|
|
|
178
|
|
|
return $checksumHelper; |
|
179
|
|
|
} |
|
180
|
|
|
} |
|
181
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.