From 3ea06826ad440528df3ec02d64aff10dcb191ea6 Mon Sep 17 00:00:00 2001 From: Sylvain Date: Wed, 3 Mar 2021 15:28:56 +0100 Subject: [PATCH] WIP: select gateway --- CHANGELOG.md | 5 +- .../components/select-gateway-modal.tsx | 47 +++++++++++++++ .../javascript/controllers/admin/invoices.js | 10 +++- .../templates/admin/invoices/payment.html | 2 +- app/models/setting.rb | 3 +- app/policies/setting_policy.rb | 2 +- app/views/application/index.html.erb | 2 +- db/structure.sql | 57 +++++++------------ lib/tasks/fablab/stripe.rake | 7 +++ package.json | 3 +- yarn.lock | 12 ++++ 11 files changed, 105 insertions(+), 45 deletions(-) create mode 100644 app/frontend/src/javascript/components/select-gateway-modal.tsx diff --git a/CHANGELOG.md b/CHANGELOG.md index ee6a8d9bc..0cd6b538e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog Fab-manager +## Next release +- [TODO DEPLOY] `rails fablab:stripe:set_gateway` + ## v4.7.3 2021 March 03 - Improved the setup script - Fix a bug: unable to install a new instance with an external reverse proxy @@ -13,7 +16,7 @@ - Fix a bug: unable to upgrade using the easy upgrade command - Fix a security issue: possible SQL injection when dropping the database - Fix a security issue: restrict allowed keys when creating/updating credits -- [TODO DEPLOY] `bundle exec rails fablab:openlab:bulk_export` if you have enabled OpenLab (projects sharing) +- [TODO DEPLOY] `rails fablab:openlab:bulk_export` if you have enabled OpenLab (projects sharing) ## v4.7.1 2021 February 24 - Fix a security issue: updated axios to 0.21.1 to fix [CVE-2020-28168](https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-28168) diff --git a/app/frontend/src/javascript/components/select-gateway-modal.tsx b/app/frontend/src/javascript/components/select-gateway-modal.tsx new file mode 100644 index 000000000..4de7d3212 --- /dev/null +++ b/app/frontend/src/javascript/components/select-gateway-modal.tsx @@ -0,0 +1,47 @@ +/** + * This component ... + */ + +import React from 'react'; +import { react2angular } from 'react2angular'; +import { Loader } from './loader'; +import { IApplication } from '../models/application'; +import { useTranslation } from 'react-i18next'; +import { FabModal, ModalSize } from './fab-modal'; +import { User } from '../models/user'; + + +declare var Application: IApplication; + +interface SelectGatewayModalModalProps { + isOpen: boolean, + toggleModal: () => void, + currentUser: User, +} + +const SelectGatewayModal: React.FC = ({ isOpen, toggleModal }) => { + + const { t } = useTranslation('admin'); + + + return ( + + + + ); +} + +const StripeModalWrapper: React.FC = ({ isOpen, toggleModal,currentUser }) => { + return ( + + + + ); +} + +Application.Components.component('stripeModal', react2angular(StripeModalWrapper, ['isOpen', 'toggleModal', 'currentUser'])); diff --git a/app/frontend/src/javascript/controllers/admin/invoices.js b/app/frontend/src/javascript/controllers/admin/invoices.js index 168e42089..4a99698b0 100644 --- a/app/frontend/src/javascript/controllers/admin/invoices.js +++ b/app/frontend/src/javascript/controllers/admin/invoices.js @@ -637,6 +637,15 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I return `${invoice.operator.first_name} ${invoice.operator.last_name}`; }; + /** + * Open a modal dialog which ask the user to select the payment gateway to use + * @param onlinePaymentModule {{name: String, value: String}} setting that defines the next status of the online payment module + */ + $scope.selectPaymentGateway = function (onlinePaymentModule) { + // if the online payment is about to be disabled, accept the change without any further question + if (onlinePaymentModule.value === false) return true; + }; + /** * Open a modal dialog which ask for the stripe keys * @param onlinePaymentModule {{name: String, value: String}} setting that defines the next status of the online payment module @@ -1370,7 +1379,6 @@ Application.Controllers.controller('StripeKeysModalController', ['$scope', '$uib $scope.publicKeyStatus = false; return; } - const today = new Date(); $http({ method: 'POST', url: 'https://api.stripe.com/v1/tokens', diff --git a/app/frontend/templates/admin/invoices/payment.html b/app/frontend/templates/admin/invoices/payment.html index 037b2a310..d5836fa00 100644 --- a/app/frontend/templates/admin/invoices/payment.html +++ b/app/frontend/templates/admin/invoices/payment.html @@ -10,7 +10,7 @@ settings="allSettings" label="app.admin.invoices.payment.enable_online_payment" classes="m-l" - on-before-save="requireStripeKeys" + on-before-save="selectPaymentGateway" fa-icon="fa-font"> diff --git a/app/models/setting.rb b/app/models/setting.rb index 58f346d5d..7ac8b385a 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -107,7 +107,8 @@ class Setting < ApplicationRecord wallet_module statistics_module upcoming_events_shown - payment_schedule_prefix] } + payment_schedule_prefix + payment_gateway] } # WARNING: when adding a new key, you may also want to add it in app/policies/setting_policy.rb#public_whitelist def value diff --git a/app/policies/setting_policy.rb b/app/policies/setting_policy.rb index 942fd0430..5f5b9cd0b 100644 --- a/app/policies/setting_policy.rb +++ b/app/policies/setting_policy.rb @@ -38,7 +38,7 @@ class SettingPolicy < ApplicationPolicy fablab_name name_genre event_explications_alert space_explications_alert link_name home_content phone_required tracking_id book_overlapping_slots slot_duration events_in_calendar spaces_module plans_module invoicing_module recaptcha_site_key feature_tour_display disqus_shortname allowed_cad_extensions openlab_app_id openlab_default - online_payment_module stripe_public_key confirmation_required wallet_module] + online_payment_module stripe_public_key confirmation_required wallet_module payment_gateway] end ## diff --git a/app/views/application/index.html.erb b/app/views/application/index.html.erb index 1d3a7c9f7..e6f961070 100644 --- a/app/views/application/index.html.erb +++ b/app/views/application/index.html.erb @@ -19,7 +19,7 @@ <% end %> - +