From 78518e17fbda241b1f58f64b6cb04fd0d49aa46b Mon Sep 17 00:00:00 2001 From: Sylvain Date: Wed, 10 Jun 2020 16:37:11 +0200 Subject: [PATCH] read stripe_currency from the UI We prevent the currency from being changed if any stripe payment was made, because a stripe user cannot made pay with different currencies. If we try to charge a user with a different currency than the currency he used for a previous payment, this will fail; so we must prevent this case --- .../controllers/admin/invoices.js.erb | 10 ++++++++-- .../directives/settings/text-setting.js.erb | 5 ++++- app/assets/javascripts/router.js.erb | 3 ++- app/assets/javascripts/services/payment.js | 4 ++++ .../templates/admin/invoices/payment.html.erb | 17 +++++++++++++++++ app/assets/templates/admin/settings/number.html | 4 ++-- .../admin/settings/select-multiple.html | 4 ++-- app/assets/templates/admin/settings/select.html | 4 ++-- app/assets/templates/admin/settings/text.html | 9 ++++++--- app/controllers/api/payments_controller.rb | 12 +++++++++++- app/models/setting.rb | 3 ++- app/policies/payment_policy.rb | 8 ++++++++ app/workers/sync_members_on_stripe_worker.rb | 4 ++-- config/locales/app.admin.en.yml | 5 +++++ config/locales/app.admin.fr.yml | 5 +++++ config/routes.rb | 1 + config/secrets.yml | 4 ---- db/seeds.rb | 2 ++ doc/environment.md | 10 ---------- env.example | 2 -- lib/tasks/fablab/setup.rake | 3 ++- setup/env.example | 2 -- setup/setup.sh | 2 +- test/fixtures/history_values.yml | 8 ++++++++ test/fixtures/settings.yml | 6 ++++++ 25 files changed, 100 insertions(+), 37 deletions(-) create mode 100644 app/policies/payment_policy.rb diff --git a/app/assets/javascripts/controllers/admin/invoices.js.erb b/app/assets/javascripts/controllers/admin/invoices.js.erb index ce8c9667a..3fb9de5e5 100644 --- a/app/assets/javascripts/controllers/admin/invoices.js.erb +++ b/app/assets/javascripts/controllers/admin/invoices.js.erb @@ -17,8 +17,8 @@ /** * Controller used in the admin invoices listing page */ -Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'Invoice', 'AccountingPeriod', 'AuthService', 'invoices', 'closedPeriods', '$uibModal', 'growl', '$filter', 'Setting', 'settings', 'stripeSecretKey', '_t', 'Member', 'uiTourService', - function ($scope, $state, Invoice, AccountingPeriod, AuthService, invoices, closedPeriods, $uibModal, growl, $filter, Setting, settings, stripeSecretKey, _t, Member, uiTourService) { +Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'Invoice', 'AccountingPeriod', 'AuthService', 'invoices', 'closedPeriods', '$uibModal', 'growl', '$filter', 'Setting', 'settings', 'stripeSecretKey', '_t', 'Member', 'uiTourService', 'Payment', 'onlinePaymentStatus', + function ($scope, $state, Invoice, AccountingPeriod, AuthService, invoices, closedPeriods, $uibModal, growl, $filter, Setting, settings, stripeSecretKey, _t, Member, uiTourService, Payment, onlinePaymentStatus) { /* PRIVATE STATIC CONSTANTS */ // number of invoices loaded each time we click on 'load more...' @@ -178,6 +178,9 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I // is the stripe private set? $scope.stripeSecretKey = (stripeSecretKey.isPresent ? STRIPE_SK_HIDDEN : ''); + // has any online payment been already made? + $scope.onlinePaymentStatus = onlinePaymentStatus.status; + // Placeholding date for the invoice creation $scope.today = moment(); @@ -619,6 +622,9 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I Setting.isPresent({ name: 'stripe_secret_key' }, function (res) { $scope.stripeSecretKey = (res.isPresent ? STRIPE_SK_HIDDEN : ''); }) + Payment.onlinePaymentStatus(function (res) { + $scope.onlinePaymentStatus = res.status; + }); } }) diff --git a/app/assets/javascripts/directives/settings/text-setting.js.erb b/app/assets/javascripts/directives/settings/text-setting.js.erb index d95c9cb92..bd9dc9215 100644 --- a/app/assets/javascripts/directives/settings/text-setting.js.erb +++ b/app/assets/javascripts/directives/settings/text-setting.js.erb @@ -10,7 +10,10 @@ Application.Directives.directive('textSetting', ['Setting', 'growl', '_t', faIcon: '@', placeholder: '@', required: '<', - type: '@' + type: '@', + maxLength: '@', + minLength: '@', + readOnly: '<' }, templateUrl: '<%= asset_path "admin/settings/text.html" %>', link ($scope, element, attributes) { diff --git a/app/assets/javascripts/router.js.erb b/app/assets/javascripts/router.js.erb index 90cf88eee..c959dc9b7 100644 --- a/app/assets/javascripts/router.js.erb +++ b/app/assets/javascripts/router.js.erb @@ -839,9 +839,10 @@ angular.module('application.router', ['ui.router']) 'accounting_VAT_code', 'accounting_VAT_label', 'accounting_subscription_code', 'accounting_subscription_label', \ 'accounting_Machine_code', 'accounting_Machine_label', 'accounting_Training_code', 'accounting_Training_label', \ 'accounting_Event_code', 'accounting_Event_label', 'accounting_Space_code', 'accounting_Space_label', \ - 'feature_tour_display', 'online_payment_module', 'stripe_public_key']` }).$promise; + 'feature_tour_display', 'online_payment_module', 'stripe_public_key', 'stripe_currency']` }).$promise; }], stripeSecretKey: ['Setting', function (Setting) { return Setting.isPresent({ name: 'stripe_secret_key' }).$promise; }], + onlinePaymentStatus: ['Payment', function (Payment) { return Payment.onlinePaymentStatus().$promise; }], invoices: [ 'Invoice', function (Invoice) { return Invoice.list({ query: { number: '', customer: '', date: null, order_by: '-reference', page: 1, size: 20 } diff --git a/app/assets/javascripts/services/payment.js b/app/assets/javascripts/services/payment.js index c3fd1883d..69c80d865 100644 --- a/app/assets/javascripts/services/payment.js +++ b/app/assets/javascripts/services/payment.js @@ -7,6 +7,10 @@ Application.Services.factory('Payment', ['$resource', function ($resource) { method: 'POST', url: '/api/payments/confirm_payment', isArray: false + }, + onlinePaymentStatus: { + method: 'GET', + url: '/api/payments/online_payment_status' } } ); diff --git a/app/assets/templates/admin/invoices/payment.html.erb b/app/assets/templates/admin/invoices/payment.html.erb index 7498bffc4..019845fc0 100644 --- a/app/assets/templates/admin/invoices/payment.html.erb +++ b/app/assets/templates/admin/invoices/payment.html.erb @@ -42,6 +42,23 @@ +
+

{{ 'app.admin.invoices.payment.currency' }}

+

+

+
+ + +
+
diff --git a/app/assets/templates/admin/settings/number.html b/app/assets/templates/admin/settings/number.html index e616d0e6a..3664e2ce0 100644 --- a/app/assets/templates/admin/settings/number.html +++ b/app/assets/templates/admin/settings/number.html @@ -1,4 +1,4 @@ -
+
@@ -11,5 +11,5 @@ {{ helperText | translate }}
- + diff --git a/app/assets/templates/admin/settings/select-multiple.html b/app/assets/templates/admin/settings/select-multiple.html index 305689b6a..09cd1dad3 100644 --- a/app/assets/templates/admin/settings/select-multiple.html +++ b/app/assets/templates/admin/settings/select-multiple.html @@ -1,4 +1,4 @@ -
+