From ca9683f0baeaca39f985cbb56e15e1978d8593c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tibor=20Heged=C5=B1s?= Date: Thu, 3 Dec 2026 12:46:48 +0100 Subject: [PATCH 1/2] Add the SimplePay Status API to the payment service SimplePay published a Status API (/v2/status) on 2026-07-28 that returns only the current status of one transaction. PaymentService::status() calls it with exactly one of the transaction ID and the order reference and maps the answer to a StatusResponse. --- src/Dto/StatusResponse.php | 35 +++++++++++++ src/Services/PaymentService.php | 36 ++++++++++++++ tests/Unit/PaymentServiceTest.php | 83 +++++++++++++++++++++++++++++++ 3 files changed, 154 insertions(+) create mode 100644 src/Dto/StatusResponse.php diff --git a/src/Dto/StatusResponse.php b/src/Dto/StatusResponse.php new file mode 100644 index 0000000..f239128 --- /dev/null +++ b/src/Dto/StatusResponse.php @@ -0,0 +1,35 @@ + $data + */ + public static function fromArray(array $data): self + { + return new self( + transactionId: (int) $data['transactionId'], + orderRef: (string) $data['orderRef'], + status: PaymentStatus::from($data['status']), + endState: (bool) $data['endState'], + merchant: (string) $data['merchant'], + ); + } +} diff --git a/src/Services/PaymentService.php b/src/Services/PaymentService.php index eb2d594..a30dc6b 100644 --- a/src/Services/PaymentService.php +++ b/src/Services/PaymentService.php @@ -5,6 +5,7 @@ namespace Netipar\SimplePay\Services; use Illuminate\Http\Client\ConnectionException; +use InvalidArgumentException; use Netipar\SimplePay\Dto\ApplePayDoRequest; use Netipar\SimplePay\Dto\ApplePayStartRequest; use Netipar\SimplePay\Dto\BackResponse; @@ -19,6 +20,7 @@ use Netipar\SimplePay\Dto\QueryResponse; use Netipar\SimplePay\Dto\RefundRequest; use Netipar\SimplePay\Dto\RefundResponse; +use Netipar\SimplePay\Dto\StatusResponse; use Netipar\SimplePay\Enums\Currency; use Netipar\SimplePay\Enums\ErrorCode; use Netipar\SimplePay\Exceptions\SimplePayApiException; @@ -238,6 +240,40 @@ public function query(Currency $currency, ?int $transactionId = null, ?string $o return QueryResponse::fromArray($response); } + /** + * The current status of one transaction, without its details: lighter than query(), meant for polling. + * + * @throws InvalidArgumentException When not exactly one of the transaction ID and the order reference is given. + * @throws RandomException + * @throws ConnectionException + */ + public function status(Currency $currency, ?int $transactionId = null, ?string $orderRef = null): StatusResponse + { + if (($transactionId === null) === ($orderRef === null)) { + throw new InvalidArgumentException('A status request needs exactly one of `transactionId` and `orderRef`.'); + } + + $merchant = $this->merchantResolver->getMerchant($currency); + $secretKey = $this->merchantResolver->getSecretKey($currency); + + $payload = [ + 'salt' => bin2hex(random_bytes(16)), + 'merchant' => $merchant, + ]; + + if ($transactionId !== null) { + $payload['transactionId'] = $transactionId; + } + + if ($orderRef !== null) { + $payload['orderRef'] = $orderRef; + } + + $response = $this->client->post('/v2/status', $payload, $secretKey); + + return StatusResponse::fromArray($response); + } + /** * @return array * diff --git a/tests/Unit/PaymentServiceTest.php b/tests/Unit/PaymentServiceTest.php index bfbaaf1..f2e6b7f 100644 --- a/tests/Unit/PaymentServiceTest.php +++ b/tests/Unit/PaymentServiceTest.php @@ -9,6 +9,7 @@ use Netipar\SimplePay\Dto\RefundRequest; use Netipar\SimplePay\Enums\Currency; use Netipar\SimplePay\Enums\PaymentMethod; +use Netipar\SimplePay\Enums\PaymentStatus; use Netipar\SimplePay\Exceptions\SimplePayApiException; use Netipar\SimplePay\Services\PaymentService; use Netipar\SimplePay\Support\Signature; @@ -219,6 +220,88 @@ }); }); +it('sends a status request by transaction id', function () { + Http::fake([ + 'sandbox.simplepay.hu/payment/v2/status' => fakeSimplePayResponse([ + 'salt' => 'response-salt', + 'merchant' => 'TEST_HUF_MERCHANT', + 'orderRef' => 'ORD-001', + 'transactionId' => 12345, + 'status' => 'INPAYMENT', + 'endState' => false, + ], 'TEST_HUF_SECRET_KEY'), + ]); + + $response = app(PaymentService::class)->status(Currency::HUF, transactionId: 12345); + + expect($response->transactionId)->toBe(12345) + ->and($response->orderRef)->toBe('ORD-001') + ->and($response->status)->toBe(PaymentStatus::InPayment) + ->and($response->endState)->toBeFalse() + ->and($response->merchant)->toBe('TEST_HUF_MERCHANT'); + + Http::assertSent(function ($request) { + $body = json_decode($request->body(), true); + + return $request->url() === 'https://sandbox.simplepay.hu/payment/v2/status' + && array_keys($body) === ['salt', 'merchant', 'transactionId', 'sdkVersion'] + && $body['merchant'] === 'TEST_HUF_MERCHANT' + && $body['transactionId'] === 12345 + && strlen($body['salt']) === 32 + && $body['sdkVersion'] === 'SimplePay_PHP_SDK_2.1_Laravel'; + }); +}); + +it('sends a status request by order reference', function () { + Http::fake([ + 'sandbox.simplepay.hu/payment/v2/status' => fakeSimplePayResponse([ + 'salt' => 'response-salt', + 'merchant' => 'TEST_EUR_MERCHANT', + 'orderRef' => 'ORD-002', + 'transactionId' => '67890', + 'status' => 'FINISHED', + 'endState' => true, + ], 'TEST_EUR_SECRET_KEY'), + ]); + + $response = app(PaymentService::class)->status(Currency::EUR, orderRef: 'ORD-002'); + + expect($response->transactionId)->toBe(67890) + ->and($response->status)->toBe(PaymentStatus::Finished) + ->and($response->endState)->toBeTrue(); + + Http::assertSent(function ($request) { + $body = json_decode($request->body(), true); + + return $body['merchant'] === 'TEST_EUR_MERCHANT' + && $body['orderRef'] === 'ORD-002' + && ! array_key_exists('transactionId', $body); + }); +}); + +it('refuses a status request without exactly one identifier', function (?int $transactionId, ?string $orderRef) { + Http::fake(); + + expect(fn () => app(PaymentService::class)->status(Currency::HUF, $transactionId, $orderRef)) + ->toThrow(InvalidArgumentException::class, 'exactly one of `transactionId` and `orderRef`'); + + Http::assertNothingSent(); +})->with([ + 'neither' => [null, null], + 'both' => [12345, 'ORD-001'], +]); + +it('throws SimplePayApiException when the status request fails', function () { + Http::fake([ + 'sandbox.simplepay.hu/payment/v2/status' => fakeSimplePayResponse([ + 'salt' => 'response-salt', + 'errorCodes' => ['5011'], + ], 'TEST_HUF_SECRET_KEY'), + ]); + + app(PaymentService::class)->status(Currency::HUF, orderRef: 'ORD-UNKNOWN'); +})->throws(SimplePayApiException::class); + it('sends a cancel request', function () { $secretKey = 'TEST_HUF_SECRET_KEY'; From 19a677047fdba2aae8a6dcaf96467d7224d52ee7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tibor=20Heged=C5=B1s?= Date: Thu, 3 Dec 2026 12:46:48 +0100 Subject: [PATCH 2/2] Document the transaction status check Describe status() in the README, the English and Hungarian examples, the Boost skill and the changelog, and name it next to query() where the Google Pay flow says how to fulfil the order. --- AGENTS.md | 2 +- CHANGELOG.md | 4 +++ README.md | 18 ++++++++-- examples/en/google-pay.md | 2 +- examples/en/query-refund-cancel.md | 34 +++++++++++++++++++ examples/hu/google-pay.md | 2 +- examples/hu/lekerdezes-es-sztorno.md | 31 ++++++++++++++++- .../skills/simplepay-development/SKILL.md | 19 +++++++++-- 8 files changed, 104 insertions(+), 8 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index c2163a0..1624219 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -30,7 +30,7 @@ This repository is a Laravel package. Keep the package focused, idiomatic, and e ## SimplePay Architecture - The package follows the official SimplePay PHP SDKs (API v2, published at https://simplepay.hu/fejlesztoknek/). `official-docs/` holds the reference PDFs; it is not part of the dist archive. -- `src/SimplePay.php` sits behind the `SimplePay` facade and exposes the services in `src/Services`: `PaymentService` (start, finish, refund, query, cancel, qvik/EAM, Apple Pay, merchant-side Google Pay with `doGooglePay()` and `googlePayConfig()`), `CardStorageService` (OneClick `do`, recurring, card and token query/cancel), `AutoPaymentService` (merchant-side card data) and `RtpService` (Request to Pay). +- `src/SimplePay.php` sits behind the `SimplePay` facade and exposes the services in `src/Services`: `PaymentService` (start, finish, refund, query, status, cancel, qvik/EAM, Apple Pay, merchant-side Google Pay with `doGooglePay()` and `googlePayConfig()`), `CardStorageService` (OneClick `do`, recurring, card and token query/cancel), `AutoPaymentService` (merchant-side card data) and `RtpService` (Request to Pay). - Request and response payloads are readonly DTOs in `src/Dto`: `toArray()` builds the API body with the field names of the official SDK samples (check `tests/Unit/RequestPayloadTest.php` when adding fields), `fromArray()` maps the response. Deprecated constructor parameters stay until the next major version but are not sent. Enums live in `src/Enums`; `ErrorCode` mirrors the official error code list with Hungarian descriptions. - `src/Support/Client.php` adds `sdkVersion` (`Client::SDK_VERSION`) to every request that lacks it, as the official SDK does, signs every request with HMAC-SHA384 (`Support/Signature`), masks card data and tokens in the debug log, verifies the response signature and throws `SimplePayApiException` when `errorCodes` is not empty; the exception keeps the response body (`getResponseData()`), e.g. the `redirectUrl` of a 3DS challenge (3004). `doGooglePay()` turns a 3004 with a `redirectUrl` into a normal `GooglePayResponse`. - Merchant credentials are configured per currency (`simplepay.merchants`) and resolved by `Support/MerchantResolver`; IPN bodies without `currency` are resolved by their `merchant` field. diff --git a/CHANGELOG.md b/CHANGELOG.md index bc68c7b..dc757bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased](https://github.com/NETipar/simplepay/compare/v2.1.0...HEAD) +### Added + +- `SimplePay::payment()->status()` calls the new SimplePay Status API (`/v2/status`, 2026-07-28): it returns only the current status of one transaction as a `StatusResponse` (`status`, `endState`, `transactionId`, `orderRef`, `merchant`), so it is lighter than `query()` and suits polling. Pass exactly one of `transactionId` and `orderRef`; otherwise it throws `InvalidArgumentException` before sending. + ## [v2.1.0](https://github.com/NETipar/simplepay/compare/v2.0.0...v2.1.0) - 2026-10-18 ### Fixed diff --git a/README.md b/README.md index 3885e24..646e5fb 100644 --- a/README.md +++ b/README.md @@ -216,6 +216,20 @@ $result->paymentDate; // Payment date $result->finishDate; // Finish date (two-step) ``` +### Check Transaction Status + +`status()` returns only the current status of one transaction, so it is lighter than `query()` and suits polling. Pass exactly one of `transactionId` and `orderRef`. + +```php +$status = SimplePay::payment()->status( + currency: Currency::HUF, + orderRef: 'ORDER-2026-001', +); + +$status->status; // PaymentStatus enum +$status->endState; // true when the status will not change any more +``` + ### Cancel a Transaction ```php @@ -571,7 +585,7 @@ Set `SIMPLEPAY_LOG_CHANNEL` to any Laravel log channel name. Example dedicated c | Service | Access | Purpose | |---|---|---| -| `PaymentService` | `SimplePay::payment()` | Standard payments, refunds, queries, Apple Pay, Google Pay, EAM | +| `PaymentService` | `SimplePay::payment()` | Standard payments, refunds, queries, status checks, Apple Pay, Google Pay, EAM | | `CardStorageService` | `SimplePay::cardStorage()` | OneClick, recurring, card/token management | | `AutoPaymentService` | `SimplePay::autoPayment()` | PCI-DSS direct card payments | | `RtpService` | `SimplePay::rtp()` | Request to Pay (bank transfers) | @@ -580,7 +594,7 @@ Set `SIMPLEPAY_LOG_CHANNEL` to any Laravel log channel name. Example dedicated c This package is built based on the **SimplePay PHP SDK v2.1** (API v2). All API requests include the `sdkVersion: SimplePay_PHP_SDK_2.1_Laravel` identifier. -The merchant-side Google Pay flow follows the Payment PHP SDK 2.1.5 (2026-06-27) and the SimplePay Google Pay documentation (2026-09-01); the `urls` and `pending` handling follows the Request to Pay documentation (2026-08-17). +The merchant-side Google Pay flow follows the Payment PHP SDK 2.1.5 (2026-06-27) and the SimplePay Google Pay documentation (2026-09-01); the `urls` and `pending` handling follows the Request to Pay documentation (2026-08-17); `status()` follows the Status API of the SimplePay developer portal (2026-07-28). ## Examples diff --git a/examples/en/google-pay.md b/examples/en/google-pay.md index 061c3fa..84a9817 100644 --- a/examples/en/google-pay.md +++ b/examples/en/google-pay.md @@ -26,7 +26,7 @@ The SimplePay merchant credentials of the currency are used as for any other pay 3. Your backend calls `doGooglePay()` and returns the result to the page. 4. Without a 3DS challenge the customer stays on the checkout page, and SimplePay makes no back redirect. Show the result on the page. 5. If the card issuer asks for a 3DS challenge, the response has a `redirectUrl`: send the browser there. After the challenge SimplePay redirects the customer to the `url` of the request with the signed `r` and `s` parameters, which the package's `simplepay.back` route handles. -6. Fulfil the order from the IPN (or a `query()`), never from the synchronous response or the back redirect alone. +6. Fulfil the order from the IPN (or a server-side `status()` or `query()` call), never from the synchronous response or the back redirect alone. ## Backend diff --git a/examples/en/query-refund-cancel.md b/examples/en/query-refund-cancel.md index 87dfb8f..3ed5ecd 100644 --- a/examples/en/query-refund-cancel.md +++ b/examples/en/query-refund-cancel.md @@ -28,6 +28,40 @@ $query = SimplePay::payment()->query( | `$query->finishDate` | `?string` | Finish date for two-step payments (ISO 8601) | | `$query->method` | `?string` | Payment method (e.g. `CARD`) | +## Check the Status of a Transaction + +`status()` asks SimplePay for the current status of one transaction only, without its details. It is lighter than `query()`, so use it when you poll a transaction, and `query()` when you need the amounts, dates or payment method. Pass exactly one of `transactionId` and `orderRef`; otherwise it throws `InvalidArgumentException` before sending anything. + +```php +use Netipar\SimplePay\Facades\SimplePay; +use Netipar\SimplePay\Enums\Currency; + +$status = SimplePay::payment()->status( + currency: Currency::HUF, + transactionId: 123456, +); + +// Or by your order reference +$status = SimplePay::payment()->status( + currency: Currency::HUF, + orderRef: 'ORDER-123', +); + +if ($status->endState) { + // FINISHED, CANCELLED, NOTAUTHORIZED, TIMEOUT or REVERSED: the status will not change any more +} +``` + +### Status Response Properties + +| Property | Type | Description | +|---|---|---| +| `$status->status` | `PaymentStatus` | Current transaction status | +| `$status->endState` | `bool` | `true` when the status is final (`FINISHED`, `CANCELLED`, `NOTAUTHORIZED`, `TIMEOUT`, `REVERSED`) | +| `$status->transactionId` | `int` | SimplePay transaction ID | +| `$status->orderRef` | `string` | Your order reference | +| `$status->merchant` | `string` | Merchant account ID | + ## Refund a Transaction Issue a partial or full refund for a completed transaction. diff --git a/examples/hu/google-pay.md b/examples/hu/google-pay.md index d21195c..f5126e3 100644 --- a/examples/hu/google-pay.md +++ b/examples/hu/google-pay.md @@ -26,7 +26,7 @@ A pénznemhez tartozó SimplePay kereskedői adatokat ugyanúgy használja, mint 3. A backend meghívja a `doGooglePay()`-t, és visszaadja az eredményt az oldalnak. 4. 3DS challenge nélkül a vásárló a fizetési oldalon marad, és a SimplePay nem irányítja vissza. Az eredményt az oldalon kell megjeleníteni. 5. Ha a kártyakibocsátó 3DS challenge-et kér, a válaszban `redirectUrl` érkezik, ide kell átirányítani a böngészőt. A challenge után a SimplePay a kérés `url` címére irányítja vissza a vásárlót az aláírt `r` és `s` paraméterekkel; ezeket a csomag `simplepay.back` route-ja kezeli. -6. A rendelést az IPN (vagy egy `query()`) alapján teljesítsd, soha ne csak a szinkron válasz vagy a visszairányítás alapján. +6. A rendelést az IPN (vagy egy szerveroldali `status()` vagy `query()` hívás) alapján teljesítsd, soha ne csak a szinkron válasz vagy a visszairányítás alapján. ## Backend diff --git a/examples/hu/lekerdezes-es-sztorno.md b/examples/hu/lekerdezes-es-sztorno.md index 74c963b..5f8ca82 100644 --- a/examples/hu/lekerdezes-es-sztorno.md +++ b/examples/hu/lekerdezes-es-sztorno.md @@ -22,6 +22,34 @@ $query->finishDate; // Finish date (?string) $query->method; // Payment method, e.g. "CARD" (?string) ``` +## Tranzakció állapotának lekérdezése + +A `status()` egyetlen tranzakciónak csak az aktuális állapotát kéri le, a részletei nélkül. Könnyebb hívás, mint a `query()`, ezért ezt használd, ha egy tranzakció állapotát figyeled; a `query()` akkor kell, ha az összegekre, a dátumokra vagy a fizetési módra is szükséged van. Pontosan az egyiket add meg a `transactionId` és az `orderRef` közül, különben a kérés elküldése előtt `InvalidArgumentException` keletkezik. + +```php +use Netipar\SimplePay\Facades\SimplePay; +use Netipar\SimplePay\Enums\Currency; + +$status = SimplePay::payment()->status( + currency: Currency::HUF, + transactionId: 123456, +); + +// Or by your order reference +$status = SimplePay::payment()->status( + currency: Currency::HUF, + orderRef: 'ORDER-123', +); + +$status->status; // Transaction status (PaymentStatus) +$status->endState; // true when the status will not change any more (bool) +$status->transactionId; // SimplePay transaction ID (int) +$status->orderRef; // Order reference (string) +$status->merchant; // Merchant account ID (string) +``` + +Végleges (`endState: true`) állapot a `FINISHED`, a `CANCELLED`, a `NOTAUTHORIZED`, a `TIMEOUT` és a `REVERSED`; az `INIT`, az `INPAYMENT`, az `INFRAUD` és az `AUTHORIZED` még változhat. + ## Visszatérítés (refund) Visszatérítés esetén az összeg (részben vagy egészben) visszakerül a vásárló számlájára. @@ -146,7 +174,8 @@ try { | Művelet | Metódus | Mikor használd | |------------------------|-------------|-----------------------------------------------------| -| Lekérdezés | `query()` | Tranzakció aktuális állapotának lekérdezése | +| Lekérdezés | `query()` | Tranzakció adatainak és állapotának lekérdezése | +| Állapot | `status()` | Csak az állapot lekérdezése, pl. ismételt figyeléshez | | Visszatérítés | `refund()` | Részleges vagy teljes visszatérítés a vásárlónak | | Sztornó | `cancel()` | Tranzakció teljes visszavonása | | Kétlépcsős befejezése | `finish()` | Preautorizált összeg tényleges terhelése | diff --git a/resources/boost/skills/simplepay-development/SKILL.md b/resources/boost/skills/simplepay-development/SKILL.md index a6711ee..3d498ae 100644 --- a/resources/boost/skills/simplepay-development/SKILL.md +++ b/resources/boost/skills/simplepay-development/SKILL.md @@ -14,7 +14,7 @@ Use this skill when: - Starting online payments and redirecting users to the SimplePay payment page - Handling IPN (Instant Payment Notification) webhooks - Processing back redirects after payment completion -- Implementing refunds, cancellations, or transaction queries +- Implementing refunds, cancellations, transaction queries, or status checks - Implementing two-step (authorize + capture) payment flows - Storing cards for OneClick payments or recurring billing - Implementing auto (PCI-DSS) payments with direct card data @@ -226,6 +226,21 @@ $response = SimplePay::payment()->query( // $response->remainingTotal ``` +## Check a transaction's status + +`status()` returns only the current status of one transaction (POST `/v2/status`). It is lighter than `query()`: use it to poll, and `query()` when you need amounts, dates or the payment method. Pass exactly one of `transactionId` and `orderRef`, otherwise it throws `InvalidArgumentException` before sending. + +```php +$status = SimplePay::payment()->status( + currency: Currency::HUF, + orderRef: 'ORDER-001', // or transactionId: 123456789 +); + +// $status->status (PaymentStatus enum) +// $status->endState (true for FINISHED, CANCELLED, NOTAUTHORIZED, TIMEOUT, REVERSED: the status will not change) +// $status->transactionId, $status->orderRef, $status->merchant +``` + ## Cancel a transaction ```php @@ -371,7 +386,7 @@ return response()->json([ - A 3DS challenge (error code 3004) does not throw: `$response->requiresChallenge()` is true and the frontend navigates to `redirectUrl`. Other error codes throw `SimplePayApiException`. - Without 3DS the customer stays on the checkout page and SimplePay sends no back redirect. -- Fulfil the order from the IPN or a `query()`, not from the synchronous response. +- Fulfil the order from the IPN or a server-side `status()` or `query()` call, not from the synchronous response. - Needs `SIMPLEPAY_GOOGLE_PAY_MERCHANT_ID` and `SIMPLEPAY_GOOGLE_PAY_MERCHANT_NAME` (Google Pay & Wallet Console). Full JavaScript example: `examples/en/google-pay.md`. ## Event-specific redirect URLs