Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Dto/IpnMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

readonly class IpnMessage
{
/**
* @param string|null $paymentMethod The `method` field of the IPN, e.g. "CARD".
*/
public function __construct(
public string $orderRef,
public int $transactionId,
Expand All @@ -33,7 +36,7 @@ public static function fromArray(array $data): self
currency: isset($data['currency']) ? Currency::from($data['currency']) : null,
total: isset($data['total']) ? (float) $data['total'] : null,
finishDate: $data['finishDate'] ?? null,
paymentMethod: $data['paymentMethod'] ?? null,
paymentMethod: $data['method'] ?? $data['paymentMethod'] ?? null,
cardMask: $data['cardMask'] ?? null,
merchant: $data['merchant'] ?? null,
);
Expand Down
1 change: 1 addition & 0 deletions tests/Feature/IpnWebhookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ function postIpn(array $payload, string $secretKey = 'TEST_HUF_SECRET_KEY'): Tes
&& $event->ipn->transactionId === 67890
&& $event->ipn->currency === null
&& $event->ipn->total === null
&& $event->ipn->paymentMethod === 'CARD'
&& $event->ipn->merchant === 'TEST_HUF_MERCHANT';
});
});
Expand Down
44 changes: 44 additions & 0 deletions tests/Unit/IpnMessageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

use Netipar\SimplePay\Dto\IpnMessage;

it('reads the payment method from the method field of the IPN', function () {
// The IPN of the official developer documentation (3.14 ipn).
$ipn = IpnMessage::fromArray([
'salt' => '223G0O18VAqdLhQYbJz73adT36YzLtak',
'orderRef' => '101010515680292482600',
'method' => 'CARD',
'merchant' => 'PUBLICTESTHUF',
'finishDate' => '2019-09-09T14:46:18+0200',
'paymentDate' => '2019-09-09T14:41:13+0200',
'transactionId' => 99844942,
'status' => 'FINISHED',
]);

expect($ipn->paymentMethod)->toBe('CARD')
->and($ipn->transactionId)->toBe(99844942)
->and($ipn->merchant)->toBe('PUBLICTESTHUF');
});

it('still reads the payment method from the paymentMethod field', function () {
$ipn = IpnMessage::fromArray([
'orderRef' => 'ORD-001',
'transactionId' => 12345,
'status' => 'FINISHED',
'paymentMethod' => 'WIRE',
]);

expect($ipn->paymentMethod)->toBe('WIRE');
});

it('has no payment method when the IPN names none', function () {
$ipn = IpnMessage::fromArray([
'orderRef' => 'ORD-001',
'transactionId' => 12345,
'status' => 'FINISHED',
]);

expect($ipn->paymentMethod)->toBeNull();
});