mirror of
https://github.com/internetee/registry.git
synced 2025-08-27 11:33:32 +02:00
creating sync with billing
This commit is contained in:
parent
162647acba
commit
0a4444b556
9 changed files with 577 additions and 60 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue