mirror of
https://github.com/internetee/registry.git
synced 2025-07-22 18:56:05 +02:00
Add EveryPay payments
* Refactor BankLink into Payments::BankLink, add Payments::EveryPay * Write tests for existing invoice views * Write basic tests for Payments module
This commit is contained in:
parent
f7c2b25a66
commit
c5591b4828
32 changed files with 818 additions and 31 deletions
|
@ -0,0 +1,8 @@
|
|||
class Registrar
|
||||
module Payments
|
||||
class CallbacksController < BaseController
|
||||
def new
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
29
app/controllers/registrar/payments/every_pay_controller.rb
Normal file
29
app/controllers/registrar/payments/every_pay_controller.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
class Registrar
|
||||
module Payments
|
||||
class EveryPayController < BaseController
|
||||
load_resource class: Invoice
|
||||
skip_authorization_check only: [:new, :update]
|
||||
skip_before_action :verify_authenticity_token, only: :update
|
||||
|
||||
def new
|
||||
set_invoice
|
||||
@every_pay = EveryPayPayment.new(@invoice)
|
||||
end
|
||||
|
||||
def create
|
||||
set_invoice
|
||||
end
|
||||
|
||||
def update
|
||||
set_invoice
|
||||
render 'complete'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_invoice
|
||||
@invoice = Invoice.find(params[:invoice_id])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -4,27 +4,35 @@ class Registrar
|
|||
|
||||
skip_authorization_check # actually anyone can pay, no problems at all
|
||||
skip_before_action :authenticate_user!, :check_ip_restriction, only: [:back]
|
||||
before_action :check_bank
|
||||
# before_action :check_bank
|
||||
|
||||
# to handle existing model we should
|
||||
# get invoice_id and then get number
|
||||
# build BankTransaction without connection with right reference number
|
||||
# do not connect transaction and invoice
|
||||
# TODO: Refactor to :new
|
||||
def pay
|
||||
invoice = Invoice.find(params[:invoice_id])
|
||||
@bank_link = BankLink::Request.new(params[:bank], invoice, self)
|
||||
@bank_link.make_transaction
|
||||
opts = {
|
||||
return_url: self.registrar_return_payment_with_url(params[:bank], invoice_id: invoice.id),
|
||||
response_url: self.registrar_return_payment_with_url(params[:bank])
|
||||
}
|
||||
@payment = ::Payments.create_with_type(params[:bank], invoice, opts)
|
||||
@payment.create_transaction
|
||||
end
|
||||
|
||||
|
||||
# connect invoice and transaction
|
||||
# both back and IPN
|
||||
# TODO: Refactor to be restful
|
||||
def back
|
||||
@bank_link = BankLink::Response.new(params[:bank], params)
|
||||
if @bank_link.valid? && @bank_link.ok?
|
||||
@bank_link.complete_payment
|
||||
invoice = Invoice.find(params[:invoice_id])
|
||||
opts = { response: params }
|
||||
@payment = ::Payments.create_with_type(params[:bank], invoice, opts)
|
||||
if @payment.valid_response? && @payment.settled_payment?
|
||||
@payment.complete_transaction
|
||||
|
||||
if @bank_link.invoice.binded?
|
||||
if invoice.binded?
|
||||
flash[:notice] = t(:pending_applied)
|
||||
else
|
||||
flash[:alert] = t(:something_wrong)
|
||||
|
@ -32,14 +40,14 @@ class Registrar
|
|||
else
|
||||
flash[:alert] = t(:something_wrong)
|
||||
end
|
||||
redirect_to registrar_invoice_path(@bank_link.invoice)
|
||||
redirect_to registrar_invoice_path(invoice)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def banks
|
||||
ENV['payments_banks'].split(",").map(&:strip)
|
||||
end
|
||||
# def banks
|
||||
# ENV['payments_banks'].split(",").map(&:strip)
|
||||
# end
|
||||
|
||||
def check_bank
|
||||
raise StandardError.new("Not Implemented bank") unless banks.include?(params[:bank])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue