| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- namespace Webkul\BagistoApi\State;
- use ApiPlatform\Metadata\Operation;
- use ApiPlatform\State\ProcessorInterface;
- use Webkul\BagistoApi\Dto\PaymentCallbackInput;
- use Webkul\BagistoApi\Exception\OperationFailedException;
- use Webkul\BagistoApi\Services\PaymentService;
- /**
- * Single point of entry for the gateway return (success/cancel/failure).
- * Address blocks on the input are required only for express success
- * calls where the gateway supplied the buyer's real shipping address.
- */
- class PaymentCallbackProcessor implements ProcessorInterface
- {
- public function __construct(
- protected PaymentService $paymentService,
- ) {}
- public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): mixed
- {
- if (! $data instanceof PaymentCallbackInput) {
- throw new OperationFailedException(__('bagistoapi::app.graphql.checkout.invalid-input'));
- }
- $result = $this->paymentService->callback($data);
- $order = $result['order'];
- return (object) [
- 'id' => (int) $order->id,
- 'success' => $result['status'] === 'success',
- 'message' => $result['message'],
- 'orderId' => (string) $order->id,
- 'status' => $result['status'],
- 'orderStatus' => (string) $order->status,
- 'gatewayStatus' => $result['gatewayStatus'],
- ];
- }
- }
|