mirror of
https://github.com/internetee/registry.git
synced 2025-08-11 03:59:33 +02:00
Merge pull request #2266 from internetee/eis_billing-request-to-generate-invoice
added api service for generate invoice in billing system
This commit is contained in:
commit
b909bf3408
55 changed files with 1355 additions and 238 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -11,6 +11,6 @@
|
||||||
/config/deploy.rb
|
/config/deploy.rb
|
||||||
/config/master.key
|
/config/master.key
|
||||||
/.idea
|
/.idea
|
||||||
|
/config/master.key
|
||||||
# Do not commit one. Instead, download the latest from https://github.com/internetee/style-guide.
|
# Do not commit one. Instead, download the latest from https://github.com/internetee/style-guide.
|
||||||
.rubocop.yml
|
.rubocop.yml
|
||||||
|
|
3
Gemfile
3
Gemfile
|
@ -104,3 +104,6 @@ gem 'pghero'
|
||||||
gem 'pg_query', '>= 0.9.0'
|
gem 'pg_query', '>= 0.9.0'
|
||||||
gem 'newrelic_rpm'
|
gem 'newrelic_rpm'
|
||||||
gem 'newrelic-infinite_tracing'
|
gem 'newrelic-infinite_tracing'
|
||||||
|
|
||||||
|
# token
|
||||||
|
gem 'jwt'
|
||||||
|
|
|
@ -275,6 +275,7 @@ GEM
|
||||||
activesupport (>= 4.2)
|
activesupport (>= 4.2)
|
||||||
aes_key_wrap
|
aes_key_wrap
|
||||||
bindata
|
bindata
|
||||||
|
jwt (2.3.0)
|
||||||
kaminari (1.2.1)
|
kaminari (1.2.1)
|
||||||
activesupport (>= 4.1.0)
|
activesupport (>= 4.1.0)
|
||||||
kaminari-actionview (= 1.2.1)
|
kaminari-actionview (= 1.2.1)
|
||||||
|
@ -560,6 +561,7 @@ DEPENDENCIES
|
||||||
iso8601 (= 0.13.0)
|
iso8601 (= 0.13.0)
|
||||||
jquery-rails
|
jquery-rails
|
||||||
jquery-ui-rails (= 6.0.1)
|
jquery-ui-rails (= 6.0.1)
|
||||||
|
jwt
|
||||||
kaminari
|
kaminari
|
||||||
lhv!
|
lhv!
|
||||||
mime-types-data
|
mime-types-data
|
||||||
|
|
BIN
app/assets/images/everypay.png
Normal file
BIN
app/assets/images/everypay.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
|
@ -13,6 +13,7 @@ module Admin
|
||||||
|
|
||||||
if @invoice&.persisted?
|
if @invoice&.persisted?
|
||||||
flash[:notice] = t(:record_created)
|
flash[:notice] = t(:record_created)
|
||||||
|
# send_invoice_data_to_billing_system
|
||||||
redirect_to [:admin, @invoice]
|
redirect_to [:admin, @invoice]
|
||||||
else
|
else
|
||||||
flash.now[:alert] = t(:failed_to_create_record)
|
flash.now[:alert] = t(:failed_to_create_record)
|
||||||
|
@ -48,6 +49,8 @@ module Admin
|
||||||
|
|
||||||
def cancel
|
def cancel
|
||||||
@invoice.cancel
|
@invoice.cancel
|
||||||
|
EisBilling::SendInvoiceStatus.send_info(invoice_number: @invoice.number, status: 'cancelled')
|
||||||
|
|
||||||
redirect_to [:admin, @invoice], notice: t('.cancelled')
|
redirect_to [:admin, @invoice], notice: t('.cancelled')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
59
app/controllers/eis_billing/base_controller.rb
Normal file
59
app/controllers/eis_billing/base_controller.rb
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
module EisBilling
|
||||||
|
class BaseController < ApplicationController
|
||||||
|
protect_from_forgery with: :null_session
|
||||||
|
skip_authorization_check # Temporary solution
|
||||||
|
# skip_before_action :verify_authenticity_token # Temporary solution
|
||||||
|
before_action :persistent
|
||||||
|
before_action :authorized
|
||||||
|
|
||||||
|
INITIATOR = 'billing'.freeze
|
||||||
|
|
||||||
|
def encode_token(payload)
|
||||||
|
JWT.encode(payload, ENV['secret_word'])
|
||||||
|
end
|
||||||
|
|
||||||
|
def auth_header
|
||||||
|
# { Authorization: 'Bearer <token>' }
|
||||||
|
request.headers['Authorization']
|
||||||
|
end
|
||||||
|
|
||||||
|
def decoded_token
|
||||||
|
return unless auth_header
|
||||||
|
|
||||||
|
token = auth_header.split(' ')[1]
|
||||||
|
begin
|
||||||
|
JWT.decode(token, billing_secret_key, true, algorithm: 'HS256')
|
||||||
|
rescue JWT::DecodeError
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def accessable_service
|
||||||
|
return decoded_token[0]['initiator'] == INITIATOR if decoded_token
|
||||||
|
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
|
def logged_in?
|
||||||
|
!!accessable_service
|
||||||
|
end
|
||||||
|
|
||||||
|
def authorized
|
||||||
|
render json: { message: 'Access denied' }, status: :unauthorized unless logged_in?
|
||||||
|
end
|
||||||
|
|
||||||
|
def billing_secret_key
|
||||||
|
ENV['billing_secret']
|
||||||
|
end
|
||||||
|
|
||||||
|
def logger
|
||||||
|
Rails.logger
|
||||||
|
end
|
||||||
|
|
||||||
|
def persistent
|
||||||
|
return true if Feature.billing_system_integrated?
|
||||||
|
|
||||||
|
render json: { message: "We don't work yet!" }, status: :unauthorized
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
36
app/controllers/eis_billing/directo_response_controller.rb
Normal file
36
app/controllers/eis_billing/directo_response_controller.rb
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
class EisBilling::DirectoResponseController < EisBilling::BaseController
|
||||||
|
def update
|
||||||
|
response = params[:response]
|
||||||
|
xml_data = params[:xml_data]
|
||||||
|
@month = params.fetch(:month, false)
|
||||||
|
|
||||||
|
process_directo_response(xml_data, response)
|
||||||
|
render status: :ok, json: { messege: 'Should return new directo number' }
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def process_directo_response(xml, req)
|
||||||
|
Rails.logger.info "[Directo] - Responded with body: #{xml}"
|
||||||
|
Nokogiri::XML(req).css('Result').each do |res|
|
||||||
|
if @month
|
||||||
|
mark_invoice_as_sent(res: res, req: req)
|
||||||
|
else
|
||||||
|
inv = Invoice.find_by(number: res.attributes['docid'].value.to_i)
|
||||||
|
|
||||||
|
mark_invoice_as_sent(invoice: inv, res: res, req: req)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def mark_invoice_as_sent(invoice: nil, res:, req:)
|
||||||
|
directo_record = Directo.new(response: res.as_json.to_h,
|
||||||
|
request: req, invoice_number: res.attributes['docid'].value.to_i)
|
||||||
|
if invoice
|
||||||
|
directo_record.item = invoice
|
||||||
|
invoice.update(in_directo: true)
|
||||||
|
end
|
||||||
|
|
||||||
|
directo_record.save!
|
||||||
|
end
|
||||||
|
end
|
15
app/controllers/eis_billing/e_invoice_response_controller.rb
Normal file
15
app/controllers/eis_billing/e_invoice_response_controller.rb
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
class EisBilling::EInvoiceResponseController < EisBilling::BaseController
|
||||||
|
def update
|
||||||
|
invoice_number = params[:invoice_number]
|
||||||
|
|
||||||
|
mark_e_invoice_sent_at(invoice_number)
|
||||||
|
render status: :ok, json: { message: 'Response received' }
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def mark_e_invoice_sent_at(invoice_number)
|
||||||
|
invoice = Invoice.find_by(number: invoice_number)
|
||||||
|
invoice.update(e_invoice_sent_at: Time.zone.now)
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,48 @@
|
||||||
|
module EisBilling
|
||||||
|
class LhvConnectTransactionsController < EisBilling::BaseController
|
||||||
|
def create
|
||||||
|
params['_json'].each do |incoming_transaction|
|
||||||
|
process_transactions(incoming_transaction)
|
||||||
|
end
|
||||||
|
|
||||||
|
render status: :ok, json: { message: 'RECEIVED', params: params }
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def process_transactions(incoming_transaction)
|
||||||
|
logger.info 'Got incoming transactions'
|
||||||
|
logger.info incoming_transaction
|
||||||
|
|
||||||
|
bank_statement = BankStatement.new(bank_code: Setting.registry_bank_code,
|
||||||
|
iban: Setting.registry_iban)
|
||||||
|
bank_statement_transaction(bank_statement: bank_statement, incoming_transaction: incoming_transaction)
|
||||||
|
end
|
||||||
|
|
||||||
|
def bank_statement_transaction(bank_statement:, incoming_transaction:)
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
bank_statement.save!
|
||||||
|
transaction = create_transaction(incoming_transaction: incoming_transaction, bank_statement: bank_statement)
|
||||||
|
|
||||||
|
next if transaction.registrar.blank?
|
||||||
|
|
||||||
|
create_invoice_if_missing(transaction) unless transaction.non_canceled?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_invoice_if_missing(transaction)
|
||||||
|
Invoice.create_from_transaction!(transaction) unless transaction.autobindable?
|
||||||
|
transaction.autobind_invoice
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_transaction(incoming_transaction:, bank_statement:)
|
||||||
|
transaction_attributes = { sum: incoming_transaction['amount'],
|
||||||
|
currency: incoming_transaction['currency'],
|
||||||
|
paid_at: incoming_transaction['date'],
|
||||||
|
reference_no: incoming_transaction['payment_reference_number'],
|
||||||
|
description: incoming_transaction['payment_description'] }
|
||||||
|
|
||||||
|
bank_statement.bank_transactions.create!(transaction_attributes)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
54
app/controllers/eis_billing/payment_status_controller.rb
Normal file
54
app/controllers/eis_billing/payment_status_controller.rb
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
module EisBilling
|
||||||
|
class PaymentStatusController < EisBilling::BaseController
|
||||||
|
TYPE = 'PaymentOrders::EveryPay'.freeze
|
||||||
|
|
||||||
|
def update
|
||||||
|
payment_status = define_payment_status(params[:payment_state])
|
||||||
|
invoice = Invoice.find_by(number: params[:order_reference])
|
||||||
|
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)
|
||||||
|
|
||||||
|
registrar = invoice.buyer
|
||||||
|
bank.create_activity(registrar, invoice)
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.json do
|
||||||
|
render status: :ok, content_type: 'application/json', layout: false, json: { message: 'ok' }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def define_payment_status(status)
|
||||||
|
return :paid if PaymentOrders::EveryPay::SUCCESSFUL_PAYMENT.include? status
|
||||||
|
|
||||||
|
: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
|
|
@ -17,6 +17,8 @@ class Registrar
|
||||||
|
|
||||||
def cancel
|
def cancel
|
||||||
@invoice.cancel
|
@invoice.cancel
|
||||||
|
EisBilling::SendInvoiceStatus.send_info(invoice_number: @invoice.number, status: 'cancelled')
|
||||||
|
|
||||||
redirect_to [:registrar, @invoice], notice: t('.cancelled')
|
redirect_to [:registrar, @invoice], notice: t('.cancelled')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@ class DirectoInvoiceForwardJob < ApplicationJob
|
||||||
Rails.logger.info "[DIRECTO] Invoice #{invoice.number} has been skipped"
|
Rails.logger.info "[DIRECTO] Invoice #{invoice.number} has been skipped"
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
@client.invoices.add_with_schema(invoice: invoice.as_directo_json, schema: 'prepayment')
|
@client.invoices.add_with_schema(invoice: invoice.as_directo_json, schema: 'prepayment')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -69,6 +70,7 @@ class DirectoInvoiceForwardJob < ApplicationJob
|
||||||
|
|
||||||
def sync_with_directo
|
def sync_with_directo
|
||||||
assign_monthly_numbers if @month
|
assign_monthly_numbers if @month
|
||||||
|
|
||||||
Rails.logger.info("[Directo] - attempting to send following XML:\n #{@client.invoices.as_xml}")
|
Rails.logger.info("[Directo] - attempting to send following XML:\n #{@client.invoices.as_xml}")
|
||||||
return if @dry
|
return if @dry
|
||||||
|
|
||||||
|
|
84
app/jobs/directo_invoice_forward_two_job.rb
Normal file
84
app/jobs/directo_invoice_forward_two_job.rb
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
class DirectoInvoiceForwardTwoJob < ApplicationJob
|
||||||
|
def perform(monthly: false, dry: false)
|
||||||
|
data = nil
|
||||||
|
|
||||||
|
if monthly
|
||||||
|
@month = Time.zone.now - 1.month
|
||||||
|
data = collect_monthly_data
|
||||||
|
else
|
||||||
|
data = collect_receipts_data
|
||||||
|
end
|
||||||
|
|
||||||
|
EisBilling::SendDataToDirecto.send_request(object_data: data, monthly: monthly, dry: dry)
|
||||||
|
end
|
||||||
|
|
||||||
|
def collect_receipts_data
|
||||||
|
unsent_invoices = Invoice.where(in_directo: false).non_cancelled
|
||||||
|
collected_data = []
|
||||||
|
|
||||||
|
unsent_invoices.each do |invoice|
|
||||||
|
unless valid_invoice_conditions?(invoice)
|
||||||
|
Rails.logger.info "[DIRECTO] Invoice #{invoice.number} has been skipped"
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
collected_data << invoice.as_directo_json
|
||||||
|
end
|
||||||
|
|
||||||
|
collected_data
|
||||||
|
end
|
||||||
|
|
||||||
|
def valid_invoice_conditions?(invoice)
|
||||||
|
if invoice.account_activity.nil? || invoice.account_activity.bank_transaction.nil? ||
|
||||||
|
invoice.account_activity.bank_transaction.sum.nil? ||
|
||||||
|
invoice.account_activity.bank_transaction.sum != invoice.total
|
||||||
|
return false
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def collect_monthly_data
|
||||||
|
registrars_data = []
|
||||||
|
|
||||||
|
Registrar.where.not(test_registrar: true).find_each do |registrar|
|
||||||
|
registrars_data << {
|
||||||
|
registrar: registrar,
|
||||||
|
registrar_summery: registrar.monthly_summary(month: @month),
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
registrars_data
|
||||||
|
end
|
||||||
|
|
||||||
|
def mark_invoice_as_sent(invoice: nil, res:, req:)
|
||||||
|
directo_record = Directo.new(response: res.as_json.to_h,
|
||||||
|
request: req, invoice_number: res.attributes['docid'].value.to_i)
|
||||||
|
if invoice
|
||||||
|
directo_record.item = invoice
|
||||||
|
invoice.update(in_directo: true)
|
||||||
|
else
|
||||||
|
update_directo_number(num: directo_record.invoice_number)
|
||||||
|
end
|
||||||
|
|
||||||
|
directo_record.save!
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_directo_number(num:)
|
||||||
|
return unless num.to_i > Setting.directo_monthly_number_last.to_i
|
||||||
|
|
||||||
|
Setting.directo_monthly_number_last = num.to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
def directo_counter_exceedable?(invoice_count)
|
||||||
|
min_directo = Setting.directo_monthly_number_min.presence.try(:to_i)
|
||||||
|
max_directo = Setting.directo_monthly_number_max.presence.try(:to_i)
|
||||||
|
last_directo = [Setting.directo_monthly_number_last.presence.try(:to_i),
|
||||||
|
min_directo].compact.max || 0
|
||||||
|
|
||||||
|
return true if max_directo && max_directo < (last_directo + invoice_count)
|
||||||
|
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
44
app/jobs/send_e_invoice_two_job.rb
Normal file
44
app/jobs/send_e_invoice_two_job.rb
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
class SendEInvoiceTwoJob < ApplicationJob
|
||||||
|
discard_on HTTPClient::TimeoutError
|
||||||
|
|
||||||
|
def perform(invoice_id, payable: true)
|
||||||
|
logger.info "Started to process e-invoice for invoice_id #{invoice_id}"
|
||||||
|
invoice = Invoice.find_by(id: invoice_id)
|
||||||
|
return unless need_to_process_invoice?(invoice: invoice, payable: payable)
|
||||||
|
|
||||||
|
send_invoice_to_eis_billing(invoice: invoice, payable: payable)
|
||||||
|
invoice.update(e_invoice_sent_at: Time.zone.now)
|
||||||
|
rescue StandardError => e
|
||||||
|
log_error(invoice: invoice, error: e)
|
||||||
|
raise e
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def need_to_process_invoice?(invoice:, payable:)
|
||||||
|
logger.info "Checking if need to process e-invoice #{invoice}, payable: #{payable}"
|
||||||
|
return false if invoice.blank?
|
||||||
|
return false if invoice.do_not_send_e_invoice? && payable
|
||||||
|
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def send_invoice_to_eis_billing(invoice:, payable:)
|
||||||
|
result = EisBilling::SendEInvoice.send_request(invoice: invoice, payable: payable)
|
||||||
|
logger.info result.body
|
||||||
|
end
|
||||||
|
|
||||||
|
def log_error(invoice:, error:)
|
||||||
|
id = invoice.try(:id) || invoice
|
||||||
|
message = <<~TEXT.squish
|
||||||
|
There was an error sending e-invoice for invoice with ID # #{id}.
|
||||||
|
The error message was the following: #{error}
|
||||||
|
This job will retry.
|
||||||
|
TEXT
|
||||||
|
logger.error message
|
||||||
|
end
|
||||||
|
|
||||||
|
def logger
|
||||||
|
Rails.logger
|
||||||
|
end
|
||||||
|
end
|
|
@ -4,9 +4,14 @@ module Billing
|
||||||
MULTI_REGEXP = /(\d{2,20})/
|
MULTI_REGEXP = /(\d{2,20})/
|
||||||
|
|
||||||
def self.generate
|
def self.generate
|
||||||
|
if Feature.billing_system_integrated?
|
||||||
|
result = EisBilling::GetReferenceNumber.send_request
|
||||||
|
JSON.parse(result.body)['reference_number']
|
||||||
|
else
|
||||||
base = Base.generate
|
base = Base.generate
|
||||||
"#{base}#{base.check_digit}"
|
"#{base}#{base.check_digit}"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def self.valid?(ref)
|
def self.valid?(ref)
|
||||||
base = Base.new(ref.to_s[0...-1])
|
base = Base.new(ref.to_s[0...-1])
|
||||||
|
|
|
@ -1,13 +1,7 @@
|
||||||
class Feature
|
class Feature
|
||||||
# def self.obj_and_extensions_statuses_enabled?
|
def self.billing_system_integrated?
|
||||||
# return false if ENV['obj_and_extensions_prohibited'] == 'false'
|
return false if ENV['billing_system_integrated'] == 'false'
|
||||||
#
|
|
||||||
# ENV['obj_and_extensions_prohibited'] || false
|
ENV['billing_system_integrated'] || false
|
||||||
# end
|
end
|
||||||
#
|
|
||||||
# def self.enable_lock_domain_with_new_statuses?
|
|
||||||
# return false if ENV['enable_lock_domain_with_new_statuses'] == 'false'
|
|
||||||
#
|
|
||||||
# ENV['enable_lock_domain_with_new_statuses'] || false
|
|
||||||
# end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -40,8 +40,38 @@ class Invoice < ApplicationRecord
|
||||||
|
|
||||||
attribute :vat_rate, ::Type::VatRate.new
|
attribute :vat_rate, ::Type::VatRate.new
|
||||||
|
|
||||||
def set_invoice_number
|
def validate_invoice_number(result)
|
||||||
last_no = Invoice.order(number: :desc).limit(1).pick(:number)
|
response = JSON.parse(result.body)
|
||||||
|
|
||||||
|
billing_restrictions_issue if response['code'] == '403'
|
||||||
|
billing_out_of_range_issue if response['error'] == 'out of range'
|
||||||
|
end
|
||||||
|
|
||||||
|
def billing_restrictions_issue
|
||||||
|
errors.add(:base, I18n.t('cannot get access'))
|
||||||
|
logger.error('PROBLEM WITH TOKEN')
|
||||||
|
throw(:abort)
|
||||||
|
end
|
||||||
|
|
||||||
|
def billing_out_of_range_issue
|
||||||
|
errors.add(:base, I18n.t('failed_to_generate_invoice_invoice_number_limit_reached'))
|
||||||
|
logger.error('INVOICE NUMBER LIMIT REACHED, COULD NOT GENERATE INVOICE')
|
||||||
|
throw(:abort)
|
||||||
|
end
|
||||||
|
|
||||||
|
def invoice_number_from_billing
|
||||||
|
result = EisBilling::GetInvoiceNumber.send_invoice
|
||||||
|
validate_invoice_number(result)
|
||||||
|
|
||||||
|
self.number = JSON.parse(result.body)['invoice_number'].to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
def generate_invoice_number_legacy
|
||||||
|
last_no = Invoice.all
|
||||||
|
.where(number: Setting.invoice_number_min.to_i...Setting.invoice_number_max.to_i)
|
||||||
|
.order(number: :desc)
|
||||||
|
.limit(1)
|
||||||
|
.pick(:number)
|
||||||
|
|
||||||
if last_no && last_no >= Setting.invoice_number_min.to_i
|
if last_no && last_no >= Setting.invoice_number_min.to_i
|
||||||
self.number = last_no + 1
|
self.number = last_no + 1
|
||||||
|
@ -51,9 +81,15 @@ class Invoice < ApplicationRecord
|
||||||
|
|
||||||
return if number <= Setting.invoice_number_max.to_i
|
return if number <= Setting.invoice_number_max.to_i
|
||||||
|
|
||||||
errors.add(:base, I18n.t('failed_to_generate_invoice_invoice_number_limit_reached'))
|
billing_out_of_range_issue
|
||||||
logger.error('INVOICE NUMBER LIMIT REACHED, COULD NOT GENERATE INVOICE')
|
end
|
||||||
throw(:abort)
|
|
||||||
|
def set_invoice_number
|
||||||
|
if Feature.billing_system_integrated?
|
||||||
|
invoice_number_from_billing
|
||||||
|
else
|
||||||
|
generate_invoice_number_legacy
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
|
|
|
@ -107,7 +107,20 @@ class Registrar < ApplicationRecord
|
||||||
.deliver_later(wait: 1.minute)
|
.deliver_later(wait: 1.minute)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if Feature.billing_system_integrated?
|
||||||
|
add_invoice_instance = EisBilling::AddDeposits.new(invoice)
|
||||||
|
result = add_invoice_instance.send_invoice
|
||||||
|
|
||||||
|
link = JSON.parse(result.body)['everypay_link']
|
||||||
|
|
||||||
|
invoice.update(payment_link: link)
|
||||||
|
end
|
||||||
|
|
||||||
|
if Feature.billing_system_integrated?
|
||||||
|
SendEInvoiceTwoJob.set(wait: 1.minute).perform_now(invoice.id, payable: payable)
|
||||||
|
else
|
||||||
SendEInvoiceJob.set(wait: 1.minute).perform_now(invoice.id, payable: payable)
|
SendEInvoiceJob.set(wait: 1.minute).perform_now(invoice.id, payable: payable)
|
||||||
|
end
|
||||||
|
|
||||||
invoice
|
invoice
|
||||||
end
|
end
|
||||||
|
|
37
app/services/eis_billing/add_deposits.rb
Normal file
37
app/services/eis_billing/add_deposits.rb
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
module EisBilling
|
||||||
|
class AddDeposits < EisBilling::Base
|
||||||
|
attr_reader :invoice
|
||||||
|
|
||||||
|
def initialize(invoice)
|
||||||
|
@invoice = invoice
|
||||||
|
end
|
||||||
|
|
||||||
|
def send_invoice
|
||||||
|
send_request(json_obj: parse_invoice)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def parse_invoice
|
||||||
|
data = {}
|
||||||
|
data[:transaction_amount] = invoice.total.to_s
|
||||||
|
data[:order_reference] = invoice.number
|
||||||
|
data[:customer_name] = invoice.buyer_name
|
||||||
|
data[:customer_email] = invoice.buyer_email
|
||||||
|
data[:custom_field1] = invoice.description
|
||||||
|
data[:custom_field2] = INITIATOR
|
||||||
|
data[:invoice_number] = invoice.number
|
||||||
|
|
||||||
|
data
|
||||||
|
end
|
||||||
|
|
||||||
|
def send_request(json_obj:)
|
||||||
|
http = EisBilling::Base.base_request(url: invoice_generator_url)
|
||||||
|
http.post(invoice_generator_url, json_obj.to_json, EisBilling::Base.headers)
|
||||||
|
end
|
||||||
|
|
||||||
|
def invoice_generator_url
|
||||||
|
"#{BASE_URL}/api/v1/invoice_generator/invoice_generator"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
35
app/services/eis_billing/base.rb
Normal file
35
app/services/eis_billing/base.rb
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
module EisBilling
|
||||||
|
class Base
|
||||||
|
BASE_URL = ENV['eis_billing_system_base_url'] || 'https://st-billing.infra.tld.ee'
|
||||||
|
INITIATOR = 'registry'.freeze
|
||||||
|
|
||||||
|
def self.base_request(url:)
|
||||||
|
uri = URI(url)
|
||||||
|
http = Net::HTTP.new(uri.host, uri.port)
|
||||||
|
|
||||||
|
http.use_ssl = true unless Rails.env.development?
|
||||||
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if Rails.env.development?
|
||||||
|
|
||||||
|
http
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.generate_token
|
||||||
|
JWT.encode(payload, billing_secret)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.payload
|
||||||
|
{ initiator: INITIATOR }
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.headers
|
||||||
|
{
|
||||||
|
'Authorization' => "Bearer #{generate_token}",
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.billing_secret
|
||||||
|
ENV['billing_secret']
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
16
app/services/eis_billing/get_invoice_number.rb
Normal file
16
app/services/eis_billing/get_invoice_number.rb
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
module EisBilling
|
||||||
|
class GetInvoiceNumber < EisBilling::Base
|
||||||
|
def self.send_invoice
|
||||||
|
send_request
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.send_request
|
||||||
|
http = EisBilling::Base.base_request(url: invoice_number_generator_url)
|
||||||
|
http.post(invoice_number_generator_url, nil, EisBilling::Base.headers)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.invoice_number_generator_url
|
||||||
|
"#{BASE_URL}/api/v1/invoice_generator/invoice_number_generator"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
22
app/services/eis_billing/get_reference_number.rb
Normal file
22
app/services/eis_billing/get_reference_number.rb
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
module EisBilling
|
||||||
|
class GetReferenceNumber < EisBilling::Base
|
||||||
|
def self.send_request
|
||||||
|
send_it
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.obj_data
|
||||||
|
{
|
||||||
|
initiator: INITIATOR,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.send_it
|
||||||
|
http = EisBilling::Base.base_request(url: reference_number_generator_url)
|
||||||
|
http.post(reference_number_generator_url, obj_data.to_json, EisBilling::Base.headers)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.reference_number_generator_url
|
||||||
|
"#{EisBilling::Base::BASE_URL}/api/v1/invoice_generator/reference_number_generator"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
23
app/services/eis_billing/send_data_to_directo.rb
Normal file
23
app/services/eis_billing/send_data_to_directo.rb
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
module EisBilling
|
||||||
|
class SendDataToDirecto < EisBilling::Base
|
||||||
|
def self.send_request(object_data:, monthly:, dry:)
|
||||||
|
send_info(object_data: object_data, monthly: monthly, dry: dry)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.send_info(object_data:, monthly:, dry:)
|
||||||
|
prepared_data = {
|
||||||
|
invoice_data: object_data,
|
||||||
|
monthly: monthly,
|
||||||
|
dry: dry,
|
||||||
|
initiator: INITIATOR,
|
||||||
|
}
|
||||||
|
|
||||||
|
http = EisBilling::Base.base_request(url: directo_url)
|
||||||
|
http.post(directo_url, prepared_data.to_json, EisBilling::Base.headers)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.directo_url
|
||||||
|
"#{BASE_URL}/api/v1/directo/directo"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
52
app/services/eis_billing/send_e_invoice.rb
Normal file
52
app/services/eis_billing/send_e_invoice.rb
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
module EisBilling
|
||||||
|
class SendEInvoice < EisBilling::Base
|
||||||
|
def self.send_request(invoice:, payable:)
|
||||||
|
send_info(invoice: invoice, payable: payable)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.send_info(invoice:, payable:)
|
||||||
|
items = []
|
||||||
|
prepared_data = prepare_data(invoice: invoice, payable: payable)
|
||||||
|
|
||||||
|
invoice.items.each do |invoice_item|
|
||||||
|
items << prepare_item(invoice_item)
|
||||||
|
end
|
||||||
|
|
||||||
|
prepared_data[:items] = items
|
||||||
|
|
||||||
|
http = EisBilling::Base.base_request(url: e_invoice_url)
|
||||||
|
http.post(e_invoice_url, prepared_data.to_json, EisBilling::Base.headers)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.prepare_item(invoice_item)
|
||||||
|
{
|
||||||
|
description: invoice_item.description,
|
||||||
|
price: invoice_item.price,
|
||||||
|
quantity: invoice_item.quantity,
|
||||||
|
unit: invoice_item.unit,
|
||||||
|
subtotal: invoice_item.subtotal,
|
||||||
|
vat_rate: invoice_item.vat_rate,
|
||||||
|
vat_amount: invoice_item.vat_amount,
|
||||||
|
total: invoice_item.total,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.prepare_data(invoice:, payable:)
|
||||||
|
{
|
||||||
|
invoice: invoice,
|
||||||
|
vat_amount: invoice.vat_amount,
|
||||||
|
invoice_subtotal: invoice.subtotal,
|
||||||
|
buyer_billing_email: invoice.buyer.billing_email,
|
||||||
|
buyer_e_invoice_iban: invoice.buyer.e_invoice_iban,
|
||||||
|
seller_country_code: invoice.seller_country_code,
|
||||||
|
buyer_country_code: invoice.buyer_country_code,
|
||||||
|
payable: payable,
|
||||||
|
initiator: EisBilling::Base::INITIATOR,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.e_invoice_url
|
||||||
|
"#{BASE_URL}/api/v1/e_invoice/e_invoice"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
21
app/services/eis_billing/send_invoice_status.rb
Normal file
21
app/services/eis_billing/send_invoice_status.rb
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
module EisBilling
|
||||||
|
class SendInvoiceStatus < EisBilling::Base
|
||||||
|
def self.send_info(invoice_number:, status:)
|
||||||
|
send_request(invoice_number: invoice_number, status: status)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.send_request(invoice_number:, status:)
|
||||||
|
json_obj = {
|
||||||
|
invoice_number: invoice_number,
|
||||||
|
status: status,
|
||||||
|
}
|
||||||
|
|
||||||
|
http = EisBilling::Base.base_request(url: invoice_status_url)
|
||||||
|
http.post(invoice_status_url, json_obj.to_json, EisBilling::Base.headers)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.invoice_status_url
|
||||||
|
"#{BASE_URL}/api/v1/invoice_generator/invoice_status"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
2
app/views/eis_billing/directo_response/update.html.erb
Normal file
2
app/views/eis_billing/directo_response/update.html.erb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
<h1>EisBilling::DirectoResponse#update</h1>
|
||||||
|
<p>Find me in app/views/eis_billing/directo_response/update.html.erb</p>
|
2
app/views/eis_billing/e_invoice_response/update.html.erb
Normal file
2
app/views/eis_billing/e_invoice_response/update.html.erb
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
<h1>EisBilling::EInvoiceResponse#update</h1>
|
||||||
|
<p>Find me in app/views/eis_billing/e_invoice_response/update.html.erb</p>
|
0
app/views/eis_billing/update.json.erb
Normal file
0
app/views/eis_billing/update.json.erb
Normal file
|
@ -1,7 +1,8 @@
|
||||||
%h4= t('registrar.invoices.pay_invoice')
|
%h4= t('registrar.invoices.pay_invoice')
|
||||||
%hr
|
%hr
|
||||||
|
|
||||||
- locals[:payment_channels].each do |meth|
|
- if @invoice.payment_link.present?
|
||||||
- meth = meth.strip
|
= link_to @invoice.payment_link, target: :_blank do
|
||||||
= link_to registrar_payment_with_path(meth, invoice_id: params[:id]), id: meth do
|
= image_tag("everypay.png", class: 'everypay', style: "width: 100px; height: 20px;")
|
||||||
= image_tag("#{meth}.png")
|
- else
|
||||||
|
= "No everypay link"
|
||||||
|
|
|
@ -235,3 +235,11 @@ registry_demo_accredited_users_url: 'http://registry.test/api/v1/accreditation_c
|
||||||
a_and_aaaa_validation_timeout: '1'
|
a_and_aaaa_validation_timeout: '1'
|
||||||
nameserver_validation_timeout: '1'
|
nameserver_validation_timeout: '1'
|
||||||
|
|
||||||
|
eis_billing_system_base_url: 'http://eis_billing_system:3000'
|
||||||
|
billing_secret: acd50ed44524d24c826d724fda922b790ca4130b02d62bcc8f85f1b863195ba8d155c4346037364eb59135d1e9dcba6cd8a4046ee4aef3c3a0878fcdf8e85efd
|
||||||
|
billing_system_integrated: 'true'
|
||||||
|
|
||||||
|
secret_access_word: 'please-Give-Me-accesS'
|
||||||
|
secret_word: 'this-secret-should-be-change'
|
||||||
|
allow_accr_endspoints: 'true'
|
||||||
|
|
||||||
|
|
1
config/credentials.yml.enc
Normal file
1
config/credentials.yml.enc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
bXY8qqnyzpMtyIDA74p4C1GiW+cLO7yeUXl5nwZB7yy1Lkv0XbF8juV07MCm7mBgh0BfjK9Ey2sx+QiXH/PimvhNDtgy6vSNbgb5AcQBJ6XwHlXei/DNF7Bt+r5V+ixrDU6FJZ8Y9EQyjZC9zcPiAaMhDMmA71bfiE2vO2TT1T6BZcjD5P4GKmYM7pMDgKATrwauzd6ejuYfTpSBHR51zuUEEBL1uZKSXW/i6vNAE+yuRxNOULWISA0zDPaCipnrMwjf8yWkp9L4qLIcggYpepZm6t+OyAD2XMTz/5skfQRtZ0PGDs7gzJLdAYD6ErUTU9N+n6SPhPpWu0zPFMR/A9t6AudgupmLeADGnkzUyRa4jCLzOnklV4rzAT1vM4zdVhGCgd3JXQL6zptrgHgRQN8i3BhBY2w3KXtFV1N61M6cMuuvTHMMFVI+V9sbRJ58Nok9EVbu5U/WRpuJElKq7xo1bgtY/0NOFq2K+TqZT6RBtSH5sWIdUGJJIbI6VngzfZpUNPiyg9eyShK2Wa2v1BlyLK3zYRD8F9/kNUvLCX7vgSjI/pwifokVAF51GhykhlmpfOyLmEEc011DwD+F4xjkYN1xHY8=--YBWnRjhG+BqNrfar--RcZCpjUq+MNhMOydjZWWTA==
|
|
@ -11,6 +11,13 @@ Rails.application.routes.draw do
|
||||||
mount PgHero::Engine, at: "pghero"
|
mount PgHero::Engine, at: "pghero"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
namespace :eis_billing do
|
||||||
|
put '/payment_status', to: 'payment_status#update', as: 'payment_status', :format => false, :defaults => { :format => 'json' }
|
||||||
|
put '/directo_response', to: 'directo_response#update', as: 'directo_response'
|
||||||
|
put '/e_invoice_response', to: 'e_invoice_response#update', as: 'e_invoice_response'
|
||||||
|
post '/lhv_connect_transactions', to: 'lhv_connect_transactions#create', as: 'lhv_connect_transactions'
|
||||||
|
end
|
||||||
|
|
||||||
namespace :epp do
|
namespace :epp do
|
||||||
constraints(EppConstraint.new(:session)) do
|
constraints(EppConstraint.new(:session)) do
|
||||||
get 'session/hello', to: 'sessions#hello', as: 'hello'
|
get 'session/hello', to: 'sessions#hello', as: 'hello'
|
||||||
|
|
5
db/migrate/20220124105717_add_payment_link_to_invoice.rb
Normal file
5
db/migrate/20220124105717_add_payment_link_to_invoice.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
class AddPaymentLinkToInvoice < ActiveRecord::Migration[6.1]
|
||||||
|
def change
|
||||||
|
add_column :invoices, :payment_link, :string
|
||||||
|
end
|
||||||
|
end
|
|
@ -5411,6 +5411,5 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||||
('20220413073315'),
|
('20220413073315'),
|
||||||
('20220413084536'),
|
('20220413084536'),
|
||||||
('20220413084748'),
|
('20220413084748'),
|
||||||
('20220504090512');
|
('20220504090512'),
|
||||||
|
('20220406085500');
|
||||||
|
|
||||||
|
|
85
lib/tasks/eis_billing_import_data.rake
Normal file
85
lib/tasks/eis_billing_import_data.rake
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
BASE_URL = ENV['eis_billing_system_base_url'] || 'https://st-billing.infra.tld.ee'
|
||||||
|
INITIATOR = 'registry'.freeze
|
||||||
|
|
||||||
|
namespace :eis_billing do
|
||||||
|
desc 'One time task to export invoice data to billing system'
|
||||||
|
task export_invoices: :environment do
|
||||||
|
parsed_data = []
|
||||||
|
status = 'unpaid'
|
||||||
|
|
||||||
|
Invoice.all.each do |invoice|
|
||||||
|
if invoice.cancelled?
|
||||||
|
status = 'cancelled'
|
||||||
|
else
|
||||||
|
status = invoice.paid? ? 'paid' : 'unpaid'
|
||||||
|
end
|
||||||
|
|
||||||
|
transaction_time = invoice.receipt_date if invoice.paid?
|
||||||
|
|
||||||
|
parsed_data << {
|
||||||
|
invoice_number: invoice.number,
|
||||||
|
initiator: 'registry',
|
||||||
|
transaction_amount: invoice.total,
|
||||||
|
status: status,
|
||||||
|
in_directo: invoice.in_directo,
|
||||||
|
e_invoice_sent_at: invoice.e_invoice_sent_at,
|
||||||
|
transaction_time: transaction_time
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
base_request(url: import_invoice_data_url, json_obj: parsed_data)
|
||||||
|
end
|
||||||
|
|
||||||
|
desc 'One time task to export reference number of registrars to billing system'
|
||||||
|
task export_references: :environment do
|
||||||
|
parsed_data = []
|
||||||
|
Registrar.all.each do |registrar|
|
||||||
|
parsed_data << {
|
||||||
|
reference_number: registrar.reference_no,
|
||||||
|
initiator: 'registry',
|
||||||
|
registrar_name: registrar.name
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
base_request(url: import_reference_data_url, json_obj: parsed_data)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def import_reference_data_url
|
||||||
|
"#{BASE_URL}/api/v1/import_data/reference_data"
|
||||||
|
end
|
||||||
|
|
||||||
|
def import_invoice_data_url
|
||||||
|
"#{BASE_URL}/api/v1/import_data/invoice_data"
|
||||||
|
end
|
||||||
|
|
||||||
|
def base_request(url:, json_obj:)
|
||||||
|
uri = URI(url)
|
||||||
|
http = Net::HTTP.new(uri.host, uri.port)
|
||||||
|
|
||||||
|
unless Rails.env.development?
|
||||||
|
http.use_ssl = true
|
||||||
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
||||||
|
end
|
||||||
|
|
||||||
|
http.post(url, json_obj.to_json, headers)
|
||||||
|
end
|
||||||
|
|
||||||
|
def generate_token
|
||||||
|
JWT.encode(payload, billing_secret)
|
||||||
|
end
|
||||||
|
|
||||||
|
def payload
|
||||||
|
{ initiator: INITIATOR }
|
||||||
|
end
|
||||||
|
|
||||||
|
def headers
|
||||||
|
{
|
||||||
|
'Authorization' => "Bearer #{generate_token}",
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.billing_secret
|
||||||
|
ENV['billing_secret']
|
||||||
|
end
|
|
@ -17,7 +17,7 @@ namespace :registrars do
|
||||||
next if reload_pending || !threshold_reached
|
next if reload_pending || !threshold_reached
|
||||||
|
|
||||||
Registrar.transaction do
|
Registrar.transaction do
|
||||||
registrar.issue_prepayment_invoice(reload_amount)
|
registrar.issue_prepayment_invoice(reload_amount, 'reload balance')
|
||||||
registrar.settings['balance_auto_reload']['pending'] = true
|
registrar.settings['balance_auto_reload']['pending'] = true
|
||||||
registrar.save!
|
registrar.save!
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,6 +24,21 @@ class AdminAreaInvoicesIntegrationTest < ApplicationIntegrationTest
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_create_new_invoice
|
def test_create_new_invoice
|
||||||
|
if Feature.billing_system_integrated?
|
||||||
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
|
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
|
||||||
|
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:put, "https://registry:3000/eis_billing/e_invoice_response").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
|
||||||
|
to_return(status: 200, body: "", headers: {})
|
||||||
|
|
||||||
visit new_admin_invoice_path
|
visit new_admin_invoice_path
|
||||||
|
|
||||||
assert_text 'Create new invoice'
|
assert_text 'Create new invoice'
|
||||||
|
@ -33,6 +48,7 @@ class AdminAreaInvoicesIntegrationTest < ApplicationIntegrationTest
|
||||||
|
|
||||||
assert_equal page.status_code, 200
|
assert_equal page.status_code, 200
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_visit_list_of_invoices_pages
|
def test_visit_list_of_invoices_pages
|
||||||
visit admin_invoices_path
|
visit admin_invoices_path
|
||||||
|
|
43
test/integration/eis_billing/directo_response_test.rb
Normal file
43
test/integration/eis_billing/directo_response_test.rb
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class DirectoResponseTest < ApplicationIntegrationTest
|
||||||
|
setup do
|
||||||
|
sign_in users(:api_bestnames)
|
||||||
|
|
||||||
|
@invoice = invoices(:one)
|
||||||
|
@response_xml = "<?xml version='1.0' encoding='UTF-8'?><results><Result Type='0' Desc='OK' docid='#{@invoice.number}' doctype='ARVE' submit='Invoices'/></results>"
|
||||||
|
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_should_created_directo_instance
|
||||||
|
if Feature.billing_system_integrated?
|
||||||
|
directo_response_from_billing = {
|
||||||
|
response: @response_xml,
|
||||||
|
month: true
|
||||||
|
}
|
||||||
|
|
||||||
|
assert_difference 'Directo.count', 1 do
|
||||||
|
put eis_billing_directo_response_path, params: JSON.parse(directo_response_from_billing.to_json),
|
||||||
|
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_should_update_related_invoice
|
||||||
|
if Feature.billing_system_integrated?
|
||||||
|
directo_response_from_billing = {
|
||||||
|
response: @response_xml
|
||||||
|
}
|
||||||
|
|
||||||
|
refute @invoice.in_directo
|
||||||
|
|
||||||
|
assert_difference 'Directo.count', 1 do
|
||||||
|
put eis_billing_directo_response_path, params: JSON.parse(directo_response_from_billing.to_json),
|
||||||
|
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||||
|
end
|
||||||
|
|
||||||
|
@invoice.reload
|
||||||
|
assert @invoice.in_directo
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
17
test/integration/eis_billing/e_invoice_response_test.rb
Normal file
17
test/integration/eis_billing/e_invoice_response_test.rb
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class EInvoiceResponseTest < ApplicationIntegrationTest
|
||||||
|
setup do
|
||||||
|
sign_in users(:api_bestnames)
|
||||||
|
@invoice = invoices(:one)
|
||||||
|
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_invoice_should_be_mark_as_sent
|
||||||
|
assert_nil @invoice.e_invoice_sent_at
|
||||||
|
put eis_billing_e_invoice_response_path, params: { invoice_number: @invoice.number}
|
||||||
|
|
||||||
|
@invoice.reload
|
||||||
|
assert_not_nil @invoice.e_invoice_sent_at
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,43 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class LhvConnectTransactionsIntegrationTest < ApplicationIntegrationTest
|
||||||
|
setup do
|
||||||
|
@invoice = invoices(:unpaid)
|
||||||
|
sign_in users(:api_bestnames)
|
||||||
|
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_should_saved_transaction_data
|
||||||
|
if Feature.billing_system_integrated?
|
||||||
|
test_transaction_1 = OpenStruct.new(amount: 0.1,
|
||||||
|
currency: 'EUR',
|
||||||
|
date: Time.zone.today,
|
||||||
|
payment_reference_number: '2199812',
|
||||||
|
payment_description: "description 2199812")
|
||||||
|
|
||||||
|
test_transaction_2 = OpenStruct.new(amount: 0.1,
|
||||||
|
currency: 'EUR',
|
||||||
|
date: Time.zone.today,
|
||||||
|
payment_reference_number: '2199813',
|
||||||
|
payment_description: "description 2199813")
|
||||||
|
|
||||||
|
test_transaction_3 = OpenStruct.new(amount: 0.1,
|
||||||
|
currency: 'EUR',
|
||||||
|
date: Time.zone.today,
|
||||||
|
payment_reference_number: '2199814',
|
||||||
|
payment_description: "description 2199814")
|
||||||
|
|
||||||
|
lhv_transactions = []
|
||||||
|
lhv_transactions << test_transaction_1
|
||||||
|
lhv_transactions << test_transaction_2
|
||||||
|
lhv_transactions << test_transaction_3
|
||||||
|
|
||||||
|
assert_difference 'BankStatement.count', 3 do
|
||||||
|
assert_difference 'BankTransaction.count', 3 do
|
||||||
|
post eis_billing_lhv_connect_transactions_path, params: { "_json" => JSON.parse(lhv_transactions.to_json) },
|
||||||
|
headers: { 'HTTP_COOKIE' => 'session=api_bestnames' }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -16,6 +16,10 @@ class BankTransactionTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_binds_if_this_sum_invoice_already_present
|
def test_binds_if_this_sum_invoice_already_present
|
||||||
|
if Feature.billing_system_integrated?
|
||||||
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
|
||||||
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
|
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
|
||||||
another_invoice = @invoice.dup
|
another_invoice = @invoice.dup
|
||||||
another_invoice.save(validate: false)
|
another_invoice.save(validate: false)
|
||||||
|
@ -38,8 +42,13 @@ class BankTransactionTest < ActiveSupport::TestCase
|
||||||
transaction.autobind_invoice
|
transaction.autobind_invoice
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_binds_if_this_sum_cancelled_invoice_already_present
|
def test_binds_if_this_sum_cancelled_invoice_already_present
|
||||||
|
if Feature.billing_system_integrated?
|
||||||
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
|
||||||
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
|
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
|
||||||
another_invoice = @invoice.dup
|
another_invoice = @invoice.dup
|
||||||
another_invoice.save(validate: false)
|
another_invoice.save(validate: false)
|
||||||
|
@ -59,8 +68,13 @@ class BankTransactionTest < ActiveSupport::TestCase
|
||||||
transaction.autobind_invoice
|
transaction.autobind_invoice
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_marks_the_first_one_as_paid_if_same_sum
|
def test_marks_the_first_one_as_paid_if_same_sum
|
||||||
|
if Feature.billing_system_integrated?
|
||||||
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
|
||||||
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
|
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
|
||||||
another_invoice = @invoice.dup
|
another_invoice = @invoice.dup
|
||||||
another_invoice.save(validate: false)
|
another_invoice.save(validate: false)
|
||||||
|
@ -83,6 +97,7 @@ class BankTransactionTest < ActiveSupport::TestCase
|
||||||
assert(@invoice.paid?)
|
assert(@invoice.paid?)
|
||||||
assert_not(another_invoice.paid?)
|
assert_not(another_invoice.paid?)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_matches_against_invoice_nubmber_and_reference_number_in_description
|
def test_matches_against_invoice_nubmber_and_reference_number_in_description
|
||||||
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
|
create_payable_invoice(number: '2222', total: 10, reference_no: '1234567')
|
||||||
|
|
|
@ -7,7 +7,12 @@ class ReferenceNoTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_generated_reference_number_conforms_to_format
|
def test_generated_reference_number_conforms_to_format
|
||||||
|
if Feature.billing_system_integrated?
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/reference_number_generator")
|
||||||
|
.to_return(status: 200, body: "{\"reference_number\":\"12332\"}", headers: {})
|
||||||
|
|
||||||
reference_no = Billing::ReferenceNo.generate
|
reference_no = Billing::ReferenceNo.generate
|
||||||
assert_match Billing::ReferenceNo::REGEXP, reference_no
|
assert_match Billing::ReferenceNo::REGEXP, reference_no
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -5,6 +5,7 @@ class InvoiceTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
@invoice = invoices(:one)
|
@invoice = invoices(:one)
|
||||||
|
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_fixture_is_valid
|
def test_fixture_is_valid
|
||||||
|
@ -79,6 +80,10 @@ class InvoiceTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_buyer_vat_no_is_taken_from_registrar_by_default
|
def test_buyer_vat_no_is_taken_from_registrar_by_default
|
||||||
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
|
response = OpenStruct.new(body: "{\"invoice_number\":\"#{invoice_n + 3}\"}")
|
||||||
|
Spy.on(EisBilling::GetInvoiceNumber, :send_invoice).and_return(response)
|
||||||
|
|
||||||
registrar = registrars(:bestnames)
|
registrar = registrars(:bestnames)
|
||||||
registrar.vat_no = 'US1234'
|
registrar.vat_no = 'US1234'
|
||||||
invoice = @invoice.dup
|
invoice = @invoice.dup
|
||||||
|
@ -113,31 +118,69 @@ class InvoiceTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_creates_invoice_with_bank_transaction_total
|
def test_creates_invoice_with_bank_transaction_total
|
||||||
|
if Feature.billing_system_integrated?
|
||||||
registrar = registrars(:bestnames)
|
registrar = registrars(:bestnames)
|
||||||
transaction = bank_transactions(:one).dup
|
transaction = bank_transactions(:one).dup
|
||||||
transaction.reference_no = registrar.reference_no
|
transaction.reference_no = registrar.reference_no
|
||||||
transaction.sum = 250
|
transaction.sum = 250
|
||||||
|
|
||||||
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator")
|
||||||
|
.to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator")
|
||||||
|
.to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:put, "https://registry:3000/eis_billing/e_invoice_response").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
|
||||||
|
to_return(status: 200, body: "", headers: {})
|
||||||
|
|
||||||
invoice = Invoice.create_from_transaction!(transaction)
|
invoice = Invoice.create_from_transaction!(transaction)
|
||||||
assert_equal 250, invoice.total
|
assert_equal 250, invoice.total
|
||||||
|
|
||||||
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 4}\"}", headers: {})
|
||||||
|
|
||||||
transaction.sum = 146.88
|
transaction.sum = 146.88
|
||||||
invoice = Invoice.create_from_transaction!(transaction)
|
invoice = Invoice.create_from_transaction!(transaction)
|
||||||
assert_equal 146.88, invoice.total
|
assert_equal 146.88, invoice.total
|
||||||
|
|
||||||
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 5}\"}", headers: {})
|
||||||
|
|
||||||
transaction.sum = 0.99
|
transaction.sum = 0.99
|
||||||
invoice = Invoice.create_from_transaction!(transaction)
|
invoice = Invoice.create_from_transaction!(transaction)
|
||||||
assert_equal 0.99, invoice.total
|
assert_equal 0.99, invoice.total
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_emails_invoice_after_creating_topup_invoice
|
def test_emails_invoice_after_creating_topup_invoice
|
||||||
|
if Feature.billing_system_integrated?
|
||||||
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
|
||||||
|
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:put, "https://registry:3000/eis_billing/e_invoice_response").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
|
||||||
|
to_return(status: 200, body: "", headers: {})
|
||||||
|
|
||||||
registrar = registrars(:bestnames)
|
registrar = registrars(:bestnames)
|
||||||
transaction = bank_transactions(:one).dup
|
transaction = bank_transactions(:one).dup
|
||||||
transaction.reference_no = registrar.reference_no
|
transaction.reference_no = registrar.reference_no
|
||||||
transaction.sum = 250
|
transaction.sum = 250
|
||||||
|
|
||||||
|
response = OpenStruct.new(body: "{\"invoice_number\":\"#{invoice_n + 3}\"}")
|
||||||
|
Spy.on(EisBilling::GetInvoiceNumber, :send_invoice).and_return(response)
|
||||||
|
|
||||||
assert_emails 1 do
|
assert_emails 1 do
|
||||||
Invoice.create_from_transaction!(transaction)
|
Invoice.create_from_transaction!(transaction)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -6,6 +6,7 @@ class RegistrarTest < ActiveJob::TestCase
|
||||||
@original_default_language = Setting.default_language
|
@original_default_language = Setting.default_language
|
||||||
@original_days_to_keep_invoices_active = Setting.days_to_keep_invoices_active
|
@original_days_to_keep_invoices_active = Setting.days_to_keep_invoices_active
|
||||||
@old_validation_type = Truemail.configure.default_validation_type
|
@old_validation_type = Truemail.configure.default_validation_type
|
||||||
|
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
teardown do
|
teardown do
|
||||||
|
@ -144,6 +145,20 @@ class RegistrarTest < ActiveJob::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_issues_new_invoice
|
def test_issues_new_invoice
|
||||||
|
if Feature.billing_system_integrated?
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
|
||||||
|
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
|
||||||
|
|
||||||
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:put, "https://registry:3000/eis_billing/e_invoice_response").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
|
||||||
|
to_return(status: 200, body: "", headers: {})
|
||||||
|
|
||||||
travel_to Time.zone.parse('2010-07-05')
|
travel_to Time.zone.parse('2010-07-05')
|
||||||
Setting.days_to_keep_invoices_active = 10
|
Setting.days_to_keep_invoices_active = 10
|
||||||
|
|
||||||
|
@ -152,16 +167,34 @@ class RegistrarTest < ActiveJob::TestCase
|
||||||
assert_equal Date.parse('2010-07-05'), invoice.issue_date
|
assert_equal Date.parse('2010-07-05'), invoice.issue_date
|
||||||
assert_equal Date.parse('2010-07-15'), invoice.due_date
|
assert_equal Date.parse('2010-07-15'), invoice.due_date
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_issues_e_invoice_along_with_invoice
|
def test_issues_e_invoice_along_with_invoice
|
||||||
|
if Feature.billing_system_integrated?
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
|
||||||
|
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
|
||||||
|
|
||||||
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:put, "https://registry:3000/eis_billing/e_invoice_response").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
|
||||||
|
to_return(status: 200, body: "", headers: {})
|
||||||
|
end
|
||||||
|
|
||||||
EInvoice::Providers::TestProvider.deliveries.clear
|
EInvoice::Providers::TestProvider.deliveries.clear
|
||||||
|
|
||||||
perform_enqueued_jobs do
|
perform_enqueued_jobs do
|
||||||
@registrar.issue_prepayment_invoice(100)
|
@registrar.issue_prepayment_invoice(100)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
unless Feature.billing_system_integrated?
|
||||||
assert_equal 1, EInvoice::Providers::TestProvider.deliveries.count
|
assert_equal 1, EInvoice::Providers::TestProvider.deliveries.count
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_invalid_without_address_street
|
def test_invalid_without_address_street
|
||||||
registrar = valid_registrar
|
registrar = valid_registrar
|
||||||
|
|
15
test/services/send_data_to_directo_test.rb
Normal file
15
test/services/send_data_to_directo_test.rb
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class SendDataToDirectoTest < ActiveSupport::TestCase
|
||||||
|
setup do
|
||||||
|
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_should_send_data_to_billing_directo
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/directo/directo").
|
||||||
|
to_return(status: 200, body: "ok", headers: {})
|
||||||
|
|
||||||
|
res = EisBilling::SendDataToDirecto.send_request(object_data: [], monthly: true, dry: true)
|
||||||
|
assert_equal res.body, "ok"
|
||||||
|
end
|
||||||
|
end
|
|
@ -6,6 +6,7 @@ class AdminAreaBankStatementTest < ApplicationSystemTestCase
|
||||||
travel_to Time.zone.parse('2010-07-05 00:30:00')
|
travel_to Time.zone.parse('2010-07-05 00:30:00')
|
||||||
|
|
||||||
@invoice = invoices(:one)
|
@invoice = invoices(:one)
|
||||||
|
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_update_bank_statement
|
def test_update_bank_statement
|
||||||
|
@ -54,7 +55,21 @@ class AdminAreaBankStatementTest < ApplicationSystemTestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_can_bind_statement_transactions
|
def test_can_bind_statement_transactions
|
||||||
|
if Feature.billing_system_integrated?
|
||||||
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator")
|
||||||
|
.to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
|
||||||
registrar = registrars(:bestnames)
|
registrar = registrars(:bestnames)
|
||||||
|
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator")
|
||||||
|
.to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:put, "https://registry:3000/eis_billing/e_invoice_response")
|
||||||
|
.to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice")
|
||||||
|
.to_return(status: 200, body: "", headers: {})
|
||||||
|
|
||||||
registrar.issue_prepayment_invoice(500)
|
registrar.issue_prepayment_invoice(500)
|
||||||
invoice = registrar.invoices.last
|
invoice = registrar.invoices.last
|
||||||
|
|
||||||
|
@ -73,6 +88,7 @@ class AdminAreaBankStatementTest < ApplicationSystemTestCase
|
||||||
|
|
||||||
assert_text 'Invoices were fully binded'
|
assert_text 'Invoices were fully binded'
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def create_bank_statement
|
def create_bank_statement
|
||||||
visit admin_bank_statements_path
|
visit admin_bank_statements_path
|
||||||
|
|
|
@ -11,6 +11,7 @@ class AdminAreaInvoicesTest < ApplicationSystemTestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_cancels_an_invoice
|
def test_cancels_an_invoice
|
||||||
|
Spy.on(EisBilling::SendInvoiceStatus, :send_info).and_return(true)
|
||||||
@invoice.account_activity = nil
|
@invoice.account_activity = nil
|
||||||
assert @invoice.cancellable?
|
assert @invoice.cancellable?
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,10 @@ class AdminRegistrarsSystemTest < ApplicationSystemTestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_creates_new_registrar
|
def test_creates_new_registrar
|
||||||
|
if Feature.billing_system_integrated?
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/reference_number_generator").
|
||||||
|
to_return(status: 200, body: "{\"reference_number\":\"12332\"}", headers: {})
|
||||||
|
|
||||||
assert_nil Registrar.find_by(name: 'Acme Ltd')
|
assert_nil Registrar.find_by(name: 'Acme Ltd')
|
||||||
|
|
||||||
visit admin_registrars_path
|
visit admin_registrars_path
|
||||||
|
@ -34,6 +38,7 @@ class AdminRegistrarsSystemTest < ApplicationSystemTestCase
|
||||||
assert_text 'Registrar has been successfully created'
|
assert_text 'Registrar has been successfully created'
|
||||||
assert_text 'Acme Ltd'
|
assert_text 'Acme Ltd'
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_updates_registrar
|
def test_updates_registrar
|
||||||
assert_not_equal 'New name', @registrar.name
|
assert_not_equal 'New name', @registrar.name
|
||||||
|
|
12
test/system/registrar_area/add_deposits_test.rb
Normal file
12
test/system/registrar_area/add_deposits_test.rb
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
require 'application_system_test_case'
|
||||||
|
|
||||||
|
class AddDepositsTest < ApplicationSystemTestCase
|
||||||
|
include ActionMailer::TestHelper
|
||||||
|
|
||||||
|
setup do
|
||||||
|
sign_in users(:api_bestnames)
|
||||||
|
@invoice = invoices(:one)
|
||||||
|
|
||||||
|
ActionMailer::Base.deliveries.clear
|
||||||
|
end
|
||||||
|
end
|
|
@ -4,6 +4,10 @@ class BalanceTopUpTest < ApplicationSystemTestCase
|
||||||
setup do
|
setup do
|
||||||
sign_in users(:api_bestnames)
|
sign_in users(:api_bestnames)
|
||||||
@original_registry_vat_rate = Setting.registry_vat_prc
|
@original_registry_vat_rate = Setting.registry_vat_prc
|
||||||
|
|
||||||
|
eis_response = OpenStruct.new(body: "{\"payment_link\":\"http://link.test\"}")
|
||||||
|
Spy.on_instance_method(EisBilling::AddDeposits, :send_invoice).and_return(eis_response)
|
||||||
|
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
teardown do
|
teardown do
|
||||||
|
@ -11,6 +15,17 @@ class BalanceTopUpTest < ApplicationSystemTestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_creates_new_invoice
|
def test_creates_new_invoice
|
||||||
|
if Feature.billing_system_integrated?
|
||||||
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:put, "https://registry:3000/eis_billing/e_invoice_response")
|
||||||
|
.to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice")
|
||||||
|
.to_return(status: 200, body: "", headers: {})
|
||||||
|
|
||||||
Setting.registry_vat_prc = 0.1
|
Setting.registry_vat_prc = 0.1
|
||||||
|
|
||||||
visit registrar_invoices_url
|
visit registrar_invoices_url
|
||||||
|
@ -28,3 +43,4 @@ class BalanceTopUpTest < ApplicationSystemTestCase
|
||||||
assert_text 'Please pay the following invoice'
|
assert_text 'Please pay the following invoice'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -3,6 +3,8 @@ require 'application_system_test_case'
|
||||||
class NewInvoicePaymentTest < ApplicationSystemTestCase
|
class NewInvoicePaymentTest < ApplicationSystemTestCase
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
|
eis_response = OpenStruct.new(body: "{\"payment_link\":\"http://link.test\"}")
|
||||||
|
Spy.on_instance_method(EisBilling::AddDeposits, :send_invoice).and_return(eis_response)
|
||||||
|
|
||||||
@original_vat_prc = Setting.registry_vat_prc
|
@original_vat_prc = Setting.registry_vat_prc
|
||||||
Setting.registry_vat_prc = 0.2
|
Setting.registry_vat_prc = 0.2
|
||||||
|
@ -23,26 +25,4 @@ class NewInvoicePaymentTest < ApplicationSystemTestCase
|
||||||
fill_in 'Description', with: 'My first invoice'
|
fill_in 'Description', with: 'My first invoice'
|
||||||
click_link_or_button 'Add'
|
click_link_or_button 'Add'
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_create_new_SEB_payment
|
|
||||||
create_invoice_and_visit_its_page
|
|
||||||
click_link_or_button 'seb'
|
|
||||||
form = page.find('form')
|
|
||||||
assert_equal('https://www.seb.ee/cgi-bin/dv.sh/ipank.r', form['action'])
|
|
||||||
assert_equal('post', form['method'])
|
|
||||||
assert_equal('240.00', form.find_by_id('VK_AMOUNT', visible: false).value)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_create_new_Every_Pay_payment
|
|
||||||
create_invoice_and_visit_its_page
|
|
||||||
click_link_or_button 'every_pay'
|
|
||||||
expected_hmac_fields = 'account_id,amount,api_username,callback_url,' +
|
|
||||||
'customer_url,hmac_fields,nonce,order_reference,timestamp,transaction_type'
|
|
||||||
|
|
||||||
form = page.find('form')
|
|
||||||
assert_equal('https://igw-demo.every-pay.com/transactions/', form['action'])
|
|
||||||
assert_equal('post', form['method'])
|
|
||||||
assert_equal(expected_hmac_fields, form.find_by_id('hmac_fields', visible: false).value)
|
|
||||||
assert_equal('240.00', form.find_by_id('amount', visible: false).value)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,6 +6,9 @@ class NewInvoiceTest < ApplicationSystemTestCase
|
||||||
|
|
||||||
@user = users(:api_bestnames)
|
@user = users(:api_bestnames)
|
||||||
sign_in @user
|
sign_in @user
|
||||||
|
|
||||||
|
eis_response = OpenStruct.new(body: "{\"payment_link\":\"http://link.test\"}")
|
||||||
|
Spy.on_instance_method(EisBilling::AddDeposits, :send_invoice).and_return(eis_response)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_show_balance
|
def test_show_balance
|
||||||
|
@ -14,6 +17,17 @@ class NewInvoiceTest < ApplicationSystemTestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_create_new_invoice_with_positive_amount
|
def test_create_new_invoice_with_positive_amount
|
||||||
|
if Feature.billing_system_integrated?
|
||||||
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:put, "https://registry:3000/eis_billing/e_invoice_response").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
|
||||||
|
to_return(status: 200, body: "", headers: {})
|
||||||
|
|
||||||
visit registrar_invoices_path
|
visit registrar_invoices_path
|
||||||
click_link_or_button 'Add deposit'
|
click_link_or_button 'Add deposit'
|
||||||
fill_in 'Amount', with: '200.00'
|
fill_in 'Amount', with: '200.00'
|
||||||
|
@ -24,12 +38,24 @@ class NewInvoiceTest < ApplicationSystemTestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_text 'Please pay the following invoice'
|
assert_text 'Please pay the following invoice'
|
||||||
assert_text 'Invoice no. 131050'
|
assert_text "Invoice no. #{invoice_n + 3}"
|
||||||
assert_text 'Subtotal 200,00 €'
|
assert_text 'Subtotal 200,00 €'
|
||||||
assert_text 'Pay invoice'
|
assert_text 'Pay invoice'
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_create_new_invoice_with_comma_in_number
|
def test_create_new_invoice_with_comma_in_number
|
||||||
|
if Feature.billing_system_integrated?
|
||||||
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:put, "https://registry:3000/eis_billing/e_invoice_response").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
|
||||||
|
to_return(status: 200, body: "", headers: {})
|
||||||
|
|
||||||
visit registrar_invoices_path
|
visit registrar_invoices_path
|
||||||
click_link_or_button 'Add deposit'
|
click_link_or_button 'Add deposit'
|
||||||
fill_in 'Amount', with: '200,00'
|
fill_in 'Amount', with: '200,00'
|
||||||
|
@ -40,10 +66,11 @@ class NewInvoiceTest < ApplicationSystemTestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
assert_text 'Please pay the following invoice'
|
assert_text 'Please pay the following invoice'
|
||||||
assert_text 'Invoice no. 131050'
|
assert_text "Invoice no. #{invoice_n + 3}"
|
||||||
assert_text 'Subtotal 200,00 €'
|
assert_text 'Subtotal 200,00 €'
|
||||||
assert_text 'Pay invoice'
|
assert_text 'Pay invoice'
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_create_new_invoice_fails_when_amount_is_0
|
def test_create_new_invoice_fails_when_amount_is_0
|
||||||
visit registrar_invoices_path
|
visit registrar_invoices_path
|
||||||
|
|
|
@ -8,9 +8,13 @@ class RegistrarAreaInvoicesTest < ApplicationSystemTestCase
|
||||||
@invoice = invoices(:one)
|
@invoice = invoices(:one)
|
||||||
|
|
||||||
ActionMailer::Base.deliveries.clear
|
ActionMailer::Base.deliveries.clear
|
||||||
|
eis_response = OpenStruct.new(body: "{\"payment_link\":\"http://link.test\"}")
|
||||||
|
Spy.on_instance_method(EisBilling::AddDeposits, :send_invoice).and_return(eis_response)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_cancels_an_invoice
|
def test_cancels_an_invoice
|
||||||
|
Spy.on(EisBilling::SendInvoiceStatus, :send_info).and_return(true)
|
||||||
|
|
||||||
@invoice.account_activity = nil
|
@invoice.account_activity = nil
|
||||||
assert @invoice.cancellable?
|
assert @invoice.cancellable?
|
||||||
|
|
||||||
|
@ -40,4 +44,18 @@ class RegistrarAreaInvoicesTest < ApplicationSystemTestCase
|
||||||
assert_current_path registrar_invoice_path(@invoice)
|
assert_current_path registrar_invoice_path(@invoice)
|
||||||
assert_text 'Invoice has been sent'
|
assert_text 'Invoice has been sent'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_if_invoice_unpaid_and_not_generated_link_comes_then_should_render_no_everypay_link
|
||||||
|
invoice = invoices(:unpaid)
|
||||||
|
visit registrar_invoice_url(invoice)
|
||||||
|
|
||||||
|
assert_text 'No everypay link'
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_if_invoice_aldready_paid_there_should_not_any_everypay_link
|
||||||
|
visit registrar_invoice_url(@invoice)
|
||||||
|
|
||||||
|
assert_no_text 'No everypay link'
|
||||||
|
assert_no_text 'Everypay link'
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -77,6 +77,23 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_if_invoice_is_overdue_than_48_hours
|
def test_if_invoice_is_overdue_than_48_hours
|
||||||
|
if Feature.billing_system_integrated?
|
||||||
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
|
|
||||||
|
Spy.on_instance_method(SendEInvoiceTwoJob, :perform_now).and_return(true)
|
||||||
|
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
|
||||||
|
to_return(status: 200, body: "", headers: {})
|
||||||
|
|
||||||
|
stub_request(:put, "https://registry:3000/eis_billing/e_invoice_response").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
|
||||||
|
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
|
||||||
|
|
||||||
assert_not @invoice.paid?
|
assert_not @invoice.paid?
|
||||||
|
|
||||||
@account_activity.update(activity_type: "add_credit", bank_transaction: nil, created_at: Time.zone.today - 3.days, creator_str: 'AdminUser')
|
@account_activity.update(activity_type: "add_credit", bank_transaction: nil, created_at: Time.zone.today - 3.days, creator_str: 'AdminUser')
|
||||||
|
@ -89,6 +106,7 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_doubles_are_valid
|
def test_doubles_are_valid
|
||||||
assert Lhv::ConnectApi.method_defined?(:credit_debit_notification_messages)
|
assert Lhv::ConnectApi.method_defined?(:credit_debit_notification_messages)
|
||||||
|
@ -143,7 +161,23 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
|
||||||
assert payment_order.failed?
|
assert payment_order.failed?
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_credits_registrar_account_without_invoice_beforehand
|
def test_credits_registrar_athout_invoice_beforehand
|
||||||
|
if Feature.billing_system_integrated?
|
||||||
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}")
|
||||||
|
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
|
||||||
|
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
|
||||||
|
|
||||||
|
Spy.on_instance_method(SendEInvoiceTwoJob, :perform_now).and_return(true)
|
||||||
|
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
|
||||||
|
to_return(status: 200, body: "", headers: {})
|
||||||
|
|
||||||
|
stub_request(:put, "https://registry:3000/eis_billing/e_invoice_response").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
|
||||||
|
|
||||||
registrar = registrars(:bestnames)
|
registrar = registrars(:bestnames)
|
||||||
|
|
||||||
assert_changes -> { registrar.accounts.first.balance } do
|
assert_changes -> { registrar.accounts.first.balance } do
|
||||||
|
@ -154,6 +188,7 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
|
||||||
run_task
|
run_task
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_topup_creates_invoice_with_total_of_transactioned_amount
|
def test_topup_creates_invoice_with_total_of_transactioned_amount
|
||||||
registrar = registrars(:bestnames)
|
registrar = registrars(:bestnames)
|
||||||
|
@ -163,6 +198,20 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_topup_creates_invoice_and_send_it_as_paid
|
def test_topup_creates_invoice_and_send_it_as_paid
|
||||||
|
if Feature.billing_system_integrated?
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
|
||||||
|
to_return(status: 200, body: "", headers: {})
|
||||||
|
|
||||||
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
|
||||||
|
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:put, "https://registry:3000/eis_billing/e_invoice_response").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
|
||||||
|
|
||||||
registrar = registrars(:bestnames)
|
registrar = registrars(:bestnames)
|
||||||
@invoice.payment_orders.destroy_all
|
@invoice.payment_orders.destroy_all
|
||||||
@invoice.destroy
|
@invoice.destroy
|
||||||
|
@ -183,6 +232,7 @@ class ProcessPaymentsTaskTest < ActiveJob::TestCase
|
||||||
|
|
||||||
assert_equal 0.1, registrar.invoices.last.total
|
assert_equal 0.1, registrar.invoices.last.total
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_output
|
def test_output
|
||||||
assert_output "Transactions processed: 1\n" do
|
assert_output "Transactions processed: 1\n" do
|
||||||
|
|
|
@ -5,6 +5,7 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
@registrar = registrars(:bestnames)
|
@registrar = registrars(:bestnames)
|
||||||
|
Spy.on_instance_method(EisBilling::BaseController, :authorized).and_return(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_issues_invoice_when_auto_reload_is_enabled_and_threshold_reached
|
def test_issues_invoice_when_auto_reload_is_enabled_and_threshold_reached
|
||||||
|
@ -20,6 +21,20 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_issues_invoice_when_auto_reload_is_enabled_and_threshold_reached
|
def test_issues_invoice_when_auto_reload_is_enabled_and_threshold_reached
|
||||||
|
if Feature.billing_system_integrated?
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
|
||||||
|
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
|
||||||
|
|
||||||
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:put, "https://registry:3000/eis_billing/e_invoice_response").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
|
||||||
|
to_return(status: 200, body: "", headers: {})
|
||||||
|
|
||||||
reload_amount = 100
|
reload_amount = 100
|
||||||
registrar = registrar_with_auto_reload_enabled_and_threshold_reached(reload_amount)
|
registrar = registrar_with_auto_reload_enabled_and_threshold_reached(reload_amount)
|
||||||
|
|
||||||
|
@ -30,6 +45,7 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
|
||||||
invoice = registrar.invoices.last
|
invoice = registrar.invoices.last
|
||||||
assert_equal Time.zone.today, invoice.e_invoice_sent_at.to_date
|
assert_equal Time.zone.today, invoice.e_invoice_sent_at.to_date
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_skips_issuing_invoice_when_threshold_is_not_reached
|
def test_skips_issuing_invoice_when_threshold_is_not_reached
|
||||||
registrar = registrar_with_auto_reload_enabled_and_threshold_not_reached
|
registrar = registrar_with_auto_reload_enabled_and_threshold_not_reached
|
||||||
|
@ -50,6 +66,20 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_marks_registrar_as_pending_balance_reload
|
def test_marks_registrar_as_pending_balance_reload
|
||||||
|
if Feature.billing_system_integrated?
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
|
||||||
|
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
|
||||||
|
|
||||||
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:put, "https://registry:3000/eis_billing/e_invoice_response").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
|
||||||
|
to_return(status: 200, body: "", headers: {})
|
||||||
|
|
||||||
registrar = registrar_with_auto_reload_enabled_and_threshold_reached
|
registrar = registrar_with_auto_reload_enabled_and_threshold_reached
|
||||||
|
|
||||||
capture_io { run_task }
|
capture_io { run_task }
|
||||||
|
@ -57,8 +87,23 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
|
||||||
|
|
||||||
assert registrar.settings['balance_auto_reload']['pending']
|
assert registrar.settings['balance_auto_reload']['pending']
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_output
|
def test_output
|
||||||
|
if Feature.billing_system_integrated?
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_generator").
|
||||||
|
to_return(status: 200, body: "{\"everypay_link\":\"http://link.test\"}", headers: {})
|
||||||
|
|
||||||
|
invoice_n = Invoice.order(number: :desc).last.number
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/invoice_generator/invoice_number_generator").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:put, "https://registry:3000/eis_billing/e_invoice_response").
|
||||||
|
to_return(status: 200, body: "{\"invoice_number\":\"#{invoice_n + 3}\"}, {\"date\":\"#{Time.zone.now-10.minutes}\"}", headers: {})
|
||||||
|
|
||||||
|
stub_request(:post, "https://eis_billing_system:3000/api/v1/e_invoice/e_invoice").
|
||||||
|
to_return(status: 200, body: "", headers: {})
|
||||||
|
|
||||||
reload_amount = 100
|
reload_amount = 100
|
||||||
registrar = registrar_with_auto_reload_enabled_and_threshold_reached(reload_amount)
|
registrar = registrar_with_auto_reload_enabled_and_threshold_reached(reload_amount)
|
||||||
assert_equal 'Best Names', registrar.name
|
assert_equal 'Best Names', registrar.name
|
||||||
|
@ -67,6 +112,7 @@ class ReloadBalanceTaskTest < ActiveSupport::TestCase
|
||||||
run_task
|
run_task
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue