diff --git a/CHANGELOG.md b/CHANGELOG.md index 7cda68b..b47990b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,14 @@ narrative. ## [Unreleased] +### Added + +- `Operation::$callbackSuccess`, `$callbackResponseCode`, `$callbackAt` and `$callbackDuration`: how + Quickpay's callback about the operation was answered, all `null` until it was sent. Before, only + `$callbackUrl` was typed and the rest had to be read from the payment's `$raw['operations']`. + The new constructor parameters come last, so positional calls are unaffected + ([#33](https://github.com/Setono/quickpay-php-sdk/pull/33)). + ## [1.3.0] — 2026-11-16 A fix for an answer whose body breaks off mid-read, which escaped `catch (QuickpayException $e)` as a diff --git a/README.md b/README.md index 90c663a..585f433 100644 --- a/README.md +++ b/README.md @@ -228,6 +228,13 @@ $payment->hasPendingOperation(OperationType::Refund); // is a refund in fli $op->hasOutcome(); // no longer pending — the status codes mean something now $op->isApproved(); // qp_status_code 20000 $op->isDeclined(); // completed but NOT approved: rejected (4xxxx), error (5xxxx), auth required (3xxxx) + +// How Quickpay's callback about the operation was answered (all null until it was sent): +$op->callbackUrl; // where it went +$op->callbackSuccess; // ?bool — Quickpay's judgment of the answer +$op->callbackResponseCode; // ?string — the status code your endpoint answered with, e.g. "204"; null when no answer came +$op->callbackAt; // ?DateTimeImmutable — when it was sent +$op->callbackDuration; // ?int — how long it took, in milliseconds ``` Only **approved** operations count towards the amounts — pending or rejected ones don't. When an diff --git a/src/Response/Payment/Operation.php b/src/Response/Payment/Operation.php index 82484d9..fcc4dcc 100644 --- a/src/Response/Payment/Operation.php +++ b/src/Response/Payment/Operation.php @@ -18,6 +18,14 @@ * status codes say nothing yet. Once it has completed, {@see self::isApproved()} tells you whether * it succeeded; any other completed outcome (rejected by the acquirer, 3-D Secure required, gateway * error, …) is described by `qpStatusCode` / `qpStatusMsg` — see the Quickpay status-code appendix. + * + * Reading the callback: Quickpay records how its callback about the operation (sent to + * `callbackUrl`) was answered. The callback fields are `null` until it was sent (e.g. while the + * operation is pending). Once sent, `callbackSuccess` is Quickpay's judgment of the answer and + * `callbackAt` when it was sent. `callbackResponseCode` is the HTTP status code the receiver + * answered with, as a string (e.g. `"204"`), and `null` when no answer came (`callbackSuccess` is + * then `false`). `callbackDuration` is how long the callback took, in milliseconds: a timed-out one + * reports about 30000, and it is `null` when the receiver couldn't be reached at all. */ final class Operation { @@ -37,6 +45,10 @@ public function __construct( public readonly ?string $aqStatusMsg = null, public readonly ?string $callbackUrl = null, public readonly ?\DateTimeImmutable $createdAt = null, + public readonly ?bool $callbackSuccess = null, + public readonly ?string $callbackResponseCode = null, + public readonly ?\DateTimeImmutable $callbackAt = null, + public readonly ?int $callbackDuration = null, ) { } diff --git a/tests/Client/Endpoint/PaymentsEndpointTest.php b/tests/Client/Endpoint/PaymentsEndpointTest.php index 54e7bbd..a55b963 100644 --- a/tests/Client/Endpoint/PaymentsEndpointTest.php +++ b/tests/Client/Endpoint/PaymentsEndpointTest.php @@ -70,6 +70,18 @@ public function it_maps_nested_link_operations_and_metadata(): void self::assertSame(1000, $payment->operations[0]->amount); self::assertSame('20000', $payment->operations[0]->qpStatusCode); + // How Quickpay's callback about each operation was answered: the shop answered 200 ... + self::assertTrue($payment->operations[0]->callbackSuccess); + self::assertSame('200', $payment->operations[0]->callbackResponseCode); + self::assertEquals(new \DateTimeImmutable('2026-06-22T10:00:02Z'), $payment->operations[0]->callbackAt); + self::assertSame(804, $payment->operations[0]->callbackDuration); + + // ... and never answered the second one + self::assertFalse($payment->operations[1]->callbackSuccess); + self::assertNull($payment->operations[1]->callbackResponseCode); + self::assertEquals(new \DateTimeImmutable('2026-06-22T10:05:01Z'), $payment->operations[1]->callbackAt); + self::assertNull($payment->operations[1]->callbackDuration); + self::assertNotNull($payment->metadata); self::assertSame('visa', $payment->metadata->brand); self::assertSame('0000', $payment->metadata->last4); diff --git a/tests/Fixtures/payment.json b/tests/Fixtures/payment.json index d361d0d..be7b549 100644 --- a/tests/Fixtures/payment.json +++ b/tests/Fixtures/payment.json @@ -55,6 +55,8 @@ "callback_url": "https://shop.example/callback", "callback_success": true, "callback_response_code": "200", + "callback_at": "2026-06-22T10:00:02Z", + "callback_duration": 804, "acquirer": "clearhaus", "created_at": "2026-06-22T10:00:00Z" }, @@ -69,6 +71,10 @@ "aq_status_msg": "Approved", "data": {}, "callback_url": "https://shop.example/callback", + "callback_success": false, + "callback_response_code": null, + "callback_at": "2026-06-22T10:05:01Z", + "callback_duration": null, "acquirer": "clearhaus", "created_at": "2026-06-22T10:05:00Z" }