diff --git a/src/elements/PaymentForm.php b/src/elements/PaymentForm.php index 95b967d..c283f25 100644 --- a/src/elements/PaymentForm.php +++ b/src/elements/PaymentForm.php @@ -621,11 +621,6 @@ public function getPublicData($options = null) $paymentTypeIds = json_decode($this->paymentType, true); $singlePlanSetupFee = $this->singlePlanSetupFee; - if ($this->settings->useSca){ - // @todo one time fees amounts are not supported in SCA - $setupFees = []; - $singlePlanSetupFee = ''; - } $publicData = [ 'useSca' => $this->settings->useSca, diff --git a/src/models/Settings.php b/src/models/Settings.php index 0becc14..fba532d 100644 --- a/src/models/Settings.php +++ b/src/models/Settings.php @@ -26,6 +26,7 @@ class Settings extends Model public $returnUrl; public $defaultCurrency = 'USD'; public $chargeDescription = 'Order from {email}'; + public $oneTimeSetupFeeLabel = 'One time set-up fee'; // Tax public $enableTaxes = 0; public $taxType = 0; diff --git a/src/services/Checkout.php b/src/services/Checkout.php index 4766d8e..e9ed086 100644 --- a/src/services/Checkout.php +++ b/src/services/Checkout.php @@ -130,6 +130,8 @@ private function handleSubscription(PaymentForm $paymentForm, $postData, $metada // By default assume that is a single plan $plan = $paymentForm->getSinglePlan(); $trialPeriodDays = null; + $settings = Stripe::$app->settings->getSettings(); + $oneTineFee = []; if ($paymentForm->subscriptionType == SubscriptionType::SINGLE_PLAN && $paymentForm->enableCustomPlanAmount) { if ($data['amount'] > 0){ @@ -157,6 +159,15 @@ private function handleSubscription(PaymentForm $paymentForm, $postData, $metada } $plan = StripePlugin::$app->plans->getStripePlan($planId); + $setupFee = StripePlugin::$app->orders->getSetupFeeFromMatrix($planId, $paymentForm); + if ($setupFee){ + $oneTineFee = [ + 'amount' => Stripe::$app->orders->convertToCents($setupFee, $paymentForm->currency), + 'currency' => $paymentForm->currency, + 'name' => $settings->oneTimeSetupFeeLabel, + 'quantity' => 1 + ]; + } } // Override plan if is a custom plan donation @@ -184,6 +195,22 @@ private function handleSubscription(PaymentForm $paymentForm, $postData, $metada $sessionParams['subscription_data'] = $subscriptionData; + // One time fees + if ($paymentForm->subscriptionType == SubscriptionType::SINGLE_PLAN){ + if ($paymentForm->singlePlanSetupFee){ + $oneTineFee = [ + 'amount' => Stripe::$app->orders->convertToCents($paymentForm->singlePlanSetupFee, $paymentForm->currency), + 'currency' => $paymentForm->currency, + 'name' => $settings->oneTimeSetupFeeLabel, + 'quantity' => 1 + ]; + } + } + + if ($oneTineFee){ + $sessionParams['line_items'] = [$oneTineFee]; + } + return $sessionParams; } diff --git a/src/services/PaymentIntents.php b/src/services/PaymentIntents.php index 102dd81..a700306 100644 --- a/src/services/PaymentIntents.php +++ b/src/services/PaymentIntents.php @@ -116,27 +116,11 @@ public function createOrderFromSubscription($subscription, $checkoutSession) { $metadata = $subscription['metadata']; $formId = $metadata['stripe_payments_form_id']; - $paymentForm = StripePlugin::$app->paymentForms->getPaymentFormById($formId); $userId = $metadata['stripe_payments_user_id']; $quantity = $metadata['stripe_payments_quantity']; $testMode = !$checkoutSession['livemode']; $customer = Stripe::$app->customers->getStripeCustomer($subscription['customer']); Stripe::$app->customers->registerCustomer($customer, $testMode); - $planId = $subscription['plan']['id']; - - if ($paymentForm->subscriptionType == SubscriptionType::SINGLE_PLAN){ - if ($paymentForm->singlePlanSetupFee){ - // @todo One-time setup fee for SCA is not supported yet. - // StripePlugin::$app->orders->addOneTimeSetupFee($customer, $paymentForm->singlePlanSetupFee, $paymentForm); - } - } - - if ($paymentForm->subscriptionType == SubscriptionType::MULTIPLE_PLANS){ - $setupFee = StripePlugin::$app->orders->getSetupFeeFromMatrix($planId, $paymentForm); - if ($setupFee){ - // StripePlugin::$app->orders->addOneTimeSetupFee($customer, $setupFee, $paymentForm); - } - } $invoice = Stripe::$app->customers->getStripeInvoice($subscription['latest_invoice']); diff --git a/src/templates/settings/default.twig b/src/templates/settings/default.twig index 971d217..61542f9 100644 --- a/src/templates/settings/default.twig +++ b/src/templates/settings/default.twig @@ -128,6 +128,16 @@ If you instead want to cancel the subscription at the end of the current billing value: settings.chargeDescription, errors: settings.getErrors('chargeDescription') }) }} + +
+ {{ forms.textField({ + label: "One time set-up fee label"|t('enupal-stripe'), + instructions: "It is displayed when a one-time setup fee to a subscription and the new Stripe Checkout is enabled"|t('enupal-stripe'), + id: 'oneTimeSetupFeeLabel', + name: 'oneTimeSetupFeeLabel', + value: settings.oneTimeSetupFeeLabel, + errors: settings.getErrors('oneTimeSetupFeeLabel') + }) }} {% endnamespace %}