mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
Story#105852786 - Push bank transfers to directo
This commit is contained in:
parent
e7aef75b25
commit
49e66d33de
10 changed files with 108 additions and 9 deletions
1
Gemfile
1
Gemfile
|
@ -12,6 +12,7 @@ gem 'rails', '4.2.4' # when update, all initializers eis_custom files nee
|
|||
gem 'iso8601', '0.8.6' # for dates and times
|
||||
gem 'hashie-forbidden_attributes', '0.1.1'
|
||||
gem 'SyslogLogger', '2.0', require: 'syslog/logger'
|
||||
gem 'rest-client'
|
||||
|
||||
# load env
|
||||
gem 'figaro', '1.1.1'
|
||||
|
|
13
Gemfile.lock
13
Gemfile.lock
|
@ -188,6 +188,8 @@ GEM
|
|||
nokogiri (>= 1.4.0)
|
||||
savon (>= 2.4.0)
|
||||
docile (1.1.5)
|
||||
domain_name (0.5.25)
|
||||
unf (>= 0.0.5, < 1.0.0)
|
||||
epp-xml (1.0.4)
|
||||
activesupport (~> 4.1)
|
||||
builder (~> 3.2)
|
||||
|
@ -261,6 +263,8 @@ GEM
|
|||
nokogiri (~> 1.6.0)
|
||||
ruby_parser (~> 3.5)
|
||||
html5_validators (1.2.2)
|
||||
http-cookie (1.0.2)
|
||||
domain_name (~> 0.5)
|
||||
httpclient (2.6.0.1)
|
||||
httpi (2.4.1)
|
||||
rack
|
||||
|
@ -320,6 +324,7 @@ GEM
|
|||
multi_json (1.11.2)
|
||||
multi_xml (0.5.5)
|
||||
nenv (0.2.0)
|
||||
netrc (0.11.0)
|
||||
newrelic_rpm (3.12.0.288)
|
||||
nokogiri (1.6.6.2)
|
||||
mini_portile (~> 0.6.0)
|
||||
|
@ -412,6 +417,10 @@ GEM
|
|||
request_store (1.1.0)
|
||||
responders (2.1.0)
|
||||
railties (>= 4.2.0, < 5)
|
||||
rest-client (1.8.0)
|
||||
http-cookie (>= 1.0.2, < 2.0)
|
||||
mime-types (>= 1.16, < 3.0)
|
||||
netrc (~> 0.7)
|
||||
rspec (3.3.0)
|
||||
rspec-core (~> 3.3.0)
|
||||
rspec-expectations (~> 3.3.0)
|
||||
|
@ -515,6 +524,9 @@ GEM
|
|||
uglifier (2.7.1)
|
||||
execjs (>= 0.3.0)
|
||||
json (>= 1.8.0)
|
||||
unf (0.1.4)
|
||||
unf_ext
|
||||
unf_ext (0.0.7.1)
|
||||
unicorn (4.9.0)
|
||||
kgio (~> 2.6)
|
||||
rack
|
||||
|
@ -617,6 +629,7 @@ DEPENDENCIES
|
|||
rails-settings-cached (= 0.4.1)
|
||||
rake
|
||||
ransack (= 1.5.1)
|
||||
rest-client
|
||||
rspec-rails (= 3.3.2)
|
||||
rubocop (= 0.32.1)
|
||||
rubycritic (= 1.4.0)
|
||||
|
|
|
@ -2,6 +2,7 @@ class BankTransaction < ActiveRecord::Base
|
|||
include Versions
|
||||
belongs_to :bank_statement
|
||||
has_one :account_activity
|
||||
has_many :directo_records, as: :item, class_name: 'Directo'
|
||||
|
||||
scope :unbinded, lambda {
|
||||
where('id NOT IN (SELECT bank_transaction_id FROM account_activities where bank_transaction_id IS NOT NULL)')
|
||||
|
@ -16,21 +17,32 @@ class BankTransaction < ActiveRecord::Base
|
|||
account_activity.invoice
|
||||
end
|
||||
|
||||
|
||||
def invoice_num
|
||||
return @invoice_no if defined?(@invoice_no)
|
||||
|
||||
match = description.match(/^[^\d]*(\d+)/)
|
||||
return unless match
|
||||
|
||||
@invoice_no = match[1].try(:to_i)
|
||||
end
|
||||
|
||||
def invoice
|
||||
@invoice ||= registrar.invoices.find_by(number: invoice_num) if registrar
|
||||
end
|
||||
|
||||
def registrar
|
||||
@registrar ||= Registrar.find_by(reference_no: reference_no)
|
||||
end
|
||||
|
||||
|
||||
# For successful binding, reference number, invoice id and sum must match with the invoice
|
||||
# rubocop: disable Metrics/PerceivedComplexity
|
||||
# rubocop: disable Metrics/CyclomaticComplexity
|
||||
def autobind_invoice
|
||||
return if binded?
|
||||
registrar = Registrar.find_by(reference_no: reference_no)
|
||||
return unless registrar
|
||||
|
||||
match = description.match(/^[^\d]*(\d+)/)
|
||||
return unless match
|
||||
|
||||
invoice_no = match[1].to_i
|
||||
return unless invoice_no
|
||||
|
||||
invoice = registrar.invoices.find_by(number: invoice_no)
|
||||
return unless invoice_num
|
||||
return unless invoice
|
||||
|
||||
return if invoice.binded?
|
||||
|
|
47
app/models/directo.rb
Normal file
47
app/models/directo.rb
Normal file
|
@ -0,0 +1,47 @@
|
|||
class Directo < ActiveRecord::Base
|
||||
belongs_to :item, polymorphic: true
|
||||
|
||||
def self.send_receipts
|
||||
new_trans = BankTransaction.where(in_directo: false)
|
||||
new_trans.find_in_batches(batch_size: 10).each do |group|
|
||||
mappers = {} # need them as no direct connection between transaction and invoice
|
||||
builder = Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
|
||||
xml.invoices {
|
||||
group.each do |transaction|
|
||||
next unless transaction.invoice
|
||||
num = transaction.invoice_num
|
||||
mappers[num] = transaction
|
||||
|
||||
xml.invoice(
|
||||
"SalesAgent" => transaction.invoice.seller_name,
|
||||
"Number" => num,
|
||||
"InvoiceDate" => (transaction.paid_at||transaction.created_at).strftime("%Y-%m-%dT%H:%M:%S"),
|
||||
"PaymentTerm" => Setting.directo_receipt_payment_term,
|
||||
"Currency" => transaction.currency,
|
||||
"CustomerCode"=> transaction.invoice.try(:buyer).try(:directo_handle)
|
||||
){
|
||||
xml.line(
|
||||
"ProductID"=> Setting.directo_receipt_product_name,
|
||||
"Quantity" => 1,
|
||||
"UnitPriceWoVAT" =>ActionController::Base.helpers.number_with_precision(transaction.sum.to_f/1.2, precision: 2, separator: "."),
|
||||
"ProductName" => transaction.description
|
||||
)
|
||||
}
|
||||
end
|
||||
}
|
||||
end
|
||||
|
||||
data = builder.to_xml.gsub("\n",'')
|
||||
response = RestClient::Request.execute(url: ENV['directo_invoice_url'], method: :post, payload: {put: "1", what: "invoice", xmldata: data}, verify_ssl: false).to_s
|
||||
dump_result_to_db(mappers, response)
|
||||
end
|
||||
end
|
||||
|
||||
def self.dump_result_to_db mappers, xml
|
||||
Nokogiri::XML(xml).css("Result").each do |res|
|
||||
obj = mappers[res.attributes["docid"].value.to_i]
|
||||
obj.directo_records.first_or_create!(response: res.as_json.to_h)
|
||||
obj.update_columns(in_directo: true)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -71,6 +71,8 @@
|
|||
= render 'setting_row', var: :days_to_keep_invoices_active
|
||||
= render 'setting_row', var: :days_to_keep_overdue_invoices_active
|
||||
= render 'setting_row', var: :minimum_deposit
|
||||
= render 'setting_row', var: :directo_receipt_payment_term
|
||||
= render 'setting_row', var: :directo_receipt_product_name
|
||||
= render 'setting_row', var: :registry_billing_email
|
||||
= render 'setting_row', var: :registry_invoice_contact
|
||||
= render 'setting_row', var: :registry_vat_no
|
||||
|
|
|
@ -45,6 +45,8 @@ ca_cert_path: '/home/registry/registry/shared/ca/certs/ca.crt.pem'
|
|||
ca_key_path: '/home/registry/registry/shared/ca/private/ca.key.pem'
|
||||
ca_key_password: 'your-root-key-password'
|
||||
|
||||
directo_invoice_url: 'https://domain/ddddd.asp'
|
||||
|
||||
|
||||
#
|
||||
# EPP
|
||||
|
|
|
@ -33,6 +33,8 @@ if con.present? && con.table_exists?('settings')
|
|||
Setting.save_default(:days_to_keep_invoices_active, 30)
|
||||
Setting.save_default(:days_to_keep_overdue_invoices_active, 30)
|
||||
Setting.save_default(:minimum_deposit, 0.0)
|
||||
Setting.save_default(:directo_receipt_payment_term, "R")
|
||||
Setting.save_default(:directo_receipt_product_name, "ETTEM06")
|
||||
|
||||
Setting.save_default(:days_to_renew_domain_before_expire, 90)
|
||||
Setting.save_default(:expire_warning_period, 15)
|
||||
|
|
10
db/migrate/20160113143447_create_directos.rb
Normal file
10
db/migrate/20160113143447_create_directos.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
class CreateDirectos < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :directos do |t|
|
||||
t.belongs_to :item, index: true, polymorphic: true
|
||||
t.json :response
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
class AddInDirectoToBankTransaction < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :bank_transactions, :in_directo, :boolean, default: false
|
||||
end
|
||||
end
|
5
spec/models/directo_spec.rb
Normal file
5
spec/models/directo_spec.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Directo, type: :model do
|
||||
pending "add some examples to (or delete) #{__FILE__}"
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue