2021-04-08 15:21:24 +02:00
|
|
|
import React, { FunctionComponent, ReactNode } from 'react';
|
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-09 08:47:34 +02:00
|
|
|
import { GatewayFormProps, AbstractPaymentModal } from '../abstract-payment-modal';
|
2021-06-01 11:01:38 +02:00
|
|
|
import { ShoppingCart } from '../../../models/payment';
|
2021-04-09 08:47:34 +02:00
|
|
|
import { PaymentSchedule } from '../../../models/payment-schedule';
|
|
|
|
import { User } from '../../../models/user';
|
2020-11-25 17:13:45 +01:00
|
|
|
|
2021-04-09 08:47:34 +02:00
|
|
|
import stripeLogo from '../../../../../images/powered_by_stripe.png';
|
|
|
|
import mastercardLogo from '../../../../../images/mastercard.png';
|
|
|
|
import visaLogo from '../../../../../images/visa.png';
|
2021-06-01 11:01:38 +02:00
|
|
|
import { Invoice } from '../../../models/invoice';
|
2020-11-24 13:26:15 +01:00
|
|
|
|
|
|
|
interface StripeModalProps {
|
|
|
|
isOpen: boolean,
|
|
|
|
toggleModal: () => void,
|
2021-06-01 11:01:38 +02:00
|
|
|
afterSuccess: (result: Invoice|PaymentSchedule) => void,
|
2021-10-07 16:43:51 +02:00
|
|
|
onError: (message: string) => void,
|
2021-05-21 18:25:18 +02:00
|
|
|
cart: ShoppingCart,
|
2020-11-24 13:26:15 +01:00
|
|
|
currentUser: User,
|
2021-06-28 18:17:11 +02:00
|
|
|
schedule?: PaymentSchedule,
|
2020-12-08 12:26:03 +01:00
|
|
|
customer: User
|
2020-11-24 13:26:15 +01:00
|
|
|
}
|
|
|
|
|
2021-04-07 16:21:12 +02:00
|
|
|
/**
|
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.
|
2021-04-07 16:21:12 +02:00
|
|
|
* Supports Strong-Customer Authentication (SCA).
|
2021-04-09 12:09:54 +02:00
|
|
|
*
|
2022-01-18 16:27:12 +01:00
|
|
|
* This component should not be called directly. Prefer using <CardPaymentModal> which can handle the configuration
|
2021-04-09 12:09:54 +02:00
|
|
|
* of a different payment gateway.
|
2021-04-07 16:21:12 +02:00
|
|
|
*/
|
2021-10-07 16:43:51 +02:00
|
|
|
export const StripeModal: React.FC<StripeModalProps> = ({ isOpen, toggleModal, afterSuccess, onError, cart, 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-24 13:26:15 +01:00
|
|
|
*/
|
2020-11-30 16:52:55 +01:00
|
|
|
const logoFooter = (): ReactNode => {
|
2020-11-24 13:26:15 +01:00
|
|
|
return (
|
2020-11-30 16:52:55 +01:00
|
|
|
<div className="stripe-modal-icons">
|
2022-06-20 15:35:38 +02:00
|
|
|
<i className="fa fa-lock fa-2x" />
|
2020-11-30 16:52:55 +01:00
|
|
|
<img src={stripeLogo} alt="powered by stripe" />
|
|
|
|
<img src={mastercardLogo} alt="mastercard" />
|
|
|
|
<img src={visaLogo} alt="visa" />
|
|
|
|
</div>
|
2020-11-24 13:26:15 +01:00
|
|
|
);
|
2021-07-01 12:34:10 +02:00
|
|
|
};
|
2020-11-24 13:26:15 +01:00
|
|
|
|
2020-12-02 10:06:18 +01:00
|
|
|
/**
|
2021-04-08 15:21:24 +02:00
|
|
|
* Integrates the StripeForm into the parent PaymentModal
|
2020-12-01 17:55:23 +01:00
|
|
|
*/
|
2021-07-01 12:34:10 +02:00
|
|
|
const renderForm: FunctionComponent<GatewayFormProps> = ({ onSubmit, onSuccess, onError, operator, className, formId, cart, customer, paymentSchedule, children }) => {
|
2021-04-08 15:21:24 +02:00
|
|
|
return (
|
|
|
|
<StripeElements>
|
|
|
|
<StripeForm onSubmit={onSubmit}
|
2021-07-01 12:34:10 +02:00
|
|
|
onSuccess={onSuccess}
|
|
|
|
onError={onError}
|
|
|
|
operator={operator}
|
|
|
|
className={className}
|
|
|
|
formId={formId}
|
|
|
|
cart={cart}
|
|
|
|
customer={customer}
|
|
|
|
paymentSchedule={paymentSchedule}>
|
2021-04-08 15:21:24 +02:00
|
|
|
{children}
|
2020-11-30 16:52:55 +01:00
|
|
|
</StripeForm>
|
2021-04-08 15:21:24 +02:00
|
|
|
</StripeElements>
|
|
|
|
);
|
2021-07-01 12:34:10 +02:00
|
|
|
};
|
2021-04-08 15:21:24 +02:00
|
|
|
|
|
|
|
return (
|
2021-04-09 08:40:46 +02:00
|
|
|
<AbstractPaymentModal className="stripe-modal"
|
2021-07-01 12:34:10 +02:00
|
|
|
isOpen={isOpen}
|
|
|
|
toggleModal={toggleModal}
|
|
|
|
logoFooter={logoFooter()}
|
|
|
|
formId="stripe-form"
|
|
|
|
formClassName="stripe-form"
|
|
|
|
currentUser={currentUser}
|
|
|
|
cart={cart}
|
|
|
|
customer={customer}
|
|
|
|
afterSuccess={afterSuccess}
|
2021-10-07 16:43:51 +02:00
|
|
|
onError={onError}
|
2021-07-01 12:34:10 +02:00
|
|
|
schedule={schedule}
|
|
|
|
GatewayForm={renderForm} />
|
2020-11-24 13:26:15 +01:00
|
|
|
);
|
2021-07-01 12:34:10 +02:00
|
|
|
};
|