Skip to content

Commit e97e644

Browse files
authored
Merge pull request #51 from paynl/extrafields
Added stats field to PayOrder class
2 parents f8613b2 + e23cfad commit e97e644

4 files changed

Lines changed: 165 additions & 9 deletions

File tree

Tests/Unit/Model/PayOrderTest.php

Lines changed: 77 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ public function testConstructorMapsPayloadObject(): void
1414
{
1515
$payload = [
1616
'object' => [
17-
'id' => 'PO-123',
18-
'description' => 'Test order',
19-
'reference' => 'REF-999',
20-
'status' => ['code' => 200, 'action' => 'PAID'],
21-
'amount' => ['value' => 1000, 'currency' => 'EUR'],
22-
'capturedAmount' => ['value' => 500, 'currency' => 'EUR'],
23-
'authorizedAmount'=> ['value' => 1000, 'currency' => 'EUR'],
17+
'id' => 'PO-123',
18+
'description' => 'Test order',
19+
'reference' => 'REF-999',
20+
'status' => ['code' => 200, 'action' => 'PAID'],
21+
'amount' => ['value' => 1000, 'currency' => 'EUR'],
22+
'capturedAmount' => ['value' => 500, 'currency' => 'EUR'],
23+
'authorizedAmount' => ['value' => 1000, 'currency' => 'EUR'],
2424
],
2525
];
2626

@@ -42,7 +42,7 @@ public function testAmountRefundedIsNullWhenNotSet(): void
4242

4343
public function testAmountRefundedReturnsValueInUnits(): void
4444
{
45-
$order = new PayOrder();
45+
$order = new PayOrder();
4646
$amount = new Amount(1234, 'EUR');
4747

4848
$order->setAmountRefunded($amount);
@@ -124,6 +124,7 @@ public function testPaymentHelpersReturnNullWhenNoPayments(): void
124124
$this->assertNull($order->getPaymentMethod());
125125
$this->assertNull($order->getCustomerId());
126126
$this->assertNull($order->getCustomerName());
127+
$this->assertSame([], $order->getPayments());
127128
}
128129

129130
public function testIsTestmodeTrueWhenIntegrationTestFlagTrue(): void
@@ -146,6 +147,13 @@ public function testIsTestmodeFalseWhenIntegrationTestFlagMissingOrFalse(): void
146147
$this->assertFalse($order->isTestmode());
147148
}
148149

150+
public function testCheckoutDataReturnsEmptyArrayWhenNotSet(): void
151+
{
152+
$order = new PayOrder();
153+
154+
$this->assertSame([], $order->getCheckoutData());
155+
}
156+
149157
public function testAmountAndCurrency(): void
150158
{
151159
$order = new PayOrder();
@@ -157,6 +165,21 @@ public function testAmountAndCurrency(): void
157165
$this->assertSame('EUR', $order->getCurrency());
158166
}
159167

168+
public function testAuthorizedAndCapturedAmountGettersAndSetters(): void
169+
{
170+
$order = new PayOrder();
171+
$authorized = new Amount(1000, 'EUR');
172+
$captured = new Amount(500, 'EUR');
173+
174+
$this->assertNull($order->getAuthorizedAmount());
175+
$this->assertNull($order->getCapturedAmount());
176+
177+
$order->setAuthorizedAmount($authorized);
178+
$order->setCapturedAmount($captured);
179+
180+
$this->assertSame($authorized, $order->getAuthorizedAmount());
181+
$this->assertSame($captured, $order->getCapturedAmount());
182+
}
160183

161184
public function testPaymentAndStatusUrls(): void
162185
{
@@ -192,8 +215,53 @@ public function testTransferDataGetterAndSetter(): void
192215
$data = ['some' => 'value', 'foo' => 'bar'];
193216

194217
$order->setTransferData($data);
195-
196218
$this->assertSame($data, $order->getTransferData());
219+
220+
$order->setTransferData(null);
221+
$this->assertNull($order->getTransferData());
197222
}
198223

224+
public function testStatsGettersReturnNullWhenNotSet(): void
225+
{
226+
$order = new PayOrder();
227+
228+
// Typed property $stats is not initialized unless setStats() is called
229+
$order->setStats([]);
230+
231+
$this->assertSame([], $order->getStats());
232+
$this->assertNull($order->getExtra1());
233+
$this->assertNull($order->getExtra2());
234+
$this->assertNull($order->getExtra3());
235+
$this->assertNull($order->getTool());
236+
$this->assertNull($order->getInfo());
237+
$this->assertNull($order->getObject());
238+
$this->assertNull($order->getDomainId());
239+
}
240+
241+
242+
public function testStatsGettersReturnValuesWhenSet(): void
243+
{
244+
$order = new PayOrder();
245+
246+
$stats = [
247+
'extra1' => 'E1',
248+
'extra2' => 'E2',
249+
'extra3' => 'E3',
250+
'tool' => 'api',
251+
'info' => ['k' => 'v'],
252+
'object' => 'order',
253+
'domainId' => 123,
254+
];
255+
256+
$order->setStats($stats);
257+
258+
$this->assertSame($stats, $order->getStats());
259+
$this->assertSame('E1', $order->getExtra1());
260+
$this->assertSame('E2', $order->getExtra2());
261+
$this->assertSame('E3', $order->getExtra3());
262+
$this->assertSame('api', $order->getTool());
263+
$this->assertSame(['k' => 'v'], $order->getInfo());
264+
$this->assertSame('order', $order->getObject());
265+
$this->assertSame(123, $order->getDomainId());
266+
}
199267
}

samples/OrderStatus.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,13 @@
5353
echo 'getCurrency: ' . $payOrder->getCurrency() . PHP_EOL;
5454
echo 'paymentMethod: ' . $payOrder->getPaymentMethod() . PHP_EOL;
5555

56+
print_r($payOrder->getStats());
57+
echo 'extra1: ' . $payOrder->getExtra1() . PHP_EOL;
58+
echo 'extra2: ' . $payOrder->getExtra2() . PHP_EOL;
59+
echo 'extra3: ' . $payOrder->getExtra3() . PHP_EOL;
60+
echo 'getTool: ' . $payOrder->getTool() . PHP_EOL;
61+
echo 'getInfo: ' . $payOrder->getInfo() . PHP_EOL;
62+
echo 'getObject: ' . $payOrder->getObject() . PHP_EOL;
63+
echo 'getDomainId: ' . $payOrder->getDomainId() . PHP_EOL;
64+
5665
print_r($payOrder->getFastCheckoutData());

src/Model/Pay/PayOrder.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ class PayOrder implements ModelInterface
145145
*/
146146
protected ?array $transferData;
147147

148+
/**
149+
* @var array
150+
*/
151+
protected ?array $stats = [];
148152

149153
/**
150154
* @param array|null $payload
@@ -854,4 +858,78 @@ public function setTransferData(?array $transferData): self
854858
$this->transferData = $transferData;
855859
return $this;
856860
}
861+
862+
/**
863+
* @return array|null
864+
*/
865+
public function getStats(): ?array
866+
{
867+
return $this->stats;
868+
}
869+
870+
/**
871+
* @param array|null $stats
872+
* @return $this
873+
*/
874+
public function setStats(?array $stats): self
875+
{
876+
$this->stats = $stats;
877+
return $this;
878+
}
879+
880+
/**
881+
* @return mixed|null
882+
*/
883+
public function getExtra1()
884+
{
885+
return $this->stats['extra1'] ?? null;
886+
}
887+
888+
/**
889+
* @return mixed|null
890+
*/
891+
public function getExtra2()
892+
{
893+
return $this->stats['extra2'] ?? null;
894+
}
895+
896+
/**
897+
* @return mixed|null
898+
*/
899+
public function getExtra3()
900+
{
901+
return $this->stats['extra3'] ?? null;
902+
}
903+
904+
/**
905+
* @return mixed|null
906+
*/
907+
public function getTool()
908+
{
909+
return $this->stats['tool'] ?? null;
910+
}
911+
912+
/**
913+
* @return mixed|null
914+
*/
915+
public function getInfo()
916+
{
917+
return $this->stats['info'] ?? null;
918+
}
919+
920+
/**
921+
* @return mixed|null
922+
*/
923+
public function getObject()
924+
{
925+
return $this->stats['object'] ?? null;
926+
}
927+
928+
/**
929+
* @return mixed|null
930+
*/
931+
public function getDomainId()
932+
{
933+
return $this->stats['domainId'] ?? null;
934+
}
857935
}

src/Util/Exchange.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Exchange
2727
public const ERROR_EMPTY_CONFIG = 8003;
2828
public const ERROR_PAYLOAD_OBJECT = 8004;
2929
public const ERROR_ACTION_FAULT = 8005;
30+
public const ERROR_PAYLOAD_VALIDATION = 8006;
3031

3132
private PayLoad $payload;
3233
private ?array $custom_payload;

0 commit comments

Comments
 (0)