creating sync with billing

This commit is contained in:
olegphenomenon 2023-01-11 12:25:49 +02:00
parent 162647acba
commit 0a4444b556
9 changed files with 577 additions and 60 deletions

View file

@ -3,19 +3,20 @@ module EisBilling
TYPE = 'PaymentOrders::EveryPay'.freeze
def update
payment_status = define_payment_status(params[:payment_state])
invoice = Invoice.find_by(number: params[:order_reference])
return if invoice.paid?
if invoice.paid?
render json: { message: 'Invoice already paid' }, status: :ok
else
invoice.process_payment(
payment_type: TYPE,
everypay_response: params,
payment_status: define_payment_status(params[:payment_state]),
sum: params[:standing_amount],
transaction_time: params[:transaction_time]
)
bank = create_bank_transfer(invoice: invoice, sum: params[:standing_amount], paid_at: params[:transaction_time])
create_payment_order(invoice: invoice, everypay_response: params, payment_status: payment_status)
bank.bind_invoice(params[:order_reference])
respond_to do |format|
format.json do
render status: :ok, content_type: 'application/json', layout: false, json: { message: 'ok' }
end
render json: { message: 'Payment is proccessing' }, status: :ok
end
end
@ -26,30 +27,5 @@ module EisBilling
:failed
end
def create_payment_order(invoice:, everypay_response:, payment_status:)
payment = PaymentOrder.new
payment.type = TYPE
payment.invoice = invoice
payment.response = everypay_response
payment.status = payment_status
payment.save
payment
end
def create_bank_transfer(invoice:, sum:, paid_at:)
bank = BankTransaction.new
bank.description = invoice.order
bank.reference_no = invoice.reference_no
bank.currency = invoice.currency
bank.iban = invoice.seller_iban
bank.sum = sum
bank.paid_at = paid_at
bank.buyer_name = invoice.buyer_name
bank.save
bank
end
end
end