unknownRefund example

public function refund(string $refundId, Context $context): void
    {
        $criteria = new Criteria([$refundId]);
        $criteria->addAssociation('stateMachineState');
        $criteria->addAssociation('transactionCapture.transaction.order');
        $criteria->addAssociation('transactionCapture.transaction.paymentMethod.appPaymentMethod.app');
        $criteria->addAssociation('transactionCapture.positions');

        $refund = $this->refundRepository->search($criteria$context)->first();

        if (!($refund instanceof OrderTransactionCaptureRefundEntity)) {
            throw PaymentException::unknownRefund($refundId);
        }

        if (!$refund->getTransactionCapture()
            || !$refund->getTransactionCapture()->getTransaction()
            || !$refund->getTransactionCapture()->getTransaction()->getOrder()
        ) {
            return;
        }

        $transaction = $refund->getTransactionCapture()->getTransaction();
        $paymentMethod = $this->getAppPaymentMethod($transaction);
        
->select('refund.id', 'state.technical_name', 'transaction.payment_method_id')
            ->from('order_transaction_capture_refund', self::TABLE_ALIAS)
            ->innerJoin(self::TABLE_ALIAS, 'state_machine_state', 'state', 'refund.state_id = state.id')
            ->innerJoin(self::TABLE_ALIAS, 'order_transaction_capture', 'capture', 'capture.id = refund.capture_id')
            ->innerJoin(self::TABLE_ALIAS, 'order_transaction', 'transaction', 'transaction.id = capture.order_transaction_id')
            ->andWhere('refund.id = :refundId')
            ->setParameter('refundId', Uuid::fromHexToBytes($refundId))
            ->executeQuery()
            ->fetchAssociative();

        if (!$result || !\array_key_exists('technical_name', $result) || !\array_key_exists('payment_method_id', $result)) {
            throw PaymentException::unknownRefund($refundId);
        }

        if ($result['technical_name'] !== OrderTransactionCaptureRefundStates::STATE_OPEN) {
            throw PaymentException::refundInvalidTransition($refundId$result['technical_name']);
        }

        $paymentMethodId = Uuid::fromBytesToHex($result['payment_method_id']);
        $refundHandler = $this->paymentHandlerRegistry->getRefundPaymentHandler($paymentMethodId);

        if (!$refundHandler instanceof RefundPaymentHandlerInterface) {
            throw PaymentException::unknownRefundHandler($refundId);
        }
Home | Imprint | This part of the site doesn't use cookies.