mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-20 14:54:15 +01:00
(bug) set cash for locale payment by default
This commit is contained in:
parent
0e554d22ff
commit
1d179e51a9
@ -13,8 +13,8 @@ import CheckoutAPI from '../../../api/checkout';
|
|||||||
import { SelectOption } from '../../../models/select';
|
import { SelectOption } from '../../../models/select';
|
||||||
import { PaymentMethod } from '../../../models/payment';
|
import { PaymentMethod } from '../../../models/payment';
|
||||||
|
|
||||||
const ALL_SCHEDULE_METHODS = ['card', 'check', 'transfer', 'cash'] as const;
|
const ALL_PAYMENT_METHODS = ['card', 'check', 'transfer', 'cash'] as const;
|
||||||
type scheduleMethod = typeof ALL_SCHEDULE_METHODS[number];
|
type paymentMethod = typeof ALL_PAYMENT_METHODS[number];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A form component to ask for confirmation before cashing a payment directly at the FabLab's reception.
|
* A form component to ask for confirmation before cashing a payment directly at the FabLab's reception.
|
||||||
@ -24,7 +24,7 @@ type scheduleMethod = typeof ALL_SCHEDULE_METHODS[number];
|
|||||||
export const LocalPaymentForm: React.FC<GatewayFormProps> = ({ onSubmit, onSuccess, onError, children, className, paymentSchedule, cart, updateCart, customer, operator, formId, order }) => {
|
export const LocalPaymentForm: React.FC<GatewayFormProps> = ({ onSubmit, onSuccess, onError, children, className, paymentSchedule, cart, updateCart, customer, operator, formId, order }) => {
|
||||||
const { t } = useTranslation('admin');
|
const { t } = useTranslation('admin');
|
||||||
|
|
||||||
const [method, setMethod] = useState<scheduleMethod>('cash');
|
const [method, setMethod] = useState<paymentMethod>('cash');
|
||||||
const [onlinePaymentModal, setOnlinePaymentModal] = useState<boolean>(false);
|
const [onlinePaymentModal, setOnlinePaymentModal] = useState<boolean>(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -44,15 +44,15 @@ export const LocalPaymentForm: React.FC<GatewayFormProps> = ({ onSubmit, onSucce
|
|||||||
/**
|
/**
|
||||||
* Convert all payement methods for schedules to the react-select format
|
* Convert all payement methods for schedules to the react-select format
|
||||||
*/
|
*/
|
||||||
const buildMethodOptions = (): Array<SelectOption<scheduleMethod>> => {
|
const buildMethodOptions = (): Array<SelectOption<paymentMethod>> => {
|
||||||
return ALL_SCHEDULE_METHODS.map(i => methodToOption(i));
|
return ALL_PAYMENT_METHODS.filter(p => p !== 'cash').map(i => methodToOption(i));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert the given payment-method to the react-select format
|
* Convert the given payment-method to the react-select format
|
||||||
*/
|
*/
|
||||||
const methodToOption = (value: scheduleMethod): SelectOption<scheduleMethod> => {
|
const methodToOption = (value: paymentMethod): SelectOption<paymentMethod> => {
|
||||||
if (!value) return { value, label: '' };
|
if (!value || value === 'cash') return { value, label: '' };
|
||||||
|
|
||||||
return { value, label: t(`app.admin.local_payment_form.method_${value}`) };
|
return { value, label: t(`app.admin.local_payment_form.method_${value}`) };
|
||||||
};
|
};
|
||||||
@ -60,7 +60,7 @@ export const LocalPaymentForm: React.FC<GatewayFormProps> = ({ onSubmit, onSucce
|
|||||||
/**
|
/**
|
||||||
* Callback triggered when the user selects a payment method for the current payment schedule.
|
* Callback triggered when the user selects a payment method for the current payment schedule.
|
||||||
*/
|
*/
|
||||||
const handleUpdateMethod = (option: SelectOption<scheduleMethod>) => {
|
const handleUpdateMethod = (option: SelectOption<paymentMethod>) => {
|
||||||
updateCart(Object.assign({}, cart, { payment_method: option.value }));
|
updateCart(Object.assign({}, cart, { payment_method: option.value }));
|
||||||
setMethod(option.value);
|
setMethod(option.value);
|
||||||
};
|
};
|
||||||
@ -69,6 +69,10 @@ export const LocalPaymentForm: React.FC<GatewayFormProps> = ({ onSubmit, onSucce
|
|||||||
* Handle the submission of the form. It will process the local payment.
|
* Handle the submission of the form. It will process the local payment.
|
||||||
*/
|
*/
|
||||||
const handleSubmit = async (event: FormEvent): Promise<void> => {
|
const handleSubmit = async (event: FormEvent): Promise<void> => {
|
||||||
|
if (paymentSchedule && !ALL_PAYMENT_METHODS.filter(p => p !== 'cash').includes(method)) {
|
||||||
|
event.preventDefault();
|
||||||
|
return;
|
||||||
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
onSubmit();
|
onSubmit();
|
||||||
|
|
||||||
|
@ -165,8 +165,6 @@ class Invoice < PaymentDocument
|
|||||||
|
|
||||||
if paid_by_card?
|
if paid_by_card?
|
||||||
res.push(means: :card, amount: amount_paid)
|
res.push(means: :card, amount: amount_paid)
|
||||||
elsif paid_by_wallet?
|
|
||||||
res.push(means: :wallet, amount: amount_paid)
|
|
||||||
elsif paid_by_transfer?
|
elsif paid_by_transfer?
|
||||||
res.push(means: :transfer, amount: amount_paid)
|
res.push(means: :transfer, amount: amount_paid)
|
||||||
elsif paid_by_check?
|
elsif paid_by_check?
|
||||||
|
@ -30,6 +30,7 @@ class AccountingServiceTest < ActionDispatch::IntegrationTest
|
|||||||
post '/api/local_payment/confirm_payment', params: {
|
post '/api/local_payment/confirm_payment', params: {
|
||||||
customer_id: @vlonchamp.id,
|
customer_id: @vlonchamp.id,
|
||||||
coupon_code: 'GIME3EUR',
|
coupon_code: 'GIME3EUR',
|
||||||
|
payment_method: 'cash',
|
||||||
items: [
|
items: [
|
||||||
{
|
{
|
||||||
reservation: {
|
reservation: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user