1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-18 07:52:23 +01:00

WIP: select gateway

This commit is contained in:
Sylvain 2021-03-03 15:28:56 +01:00
parent 4fa3eba2e9
commit 3ea06826ad
11 changed files with 105 additions and 45 deletions

View File

@ -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)

View File

@ -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<SelectGatewayModalModalProps> = ({ isOpen, toggleModal }) => {
const { t } = useTranslation('admin');
return (
<FabModal title={t('app.shared.stripe.online_payment')}
isOpen={isOpen}
toggleModal={toggleModal}
width={ModalSize.medium}
closeButton={false}
className="stripe-modal">
</FabModal>
);
}
const StripeModalWrapper: React.FC<SelectGatewayModalModalProps> = ({ isOpen, toggleModal,currentUser }) => {
return (
<Loader>
<SelectGatewayModal isOpen={isOpen} toggleModal={toggleModal} currentUser={currentUser} />
</Loader>
);
}
Application.Components.component('stripeModal', react2angular(StripeModalWrapper, ['isOpen', 'toggleModal', 'currentUser']));

View File

@ -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',

View File

@ -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">
</boolean-setting>
</div>

View File

@ -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

View File

@ -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
##

View File

@ -19,7 +19,7 @@
</script>
<script type="text/javascript" src="//cdn.crowdin.com/jipt/jipt.js"></script>
<% end %>
<script type="text/javascript" src="https://js.stripe.com/v3/"></script>
<script type="text/javascript">
var Fablab = Fablab || {};

View File

@ -108,8 +108,8 @@ SET default_tablespace = '';
CREATE TABLE public.abuses (
id integer NOT NULL,
signaled_id integer,
signaled_type character varying,
signaled_id integer,
first_name character varying,
last_name character varying,
email character varying,
@ -187,8 +187,8 @@ CREATE TABLE public.addresses (
locality character varying,
country character varying,
postal_code character varying,
placeable_id integer,
placeable_type character varying,
placeable_id integer,
created_at timestamp without time zone,
updated_at timestamp without time zone
);
@ -263,8 +263,8 @@ CREATE TABLE public.ar_internal_metadata (
CREATE TABLE public.assets (
id integer NOT NULL,
viewable_id integer,
viewable_type character varying,
viewable_id integer,
attachment character varying,
type character varying,
created_at timestamp without time zone,
@ -504,8 +504,8 @@ ALTER SEQUENCE public.coupons_id_seq OWNED BY public.coupons.id;
CREATE TABLE public.credits (
id integer NOT NULL,
creditable_id integer,
creditable_type character varying,
creditable_id integer,
plan_id integer,
hours integer,
created_at timestamp without time zone,
@ -1046,8 +1046,8 @@ ALTER SEQUENCE public.invoice_items_id_seq OWNED BY public.invoice_items.id;
CREATE TABLE public.invoices (
id integer NOT NULL,
invoiced_id integer,
invoiced_type character varying,
invoiced_id integer,
stp_invoice_id character varying,
total integer,
created_at timestamp without time zone,
@ -1227,15 +1227,15 @@ ALTER SEQUENCE public.machines_id_seq OWNED BY public.machines.id;
CREATE TABLE public.notifications (
id integer NOT NULL,
receiver_id integer,
attached_object_id integer,
attached_object_type character varying,
attached_object_id integer,
notification_type_id integer,
is_read boolean DEFAULT false,
created_at timestamp without time zone,
updated_at timestamp without time zone,
receiver_type character varying,
is_send boolean DEFAULT false,
meta_data jsonb DEFAULT '{}'::jsonb
meta_data jsonb DEFAULT '"{}"'::jsonb
);
@ -1663,8 +1663,8 @@ CREATE TABLE public.prices (
id integer NOT NULL,
group_id integer,
plan_id integer,
priceable_id integer,
priceable_type character varying,
priceable_id integer,
amount integer,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
@ -1979,8 +1979,8 @@ CREATE TABLE public.reservations (
message text,
created_at timestamp without time zone,
updated_at timestamp without time zone,
reservable_id integer,
reservable_type character varying,
reservable_id integer,
nb_reserve_places integer,
statistic_profile_id integer
);
@ -2012,8 +2012,8 @@ ALTER SEQUENCE public.reservations_id_seq OWNED BY public.reservations.id;
CREATE TABLE public.roles (
id integer NOT NULL,
name character varying,
resource_id integer,
resource_type character varying,
resource_id integer,
created_at timestamp without time zone,
updated_at timestamp without time zone
);
@ -2949,8 +2949,8 @@ CREATE TABLE public.users_roles (
CREATE TABLE public.wallet_transactions (
id integer NOT NULL,
wallet_id integer,
transactable_id integer,
transactable_type character varying,
transactable_id integer,
transaction_type character varying,
amount integer,
created_at timestamp without time zone NOT NULL,
@ -4039,6 +4039,14 @@ ALTER TABLE ONLY public.roles
ADD CONSTRAINT roles_pkey PRIMARY KEY (id);
--
-- Name: schema_migrations schema_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.schema_migrations
ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version);
--
-- Name: settings settings_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
@ -5110,29 +5118,6 @@ CREATE INDEX profiles_lower_unaccent_last_name_trgm_idx ON public.profiles USING
CREATE INDEX projects_search_vector_idx ON public.projects USING gin (search_vector);
--
-- Name: unique_schema_migrations; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX unique_schema_migrations ON public.schema_migrations USING btree (version);
--
-- Name: accounting_periods accounting_periods_del_protect; Type: RULE; Schema: public; Owner: -
--
CREATE RULE accounting_periods_del_protect AS
ON DELETE TO public.accounting_periods DO INSTEAD NOTHING;
--
-- Name: accounting_periods accounting_periods_upd_protect; Type: RULE; Schema: public; Owner: -
--
CREATE RULE accounting_periods_upd_protect AS
ON UPDATE TO public.accounting_periods DO INSTEAD NOTHING;
--
-- Name: projects projects_search_content_trigger; Type: TRIGGER; Schema: public; Owner: -
--
@ -5675,7 +5660,6 @@ INSERT INTO "schema_migrations" (version) VALUES
('20140605125131'),
('20140605142133'),
('20140605151442'),
('20140606133116'),
('20140609092700'),
('20140609092827'),
('20140610153123'),
@ -5744,14 +5728,12 @@ INSERT INTO "schema_migrations" (version) VALUES
('20150507075620'),
('20150512123546'),
('20150520132030'),
('20150520133409'),
('20150526130729'),
('20150527153312'),
('20150529113555'),
('20150601125944'),
('20150603104502'),
('20150603104658'),
('20150603133050'),
('20150604081757'),
('20150604131525'),
('20150608142234'),
@ -5833,7 +5815,6 @@ INSERT INTO "schema_migrations" (version) VALUES
('20160905142700'),
('20160906094739'),
('20160906094847'),
('20160906145713'),
('20160915105234'),
('20161123104604'),
('20170109085345'),

View File

@ -71,6 +71,13 @@ namespace :fablab do
end
end
desc 'set stripe as the default payment gateway'
task set_gateway: :environment do
if Setting.find_by(name: 'stripe_public_key').try(:value) && Setting.find_by(name: 'stripe_secret_key').try(:value)
Setting.set('payment_gateway', 'stripe') unless Setting.find_by(name: 'payment_gateway').try(:value)
end
end
def print_on_line(str)
print "#{str}\r"
$stdout.flush

View File

@ -1,6 +1,6 @@
{
"name": "fab-manager",
"version": "4.7.3",
"version": "4.8.0-dev",
"description": "Fab-manager is the FabLab management solution. It provides a comprehensive, web-based, open-source tool to simplify your administrative tasks and your marker's projects.",
"keywords": [
"fablab",
@ -40,6 +40,7 @@
"@babel/preset-typescript": "^7.12.1",
"@claviska/jquery-minicolors": "^2.3.5",
"@fortawesome/fontawesome-free": "5.14.0",
"@lyracom/embedded-form-glue": "^0.3.3",
"@rails/webpacker": "5.2.1",
"@stripe/react-stripe-js": "^1.1.2",
"@stripe/stripe-js": "^1.11.0",

View File

@ -1064,6 +1064,13 @@
resolved "https://registry.yarnpkg.com/@fortawesome/fontawesome-free/-/fontawesome-free-5.14.0.tgz#a371e91029ebf265015e64f81bfbf7d228c9681f"
integrity sha512-OfdMsF+ZQgdKHP9jUbmDcRrP0eX90XXrsXIdyjLbkmSBzmMXPABB8eobUJtivaupucYaByz6WNe1PI1JuYm3qA==
"@lyracom/embedded-form-glue@^0.3.3":
version "0.3.3"
resolved "https://registry.yarnpkg.com/@lyracom/embedded-form-glue/-/embedded-form-glue-0.3.3.tgz#e1f1450a67678526da03500f13743fd4d749c734"
integrity sha512-8N5IxUPcZr2UL1cend/TiTVuLHVyDIpw/2K3P1ox4ilSj79aaO46U3xJHAfd6HnU6lLbh2ldDOT2kVdVf2l+nQ==
dependencies:
es6-promise "^4.2.8"
"@npmcli/move-file@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@npmcli/move-file/-/move-file-1.0.1.tgz#de103070dac0f48ce49cf6693c23af59c0f70464"
@ -3562,6 +3569,11 @@ es6-iterator@2.0.3, es6-iterator@~2.0.3:
es5-ext "^0.10.35"
es6-symbol "^3.1.1"
es6-promise@^4.2.8:
version "4.2.8"
resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.2.8.tgz#4eb21594c972bc40553d276e510539143db53e0a"
integrity sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==
es6-symbol@^3.1.1, es6-symbol@~3.1.3:
version "3.1.3"
resolved "https://registry.yarnpkg.com/es6-symbol/-/es6-symbol-3.1.3.tgz#bad5d3c1bcdac28269f4cb331e431c78ac705d18"