mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-19 13:54:25 +01:00
(bug) Incorrect amount calculation when paying monthly subcription with a wallet
This commit is contained in:
parent
75259773d5
commit
48ea7509cf
@ -3,6 +3,7 @@
|
||||
- Fix a bug: OpenAPI accounting gateway_object_id missing error
|
||||
- Fix a bug: unable to modify the price of prepaid pack
|
||||
- Fix a bug: notification type missing
|
||||
- Fix critical bug: Incorrect amount calculation when paying monthly subcription with a wallet for PayZen
|
||||
|
||||
## v6.0.6 2023 May 4
|
||||
|
||||
|
@ -25,8 +25,15 @@ class PayZen::Service < Payment::Service
|
||||
order_id: order_id
|
||||
}
|
||||
unless first_item.details['adjustment']&.zero? && first_item.details['other_items']&.zero?
|
||||
params[:initial_amount] = payzen_amount(first_item.amount)
|
||||
params[:initial_amount_number] = 1
|
||||
initial_amount = first_item.amount
|
||||
initial_amount -= payment_schedule.wallet_amount if payment_schedule.wallet_amount
|
||||
if initial_amount.zero?
|
||||
params[:effect_date] = (first_item.due_date + 1.month).iso8601
|
||||
params[:rrule] = rrule(payment_schedule, -1)
|
||||
else
|
||||
params[:initial_amount] = payzen_amount(initial_amount)
|
||||
params[:initial_amount_number] = 1
|
||||
end
|
||||
end
|
||||
pz_subscription = client.create_subscription(**params)
|
||||
|
||||
@ -123,16 +130,21 @@ class PayZen::Service < Payment::Service
|
||||
|
||||
private
|
||||
|
||||
def rrule(payment_schedule)
|
||||
def rrule(payment_schedule, offset = 0)
|
||||
count = payment_schedule.payment_schedule_items.count
|
||||
"RRULE:FREQ=MONTHLY;COUNT=#{count}"
|
||||
"RRULE:FREQ=MONTHLY;COUNT=#{count + offset}"
|
||||
end
|
||||
|
||||
# check if the given transaction matches the given PaymentScheduleItem
|
||||
def transaction_matches?(transaction, payment_schedule_item)
|
||||
transaction_date = Time.zone.parse(transaction['creationDate']).to_date
|
||||
|
||||
transaction['amount'] == payment_schedule_item.amount &&
|
||||
amount = payment_schedule_item.amount
|
||||
if !payment_schedule_item.details['adjustment']&.zero? && payment_schedule_item.payment_schedule.wallet_amount
|
||||
amount -= payment_schedule_item.payment_schedule.wallet_amount
|
||||
end
|
||||
|
||||
transaction['amount'] == amount &&
|
||||
transaction_date >= payment_schedule_item.due_date.to_date &&
|
||||
transaction_date <= payment_schedule_item.due_date.to_date + 7.days
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user