mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-01 12:24:28 +01:00
handle after payment method was created
This commit is contained in:
parent
96b1cfcbc7
commit
b6240c5046
@ -8,7 +8,7 @@ import { Reservation } from '../models/reservation';
|
||||
|
||||
interface StripeFormProps {
|
||||
onSubmit: () => void,
|
||||
onSuccess: (result: PaymentMethod|PaymentConfirmation) => void,
|
||||
onSuccess: (result: PaymentMethod|PaymentConfirmation|any) => void,
|
||||
onError: (message: string) => void,
|
||||
className?: string,
|
||||
processPayment?: boolean,
|
||||
@ -19,7 +19,7 @@ interface StripeFormProps {
|
||||
* A form component to collect the credit card details and to create the payment method on Stripe.
|
||||
* The form validation button must be created elsewhere, using the attribute form="stripe-form".
|
||||
*/
|
||||
export const StripeForm: React.FC<StripeFormProps> = ({ onSubmit, onSuccess, onError, children, className, processPayment , cartItems}) => {
|
||||
export const StripeForm: React.FC<StripeFormProps> = ({ onSubmit, onSuccess, onError, children, className, processPayment = true, cartItems}) => {
|
||||
|
||||
const { t } = useTranslation('shared');
|
||||
|
||||
|
@ -37,12 +37,11 @@ interface StripeModalProps {
|
||||
cartItems: CartItems,
|
||||
currentUser: User,
|
||||
schedule: PaymentSchedule,
|
||||
processPayment?: boolean,
|
||||
}
|
||||
|
||||
const cgvFile = CustomAssetAPI.get(CustomAssetName.CgvFile);
|
||||
|
||||
const StripeModal: React.FC<StripeModalProps> = ({ isOpen, toggleModal, afterSuccess, cartItems, currentUser, schedule , processPayment = true }) => {
|
||||
const StripeModal: React.FC<StripeModalProps> = ({ isOpen, toggleModal, afterSuccess, cartItems, currentUser, schedule }) => {
|
||||
// customer's wallet
|
||||
const [wallet, setWallet] = useState(null);
|
||||
// server-computed price with all details
|
||||
@ -140,7 +139,7 @@ const StripeModal: React.FC<StripeModalProps> = ({ isOpen, toggleModal, afterSuc
|
||||
/**
|
||||
* After sending the form with success, process the resulting payment method
|
||||
*/
|
||||
const handleFormSuccess = async (result: PaymentMethod|PaymentConfirmation): Promise<void> => {
|
||||
const handleFormSuccess = async (result: PaymentMethod|PaymentConfirmation|any): Promise<void> => {
|
||||
setSubmitState(false);
|
||||
afterSuccess(result);
|
||||
}
|
||||
@ -179,7 +178,7 @@ const StripeModal: React.FC<StripeModalProps> = ({ isOpen, toggleModal, afterSuc
|
||||
onError={handleFormError}
|
||||
className="stripe-form"
|
||||
cartItems={cartItems}
|
||||
processPayment={processPayment}>
|
||||
processPayment={!isPaymentSchedule()}>
|
||||
{hasErrors() && <div className="stripe-errors">
|
||||
{errors}
|
||||
</div>}
|
||||
@ -212,12 +211,12 @@ const StripeModal: React.FC<StripeModalProps> = ({ isOpen, toggleModal, afterSuc
|
||||
);
|
||||
}
|
||||
|
||||
const StripeModalWrapper: React.FC<StripeModalProps> = ({ isOpen, toggleModal, afterSuccess, currentUser, schedule , cartItems, processPayment}) => {
|
||||
const StripeModalWrapper: React.FC<StripeModalProps> = ({ isOpen, toggleModal, afterSuccess, currentUser, schedule , cartItems}) => {
|
||||
return (
|
||||
<Loader>
|
||||
<StripeModal isOpen={isOpen} toggleModal={toggleModal} afterSuccess={afterSuccess} currentUser={currentUser} schedule={schedule} processPayment={processPayment} cartItems={cartItems}/>
|
||||
<StripeModal isOpen={isOpen} toggleModal={toggleModal} afterSuccess={afterSuccess} currentUser={currentUser} schedule={schedule} cartItems={cartItems}/>
|
||||
</Loader>
|
||||
);
|
||||
}
|
||||
|
||||
Application.Components.component('stripeModal', react2angular(StripeModalWrapper, ['isOpen', 'toggleModal', 'afterSuccess','currentUser', 'schedule', 'cartItems', 'processPayment']));
|
||||
Application.Components.component('stripeModal', react2angular(StripeModalWrapper, ['isOpen', 'toggleModal', 'afterSuccess','currentUser', 'schedule', 'cartItems']));
|
||||
|
@ -331,7 +331,11 @@ Application.Directives.directive('cart', ['$rootScope', '$uibModal', 'dialogs',
|
||||
*/
|
||||
$scope.afterStripeSuccess = (result) => {
|
||||
$scope.toggleStripeModal();
|
||||
afterPayment(result);
|
||||
if ($scope.schedule.requested_schedule) {
|
||||
afterPaymentMethodCreation(result);
|
||||
} else {
|
||||
afterPayment(result);
|
||||
}
|
||||
};
|
||||
|
||||
/* PRIVATE SCOPE */
|
||||
@ -895,6 +899,15 @@ Application.Directives.directive('cart', ['$rootScope', '$uibModal', 'dialogs',
|
||||
$scope.schedule.payment_schedule = undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* Actions to run after the payment method was created on Stripe. Used for payment schedules.
|
||||
* @param paymentMethod {PaymentMethod}
|
||||
*/
|
||||
const afterPaymentMethodCreation = function (paymentMethod) {
|
||||
// TODO, create an API point for payment_schedule validation
|
||||
// or: POST reservation || POST subscription (if admin/manager)
|
||||
};
|
||||
|
||||
/**
|
||||
* Actions to pay slots
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user