Skip to content
Code-Schnipsel Gruppen Projekte
confirmSubscription.php 1,25 KiB
Newer Older
Patrick Müller's avatar
Patrick Müller committed
<?php

use QUI\ERP\Order\Handler;
use QUI\Utils\Security\Orthos;
use QUI\ERP\Payments\Stripe\StripeException;
use QUI\ERP\Payments\Stripe\PaymentMethods\Recurring\Subscriptions;
use QUI\ERP\Payments\Stripe\AbstractBasePayment;
Patrick Müller's avatar
Patrick Müller committed

/**
 * Confirm a Stripe Subscription
 *
 * @param int $basketId - Basket ID
 * @return array - Subscription confirmation data
 */
QUI::$Ajax->registerFunction(
    'package_quiqqer_payment-stripe_ajax_confirmSubscription',
    function ($orderHash) {
        try {
            $orderHash = Orthos::clear($orderHash);
            $Order     = Handler::getInstance()->getOrderByHash($orderHash);

            return Subscriptions::confirmSubscription(
                $Order->getPaymentDataEntry(AbstractBasePayment::ATTR_STRIPE_SUBSCRIPTION_ID)
Patrick Müller's avatar
Patrick Müller committed
            );
        } catch (\Exception $Exception) {
            if ($Exception instanceof CardException) {
                QUI\System\Log::writeDebugException($Exception);
            } else {
                QUI\System\Log::writeException($Exception);
            }
Patrick Müller's avatar
Patrick Müller committed

            throw new StripeException([
                'quiqqer/payment-stripe',
                'exception.ajax.createPaymentIntent.general_error'
            ]);
        }
    },
    ['orderHash']