Page MenuHomePhorge

D4097.1775492197.diff
No OneTemporary

Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None

D4097.1775492197.diff

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,19 @@
// 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.
+ // FIXME: for now we just go with this mode as soon as we have months set.
+ if (($plan = $wallet->plan()) && $plan->months >= 1) {
+ $mandate['amount'] = $plan->cost() * $plan->months;
+ $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 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::table(
+ 'plans',
+ function (Blueprint $table) {
+ $table->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 @@
<div v-if="mandate.isDisabled" class="disabled-mandate alert alert-danger">
{{ $t('wallet.auto-payment-disabled') }}
</div>
+ <div v-if="mandate.isFixed" class="disabled-mandate alert alert-danger">
+ This is a fixed mandate
+ </div>
<template v-else>
<p v-html="$t('wallet.auto-payment-info', { amount: mandate.amount + ' ' + wallet.currency, balance: mandate.balance + ' ' + wallet.currency})"></p>
<p>{{ $t('wallet.payment-method', { method: mandate.method }) }}</p>

File Metadata

Mime Type
text/plain
Expires
Mon, Apr 6, 4:16 PM (2 h, 40 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18838257
Default Alt Text
D4097.1775492197.diff (3 KB)

Event Timeline