mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-29 18:52:22 +01:00
Merge branch 'monthly-payment' into staging
This commit is contained in:
commit
b4eb5d3f81
@ -7,4 +7,4 @@ import { IApplication } from '../../models/application';
|
||||
|
||||
declare var Application: IApplication;
|
||||
|
||||
Application.Components.component('switch', react2angular(Switch, ['checked', 'onChange', 'id', 'className']));
|
||||
Application.Components.component('switch', react2angular(Switch, ['checked', 'onChange', 'id', 'className', 'disabled']));
|
||||
|
@ -810,12 +810,18 @@ Application.Controllers.controller('EditMemberController', ['$scope', '$state',
|
||||
templateUrl: '/admin/subscriptions/create_modal.html',
|
||||
size: 'lg',
|
||||
controller: ['$scope', '$uibModalInstance', 'Subscription', function ($scope, $uibModalInstance, Subscription) {
|
||||
// selected user
|
||||
// selected user
|
||||
$scope.user = user;
|
||||
|
||||
// available plans for the selected user
|
||||
$scope.plans = plans;
|
||||
|
||||
// default parameters for the new subscription
|
||||
$scope.subscription = {
|
||||
payment_schedule: false,
|
||||
payment_method: 'check'
|
||||
};
|
||||
|
||||
/**
|
||||
* Generate a string identifying the given plan by literal human-readable name
|
||||
* @param plan {Object} Plan object, as recovered from GET /api/plan/:id
|
||||
@ -826,6 +832,29 @@ Application.Controllers.controller('EditMemberController', ['$scope', '$state',
|
||||
*/
|
||||
$scope.humanReadablePlanName = function (plan, groups, short) { return `${$filter('humanReadablePlanName')(plan, groups, short)}`; };
|
||||
|
||||
/**
|
||||
* Check if the currently selected plan can be paid with a payment schedule or not
|
||||
* @return {boolean}
|
||||
*/
|
||||
$scope.allowMonthlySchedule = function () {
|
||||
if (!$scope.subscription) return false;
|
||||
|
||||
const plan = plans.find(p => p.id === $scope.subscription.plan_id);
|
||||
return plan && plan.monthly_payment;
|
||||
};
|
||||
|
||||
/**
|
||||
* Triggered by the <switch> component.
|
||||
* We must use a setTimeout to workaround the react integration.
|
||||
* @param checked {Boolean}
|
||||
*/
|
||||
$scope.toggleSchedule = function (checked) {
|
||||
setTimeout(() => {
|
||||
$scope.subscription.payment_schedule = checked;
|
||||
$scope.$apply();
|
||||
}, 50);
|
||||
};
|
||||
|
||||
/**
|
||||
* Modal dialog validation callback
|
||||
*/
|
||||
|
@ -182,6 +182,14 @@ Application.Controllers.controller('NewPlanController', ['$scope', '$uibModal',
|
||||
};
|
||||
|
||||
/* PRIVATE SCOPE */
|
||||
const initialize = function () {
|
||||
$scope.$watch(scope => scope.plan.interval,
|
||||
(newValue, oldValue) => {
|
||||
if (newValue === 'week') { $scope.plan.monthly_payment = false; }
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Asynchronously updates the given property with the new provided value
|
||||
* @param property {string}
|
||||
@ -194,6 +202,7 @@ Application.Controllers.controller('NewPlanController', ['$scope', '$uibModal',
|
||||
}, 50);
|
||||
};
|
||||
|
||||
initialize();
|
||||
return new PlanController($scope, groups, prices, partners, CSRF, _t);
|
||||
}
|
||||
]);
|
||||
|
@ -121,7 +121,7 @@
|
||||
|
||||
<div class="input-group m-t-md">
|
||||
<label for="plan[monthly_payment]" class="control-label m-r-md">{{ 'app.shared.plan.monthly_payment' | translate }} *</label>
|
||||
<switch id="plan[monthly_payment]" checked="plan.monthly_payment" on-change="toggleMonthlyPayment" class-name="'v-middle'" ng-if="plan && method != 'PATCH'"></switch>
|
||||
<switch id="plan[monthly_payment]" disabled="plan.interval === 'week'" checked="plan.monthly_payment" on-change="toggleMonthlyPayment" class-name="'v-middle'" ng-if="plan && method != 'PATCH'"></switch>
|
||||
<span ng-if="method == 'PATCH'">{{ (plan.monthly_payment ? 'app.shared.buttons.yes' : 'app.shared.buttons.no') | translate }}</span>
|
||||
<input type="hidden" id="plan_monthly_input" name="plan[monthly_payment]" value="{{plan.monthly_payment}}" />
|
||||
<span class="help-block" translate>{{ 'app.shared.plan.monthly_payment_info' }}</span>
|
||||
|
@ -7,11 +7,15 @@
|
||||
{{ 'app.admin.members_edit.you_are_about_to_purchase_a_subscription_to_NAME' }}
|
||||
</p>
|
||||
</div>
|
||||
<form role="form" name="subscriptionForm" class="form-horizontal col-md-8" novalidate>
|
||||
<form role="form" name="subscriptionForm" class="form-horizontal" novalidate>
|
||||
<div class="form-group">
|
||||
<select ng-model="subscription.plan_id" ng-options="plan.id as humanReadablePlanName(plan) for plan in plans" class="form-control" required>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-group" ng-show="allowMonthlySchedule()">
|
||||
<label for="schedule" class="control-label m-r-md">{{ 'app.admin.members_edit.with_schedule' | translate }}</label>
|
||||
<switch id="schedule" checked="subscription.payment_schedule" on-change="toggleSchedule"></switch>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
|
@ -66,6 +66,7 @@ class Subscriptions::Subscribe
|
||||
generate_invoice(subscription, operator_profile_id, details)
|
||||
end
|
||||
payment.save
|
||||
payment.post_save(schedule&.stp_setup_intent_id)
|
||||
UsersCredits::Manager.new(user: new_sub.user).reset_credits
|
||||
return new_sub
|
||||
end
|
||||
|
@ -830,6 +830,7 @@ en:
|
||||
a_problem_occurred_while_saving_the_date: "A problem occurred while saving the date."
|
||||
new_subscription: "New subscription"
|
||||
you_are_about_to_purchase_a_subscription_to_NAME: "You are about to purchase a subscription to {NAME}."
|
||||
with_schedule: "Subscribe with a monthly payment schedule"
|
||||
subscription_successfully_purchased: "Subscription successfully purchased."
|
||||
a_problem_occurred_while_taking_the_subscription: "A problem occurred while taking the subscription"
|
||||
wallet: "Wallet"
|
||||
|
@ -830,6 +830,7 @@ fr:
|
||||
a_problem_occurred_while_saving_the_date: "Il y a eu un problème lors de l'enregistrement de la date."
|
||||
new_subscription: "Nouvelle souscription"
|
||||
you_are_about_to_purchase_a_subscription_to_NAME: "Vous êtes sur le point de souscrire à un abonnement l'utilisateur {NAME}."
|
||||
with_schedule: "Souscrire via un échéancier mensuel"
|
||||
subscription_successfully_purchased: "La souscription à l'abonnement a été réalisée avec succès."
|
||||
a_problem_occurred_while_taking_the_subscription: "Il y a eu un problème lors de la souscription à l'abonnement"
|
||||
wallet: "Porte-monnaie"
|
||||
|
Loading…
x
Reference in New Issue
Block a user