diff --git a/src/app/Http/Controllers/API/V4/PaymentsController.php b/src/app/Http/Controllers/API/V4/PaymentsController.php --- a/src/app/Http/Controllers/API/V4/PaymentsController.php +++ b/src/app/Http/Controllers/API/V4/PaymentsController.php @@ -360,9 +360,18 @@ // Get the Mandate info $mandate = (array) $provider->getMandate($wallet); - $mandate['amount'] = (int) (PaymentProvider::MIN_AMOUNT / 100); - $mandate['balance'] = 0; - $mandate['isDisabled'] = !empty($mandate['id']) && $settings['mandate_disabled']; + // If this is a multi-month plan, we calculate the expected amount to be payed. + if (($plan = $wallet->plan()) && $plan->months >= 1) { + $mandate['amount'] = (int) (($plan->cost() * $plan->months) / 100); + $mandate['balance'] = 0; + $mandate['isDisabled'] = !empty($mandate['id']) && $settings['mandate_disabled']; + $mandate['isFixed'] = true; + } else { + $mandate['amount'] = (int) (PaymentProvider::MIN_AMOUNT / 100); + $mandate['balance'] = 0; + $mandate['isDisabled'] = !empty($mandate['id']) && $settings['mandate_disabled']; + $mandate['isFixed'] = false; + } foreach (['amount', 'balance'] as $key) { if (($value = $settings["mandate_{$key}"]) !== null) { diff --git a/src/app/Plan.php b/src/app/Plan.php --- a/src/app/Plan.php +++ b/src/app/Plan.php @@ -49,6 +49,8 @@ 'discount_qty', // the rate of the discount for this plan 'discount_rate', + // minimum number of months this plan is for + 'months', // number of free months (trial) 'free_months', ]; @@ -59,6 +61,7 @@ 'promo_to' => 'datetime:Y-m-d H:i:s', 'discount_qty' => 'integer', 'discount_rate' => 'integer', + 'months' => 'integer', 'free_months' => 'integer' ]; diff --git a/src/database/migrations/2023_01_03_100000_plans_months.php b/src/database/migrations/2023_01_03_100000_plans_months.php new file mode 100644 --- /dev/null +++ b/src/database/migrations/2023_01_03_100000_plans_months.php @@ -0,0 +1,38 @@ +tinyInteger('months')->unsigned()->default(1); + } + ); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table( + 'plans', + function (Blueprint $table) { + $table->dropColumn('months'); + } + ); + } +}; diff --git a/src/resources/vue/Wallet.vue b/src/resources/vue/Wallet.vue --- a/src/resources/vue/Wallet.vue +++ b/src/resources/vue/Wallet.vue @@ -25,6 +25,9 @@
{{ $t('wallet.auto-payment-disabled') }}
+
+ This is a fixed mandate +