mirror of
https://github.com/internetee/registry.git
synced 2025-07-23 03:06:14 +02:00
Implement partial payment logging for EveryPay / Bank links
This commit is contained in:
parent
feb3a5d9da
commit
53fbd2f50c
14 changed files with 470 additions and 345 deletions
|
@ -9,27 +9,37 @@ class Registrar
|
|||
|
||||
def pay
|
||||
invoice = Invoice.find(params[:invoice_id])
|
||||
bank = params[:bank]
|
||||
opts = {
|
||||
return_url: registrar_return_payment_with_url(
|
||||
bank, invoice_id: invoice
|
||||
),
|
||||
response_url: registrar_response_payment_with_url(
|
||||
bank, invoice_id: invoice
|
||||
)
|
||||
}
|
||||
@payment = ::PaymentOrders.create_with_type(bank, invoice, opts)
|
||||
@payment.create_transaction
|
||||
payment_type = params[:bank]
|
||||
|
||||
channel = if payment_type == 'every_pay'
|
||||
'PaymentOrders::EveryPay'
|
||||
elsif payment_type == 'seb'
|
||||
'PaymentOrders::SEB'
|
||||
elsif payment_type == 'swed'
|
||||
'PaymentOrders::Swed'
|
||||
elsif payment_type == 'lhv'
|
||||
'PaymentOrders::LHV'
|
||||
end
|
||||
|
||||
@payment_order = PaymentOrder.new(type: channel, invoice: invoice)
|
||||
@payment_order.save && @payment_order.reload
|
||||
|
||||
@payment_order.return_url = registrar_return_payment_with_url(@payment_order)
|
||||
@payment_order.response_url = registrar_response_payment_with_url(@payment_order)
|
||||
|
||||
@payment_order.save && @payment_order.reload
|
||||
end
|
||||
|
||||
def back
|
||||
invoice = Invoice.find(params[:invoice_id])
|
||||
opts = { response: params }
|
||||
@payment = ::PaymentOrders.create_with_type(params[:bank], invoice, opts)
|
||||
if @payment.valid_response_from_intermediary? && @payment.settled_payment?
|
||||
@payment.complete_transaction
|
||||
puts params
|
||||
|
||||
if invoice.paid?
|
||||
@payment_order = PaymentOrder.find_by!(id: params[:bank])
|
||||
@payment_order.update!(response: params.to_unsafe_h)
|
||||
|
||||
if @payment_order.valid_response_from_intermediary? && @payment_order.settled_payment?
|
||||
@payment_order.complete_transaction
|
||||
|
||||
if @payment_order.invoice.paid?
|
||||
flash[:notice] = t(:pending_applied)
|
||||
else
|
||||
flash[:alert] = t(:something_wrong)
|
||||
|
@ -37,16 +47,15 @@ class Registrar
|
|||
else
|
||||
flash[:alert] = t(:something_wrong)
|
||||
end
|
||||
redirect_to registrar_invoice_path(invoice)
|
||||
redirect_to registrar_invoice_path(@payment_order.invoice)
|
||||
end
|
||||
|
||||
def callback
|
||||
invoice = Invoice.find(params[:invoice_id])
|
||||
opts = { response: params }
|
||||
@payment = ::PaymentOrders.create_with_type(params[:bank], invoice, opts)
|
||||
@payment_order = PaymentOrder.find_by!(id: params[:bank])
|
||||
@payment_order.update!(response: params.to_unsafe_h)
|
||||
|
||||
if @payment.valid_response_from_intermediary? && @payment.settled_payment?
|
||||
@payment.complete_transaction
|
||||
if @payment_order.valid_response_from_intermediary? && @payment_order.settled_payment?
|
||||
@payment_order.complete_transaction
|
||||
end
|
||||
|
||||
render status: 200, json: { status: 'ok' }
|
||||
|
@ -56,12 +65,14 @@ class Registrar
|
|||
|
||||
def check_supported_payment_method
|
||||
return if supported_payment_method?
|
||||
raise StandardError.new("Not supported payment method")
|
||||
|
||||
raise StandardError.new('Not supported payment method')
|
||||
end
|
||||
|
||||
|
||||
def supported_payment_method?
|
||||
PaymentOrders::PAYMENT_METHODS.include?(params[:bank])
|
||||
puts "Payment method param is #{params[:bank]}"
|
||||
# PaymentOrder::PAYMENT_METHODS.include?(params[:bank])
|
||||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue