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
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) |
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion examples/en/google-pay.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
34 changes: 34 additions & 0 deletions examples/en/query-refund-cancel.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion examples/hu/google-pay.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
31 changes: 30 additions & 1 deletion examples/hu/lekerdezes-es-sztorno.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 |
19 changes: 17 additions & 2 deletions resources/boost/skills/simplepay-development/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions src/Dto/StatusResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Netipar\SimplePay\Dto;

use Netipar\SimplePay\Enums\PaymentStatus;

readonly class StatusResponse
{
/**
* @param bool $endState True when the status is final and will not change any more.
*/
public function __construct(
public int $transactionId,
public string $orderRef,
public PaymentStatus $status,
public bool $endState,
public string $merchant,
) {}

/**
* @param array<string, mixed> $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'],
);
}
}
36 changes: 36 additions & 0 deletions src/Services/PaymentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<string, mixed>
*
Expand Down
83 changes: 83 additions & 0 deletions tests/Unit/PaymentServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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';

Expand Down