mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-29 18:52:22 +01:00
wait for the first payzen transaction + fix initial amount
This commit is contained in:
parent
dc0a75e52d
commit
ea774e2080
@ -1,5 +1,5 @@
|
||||
import axios, { AxiosInstance } from 'axios'
|
||||
// compile
|
||||
|
||||
const token: HTMLMetaElement = document.querySelector('[name="csrf-token"]');
|
||||
const client: AxiosInstance = axios.create({
|
||||
headers: {
|
||||
|
@ -24,7 +24,7 @@ class PayZen::Service < Payment::Service
|
||||
rrule: rrule(payment_schedule),
|
||||
order_id: order_id
|
||||
}
|
||||
unless first_item.details['adjustment']&.zero?
|
||||
unless first_item.details['adjustment']&.zero? && first_item.details['other_items']&.zero?
|
||||
params[:initial_amount] = first_item.amount
|
||||
params[:initial_amount_number] = 1
|
||||
end
|
||||
@ -51,31 +51,37 @@ class PayZen::Service < Payment::Service
|
||||
def process_payment_schedule_item(payment_schedule_item)
|
||||
pz_order = payment_schedule_item.payment_schedule.payment_gateway_objects.find { |pgo| pgo.gateway_object_type == 'PayZen::Order' }.gateway_object.retrieve
|
||||
transaction = pz_order['answer']['transactions'].last
|
||||
if transaction['status'] == 'PAID'
|
||||
PaymentScheduleService.new.generate_invoice(payment_schedule_item,
|
||||
payment_method: 'card',
|
||||
payment_id: transaction['uuid'],
|
||||
payment_type: 'PayZen::Transaction')
|
||||
payment_schedule_item.update_attributes(state: 'paid', payment_method: 'card')
|
||||
pgo = PaymentGatewayObject.find_or_initialize_by(item: payment_schedule_item)
|
||||
pgo.gateway_object = PayZen::Item.new('PayZen::Transaction', transaction['uuid'])
|
||||
pgo.save!
|
||||
elsif transaction['status'] == 'RUNNING'
|
||||
if payment_schedule_item.state == 'new'
|
||||
# notify only for new deadlines, to prevent spamming
|
||||
NotificationCenter.call type: 'notify_admin_payment_schedule_failed',
|
||||
receiver: User.admins_and_managers,
|
||||
attached_object: payment_schedule_item
|
||||
NotificationCenter.call type: 'notify_member_payment_schedule_failed',
|
||||
receiver: payment_schedule_item.payment_schedule.user,
|
||||
attached_object: payment_schedule_item
|
||||
transaction_date = DateTime.parse(transaction['creationDate']).to_date
|
||||
# check that the transaction matches the current PaymentScheduleItem
|
||||
if transaction['amount'] == payment_schedule_item.amount &&
|
||||
transaction_date >= payment_schedule_item.due_date.to_date &&
|
||||
transaction_date <= payment_schedule_item.due_date.to_date + 7.days
|
||||
if transaction['status'] == 'PAID'
|
||||
PaymentScheduleService.new.generate_invoice(payment_schedule_item,
|
||||
payment_method: 'card',
|
||||
payment_id: transaction['uuid'],
|
||||
payment_type: 'PayZen::Transaction')
|
||||
payment_schedule_item.update_attributes(state: 'paid', payment_method: 'card')
|
||||
pgo = PaymentGatewayObject.find_or_initialize_by(item: payment_schedule_item)
|
||||
pgo.gateway_object = PayZen::Item.new('PayZen::Transaction', transaction['uuid'])
|
||||
pgo.save!
|
||||
elsif transaction['status'] == 'RUNNING'
|
||||
if payment_schedule_item.state == 'new'
|
||||
# notify only for new deadlines, to prevent spamming
|
||||
NotificationCenter.call type: 'notify_admin_payment_schedule_failed',
|
||||
receiver: User.admins_and_managers,
|
||||
attached_object: payment_schedule_item
|
||||
NotificationCenter.call type: 'notify_member_payment_schedule_failed',
|
||||
receiver: payment_schedule_item.payment_schedule.user,
|
||||
attached_object: payment_schedule_item
|
||||
end
|
||||
payment_schedule_item.update_attributes(state: transaction['detailedStatus'])
|
||||
pgo = PaymentGatewayObject.find_or_initialize_by(item: payment_schedule_item)
|
||||
pgo.gateway_object = PayZen::Item.new('PayZen::Transaction', transaction['uuid'])
|
||||
pgo.save!
|
||||
else
|
||||
payment_schedule_item.update_attributes(state: 'error')
|
||||
end
|
||||
payment_schedule_item.update_attributes(state: transaction['detailedStatus'])
|
||||
pgo = PaymentGatewayObject.find_or_initialize_by(item: payment_schedule_item)
|
||||
pgo.gateway_object = PayZen::Item.new('PayZen::Transaction', transaction['uuid'])
|
||||
pgo.save!
|
||||
else
|
||||
payment_schedule_item.update_attributes(state: 'error')
|
||||
end
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user