mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-26 20:54:21 +01:00
(feat) Allow the admin to update payment method only the overdue subscription item without cancel PayZen subscription
This commit is contained in:
parent
34e9a0cc97
commit
ff80216d9b
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
## Next release
|
## Next release
|
||||||
|
|
||||||
|
- improvement: Allow the admin to update payment method only the overdue subscription item without cancel PayZen subscription
|
||||||
|
|
||||||
## v6.3.11 2024 February 2
|
## v6.3.11 2024 February 2
|
||||||
|
|
||||||
- Fix a bug: if there is a reservation with a deleted user, it is not possible to delete the event
|
- Fix a bug: if there is a reservation with a deleted user, it is not possible to delete the event
|
||||||
|
@ -89,10 +89,11 @@ class API::PaymentSchedulesController < API::APIController
|
|||||||
def update
|
def update
|
||||||
authorize PaymentSchedule
|
authorize PaymentSchedule
|
||||||
|
|
||||||
if PaymentScheduleService.new.update_payment_mean(@payment_schedule, update_params)
|
payment_schedule_item = PaymentScheduleItem.find(update_params[:payment_schedule_item_id])
|
||||||
|
if PaymentScheduleService.new.update_payment_mean(payment_schedule_item, update_params[:payment_method])
|
||||||
render :show, status: :ok, location: @payment_schedule
|
render :show, status: :ok, location: @payment_schedule
|
||||||
else
|
else
|
||||||
render json: @payment_schedule.errors, status: :unprocessable_entity
|
render json: payment_schedule_item.errors, status: :unprocessable_entity
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -107,6 +108,6 @@ class API::PaymentSchedulesController < API::APIController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def update_params
|
def update_params
|
||||||
params.require(:payment_schedule).permit(:payment_method)
|
params.permit(:payment_method, :payment_schedule_item_id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -48,8 +48,8 @@ export default class PaymentScheduleAPI {
|
|||||||
return res?.data;
|
return res?.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static async update (paymentSchedule: PaymentSchedule): Promise<PaymentSchedule> {
|
static async update (paymentScheduleId: number, paymentScheduleItemId: number, paymentMethod: string): Promise<PaymentSchedule> {
|
||||||
const res:AxiosResponse<PaymentSchedule> = await apiClient.patch(`/api/payment_schedules/${paymentSchedule.id}`, paymentSchedule);
|
const res:AxiosResponse<PaymentSchedule> = await apiClient.patch(`/api/payment_schedules/${paymentScheduleId}`, { payment_method: paymentMethod, payment_schedule_item_id: paymentScheduleItemId });
|
||||||
return res?.data;
|
return res?.data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,10 +169,10 @@ export const PaymentScheduleItemActions: React.FC<PaymentScheduleItemActionsProp
|
|||||||
*/
|
*/
|
||||||
const pendingActions = (): ReactElement => {
|
const pendingActions = (): ReactElement => {
|
||||||
if (isPrivileged()) {
|
if (isPrivileged()) {
|
||||||
if (paymentSchedule.payment_method === PaymentMethod.Transfer) {
|
if (paymentSchedule.payment_method === PaymentMethod.Transfer || paymentScheduleItem.payment_method === PaymentMethod.Transfer) {
|
||||||
return confirmTransferButton();
|
return confirmTransferButton();
|
||||||
}
|
}
|
||||||
if (paymentSchedule.payment_method === PaymentMethod.Check) {
|
if (paymentSchedule.payment_method === PaymentMethod.Check || paymentScheduleItem.payment_method === PaymentMethod.Check) {
|
||||||
return confirmCheckButton();
|
return confirmCheckButton();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -202,7 +202,7 @@ export const PaymentScheduleItemActions: React.FC<PaymentScheduleItemActionsProp
|
|||||||
*/
|
*/
|
||||||
const newActions = (): Array<ReactElement> => {
|
const newActions = (): Array<ReactElement> => {
|
||||||
const buttons = [];
|
const buttons = [];
|
||||||
if (paymentSchedule.payment_method === PaymentMethod.Card) {
|
if (paymentSchedule.payment_method === PaymentMethod.Card && !paymentScheduleItem.payment_method) {
|
||||||
buttons.push(updateCardButton());
|
buttons.push(updateCardButton());
|
||||||
}
|
}
|
||||||
if (isPrivileged()) {
|
if (isPrivileged()) {
|
||||||
@ -400,7 +400,9 @@ export const PaymentScheduleItemActions: React.FC<PaymentScheduleItemActionsProp
|
|||||||
toggleModal={toggleUpdatePaymentMeanModal}
|
toggleModal={toggleUpdatePaymentMeanModal}
|
||||||
onError={onError}
|
onError={onError}
|
||||||
afterSuccess={onPaymentMeanUpdateSuccess}
|
afterSuccess={onPaymentMeanUpdateSuccess}
|
||||||
paymentSchedule={paymentSchedule} />
|
paymentSchedule={paymentSchedule}
|
||||||
|
paymentScheduleItemId={paymentScheduleItem.id}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
|
@ -104,7 +104,8 @@ const PaymentSchedulesTable: React.FC<PaymentSchedulesTableProps> = ({ paymentSc
|
|||||||
* Return the human-readable string for the status of the provided deadline.
|
* Return the human-readable string for the status of the provided deadline.
|
||||||
*/
|
*/
|
||||||
const formatState = (item: PaymentScheduleItem, schedule: PaymentSchedule): JSX.Element => {
|
const formatState = (item: PaymentScheduleItem, schedule: PaymentSchedule): JSX.Element => {
|
||||||
let res = t(`app.shared.payment_schedules_table.state_${item.state}${item.state === 'pending' ? '_' + schedule.payment_method : ''}`);
|
const paymentMethod = item.payment_method || schedule.payment_method;
|
||||||
|
let res = t(`app.shared.payment_schedules_table.state_${item.state}${item.state === 'pending' ? '_' + paymentMethod : ''}`);
|
||||||
if (item.state === 'paid') {
|
if (item.state === 'paid') {
|
||||||
const key = `app.shared.payment_schedules_table.method_${item.payment_method}`;
|
const key = `app.shared.payment_schedules_table.method_${item.payment_method}`;
|
||||||
res += ` (${t(key)})`;
|
res += ` (${t(key)})`;
|
||||||
|
@ -12,12 +12,13 @@ interface UpdatePaymentMeanModalProps {
|
|||||||
onError: (message: string) => void,
|
onError: (message: string) => void,
|
||||||
afterSuccess: () => void,
|
afterSuccess: () => void,
|
||||||
paymentSchedule: PaymentSchedule
|
paymentSchedule: PaymentSchedule
|
||||||
|
paymentScheduleItemId: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Component to allow the member to change his payment mean for the given payment schedule (e.g. from card to transfer)
|
* Component to allow the member to change his payment mean for the given payment schedule (e.g. from card to transfer)
|
||||||
*/
|
*/
|
||||||
export const UpdatePaymentMeanModal: React.FC<UpdatePaymentMeanModalProps> = ({ isOpen, toggleModal, onError, afterSuccess, paymentSchedule }) => {
|
export const UpdatePaymentMeanModal: React.FC<UpdatePaymentMeanModalProps> = ({ isOpen, toggleModal, onError, afterSuccess, paymentSchedule, paymentScheduleItemId }) => {
|
||||||
const { t } = useTranslation('admin');
|
const { t } = useTranslation('admin');
|
||||||
|
|
||||||
const [paymentMean, setPaymentMean] = React.useState<PaymentMethod>();
|
const [paymentMean, setPaymentMean] = React.useState<PaymentMethod>();
|
||||||
@ -42,10 +43,11 @@ export const UpdatePaymentMeanModal: React.FC<UpdatePaymentMeanModalProps> = ({
|
|||||||
* When the user clicks on the update button, update the default payment mean for the given payment schedule
|
* When the user clicks on the update button, update the default payment mean for the given payment schedule
|
||||||
*/
|
*/
|
||||||
const handlePaymentMeanUpdate = (): void => {
|
const handlePaymentMeanUpdate = (): void => {
|
||||||
PaymentScheduleAPI.update({
|
PaymentScheduleAPI.update(
|
||||||
id: paymentSchedule.id,
|
paymentSchedule.id,
|
||||||
payment_method: paymentMean
|
paymentScheduleItemId,
|
||||||
}).then(() => {
|
paymentMean
|
||||||
|
).then(() => {
|
||||||
afterSuccess();
|
afterSuccess();
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
onError(error.message);
|
onError(error.message);
|
||||||
|
@ -177,9 +177,8 @@ class PaymentScheduleService
|
|||||||
##
|
##
|
||||||
# Update the payment mean associated with the given PaymentSchedule and reset the erroneous items
|
# Update the payment mean associated with the given PaymentSchedule and reset the erroneous items
|
||||||
##
|
##
|
||||||
def update_payment_mean(payment_schedule, payment_mean)
|
def update_payment_mean(payment_schedule_item, payment_method)
|
||||||
PaymentGatewayService.new.cancel_subscription(payment_schedule)
|
payment_schedule_item.update(payment_method: payment_method, state: payment_schedule_item.due_date < Time.current ? 'pending' : 'new')
|
||||||
payment_schedule.update(payment_mean) && reset_erroneous_payment_schedule_items(payment_schedule)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -19,12 +19,12 @@ class PaymentScheduleItemWorker
|
|||||||
# @param psi [PaymentScheduleItem]
|
# @param psi [PaymentScheduleItem]
|
||||||
def check_item(psi)
|
def check_item(psi)
|
||||||
# the following depends on the payment method (card/check)
|
# the following depends on the payment method (card/check)
|
||||||
if psi.payment_schedule.payment_method == 'card'
|
if psi.payment_schedule.payment_method == 'card' && psi.payment_method.nil?
|
||||||
### Cards
|
### Cards
|
||||||
PaymentGatewayService.new.process_payment_schedule_item(psi)
|
PaymentGatewayService.new.process_payment_schedule_item(psi)
|
||||||
elsif psi.state == 'new'
|
elsif psi.state == 'new'
|
||||||
### Check/Bank transfer (only new deadlines, to prevent spamming)
|
### Check/Bank transfer (only new deadlines, to prevent spamming)
|
||||||
NotificationCenter.call type: "notify_admin_payment_schedule_#{psi.payment_schedule.payment_method}_deadline",
|
NotificationCenter.call type: "notify_admin_payment_schedule_#{psi.payment_method || psi.payment_schedule.payment_method}_deadline",
|
||||||
receiver: User.admins_and_managers,
|
receiver: User.admins_and_managers,
|
||||||
attached_object: psi
|
attached_object: psi
|
||||||
psi.update(state: 'pending')
|
psi.update(state: 'pending')
|
||||||
|
@ -1147,7 +1147,7 @@ en:
|
|||||||
date: "Date"
|
date: "Date"
|
||||||
update_payment_mean_modal:
|
update_payment_mean_modal:
|
||||||
title: "Update the payment mean"
|
title: "Update the payment mean"
|
||||||
update_info: "Please specify below the new payment mean for this payment schedule to continue."
|
update_info: "Please specify below the payment method to update this payment schedule."
|
||||||
select_payment_mean: "Select a new payment mean"
|
select_payment_mean: "Select a new payment mean"
|
||||||
method_Transfer: "By bank transfer"
|
method_Transfer: "By bank transfer"
|
||||||
method_Check: "By check"
|
method_Check: "By check"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user