commandPool = $commandPool; $this->subjectReader = $subjectReader; } /** * @inheritdoc */ public function execute(array $commandSubject): void { $command = $this->getCommand($commandSubject); $this->commandPool->get($command) ->execute($commandSubject); } /** * Determines the command that should be used based on the status of the transaction * * @param array $commandSubject * @return string * @throws CommandException */ private function getCommand(array $commandSubject): string { $details = $this->commandPool->get('get_transaction_details') ->execute($commandSubject) ->get(); if ($details['transaction']['transactionStatus'] === 'capturedPendingSettlement') { return self::VOID; } elseif ($details['transaction']['transactionStatus'] !== 'settledSuccessfully') { throw new CommandException(__('This transaction cannot be refunded with its current status.')); } return self::REFUND; } }