diff --git a/app/Callbacks/WatchCallbacks.php b/app/Callbacks/WatchCallbacks.php index 2684184..837844a 100644 --- a/app/Callbacks/WatchCallbacks.php +++ b/app/Callbacks/WatchCallbacks.php @@ -5,8 +5,9 @@ use App\Callbacks\Input\CallbackRequest; use App\Callbacks\Resolution\PrivateKeyResolver; use App\Callbacks\Watching\CallbackWatcherFactory; +use App\Callbacks\Watching\CallbackWatchObserver; +use App\Callbacks\Watching\CallbackWatchRequest; use App\Quickpay\QuickpayClient; -use Closure; use Illuminate\Http\Client\Factory; final readonly class WatchCallbacks @@ -17,24 +18,25 @@ public function __construct( private PrivateKeyResolver $privateKeys, ) {} - /** @param Closure(string, array): void $observer */ public function execute( QuickpayClient $quickpay, string $apiKey, CallbackRequest $request, int $interval, int $deliveryAttempts, - Closure $observer, + CallbackWatchObserver $observer, ): void { $this->watchers->make($quickpay, $this->http)->run( - paymentId: $request->paymentId, - orderId: $request->orderId, - target: $request->target, - apiKey: $apiKey, - privateKey: $this->privateKeys->resolve($quickpay), - interval: $interval, - deliveryAttempts: $deliveryAttempts, - observer: $observer, + new CallbackWatchRequest( + paymentId: $request->paymentId, + orderId: $request->orderId, + target: $request->target, + apiKey: $apiKey, + privateKey: $this->privateKeys->resolve($quickpay), + interval: $interval, + deliveryAttempts: $deliveryAttempts, + ), + $observer, ); } } diff --git a/app/Callbacks/Watching/AccountWideWatch.php b/app/Callbacks/Watching/AccountWideWatch.php new file mode 100644 index 0000000..31fa828 --- /dev/null +++ b/app/Callbacks/Watching/AccountWideWatch.php @@ -0,0 +1,85 @@ +wholeUtcSecond(($this->clock)())->modify('+1 second'); + ($this->waitUntil)($readiness); + $observer->watchingAllPayments($readiness); + $watermark = $readiness; + $known = []; + + while (($this->continue)()) { + ($this->sleep)($request->interval); + $windowEnd = $this->wholeUtcSecond(($this->clock)()); + + if ($windowEnd < $watermark) { + throw new UnexpectedValueException('The callback watcher clock moved before its payment watermark.'); + } + + $payments = $this->poller->poll( + fn (): array => $this->locator->changedBetween($watermark->modify('-1 second'), $windowEnd), + $request->interval, + $observer, + ); + $watermark = $windowEnd; + + foreach ($payments as $payment) { + $paymentId = WatchedPayment::id($payment->json); + $new = array_column(array_filter( + WatchedPayment::operations($payment->json), + fn (array $operation): bool => $operation['created_at'] >= $readiness + && ! isset($known[$paymentId][$operation['id']]), + ), 'id'); + + $this->forwarder->forward($payment, $paymentId, $new, $request, $observer); + $known[$paymentId] = ($known[$paymentId] ?? []) + array_fill_keys($new, true); + } + } + } + + private function wholeUtcSecond(DateTimeImmutable $time): DateTimeImmutable + { + $utc = $time->setTimezone(new DateTimeZone('UTC')); + + return $utc->setTime( + (int) $utc->format('H'), + (int) $utc->format('i'), + (int) $utc->format('s'), + ); + } +} diff --git a/app/Callbacks/Watching/CallbackWatchObserver.php b/app/Callbacks/Watching/CallbackWatchObserver.php new file mode 100644 index 0000000..0110c5a --- /dev/null +++ b/app/Callbacks/Watching/CallbackWatchObserver.php @@ -0,0 +1,43 @@ +paymentId === null && $this->orderId === null; + } +} diff --git a/app/Callbacks/Watching/CallbackWatchRunner.php b/app/Callbacks/Watching/CallbackWatchRunner.php index f4f91de..bcde02b 100644 --- a/app/Callbacks/Watching/CallbackWatchRunner.php +++ b/app/Callbacks/Watching/CallbackWatchRunner.php @@ -3,15 +3,11 @@ namespace App\Callbacks\Watching; use App\Callbacks\Delivery\CallbackForwarder; -use App\Callbacks\Delivery\CallbackTarget; use App\Callbacks\Resolution\PaymentLocator; use App\Callbacks\Signing\CallbackEnvelopeFactory; -use App\Quickpay\Exceptions\QuickpayRequestException; -use App\Quickpay\QuickpayResponse; use Closure; use DateTimeImmutable; use DateTimeZone; -use UnexpectedValueException; /** * Polls all payments or one selected payment for operations observed after start. @@ -21,353 +17,54 @@ * immutable envelope. Delivery stays FIFO and retries block later operations, * matching Quickpay's same-resource ordering guarantee as closely as polling * permits. + * + * The runner picks the watch mode and shares one poller and one forwarder + * between them. The optional hooks replace sleeping, the loop condition and + * the clock in tests. */ -final class CallbackWatchRunner implements CallbackWatcher +final readonly class CallbackWatchRunner implements CallbackWatcher { - private readonly Closure $sleep; - - private readonly Closure $continue; - - private readonly Closure $clock; + private SinglePaymentWatch $singlePayment; - private readonly Closure $waitUntil; + private AccountWideWatch $accountWide; public function __construct( - private readonly PaymentLocator $locator, - private readonly CallbackEnvelopeFactory $envelopes, - private readonly CallbackForwarder $forwarder, + PaymentLocator $locator, + CallbackEnvelopeFactory $envelopes, + CallbackForwarder $forwarder, ?callable $sleep = null, ?callable $continue = null, ?callable $clock = null, ?callable $waitUntil = null, ) { - $this->sleep = Closure::fromCallable($sleep ?? sleep(...)); - $this->continue = Closure::fromCallable($continue ?? static fn (): bool => true); - $this->clock = Closure::fromCallable( + $sleep = Closure::fromCallable($sleep ?? sleep(...)); + $continue = Closure::fromCallable($continue ?? static fn (): bool => true); + $clock = Closure::fromCallable( $clock ?? static fn (): DateTimeImmutable => new DateTimeImmutable('now', new DateTimeZone('UTC')), ); - $this->waitUntil = Closure::fromCallable($waitUntil ?? function (DateTimeImmutable $target): void { - $remaining = (float) $target->format('U.u') - (float) (($this->clock)())->format('U.u'); + $waitUntil = Closure::fromCallable($waitUntil ?? static function (DateTimeImmutable $target) use ($clock): void { + $remaining = (float) $target->format('U.u') - (float) $clock()->format('U.u'); if ($remaining > 0) { usleep((int) ceil($remaining * 1_000_000)); } }); - } - - /** - * @param Closure(string, array): void $observer - */ - public function run( - ?string $paymentId, - ?string $orderId, - CallbackTarget $target, - string $apiKey, - string $privateKey, - int $interval, - int $deliveryAttempts, - Closure $observer, - ): void { - if ($paymentId === null && $orderId === null) { - $this->runAccountWide($target, $apiKey, $privateKey, $interval, $deliveryAttempts, $observer); - - return; - } - - $payment = $this->poll( - $paymentId !== null - ? fn (): QuickpayResponse => $this->locator->byId($paymentId) - : fn (): ?QuickpayResponse => $this->locator->byOrderId($orderId), - $interval, - $observer, - ); - $known = []; - if ($payment === null) { - $observer('waiting-for-payment', ['order_id' => $orderId]); - } else { - $paymentId = $this->paymentId($payment->json); - $known = array_fill_keys(array_column($this->operations($payment->json), 'id'), true); - $observer('watching', ['payment_id' => $paymentId, 'baseline_operations' => count($known)]); - } - - while (($this->continue)()) { - ($this->sleep)($interval); - - if ($paymentId === null) { - $payment = $this->poll( - fn (): ?QuickpayResponse => $this->locator->byOrderId($orderId), - $interval, - $observer, - ); - - if ($payment === null) { - continue; - } - - $paymentId = $this->paymentId($payment->json); - $observer('payment-found', ['payment_id' => $paymentId, 'order_id' => $orderId]); - } else { - $payment = $this->poll( - fn (): QuickpayResponse => $this->locator->byId($paymentId), - $interval, - $observer, - ); - } - - $new = array_values(array_filter( - $this->operations($payment->json), - fn (array $operation): bool => ! isset($known[$operation['id']]), - )); + $poller = new WatchPoller($sleep); + $operations = new OperationForwarder($envelopes, $forwarder, $sleep); - if (count($new) > 1) { - // Polling observes only the latest resource snapshot. One POST - // is still made per operation, but same-poll bodies are equal. - $observer('multiple-operations', ['count' => count($new)]); - } - - foreach ($new as $operation) { - $this->deliverOperation( - $payment, - $paymentId, - $operation['id'], - $apiKey, - $privateKey, - $target, - $interval, - $deliveryAttempts, - $observer, - ); - $known[$operation['id']] = true; - } - } + $this->singlePayment = new SinglePaymentWatch($locator, $poller, $operations, $sleep, $continue); + $this->accountWide = new AccountWideWatch($locator, $poller, $operations, $sleep, $continue, $clock, $waitUntil); } - /** @param Closure(string, array): void $observer */ - private function runAccountWide( - CallbackTarget $target, - string $apiKey, - string $privateKey, - int $interval, - int $deliveryAttempts, - Closure $observer, - ): void { - $readiness = $this->nextWholeUtcSecond(($this->clock)()); - ($this->waitUntil)($readiness); - $observer('watching-all', ['ready_at' => $readiness->format(DateTimeImmutable::ATOM)]); - $watermark = $readiness; - $known = []; - - while (($this->continue)()) { - ($this->sleep)($interval); - $windowEnd = $this->wholeUtcSecond(($this->clock)()); - - if ($windowEnd < $watermark) { - throw new UnexpectedValueException('The callback watcher clock moved before its payment watermark.'); - } - - $payments = $this->poll( - fn (): array => $this->locator->changedBetween($watermark->modify('-1 second'), $windowEnd), - $interval, - $observer, - ); - $watermark = $windowEnd; - - foreach ($payments as $payment) { - $paymentId = $this->paymentId($payment->json); - $operations = array_values(array_filter( - $this->operations($payment->json), - fn (array $operation): bool => $operation['created_at'] >= $readiness - && ! isset($known[$paymentId][$operation['id']]), - )); - - if (count($operations) > 1) { - $observer('multiple-operations', ['count' => count($operations)]); - } - - foreach ($operations as $operation) { - $this->deliverOperation( - $payment, - $paymentId, - $operation['id'], - $apiKey, - $privateKey, - $target, - $interval, - $deliveryAttempts, - $observer, - ); - $known[$paymentId][$operation['id']] = true; - } - } - } - } - - /** @param Closure(string, array): void $observer */ - private function deliverOperation( - QuickpayResponse $payment, - string $paymentId, - string $operationId, - string $apiKey, - string $privateKey, - CallbackTarget $target, - int $interval, - int $deliveryAttempts, - Closure $observer, - ): void { - $envelope = $this->envelopes->make( - $payment, - $apiKey, - $privateKey, - ); - - $attempt = 0; - - do { - $attempt++; - $delivery = $this->forwarder->deliver($target, $envelope); - - if ($delivery->successful) { - break; - } - - if (! $delivery->isRetryable() || $attempt >= $deliveryAttempts) { - throw new CallbackDeliveryException( - $paymentId, - $operationId, - $delivery, - $attempt, - $deliveryAttempts, - ); - } - - $observer('delivery-retry', [ - 'attempt' => $attempt, - 'maximum_attempts' => $deliveryAttempts, - 'delay' => $interval, - 'payment_id' => $paymentId, - 'operation_id' => $operationId, - 'status' => $delivery->status, - ]); - ($this->sleep)($interval); - } while (true); - - $observer('delivered', [ - 'payment_id' => $paymentId, - 'operation_id' => $operationId, - 'status' => $delivery->status, - ]); - } - - /** - * @template T - * - * @param Closure(): T $request - * @param Closure(string, array): void $observer - * @return T - */ - private function poll(Closure $request, int $interval, Closure $observer): mixed - { - while (true) { - try { - return $request(); - } catch (CallbackPollingException $exception) { - if (! $exception->retryable) { - throw $exception; - } - - $delay = $exception->retryAfter ?? $interval; - $observer('polling-retry', ['status' => $exception->status, 'delay' => $delay]); - ($this->sleep)($delay); - } catch (QuickpayRequestException) { - // QuickpayClient emits this safe generic exception for network - // failures; GET polling can be retried without mutation risk. - $observer('polling-retry', ['status' => null, 'delay' => $interval]); - ($this->sleep)($interval); - } - } - } - - private function nextWholeUtcSecond(DateTimeImmutable $time): DateTimeImmutable - { - return $this->wholeUtcSecond($time)->modify('+1 second'); - } - - private function wholeUtcSecond(DateTimeImmutable $time): DateTimeImmutable - { - $utc = $time->setTimezone(new DateTimeZone('UTC')); - - return $utc->setTime( - (int) $utc->format('H'), - (int) $utc->format('i'), - (int) $utc->format('s'), - ); - } - - private function paymentId(mixed $payment): string - { - $id = is_array($payment) ? ($payment['id'] ?? null) : null; - - if ((! is_int($id) && ! is_string($id)) || (string) $id === '') { - throw new UnexpectedValueException('Quickpay returned a payment without a valid payment ID.'); - } - - return (string) $id; - } - - /** - * @return array - */ - private function operations(mixed $payment): array + public function run(CallbackWatchRequest $request, CallbackWatchObserver $observer): void { - $operations = is_array($payment) ? ($payment['operations'] ?? null) : null; - - if (! is_array($operations) || ! array_is_list($operations)) { - throw new UnexpectedValueException('Quickpay returned a payment with malformed operations.'); - } - - $normalized = array_map(function (mixed $operation): array { - $id = is_array($operation) ? ($operation['id'] ?? null) : null; - - if ((! is_int($id) && ! is_string($id)) || (string) $id === '') { - throw new UnexpectedValueException('Quickpay returned an operation without a valid operation ID.'); - } + if ($request->isAccountWide()) { + $this->accountWide->run($request, $observer); - return [ - 'id' => (string) $id, - 'created_at' => $this->operationTimestamp($operation['created_at'] ?? null), - ]; - }, $operations); - - usort($normalized, fn (array $left, array $right): int => [ - (int) $left['created_at']->format('U'), - (int) $left['created_at']->format('u'), - str_pad($left['id'], 20, '0', STR_PAD_LEFT), - ] <=> [ - (int) $right['created_at']->format('U'), - (int) $right['created_at']->format('u'), - str_pad($right['id'], 20, '0', STR_PAD_LEFT), - ]); - - return $normalized; - } - - private function operationTimestamp(mixed $value): DateTimeImmutable - { - if (! is_string($value) - || preg_match('/\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,6})?(?:Z|[+-]\d{2}:\d{2})\z/D', $value) !== 1) { - throw new UnexpectedValueException('Quickpay returned an operation without a valid timestamp.'); - } - - $format = str_contains($value, '.') ? '!Y-m-d\TH:i:s.uP' : '!Y-m-d\TH:i:sP'; - $timestamp = DateTimeImmutable::createFromFormat($format, $value); - $errors = DateTimeImmutable::getLastErrors(); - - if ($timestamp === false - || ($errors !== false && ($errors['warning_count'] > 0 || $errors['error_count'] > 0))) { - throw new UnexpectedValueException('Quickpay returned an operation without a valid timestamp.'); + return; } - return $timestamp->setTimezone(new DateTimeZone('UTC')); + $this->singlePayment->run($request, $observer); } } diff --git a/app/Callbacks/Watching/CallbackWatcher.php b/app/Callbacks/Watching/CallbackWatcher.php index a8f12da..6cebb9b 100644 --- a/app/Callbacks/Watching/CallbackWatcher.php +++ b/app/Callbacks/Watching/CallbackWatcher.php @@ -2,9 +2,6 @@ namespace App\Callbacks\Watching; -use App\Callbacks\Delivery\CallbackTarget; -use Closure; - /** * Runs one foreground callback watch session. * @@ -13,17 +10,5 @@ */ interface CallbackWatcher { - /** - * @param Closure(string, array): void $observer - */ - public function run( - ?string $paymentId, - ?string $orderId, - CallbackTarget $target, - string $apiKey, - string $privateKey, - int $interval, - int $deliveryAttempts, - Closure $observer, - ): void; + public function run(CallbackWatchRequest $request, CallbackWatchObserver $observer): void; } diff --git a/app/Callbacks/Watching/OperationForwarder.php b/app/Callbacks/Watching/OperationForwarder.php new file mode 100644 index 0000000..ae19a7b --- /dev/null +++ b/app/Callbacks/Watching/OperationForwarder.php @@ -0,0 +1,93 @@ + $operationIds in delivery order + */ + public function forward( + QuickpayResponse $payment, + string $paymentId, + array $operationIds, + CallbackWatchRequest $request, + CallbackWatchObserver $observer, + ): void { + if (count($operationIds) > 1) { + // Polling observes only the latest resource snapshot. One POST + // is still made per operation, but same-poll bodies are equal. + $observer->multipleOperations(count($operationIds)); + } + + foreach ($operationIds as $operationId) { + $this->deliver($payment, $paymentId, $operationId, $request, $observer); + } + } + + private function deliver( + QuickpayResponse $payment, + string $paymentId, + string $operationId, + CallbackWatchRequest $request, + CallbackWatchObserver $observer, + ): void { + $envelope = $this->envelopes->make( + $payment, + $request->apiKey, + $request->privateKey, + ); + + $attempt = 0; + + do { + $attempt++; + $delivery = $this->forwarder->deliver($request->target, $envelope); + + if ($delivery->successful) { + break; + } + + if (! $delivery->isRetryable() || $attempt >= $request->deliveryAttempts) { + throw new CallbackDeliveryException( + $paymentId, + $operationId, + $delivery, + $attempt, + $request->deliveryAttempts, + ); + } + + $observer->deliveryRetrying( + paymentId: $paymentId, + operationId: $operationId, + attempt: $attempt, + maximumAttempts: $request->deliveryAttempts, + delay: $request->interval, + status: $delivery->status, + ); + ($this->sleep)($request->interval); + } while (true); + + $observer->delivered($paymentId, $operationId, $delivery->status); + } +} diff --git a/app/Callbacks/Watching/SinglePaymentWatch.php b/app/Callbacks/Watching/SinglePaymentWatch.php new file mode 100644 index 0000000..ac53ce0 --- /dev/null +++ b/app/Callbacks/Watching/SinglePaymentWatch.php @@ -0,0 +1,98 @@ +paymentId; + $payment = $paymentId !== null + ? $this->byId($paymentId, $request, $observer) + : $this->byOrderId($request, $observer); + $known = []; + + if ($payment === null) { + $observer->waitingForPayment($this->orderId($request)); + } else { + $paymentId = WatchedPayment::id($payment->json); + $known = array_fill_keys(array_column(WatchedPayment::operations($payment->json), 'id'), true); + $observer->watchingPayment($paymentId, count($known)); + } + + while (($this->continue)()) { + ($this->sleep)($request->interval); + + if ($paymentId === null) { + $payment = $this->byOrderId($request, $observer); + + if ($payment === null) { + continue; + } + + $paymentId = WatchedPayment::id($payment->json); + $observer->paymentFound($paymentId, $this->orderId($request)); + } else { + $payment = $this->byId($paymentId, $request, $observer); + } + + $new = array_values(array_filter( + array_column(WatchedPayment::operations($payment->json), 'id'), + fn (string $operationId): bool => ! isset($known[$operationId]), + )); + + $this->forwarder->forward($payment, $paymentId, $new, $request, $observer); + $known += array_fill_keys($new, true); + } + } + + private function byId(string $paymentId, CallbackWatchRequest $request, CallbackWatchObserver $observer): QuickpayResponse + { + return $this->poller->poll( + fn (): QuickpayResponse => $this->locator->byId($paymentId), + $request->interval, + $observer, + ); + } + + private function byOrderId(CallbackWatchRequest $request, CallbackWatchObserver $observer): ?QuickpayResponse + { + $orderId = $this->orderId($request); + + return $this->poller->poll( + fn (): ?QuickpayResponse => $this->locator->byOrderId($orderId), + $request->interval, + $observer, + ); + } + + private function orderId(CallbackWatchRequest $request): string + { + return $request->orderId + ?? throw new LogicException('A payment watch without a payment ID needs an order ID.'); + } +} diff --git a/app/Callbacks/Watching/WatchPoller.php b/app/Callbacks/Watching/WatchPoller.php new file mode 100644 index 0000000..3a27b28 --- /dev/null +++ b/app/Callbacks/Watching/WatchPoller.php @@ -0,0 +1,46 @@ +retryable) { + throw $exception; + } + + $delay = $exception->retryAfter ?? $interval; + $observer->pollingRetrying($exception->status, $delay); + ($this->sleep)($delay); + } catch (QuickpayRequestException) { + // QuickpayClient emits this safe generic exception for network + // failures; GET polling can be retried without mutation risk. + $observer->pollingRetrying(null, $interval); + ($this->sleep)($interval); + } + } + } +} diff --git a/app/Callbacks/Watching/WatchedPayment.php b/app/Callbacks/Watching/WatchedPayment.php new file mode 100644 index 0000000..56f4479 --- /dev/null +++ b/app/Callbacks/Watching/WatchedPayment.php @@ -0,0 +1,83 @@ + + */ + public static function operations(mixed $payment): array + { + $operations = is_array($payment) ? ($payment['operations'] ?? null) : null; + + if (! is_array($operations) || ! array_is_list($operations)) { + throw new UnexpectedValueException('Quickpay returned a payment with malformed operations.'); + } + + $normalized = array_map(function (mixed $operation): array { + $id = is_array($operation) ? ($operation['id'] ?? null) : null; + + if ((! is_int($id) && ! is_string($id)) || (string) $id === '') { + throw new UnexpectedValueException('Quickpay returned an operation without a valid operation ID.'); + } + + return [ + 'id' => (string) $id, + 'created_at' => self::operationTimestamp($operation['created_at'] ?? null), + ]; + }, $operations); + + usort($normalized, fn (array $left, array $right): int => [ + (int) $left['created_at']->format('U'), + (int) $left['created_at']->format('u'), + str_pad($left['id'], 20, '0', STR_PAD_LEFT), + ] <=> [ + (int) $right['created_at']->format('U'), + (int) $right['created_at']->format('u'), + str_pad($right['id'], 20, '0', STR_PAD_LEFT), + ]); + + return $normalized; + } + + private static function operationTimestamp(mixed $value): DateTimeImmutable + { + if (! is_string($value) + || preg_match('/\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,6})?(?:Z|[+-]\d{2}:\d{2})\z/D', $value) !== 1) { + throw new UnexpectedValueException('Quickpay returned an operation without a valid timestamp.'); + } + + $format = str_contains($value, '.') ? '!Y-m-d\TH:i:s.uP' : '!Y-m-d\TH:i:sP'; + $timestamp = DateTimeImmutable::createFromFormat($format, $value); + $errors = DateTimeImmutable::getLastErrors(); + + if ($timestamp === false + || ($errors !== false && ($errors['warning_count'] > 0 || $errors['error_count'] > 0))) { + throw new UnexpectedValueException('Quickpay returned an operation without a valid timestamp.'); + } + + return $timestamp->setTimezone(new DateTimeZone('UTC')); + } +} diff --git a/app/Commands/Callbacks/WatchCallbacksCommand.php b/app/Commands/Callbacks/WatchCallbacksCommand.php index 0efe791..b799aa6 100644 --- a/app/Commands/Callbacks/WatchCallbacksCommand.php +++ b/app/Commands/Callbacks/WatchCallbacksCommand.php @@ -7,6 +7,7 @@ use App\Callbacks\WatchCallbacks; use App\Console\AuthenticatedCommand; use App\Console\Input\IntegerInput; +use App\Console\Output\CallbackWatchProgress; use App\Console\Output\ResponseBodySanitizer; use App\Quickpay\AuthenticatedQuickpay; use App\Quickpay\AuthenticatedQuickpayFactory; @@ -75,9 +76,7 @@ function (AuthenticatedQuickpay $authenticated) use ($watch, $privateKeys): int $request, $interval, $deliveryAttempts, - function (string $event, array $context) use ($apiKey, $request): void { - $this->writeWatchEvent($event, $context, $apiKey, $request->target->url); - }, + new CallbackWatchProgress($this, $apiKey, $request->target->url), ); return self::SUCCESS; @@ -114,37 +113,4 @@ private function interval(): int return $interval; } - - /** @param array $context */ - private function writeWatchEvent(string $event, array $context, string $apiKey, string $destination): int - { - $value = fn (string $key): string => ResponseBodySanitizer::terminalLine((string) ($context[$key] ?? '-'), $apiKey); - $safeDestination = ResponseBodySanitizer::terminalLine($destination, $apiKey); - $operation = isset($context['payment_id']) - ? "payment {$value('payment_id')} operation {$value('operation_id')}" - : "operation {$value('operation_id')}"; - $deliveryStatus = ($context['status'] ?? null) === null - ? 'no HTTP response' - : "HTTP {$value('status')}"; - - if ($event === 'watching-all') { - $this->info('Watching all Quickpay payment callbacks. Press Ctrl-C to stop.'); - $this->line("Ready at {$value('ready_at')}; forwarding to {$safeDestination}."); - - return self::SUCCESS; - } - - match ($event) { - 'waiting-for-payment' => $this->line("Waiting for order {$value('order_id')} to create a payment."), - 'watching' => $this->line("Payment {$value('payment_id')} ready; {$value('baseline_operations')} existing operation(s) baselined."), - 'payment-found' => $this->line("Order {$value('order_id')} created payment {$value('payment_id')}."), - 'multiple-operations' => $this->warn("Detected {$value('count')} operations in one poll; forwarding one callback per operation with the same latest payment snapshot."), - 'delivery-retry' => $this->warn("Callback for {$operation} failed on attempt {$value('attempt')} of {$value('maximum_attempts')} ({$deliveryStatus}); retrying in {$value('delay')} second(s) before later operations."), - 'polling-retry' => $this->warn("Quickpay polling failed (HTTP {$value('status')}); retrying in {$value('delay')} second(s)."), - 'delivered' => $this->info("Delivered callback for {$operation} with HTTP {$value('status')}."), - default => null, - }; - - return self::SUCCESS; - } } diff --git a/app/Console/Output/CallbackWatchProgress.php b/app/Console/Output/CallbackWatchProgress.php new file mode 100644 index 0000000..87d7508 --- /dev/null +++ b/app/Console/Output/CallbackWatchProgress.php @@ -0,0 +1,86 @@ +command->info('Watching all Quickpay payment callbacks. Press Ctrl-C to stop.'); + $this->command->line( + "Ready at {$this->safe($readyAt->format(DateTimeImmutable::ATOM))}; " + ."forwarding to {$this->safe($this->destination)}.", + ); + } + + public function waitingForPayment(string $orderId): void + { + $this->command->line("Waiting for order {$this->safe($orderId)} to create a payment."); + } + + public function watchingPayment(string $paymentId, int $baselineOperations): void + { + $this->command->line("Payment {$this->safe($paymentId)} ready; {$this->safe((string) $baselineOperations)} existing operation(s) baselined."); + } + + public function paymentFound(string $paymentId, string $orderId): void + { + $this->command->line("Order {$this->safe($orderId)} created payment {$this->safe($paymentId)}."); + } + + public function multipleOperations(int $count): void + { + $this->command->warn("Detected {$this->safe((string) $count)} operations in one poll; forwarding one callback per operation with the same latest payment snapshot."); + } + + public function deliveryRetrying( + string $paymentId, + string $operationId, + int $attempt, + int $maximumAttempts, + int $delay, + ?int $status, + ): void { + $deliveryStatus = $status === null ? 'no HTTP response' : "HTTP {$this->safe((string) $status)}"; + + $this->command->warn( + "Callback for {$this->operation($paymentId, $operationId)} failed on attempt {$this->safe((string) $attempt)} of {$this->safe((string) $maximumAttempts)} " + ."({$deliveryStatus}); retrying in {$this->safe((string) $delay)} second(s) before later operations.", + ); + } + + public function pollingRetrying(?int $status, int $delay): void + { + $this->command->warn("Quickpay polling failed (HTTP {$this->safe((string) ($status ?? '-'))}); retrying in {$this->safe((string) $delay)} second(s)."); + } + + public function delivered(string $paymentId, string $operationId, ?int $status): void + { + $this->command->info( + "Delivered callback for {$this->operation($paymentId, $operationId)} with HTTP {$this->safe((string) ($status ?? '-'))}.", + ); + } + + private function operation(string $paymentId, string $operationId): string + { + return "payment {$this->safe($paymentId)} operation {$this->safe($operationId)}"; + } + + private function safe(string $value): string + { + return ResponseBodySanitizer::terminalLine($value, $this->apiKey); + } +} diff --git a/tests/Feature/Callbacks/Watching/CallbackWatchRunnerTest.php b/tests/Feature/Callbacks/Watching/CallbackWatchRunnerTest.php index f98529d..3b96beb 100644 --- a/tests/Feature/Callbacks/Watching/CallbackWatchRunnerTest.php +++ b/tests/Feature/Callbacks/Watching/CallbackWatchRunnerTest.php @@ -6,6 +6,8 @@ use App\Callbacks\Signing\CallbackEnvelopeFactory; use App\Callbacks\Watching\CallbackDeliveryException; use App\Callbacks\Watching\CallbackWatcherFactory; +use App\Callbacks\Watching\CallbackWatchObserver; +use App\Callbacks\Watching\CallbackWatchRequest; use App\Callbacks\Watching\CallbackWatchRunner; use App\Credentials\MerchantAccess; use App\Quickpay\QuickpayClient; @@ -34,16 +36,16 @@ ); $runner->run( - paymentId: null, - orderId: null, - target: CallbackTarget::fromString('http://localhost/callback'), - apiKey: 'api-key', - privateKey: 'private-key', - interval: 2, - deliveryAttempts: 5, - observer: function (string $event, array $context) use (&$events): void { - $events[] = [$event, $context]; - }, + new CallbackWatchRequest( + paymentId: null, + orderId: null, + target: CallbackTarget::fromString('http://localhost/callback'), + apiKey: 'api-key', + privateKey: 'private-key', + interval: 2, + deliveryAttempts: 5, + ), + recordedWatchEvents($events), ); expect($waitedUntil)->toBe(['2026-08-07T10:00:01.000000+00:00']) @@ -93,16 +95,16 @@ ); $runner->run( - paymentId: null, - orderId: null, - target: CallbackTarget::fromString('http://localhost/callback'), - apiKey: 'api-key', - privateKey: 'private-key', - interval: 2, - deliveryAttempts: 5, - observer: function (string $event, array $context) use (&$events): void { - $events[] = [$event, $context]; - }, + new CallbackWatchRequest( + paymentId: null, + orderId: null, + target: CallbackTarget::fromString('http://localhost/callback'), + apiKey: 'api-key', + privateKey: 'private-key', + interval: 2, + deliveryAttempts: 5, + ), + recordedWatchEvents($events), ); $callbackPaymentIds = collect(Http::recorded()) @@ -159,16 +161,16 @@ ); $runner->run( - paymentId: null, - orderId: null, - target: CallbackTarget::fromString('http://localhost/callback'), - apiKey: 'api-key', - privateKey: 'private-key', - interval: 2, - deliveryAttempts: 5, - observer: function (string $event, array $context) use (&$events): void { - $events[] = [$event, $context]; - }, + new CallbackWatchRequest( + paymentId: null, + orderId: null, + target: CallbackTarget::fromString('http://localhost/callback'), + apiKey: 'api-key', + privateKey: 'private-key', + interval: 2, + deliveryAttempts: 5, + ), + recordedWatchEvents($events), ); $delivered = collect($events) @@ -216,16 +218,16 @@ ); $runner->run( - paymentId: null, - orderId: null, - target: CallbackTarget::fromString('http://localhost/callback'), - apiKey: 'api-key', - privateKey: 'private-key', - interval: 2, - deliveryAttempts: 5, - observer: function (string $event, array $context) use (&$events): void { - $events[] = [$event, $context]; - }, + new CallbackWatchRequest( + paymentId: null, + orderId: null, + target: CallbackTarget::fromString('http://localhost/callback'), + apiKey: 'api-key', + privateKey: 'private-key', + interval: 2, + deliveryAttempts: 5, + ), + recordedWatchEvents($events), ); $scanUrls = collect(Http::recorded()) @@ -264,16 +266,16 @@ ); $runner->run( - paymentId: null, - orderId: null, - target: CallbackTarget::fromString('http://localhost/callback'), - apiKey: 'api-key', - privateKey: 'private-key', - interval: 2, - deliveryAttempts: 5, - observer: function (string $event, array $context) use (&$events): void { - $events[] = [$event, $context]; - }, + new CallbackWatchRequest( + paymentId: null, + orderId: null, + target: CallbackTarget::fromString('http://localhost/callback'), + apiKey: 'api-key', + privateKey: 'private-key', + interval: 2, + deliveryAttempts: 5, + ), + recordedWatchEvents($events), ); $scanUrls = collect(Http::recorded()) @@ -314,14 +316,16 @@ ); expect(fn () => $runner->run( - paymentId: null, - orderId: null, - target: CallbackTarget::fromString('http://localhost/callback'), - apiKey: 'api-key', - privateKey: 'private-key', - interval: 2, - deliveryAttempts: 5, - observer: fn (string $event, array $context): null => null, + new CallbackWatchRequest( + paymentId: null, + orderId: null, + target: CallbackTarget::fromString('http://localhost/callback'), + apiKey: 'api-key', + privateKey: 'private-key', + interval: 2, + deliveryAttempts: 5, + ), + recordedWatchEvents(), ))->toThrow(UnexpectedValueException::class, 'valid timestamp'); Http::assertNotSent(fn (Request $request): bool => $request->url() === 'http://localhost/callback'); @@ -356,14 +360,16 @@ ); expect(fn () => $runner->run( - paymentId: null, - orderId: null, - target: CallbackTarget::fromString('http://localhost/callback'), - apiKey: 'api-key', - privateKey: 'private-key', - interval: 2, - deliveryAttempts: 5, - observer: fn (string $event, array $context): null => null, + new CallbackWatchRequest( + paymentId: null, + orderId: null, + target: CallbackTarget::fromString('http://localhost/callback'), + apiKey: 'api-key', + privateKey: 'private-key', + interval: 2, + deliveryAttempts: 5, + ), + recordedWatchEvents(), ))->toThrow(UnexpectedValueException::class, 'malformed operations'); }); @@ -384,16 +390,16 @@ $runner = callbackWatchRunner($sleeps, 1); $runner->run( - paymentId: '42', - orderId: null, - target: CallbackTarget::fromString('http://localhost/callback'), - apiKey: 'api-key', - privateKey: 'private-key', - interval: 2, - deliveryAttempts: 5, - observer: function (string $event, array $context) use (&$events): void { - $events[] = [$event, $context]; - }, + new CallbackWatchRequest( + paymentId: '42', + orderId: null, + target: CallbackTarget::fromString('http://localhost/callback'), + apiKey: 'api-key', + privateKey: 'private-key', + interval: 2, + deliveryAttempts: 5, + ), + recordedWatchEvents($events), ); $localRequests = collect(Http::recorded()) @@ -423,16 +429,16 @@ $runner = callbackWatchRunner($sleeps, 1); $runner->run( - paymentId: '42', - orderId: null, - target: CallbackTarget::fromString('http://localhost/callback'), - apiKey: 'api-key', - privateKey: 'private-key', - interval: 2, - deliveryAttempts: 5, - observer: function (string $event, array $context) use (&$events): void { - $events[] = [$event, $context]; - }, + new CallbackWatchRequest( + paymentId: '42', + orderId: null, + target: CallbackTarget::fromString('http://localhost/callback'), + apiKey: 'api-key', + privateKey: 'private-key', + interval: 2, + deliveryAttempts: 5, + ), + recordedWatchEvents($events), ); $delivered = collect($events) @@ -459,16 +465,16 @@ $events = []; $runner->run( - paymentId: null, - orderId: 'new-order', - target: CallbackTarget::fromString('http://localhost/callback'), - apiKey: 'api-key', - privateKey: 'private-key', - interval: 3, - deliveryAttempts: 5, - observer: function (string $event, array $context) use (&$events): void { - $events[] = [$event, $context]; - }, + new CallbackWatchRequest( + paymentId: null, + orderId: 'new-order', + target: CallbackTarget::fromString('http://localhost/callback'), + apiKey: 'api-key', + privateKey: 'private-key', + interval: 3, + deliveryAttempts: 5, + ), + recordedWatchEvents($events), ); Http::assertSent(fn (Request $request): bool => $request->url() === 'http://localhost/callback'); @@ -495,16 +501,16 @@ $runner = callbackWatchRunner($sleeps, 1); $runner->run( - paymentId: '42', - orderId: null, - target: CallbackTarget::fromString('http://localhost/callback'), - apiKey: 'api-key', - privateKey: 'private-key', - interval: 2, - deliveryAttempts: 5, - observer: function (string $event, array $context) use (&$events): void { - $events[] = [$event, $context]; - }, + new CallbackWatchRequest( + paymentId: '42', + orderId: null, + target: CallbackTarget::fromString('http://localhost/callback'), + apiKey: 'api-key', + privateKey: 'private-key', + interval: 2, + deliveryAttempts: 5, + ), + recordedWatchEvents($events), ); $requests = collect(Http::recorded()) @@ -546,14 +552,16 @@ $runner = callbackWatchRunner($sleeps, 1); expect(fn () => $runner->run( - paymentId: '42', - orderId: null, - target: CallbackTarget::fromString('http://localhost/callback'), - apiKey: 'api-key', - privateKey: 'private-key', - interval: 2, - deliveryAttempts: 5, - observer: fn (string $event, array $context): null => null, + new CallbackWatchRequest( + paymentId: '42', + orderId: null, + target: CallbackTarget::fromString('http://localhost/callback'), + apiKey: 'api-key', + privateKey: 'private-key', + interval: 2, + deliveryAttempts: 5, + ), + recordedWatchEvents(), ))->toThrow(CallbackDeliveryException::class, 'payment 42 operation 1 after attempt 1 of 5 (HTTP 405)'); $callbackRequests = collect(Http::recorded()) @@ -584,16 +592,16 @@ $runner = callbackWatchRunner($sleeps, 1); expect(fn () => $runner->run( - paymentId: '42', - orderId: null, - target: CallbackTarget::fromString('http://localhost/callback'), - apiKey: 'api-key', - privateKey: 'private-key', - interval: 2, - deliveryAttempts: 5, - observer: function (string $event, array $context) use ($events): void { - $events[] = [$event, $context]; - }, + new CallbackWatchRequest( + paymentId: '42', + orderId: null, + target: CallbackTarget::fromString('http://localhost/callback'), + apiKey: 'api-key', + privateKey: 'private-key', + interval: 2, + deliveryAttempts: 5, + ), + recordedWatchEvents($events), ))->toThrow(CallbackDeliveryException::class, 'payment 42 operation 1 after attempt 5 of 5 (HTTP 503)'); $callbackRequests = collect(Http::recorded()) @@ -618,16 +626,16 @@ $runner = callbackWatchRunner($sleeps, 1); expect(fn () => $runner->run( - paymentId: '42', - orderId: null, - target: CallbackTarget::fromString('http://localhost/callback'), - apiKey: 'api-key', - privateKey: 'private-key', - interval: 2, - deliveryAttempts: 1, - observer: function (string $event, array $context) use ($events): void { - $events[] = [$event, $context]; - }, + new CallbackWatchRequest( + paymentId: '42', + orderId: null, + target: CallbackTarget::fromString('http://localhost/callback'), + apiKey: 'api-key', + privateKey: 'private-key', + interval: 2, + deliveryAttempts: 1, + ), + recordedWatchEvents($events), ))->toThrow(CallbackDeliveryException::class, 'after attempt 1 of 1 (HTTP 503)'); $callbackRequests = collect(Http::recorded()) @@ -650,16 +658,16 @@ $runner = callbackWatchRunner($sleeps, 0); $runner->run( - paymentId: '42', - orderId: null, - target: CallbackTarget::fromString('http://localhost/callback'), - apiKey: 'api-key', - privateKey: 'private-key', - interval: 2, - deliveryAttempts: 5, - observer: function (string $event, array $context) use (&$events): void { - $events[] = [$event, $context]; - }, + new CallbackWatchRequest( + paymentId: '42', + orderId: null, + target: CallbackTarget::fromString('http://localhost/callback'), + apiKey: 'api-key', + privateKey: 'private-key', + interval: 2, + deliveryAttempts: 5, + ), + recordedWatchEvents($events), ); expect($sleeps)->toBe([7]) @@ -715,3 +723,74 @@ function callbackWatchRunner( waitUntil: $waitUntil, ); } + +/** + * Records observer calls as [event, context] pairs named after the watch events. + * + * @param array}>|ArrayObject $events + */ +function recordedWatchEvents(array|ArrayObject &$events = []): CallbackWatchObserver +{ + return new class($events) implements CallbackWatchObserver + { + /** @param array|ArrayObject $events */ + public function __construct(private array|ArrayObject &$events) {} + + public function watchingAllPayments(DateTimeImmutable $readyAt): void + { + $this->events[] = ['watching-all', ['ready_at' => $readyAt->format(DateTimeImmutable::ATOM)]]; + } + + public function waitingForPayment(string $orderId): void + { + $this->events[] = ['waiting-for-payment', ['order_id' => $orderId]]; + } + + public function watchingPayment(string $paymentId, int $baselineOperations): void + { + $this->events[] = ['watching', ['payment_id' => $paymentId, 'baseline_operations' => $baselineOperations]]; + } + + public function paymentFound(string $paymentId, string $orderId): void + { + $this->events[] = ['payment-found', ['payment_id' => $paymentId, 'order_id' => $orderId]]; + } + + public function multipleOperations(int $count): void + { + $this->events[] = ['multiple-operations', ['count' => $count]]; + } + + public function deliveryRetrying( + string $paymentId, + string $operationId, + int $attempt, + int $maximumAttempts, + int $delay, + ?int $status, + ): void { + $this->events[] = ['delivery-retry', [ + 'attempt' => $attempt, + 'maximum_attempts' => $maximumAttempts, + 'delay' => $delay, + 'payment_id' => $paymentId, + 'operation_id' => $operationId, + 'status' => $status, + ]]; + } + + public function pollingRetrying(?int $status, int $delay): void + { + $this->events[] = ['polling-retry', ['status' => $status, 'delay' => $delay]]; + } + + public function delivered(string $paymentId, string $operationId, ?int $status): void + { + $this->events[] = ['delivered', [ + 'payment_id' => $paymentId, + 'operation_id' => $operationId, + 'status' => $status, + ]]; + } + }; +} diff --git a/tests/Feature/Commands/Callbacks/WatchCallbacksCommandTest.php b/tests/Feature/Commands/Callbacks/WatchCallbacksCommandTest.php index b3b023f..a267110 100644 --- a/tests/Feature/Commands/Callbacks/WatchCallbacksCommandTest.php +++ b/tests/Feature/Commands/Callbacks/WatchCallbacksCommandTest.php @@ -2,10 +2,11 @@ use App\Callbacks\Delivery\CallbackDelivery; use App\Callbacks\Delivery\CallbackDeliveryFailure; -use App\Callbacks\Delivery\CallbackTarget; use App\Callbacks\Watching\CallbackDeliveryException; use App\Callbacks\Watching\CallbackWatcher; use App\Callbacks\Watching\CallbackWatcherFactory; +use App\Callbacks\Watching\CallbackWatchObserver; +use App\Callbacks\Watching\CallbackWatchRequest; use App\Commands\Callbacks\WatchCallbacksCommand; use App\Commands\Payments\CancelPaymentCommand; use App\Commands\Payments\CapturePaymentCommand; @@ -70,24 +71,16 @@ public function make(QuickpayClient $quickpay, Factory $http): CallbackWatcher { return new class implements CallbackWatcher { - public function run( - ?string $paymentId, - ?string $orderId, - CallbackTarget $target, - string $apiKey, - string $privateKey, - int $interval, - int $deliveryAttempts, - Closure $observer, - ): void { - expect($paymentId)->toBeNull() - ->and($orderId)->toBeNull() - ->and($target->url)->toBe('http://localhost/callback') - ->and($deliveryAttempts)->toBe(5); - - $observer('watching-all', ['ready_at' => '2026-08-07T10:00:01+00:00']); - $observer('delivered', ['payment_id' => '42', 'operation_id' => '1', 'status' => 204]); - $observer('delivered', ['payment_id' => '43', 'operation_id' => '1', 'status' => 204]); + public function run(CallbackWatchRequest $request, CallbackWatchObserver $observer): void + { + expect($request->paymentId)->toBeNull() + ->and($request->orderId)->toBeNull() + ->and($request->target->url)->toBe('http://localhost/callback') + ->and($request->deliveryAttempts)->toBe(5); + + $observer->watchingAllPayments(new DateTimeImmutable('2026-08-07T10:00:01+00:00')); + $observer->delivered('42', '1', 204); + $observer->delivered('43', '1', 204); } }; } @@ -157,38 +150,30 @@ public function make(QuickpayClient $quickpay, Factory $http): CallbackWatcher { return new class implements CallbackWatcher { - public function run( - ?string $paymentId, - ?string $orderId, - CallbackTarget $target, - string $apiKey, - string $privateKey, - int $interval, - int $deliveryAttempts, - Closure $observer, - ): void { - expect($paymentId)->toBe('42') - ->and($orderId)->toBeNull() - ->and($target->url)->toBe('http://localhost/callback') - ->and($apiKey)->toBe('watch-api-key') - ->and($privateKey)->toBe('watch-private-key') - ->and($interval)->toBe(2) - ->and($deliveryAttempts)->toBe(7); - - $observer('waiting-for-payment', ['order_id' => 'order-42']); - $observer('watching', ['payment_id' => '42', 'baseline_operations' => 1]); - $observer('payment-found', ['payment_id' => '42', 'order_id' => 'order-42']); - $observer('multiple-operations', ['count' => 2]); - $observer('delivery-retry', [ - 'attempt' => 1, - 'maximum_attempts' => 7, - 'delay' => 2, - 'payment_id' => '42', - 'operation_id' => '7', - 'status' => 500, - ]); - $observer('polling-retry', ['status' => 429, 'delay' => 3]); - $observer('delivered', ['operation_id' => '7', 'status' => 204]); + public function run(CallbackWatchRequest $request, CallbackWatchObserver $observer): void + { + expect($request->paymentId)->toBe('42') + ->and($request->orderId)->toBeNull() + ->and($request->target->url)->toBe('http://localhost/callback') + ->and($request->apiKey)->toBe('watch-api-key') + ->and($request->privateKey)->toBe('watch-private-key') + ->and($request->interval)->toBe(2) + ->and($request->deliveryAttempts)->toBe(7); + + $observer->waitingForPayment('order-42'); + $observer->watchingPayment('42', 1); + $observer->paymentFound('42', 'order-42'); + $observer->multipleOperations(2); + $observer->deliveryRetrying( + paymentId: '42', + operationId: '7', + attempt: 1, + maximumAttempts: 7, + delay: 2, + status: 500, + ); + $observer->pollingRetrying(429, 3); + $observer->delivered('42', '7', 204); } }; } @@ -216,7 +201,7 @@ public function run( ->toContain('HTTP 500') ->toContain('retrying in 2 second(s) before later operations') ->toContain('retrying in 3 second(s)') - ->toContain('Delivered callback for operation 7'); + ->toContain('Delivered callback for payment 42 operation 7'); Http::assertNothingSent(); }); @@ -231,17 +216,9 @@ public function make(QuickpayClient $quickpay, Factory $http): CallbackWatcher { public function __construct(private readonly int $expectedAttempts) {} - public function run( - ?string $paymentId, - ?string $orderId, - CallbackTarget $target, - string $apiKey, - string $privateKey, - int $interval, - int $deliveryAttempts, - Closure $observer, - ): void { - expect($deliveryAttempts)->toBe($this->expectedAttempts); + public function run(CallbackWatchRequest $request, CallbackWatchObserver $observer): void + { + expect($request->deliveryAttempts)->toBe($this->expectedAttempts); } }; } @@ -282,27 +259,19 @@ public function __construct( private readonly int $attempt, ) {} - public function run( - ?string $paymentId, - ?string $orderId, - CallbackTarget $target, - string $apiKey, - string $privateKey, - int $interval, - int $deliveryAttempts, - Closure $observer, - ): void { + public function run(CallbackWatchRequest $request, CallbackWatchObserver $observer): void + { throw new CallbackDeliveryException( paymentId: '42', operationId: 'watch-api-key-operation', delivery: new CallbackDelivery( - url: $target->url, + url: $request->target->url, status: $this->status, successful: false, failure: $this->failure, ), attempt: $this->attempt, - maximumAttempts: $deliveryAttempts, + maximumAttempts: $request->deliveryAttempts, ); } }; diff --git a/tests/Feature/Console/AuthenticatedCommandTest.php b/tests/Feature/Console/AuthenticatedCommandTest.php index d74966e..bf1da4d 100644 --- a/tests/Feature/Console/AuthenticatedCommandTest.php +++ b/tests/Feature/Console/AuthenticatedCommandTest.php @@ -1,8 +1,9 @@ store->select('shop-a'); $this->store->remove('shop-b'); $this->quickpay->get('/ping'); $this->quickpay->get('/ping'); - if ($paymentId === null) { - $observer('watching-all', ['ready_at' => '2026-09-30T10:00:00+00:00']); + if ($request->isAccountWide()) { + $observer->watchingAllPayments(new DateTimeImmutable('2026-09-30T10:00:00+00:00')); } } }; @@ -277,7 +278,7 @@ public function make(QuickpayClient $quickpay, Factory $http): CallbackWatcher { return new class implements CallbackWatcher { - public function run(?string $paymentId, ?string $orderId, CallbackTarget $target, string $apiKey, string $privateKey, int $interval, int $deliveryAttempts, Closure $observer): void {} + public function run(CallbackWatchRequest $request, CallbackWatchObserver $observer): void {} }; } });