diff --git a/src/Dto/IpnMessage.php b/src/Dto/IpnMessage.php index df243a4..4776af4 100644 --- a/src/Dto/IpnMessage.php +++ b/src/Dto/IpnMessage.php @@ -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, @@ -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, ); diff --git a/tests/Feature/IpnWebhookTest.php b/tests/Feature/IpnWebhookTest.php index 9662f4d..6c142b3 100644 --- a/tests/Feature/IpnWebhookTest.php +++ b/tests/Feature/IpnWebhookTest.php @@ -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'; }); }); diff --git a/tests/Unit/IpnMessageTest.php b/tests/Unit/IpnMessageTest.php new file mode 100644 index 0000000..143f434 --- /dev/null +++ b/tests/Unit/IpnMessageTest.php @@ -0,0 +1,44 @@ + '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(); +});