1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-10 00:46:15 +01:00
fab-manager/app/frontend/src/javascript/components/stripe/stripe-modal.tsx

94 lines
3.5 KiB
TypeScript
Raw Normal View History

2021-04-08 15:21:24 +02:00
import React, { FunctionComponent, ReactNode } from 'react';
import { react2angular } from 'react2angular';
import { SetupIntent } from '@stripe/stripe-js';
2021-04-08 10:46:09 +02:00
import { StripeElements } from './stripe-elements';
2020-11-25 17:13:45 +01:00
import { StripeForm } from './stripe-form';
2021-04-08 10:46:09 +02:00
import { Loader } from '../base/loader';
import { IApplication } from '../../models/application';
import { CartItems, PaymentConfirmation } from '../../models/payment';
import { PaymentSchedule } from '../../models/payment-schedule';
import { User } from '../../models/user';
2020-11-25 17:13:45 +01:00
2021-04-08 10:46:09 +02:00
import stripeLogo from '../../../../images/powered_by_stripe.png';
import mastercardLogo from '../../../../images/mastercard.png';
import visaLogo from '../../../../images/visa.png';
import { GatewayFormProps, PaymentModal } from '../payment/payment-modal';
declare var Application: IApplication;
interface StripeModalProps {
isOpen: boolean,
toggleModal: () => void,
afterSuccess: (result: SetupIntent|PaymentConfirmation) => void,
cartItems: CartItems,
currentUser: User,
schedule: PaymentSchedule,
customer: User
}
/**
2021-04-08 15:21:24 +02:00
* 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<StripeModalProps> = ({ isOpen, toggleModal, afterSuccess, cartItems, currentUser, schedule, customer }) => {
2020-11-24 16:26:18 +01:00
/**
2020-11-30 16:52:55 +01:00
* Return the logos, shown in the modal footer.
*/
2020-11-30 16:52:55 +01:00
const logoFooter = (): ReactNode => {
return (
2020-11-30 16:52:55 +01:00
<div className="stripe-modal-icons">
<i className="fa fa-lock fa-2x m-r-sm pos-rlt" />
<img src={stripeLogo} alt="powered by stripe" />
<img src={mastercardLogo} alt="mastercard" />
<img src={visaLogo} alt="visa" />
</div>
);
}
/**
2021-04-08 15:21:24 +02:00
* Integrates the StripeForm into the parent PaymentModal
*/
2021-04-08 15:21:24 +02:00
const renderForm: FunctionComponent<GatewayFormProps> = ({ onSubmit, onSuccess, onError, operator, className, formId, cartItems, customer, paymentSchedule, children}) => {
return (
<StripeElements>
<StripeForm onSubmit={onSubmit}
onSuccess={onSuccess}
onError={onError}
operator={operator}
className={className}
formId={formId}
cartItems={cartItems}
customer={customer}
2021-04-08 15:21:24 +02:00
paymentSchedule={paymentSchedule}>
{children}
2020-11-30 16:52:55 +01:00
</StripeForm>
2021-04-08 15:21:24 +02:00
</StripeElements>
);
}
return (
<PaymentModal className="stripe-modal"
isOpen={isOpen}
toggleModal={toggleModal}
logoFooter={logoFooter()}
formId="stripe-form"
formClassName="stripe-form"
currentUser={currentUser}
cartItems={cartItems}
customer={customer}
afterSuccess={afterSuccess}
schedule={schedule}
GatewayForm={renderForm} />
);
}
const StripeModalWrapper: React.FC<StripeModalProps> = ({ isOpen, toggleModal, afterSuccess, currentUser, schedule , cartItems, customer }) => {
return (
<Loader>
<StripeModal isOpen={isOpen} toggleModal={toggleModal} afterSuccess={afterSuccess} currentUser={currentUser} schedule={schedule} cartItems={cartItems} customer={customer} />
</Loader>
);
}
Application.Components.component('stripeModal', react2angular(StripeModalWrapper, ['isOpen', 'toggleModal', 'afterSuccess','currentUser', 'schedule', 'cartItems', 'customer']));