diff --git a/app/frontend/src/javascript/components/payment/payment-modal.tsx b/app/frontend/src/javascript/components/payment/payment-modal.tsx new file mode 100644 index 000000000..9a0c22b01 --- /dev/null +++ b/app/frontend/src/javascript/components/payment/payment-modal.tsx @@ -0,0 +1,80 @@ +import React, { ReactElement, ReactNode } from 'react'; +import { IApplication } from '../../models/application'; +import { CartItems } from '../../models/payment'; +import { User } from '../../models/user'; +import { PaymentSchedule } from '../../models/payment-schedule'; +import { Loader } from '../base/loader'; +import { react2angular } from 'react2angular'; +import SettingAPI from '../../api/setting'; +import { SettingName } from '../../models/setting'; +import { StripeModal } from './stripe/stripe-modal'; +import { PayZenModal } from './payzen/payzen-modal'; + +declare var Application: IApplication; + +interface PaymentModalProps { + isOpen: boolean, + toggleModal: () => void, + afterSuccess: (result: any) => void, + cartItems: CartItems, + currentUser: User, + schedule: PaymentSchedule, + customer: User +} + +// initial request to the API +const paymentGateway = SettingAPI.get(SettingName.PaymentGateway); + +const PaymentModal: React.FC = ({ isOpen, toggleModal, afterSuccess, currentUser, schedule , cartItems, customer }) => { + const gateway = paymentGateway.read(); + + /** + * Render the Stripe payment modal + */ + const renderStripeModal = (): ReactElement => { + return + } + + /** + * Render the PayZen payment modal + */ + const renderPayZenModal = (): ReactElement => { + return + } + + /** + * Determine which gateway is enabled and return the appropriate payment modal + */ + switch (gateway.value) { + case 'stripe': + return renderStripeModal(); + case 'payzen': + return renderPayZenModal(); + default: + console.error(`[PaymentModal] Unimplemented gateway: ${gateway.value}`); + return
+ } +} + + +const PaymentModalWrapper: React.FC = ({ isOpen, toggleModal, afterSuccess, currentUser, schedule , cartItems, customer }) => { + return ( + + + + ); +} + +Application.Components.component('paymentModal', react2angular(PaymentModalWrapper, ['isOpen', 'toggleModal', 'afterSuccess','currentUser', 'schedule', 'cartItems', 'customer'])); diff --git a/app/frontend/src/javascript/components/payment/payzen/payzen-modal.tsx b/app/frontend/src/javascript/components/payment/payzen/payzen-modal.tsx index 09f0c719d..fc8d70775 100644 --- a/app/frontend/src/javascript/components/payment/payzen/payzen-modal.tsx +++ b/app/frontend/src/javascript/components/payment/payzen/payzen-modal.tsx @@ -27,7 +27,7 @@ interface PayZenModalProps { * This component enables the user to input his card data or process payments, using the PayZen gateway. * Supports Strong-Customer Authentication (SCA). */ -const PayZenModal: React.FC = ({ isOpen, toggleModal, afterSuccess, cartItems, currentUser, schedule, customer }) => { +export const PayZenModal: React.FC = ({ isOpen, toggleModal, afterSuccess, cartItems, currentUser, schedule, customer }) => { /** * Return the logos, shown in the modal footer. */ @@ -71,13 +71,3 @@ const PayZenModal: React.FC = ({ isOpen, toggleModal, afterSuc GatewayForm={renderForm} /> ); } - -const PayZenModalWrapper: React.FC = ({ isOpen, toggleModal, afterSuccess, currentUser, schedule , cartItems, customer }) => { - return ( - - - - ); -} - -Application.Components.component('payzenModal', react2angular(PayZenModalWrapper, ['isOpen', 'toggleModal', 'afterSuccess','currentUser', 'schedule', 'cartItems', 'customer'])); diff --git a/app/frontend/src/javascript/components/payment/stripe/stripe-modal.tsx b/app/frontend/src/javascript/components/payment/stripe/stripe-modal.tsx index 8d0e71222..580b80f59 100644 --- a/app/frontend/src/javascript/components/payment/stripe/stripe-modal.tsx +++ b/app/frontend/src/javascript/components/payment/stripe/stripe-modal.tsx @@ -30,7 +30,7 @@ interface StripeModalProps { * This component enables the user to input his card data or process payments, using the Stripe gateway. * Supports Strong-Customer Authentication (SCA). */ -const StripeModal: React.FC = ({ isOpen, toggleModal, afterSuccess, cartItems, currentUser, schedule, customer }) => { +export const StripeModal: React.FC = ({ isOpen, toggleModal, afterSuccess, cartItems, currentUser, schedule, customer }) => { /** * Return the logos, shown in the modal footer. */ @@ -81,13 +81,3 @@ const StripeModal: React.FC = ({ isOpen, toggleModal, afterSuc GatewayForm={renderForm} /> ); } - -const StripeModalWrapper: React.FC = ({ isOpen, toggleModal, afterSuccess, currentUser, schedule , cartItems, customer }) => { - return ( - - - - ); -} - -Application.Components.component('stripeModal', react2angular(StripeModalWrapper, ['isOpen', 'toggleModal', 'afterSuccess','currentUser', 'schedule', 'cartItems', 'customer'])); diff --git a/app/frontend/templates/shared/_cart.html b/app/frontend/templates/shared/_cart.html index 9e7301153..fa45a0376 100644 --- a/app/frontend/templates/shared/_cart.html +++ b/app/frontend/templates/shared/_cart.html @@ -200,11 +200,11 @@
- +
diff --git a/app/frontend/templates/shared/valid_reservation_modal.html b/app/frontend/templates/shared/valid_reservation_modal.html index 6c6aea905..22ab79a63 100644 --- a/app/frontend/templates/shared/valid_reservation_modal.html +++ b/app/frontend/templates/shared/valid_reservation_modal.html @@ -49,12 +49,12 @@