1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-12-01 12:24:28 +01:00

factorize payment form props

This commit is contained in:
Sylvain 2021-04-28 16:41:15 +02:00
parent f9b47cf1f4
commit 30c1c91590
3 changed files with 6 additions and 27 deletions

View File

@ -1,31 +1,18 @@
import React, { FormEvent, FunctionComponent, useEffect, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import KRGlue from "@lyracom/embedded-form-glue";
import { CartItems } from '../../../models/payment';
import { User } from '../../../models/user';
import { GatewayFormProps } from '../abstract-payment-modal';
import SettingAPI from '../../../api/setting';
import { SettingName } from '../../../models/setting';
import PayzenAPI from '../../../api/payzen';
import { Loader } from '../../base/loader';
import { KryptonClient, KryptonError, ProcessPaymentAnswer } from '../../../models/payzen';
interface PayzenFormProps {
onSubmit: () => void,
onSuccess: (result: any) => void,
onError: (message: string) => void,
customer: User,
operator: User,
className?: string,
paymentSchedule?: boolean,
cartItems?: CartItems,
formId: string,
}
/**
* 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={formId}.
*/
export const PayzenForm: React.FC<PayzenFormProps> = ({ onSubmit, onSuccess, onError, children, className, paymentSchedule = false, cartItems, customer, operator, formId }) => {
export const PayzenForm: React.FC<GatewayFormProps> = ({ onSubmit, onSuccess, onError, children, className, paymentSchedule = false, cartItems, customer, operator, formId }) => {
const { t } = useTranslation('shared');
const PayZenKR = useRef<KryptonClient>(null);

View File

@ -2,20 +2,12 @@ import React, { FormEvent } from 'react';
import { CardElement, useElements, useStripe } from '@stripe/react-stripe-js';
import { SetupIntent } from "@stripe/stripe-js";
import { useTranslation } from 'react-i18next';
import { CartItems, PaymentConfirmation } from '../../../models/payment';
import { User } from '../../../models/user';
import { GatewayFormProps } from '../abstract-payment-modal';
import { PaymentConfirmation } from '../../../models/payment';
import StripeAPI from '../../../api/stripe';
interface StripeFormProps {
onSubmit: () => void,
interface StripeFormProps extends GatewayFormProps {
onSuccess: (result: SetupIntent|PaymentConfirmation|any) => void,
onError: (message: string) => void,
customer: User,
operator: User,
className?: string,
paymentSchedule?: boolean,
cartItems?: CartItems,
formId: string,
}
/**

View File

@ -724,7 +724,7 @@ Application.Directives.directive('cart', ['$rootScope', '$uibModal', 'dialogs',
return Price.compute(mkCartItems(items, '')).$promise;
},
cartItems () {
return mkCartItems(items, '');
return mkCartItems(items, 'card');
},
wallet () {
return Wallet.getWalletByUser({ user_id: $scope.user.id }).$promise;