diff --git a/app/controllers/eis_billing/e_invoice_response_controller.rb b/app/controllers/eis_billing/e_invoice_response_controller.rb
new file mode 100644
index 000000000..e02032184
--- /dev/null
+++ b/app/controllers/eis_billing/e_invoice_response_controller.rb
@@ -0,0 +1,17 @@
+module EisBilling
+ class 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
+end
diff --git a/app/controllers/invoices_controller.rb b/app/controllers/invoices_controller.rb
index 93ace6674..bb2fe392d 100644
--- a/app/controllers/invoices_controller.rb
+++ b/app/controllers/invoices_controller.rb
@@ -91,6 +91,17 @@ def oneoff
end
end
+ def send_e_invoice
+ invoice = Invoice.accessible_by(current_ability).find_by!(uuid: params[:uuid])
+ response = EisBilling::SendEInvoice.call(invoice: invoice, payable: false)
+
+ if response.result?
+ redirect_to invoice_path(invoice.uuid), notice: t('.sent_to_omniva')
+ else
+ redirect_to invoice_path(invoice.uuid), alert: response.errors
+ end
+ end
+
def update_predicate
@invoice.issued? && @invoice.update(update_params)
end
diff --git a/app/models/concerns/invoice/book_keeping.rb b/app/models/concerns/invoice/book_keeping.rb
index 3cdb083d2..886d8f77c 100644
--- a/app/models/concerns/invoice/book_keeping.rb
+++ b/app/models/concerns/invoice/book_keeping.rb
@@ -12,6 +12,88 @@ def as_directo_json
invoice
end
+ def e_invoice_data
+ invoice = as_json(only: %i[id issue_date due_date number])
+ invoice['seller_name'] = seller_contact_name
+ invoice['seller_reg_no'] = seller_reg_no
+ invoice['seller_vat_no'] = seller_vat_no
+ invoice['seller_street'] = seller_street
+ invoice['seller_state'] = seller_state
+ invoice['seller_zip'] = seller_zip
+ invoice['seller_city'] = seller_city
+ invoice['seller_country_code'] = seller_country_code
+ invoice['buyer_name'] = billing_name
+ invoice['buyer_vat_no'] = billing_vat_code
+ invoice['buyer_street'] = street
+ invoice['buyer_state'] = state
+ invoice['buyer_zip'] = postal_code
+ invoice['buyer_city'] = city
+ invoice['buyer_country_code'] = billing_alpha_two_country_code
+ invoice['total'] = total.to_f + (enable_deposit? ? deposit : 0.0)
+ invoice['vat_rate'] = vat_rate * 100
+ invoice['currency'] = Setting.find_by(code: 'auction_currency').retrieve
+
+ invoice
+ end
+
+ def e_invoice_sent?
+ e_invoice_sent_at.present?
+ end
+
+ def do_not_send_e_invoice?
+ e_invoice_sent? || cancelled?
+ end
+
+ def seller_contact_name
+ Setting.find_by(code: 'invoice_issuer').retrieve
+ end
+
+ def seller_address
+ country_name = Countries.name_from_alpha2_code(seller_country_code)
+ [
+ seller_street,
+ seller_state,
+ seller_zip,
+ country_name,
+ seller_city
+ ].reject(&:blank?).compact.join(', ')
+ end
+
+ def seller_reg_no
+ Setting.find_by(code: 'invoice_issuer_reg_no').retrieve
+ end
+
+ def seller_vat_no
+ Setting.find_by(code: 'invoice_issuer_vat_no').retrieve
+ end
+
+ def seller_street
+ Setting.find_by(code: 'invoice_issuer_street').retrieve
+ end
+
+ def seller_city
+ Setting.find_by(code: 'invoice_issuer_city').retrieve
+ end
+
+ def seller_zip
+ Setting.find_by(code: 'invoice_issuer_zip').retrieve
+ end
+
+ def seller_country_code
+ Setting.find_by(code: 'invoice_issuer_country_code').retrieve
+ end
+
+ def seller_state
+ Setting.find_by(code: 'invoice_issuer_state').retrieve
+ end
+
+ def issuer
+ "#{seller_contact_name}, #{seller_address}, " \
+ "Reg. no #{seller_reg_no}, VAT number #{seller_vat_no}"
+ end
+
+ private
+
def compose_invoice_meta(invoice)
invoice['issue_date'] = issue_date.strftime('%Y-%m-%d')
invoice['transaction_date'] = paid_at.strftime('%Y-%m-%d')
@@ -36,12 +118,14 @@ def compose_directo_customer
end
def compose_directo_product
- [{ 'product_id': 'OKSJON',
+ [
+ { 'product_id': 'OKSJON',
'description': result.auction.domain_name,
'quantity': 1,
'unit': 1,
'price': ActionController::Base.helpers.number_with_precision(
price.amount, precision: 2, separator: '.'
- ) }].as_json
+ ) }
+ ].as_json
end
end
diff --git a/app/services/application_service.rb b/app/services/application_service.rb
new file mode 100644
index 000000000..00e548486
--- /dev/null
+++ b/app/services/application_service.rb
@@ -0,0 +1,6 @@
+# app/services/application_service.rb
+class ApplicationService
+ def self.call(*args, &block)
+ new(*args, &block).call
+ end
+end
diff --git a/app/services/eis_billing/send_e_invoice.rb b/app/services/eis_billing/send_e_invoice.rb
new file mode 100644
index 000000000..d62e49471
--- /dev/null
+++ b/app/services/eis_billing/send_e_invoice.rb
@@ -0,0 +1,53 @@
+module EisBilling
+ class SendEInvoice < ApplicationService
+ include EisBilling::Request
+ include EisBilling::BaseService
+
+ attr_reader :invoice, :payable
+
+ def initialize(invoice:, payable:)
+ @invoice = invoice
+ @payable = payable
+ end
+
+ def call
+ prepared_data = {
+ invoice: invoice.e_invoice_data,
+ vat_amount: invoice.vat.amount,
+ invoice_subtotal: invoice.price.amount,
+ buyer_billing_email: invoice.user&.email,
+ payable: payable,
+ initiator: INITIATOR,
+ items: prepare_items(invoice)
+ }
+
+ struct_response(post(e_invoice_url, prepared_data))
+ end
+
+ private
+
+ def prepare_items(invoice)
+ invoice.items.map do |invoice_item|
+ {
+ description: item_description(invoice.result),
+ price: invoice_item.price.amount,
+ quantity: 1,
+ unit: 'piece',
+ subtotal: invoice_item.price.amount,
+ vat_rate: invoice.vat_rate.to_f * 100,
+ vat_amount: invoice.vat.amount,
+ total: invoice.total.to_f,
+ }
+ end
+ end
+
+ def e_invoice_url
+ '/api/v1/e_invoice/e_invoice'
+ end
+
+ def item_description(result)
+ I18n.t('invoice_items.name', domain_name: result.auction.domain_name,
+ auction_end: result.auction.ends_at.to_date)
+ end
+ end
+end
diff --git a/app/views/common/pdf.html.erb b/app/views/common/pdf.html.erb
index 3d8eb1489..5cd3152e4 100644
--- a/app/views/common/pdf.html.erb
+++ b/app/views/common/pdf.html.erb
@@ -192,7 +192,7 @@
<%= t('invoices.issuer') %>
- <%= Setting.find_by(code: 'invoice_issuer').retrieve %>
+ <%= @invoice.issuer %>
<%= t('invoices.number') %>
@@ -301,7 +301,7 @@
- <%= Setting.find_by(code: 'invoice_issuer').retrieve %>
+ <%= @invoice.issuer %>
diff --git a/app/views/invoices/show.html.erb b/app/views/invoices/show.html.erb
index e8e4cfd67..2bf745660 100644
--- a/app/views/invoices/show.html.erb
+++ b/app/views/invoices/show.html.erb
@@ -27,15 +27,15 @@
- <%= Setting.find_by(code: 'invoice_issuer').retrieve %>
-
+ <%= @invoice.issuer %>
+
- <%= @invoice.issue_date %>
+ <%= @invoice.issue_date %>
- <%= @invoice.due_date %>
+ <%= @invoice.due_date %>
<% if @invoice.paid? %>
@@ -62,8 +62,8 @@
<%= index + 1 %> |
<%= I18n.t('invoice_items.name',
- domain_name: item.invoice.result.auction.domain_name,
- auction_end: item.invoice.result.auction.ends_at.to_date) %>
+ domain_name: @invoice.result.auction.domain_name,
+ auction_end: @invoice.result.auction.ends_at.to_date) %>
|
|
<%= item.price %> |
@@ -104,10 +104,18 @@
<% if @invoice.payable? %>
-
+
<%= button_to t('invoices.show.pay'), oneoff_invoice_path(uuid: @invoice.uuid), class: 'ui button primary' %>
<% end %>
+
+ <% if @invoice.do_not_send_e_invoice? %>
+
+ <% else %>
+ <%= button_to t('invoices.show.send_e_invoice'), send_e_invoice_path(uuid: @invoice.uuid), class: 'ui button default', data: { turbo: false } %>
+ <% end %>
+
+
diff --git a/config/customization.yml.sample b/config/customization.yml.sample
index 184ad9e23..ec6071cb5 100644
--- a/config/customization.yml.sample
+++ b/config/customization.yml.sample
@@ -1,14 +1,4 @@
default: &default
- billing_system_integration:
- enabled: true
- #eis_billing_system_base_url_dev: 'http://eis_billing_system:3000'
- #eis_billing_system_base_url_staging: 'https://st-billing.infra.tld.ee'
- eis_billing_system_base_url: 'http://eis_billing_system:3000'
- secret_access_word: 'please-Give-Me-accesS'
- secret_word: 'this-secret-should-be-change'
- billing_system_integrated: 'true'
-
- billing_secret: '0fb3661d89134de0cbcdd6b29780e23f2ec05e744c4d15feb381b1e7d7549d5ec960989c6471c9a31835ee455865cf7b2641529ae7cf1e6b4c3675f6361e98d0'
# This is your application name, as displayed in the UI
application_name: "EIS Auction Center"
@@ -124,7 +114,6 @@ default: &default
secret_word: 'this-secret-should-be-change'
billing_system_integrated: 'true'
billing_secret: ''
- test_env: false
development:
<<: *default
diff --git a/config/locales/invoices.en.yml b/config/locales/invoices.en.yml
index 80ac8986d..ea8c6821a 100644
--- a/config/locales/invoices.en.yml
+++ b/config/locales/invoices.en.yml
@@ -26,6 +26,7 @@ en:
paid_through: "Paid through"
deposit: "Deposit"
amount_due: "Amount due"
+ sent_to_omniva: "E-Invoice was successfully sent"
outstanding: "Outstanding invoices"
paid: "Paid invoices"
@@ -49,6 +50,7 @@ en:
change_billing_profile: "Change billing profile"
pay: "Pay"
redeem: Paying for cancelled invoice will redeem the violation but will not grant priority right to register that domain
+ send_e_invoice: "Send E-Invoice"
edit:
title: "Edit your invoice"
diff --git a/config/locales/invoices.et.yml b/config/locales/invoices.et.yml
index cdcb043d7..fcb231143 100644
--- a/config/locales/invoices.et.yml
+++ b/config/locales/invoices.et.yml
@@ -26,6 +26,7 @@ et:
paid_through: "Makseviis"
deposit: "Ettemaks"
amount_due: "Tasuda"
+ sent_to_omniva: "E-arve saadeti edukalt"
outstanding: "Tasumata arved"
paid: "Tasutud arved"
@@ -49,6 +50,7 @@ et:
change_billing_profile: "Muuda arve aadressi"
pay: "Maksa"
redeem: Tühistatud arve tasumine eemaldab vastava arvega seotud rikkumise, kuid ei anna vastava domeeni registreerimiseks eelisõigust.
+ send_e_invoice: "Saada E-Arve"
edit:
title: "Muuda arvet"
diff --git a/config/routes.rb b/config/routes.rb
index 4b75d3594..b185fabce 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -38,6 +38,7 @@
namespace :eis_billing, defaults: { format: 'json' } do
put '/payment_status', to: 'payment_status#update', as: 'payment_status'
put '/directo_response', to: 'directo_response#update', as: 'directo_response'
+ put '/e_invoice_response', to: 'e_invoice_response#update', as: 'e_invoice_response'
end
namespace :admin, constraints: Constraints::Administrator.new do
@@ -90,11 +91,11 @@
resources :billing_profiles, param: :uuid
match '/status', via: :get, to: 'health_checks#index'
-
resources :invoices, only: %i[show edit update index], param: :uuid do
member do
get 'download'
post 'oneoff'
+ post 'send_e_invoice', as: :send_e
end
collection do
diff --git a/db/data/20230925104427_modify_invoice_issuer_data.rb b/db/data/20230925104427_modify_invoice_issuer_data.rb
new file mode 100644
index 000000000..707eed5a5
--- /dev/null
+++ b/db/data/20230925104427_modify_invoice_issuer_data.rb
@@ -0,0 +1,78 @@
+# frozen_string_literal: true
+
+class ModifyInvoiceIssuerData < ActiveRecord::Migration[7.0]
+ def up
+ hash = {
+ invoice_issuer: {
+ description: <<~TEXT.squish,
+ Text that should appear in invoice as issuer. Usually contains a company name.
+ TEXT
+ value: 'Eesti Interneti SA',
+ value_format: 'string'
+ },
+ invoice_issuer_reg_no: {
+ description: <<~TEXT.squish,
+ Invoice issuer registration number
+ TEXT
+ value: '90010019',
+ value_format: 'string'
+ },
+ invoice_issuer_vat_no: {
+ description: <<~TEXT.squish,
+ Invoice issuer VAT number.
+ TEXT
+ value: 'EE101286464',
+ value_format: 'string'
+ },
+ invoice_issuer_street: {
+ description: <<~TEXT.squish,
+ Invoice issuer street name.
+ TEXT
+ value: 'Paldiski mnt 80',
+ value_format: 'string'
+ },
+ invoice_issuer_state: {
+ description: <<~TEXT.squish,
+ Invoice issuer state name.
+ TEXT
+ value: 'Harjumaa',
+ value_format: 'string'
+ },
+ invoice_issuer_zip: {
+ description: <<~TEXT.squish,
+ Invoice issuer zip code.
+ TEXT
+ value: '10617',
+ value_format: 'string'
+ },
+ invoice_issuer_city: {
+ description: <<~TEXT.squish,
+ Invoice issuer city name.
+ TEXT
+ value: 'Tallinn',
+ value_format: 'string'
+ },
+ invoice_issuer_country_code: {
+ description: <<~TEXT.squish,
+ Invoice issuer country code.
+ TEXT
+ value: 'EE',
+ value_format: 'string'
+ }
+ }
+
+ Setting.transaction do
+ hash.each do |key, value_hash|
+ setting = Setting.find_or_create_by(code: key)
+ setting.update!(value: value_hash[:value],
+ description: value_hash[:description],
+ value_format: value_hash[:value_format])
+ end
+ puts 'Invoice issuer settings updated.'
+ end
+ end
+
+ def down
+ raise ActiveRecord::IrreversibleMigration
+ end
+end
diff --git a/db/data_schema.rb b/db/data_schema.rb
index bcf096a15..f8654a3da 100644
--- a/db/data_schema.rb
+++ b/db/data_schema.rb
@@ -1,2 +1 @@
-# encoding: UTF-8
-DataMigrate::Data.define(version: 20200527081406)
+DataMigrate::Data.define(version: 20230925104427)
diff --git a/db/migrate/20230925130405_add_e_invoice_sent_at_to_invoice.rb b/db/migrate/20230925130405_add_e_invoice_sent_at_to_invoice.rb
new file mode 100644
index 000000000..bd3db63f2
--- /dev/null
+++ b/db/migrate/20230925130405_add_e_invoice_sent_at_to_invoice.rb
@@ -0,0 +1,5 @@
+class AddEInvoiceSentAtToInvoice < ActiveRecord::Migration[7.0]
+ def change
+ add_column :invoices, :e_invoice_sent_at, :datetime
+ end
+end
diff --git a/db/structure.sql b/db/structure.sql
index bbd6d4173..2e592e364 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -912,6 +912,38 @@ CREATE SEQUENCE public.auctions_id_seq
ALTER SEQUENCE public.auctions_id_seq OWNED BY public.auctions.id;
+--
+-- Name: auto_bids; Type: TABLE; Schema: public; Owner: -
+--
+
+CREATE TABLE public.auto_bids (
+ id bigint NOT NULL,
+ wishlist_item_id bigint NOT NULL,
+ cents integer NOT NULL,
+ created_at timestamp(6) without time zone NOT NULL,
+ updated_at timestamp(6) without time zone NOT NULL
+);
+
+
+--
+-- Name: auto_bids_id_seq; Type: SEQUENCE; Schema: public; Owner: -
+--
+
+CREATE SEQUENCE public.auto_bids_id_seq
+ START WITH 1
+ INCREMENT BY 1
+ NO MINVALUE
+ NO MAXVALUE
+ CACHE 1;
+
+
+--
+-- Name: auto_bids_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
+--
+
+ALTER SEQUENCE public.auto_bids_id_seq OWNED BY public.auto_bids.id;
+
+
--
-- Name: autobiders; Type: TABLE; Schema: public; Owner: -
--
@@ -921,7 +953,7 @@ CREATE TABLE public.autobiders (
user_id bigint,
domain_name character varying,
cents integer,
- uuid uuid DEFAULT gen_random_uuid(),
+ uuid uuid DEFAULT public.gen_random_uuid(),
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL
);
@@ -1021,6 +1053,15 @@ CREATE SEQUENCE public.billing_profiles_id_seq
ALTER SEQUENCE public.billing_profiles_id_seq OWNED BY public.billing_profiles.id;
+--
+-- Name: data_migrations; Type: TABLE; Schema: public; Owner: -
+--
+
+CREATE TABLE public.data_migrations (
+ version character varying NOT NULL
+);
+
+
--
-- Name: delayed_jobs; Type: TABLE; Schema: public; Owner: -
--
@@ -1229,6 +1270,7 @@ CREATE TABLE public.invoices (
billing_address character varying DEFAULT ''::character varying NOT NULL,
billing_vat_code character varying,
billing_alpha_two_country_code character varying DEFAULT ''::character varying NOT NULL,
+ e_invoice_sent_at timestamp(6) without time zone,
CONSTRAINT invoices_cents_are_non_negative CHECK ((cents >= 0)),
CONSTRAINT invoices_due_date_is_not_before_issue_date CHECK ((issue_date <= due_date)),
CONSTRAINT paid_at_is_filled_when_status_is_paid CHECK ((NOT ((status = 'paid'::public.invoice_status) AND (paid_at IS NULL)))),
@@ -1544,6 +1586,7 @@ CREATE TABLE public.users (
uid character varying,
updated_by character varying,
daily_summary boolean DEFAULT false NOT NULL,
+ discarded_at timestamp without time zone,
CONSTRAINT users_roles_are_known CHECK ((roles <@ ARRAY['participant'::character varying, 'administrator'::character varying]))
);
@@ -1726,6 +1769,13 @@ ALTER TABLE ONLY audit.wishlist_items ALTER COLUMN id SET DEFAULT nextval('audit
ALTER TABLE ONLY public.auctions ALTER COLUMN id SET DEFAULT nextval('public.auctions_id_seq'::regclass);
+--
+-- Name: auto_bids id; Type: DEFAULT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY public.auto_bids ALTER COLUMN id SET DEFAULT nextval('public.auto_bids_id_seq'::regclass);
+
+
--
-- Name: autobiders id; Type: DEFAULT; Schema: public; Owner: -
--
@@ -2027,6 +2077,14 @@ ALTER TABLE ONLY public.ar_internal_metadata
ADD CONSTRAINT ar_internal_metadata_pkey PRIMARY KEY (key);
+--
+-- Name: auto_bids auto_bids_pkey; Type: CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY public.auto_bids
+ ADD CONSTRAINT auto_bids_pkey PRIMARY KEY (id);
+
+
--
-- Name: autobiders autobiders_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
@@ -2051,6 +2109,14 @@ ALTER TABLE ONLY public.billing_profiles
ADD CONSTRAINT billing_profiles_pkey PRIMARY KEY (id);
+--
+-- Name: data_migrations data_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY public.data_migrations
+ ADD CONSTRAINT data_migrations_pkey PRIMARY KEY (version);
+
+
--
-- Name: delayed_jobs delayed_jobs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
@@ -2375,6 +2441,13 @@ CREATE UNIQUE INDEX index_auctions_on_remote_id ON public.auctions USING btree (
CREATE UNIQUE INDEX index_auctions_on_uuid ON public.auctions USING btree (uuid);
+--
+-- Name: index_auto_bids_on_wishlist_item_id; Type: INDEX; Schema: public; Owner: -
+--
+
+CREATE INDEX index_auto_bids_on_wishlist_item_id ON public.auto_bids USING btree (wishlist_item_id);
+
+
--
-- Name: index_autobiders_on_domain_name; Type: INDEX; Schema: public; Owner: -
--
@@ -2696,7 +2769,6 @@ CREATE INDEX index_wishlist_items_on_domain_name ON public.wishlist_items USING
CREATE UNIQUE INDEX users_by_identity_code_and_country ON public.users USING btree (alpha_two_country_code, identity_code) WHERE ((alpha_two_country_code)::text = 'EE'::text);
-
--
-- Name: auctions process_auction_audit; Type: TRIGGER; Schema: public; Owner: -
--
@@ -2780,7 +2852,6 @@ CREATE TRIGGER process_user_audit AFTER INSERT OR DELETE OR UPDATE ON public.use
CREATE TRIGGER process_wishlist_item_audit AFTER INSERT OR DELETE OR UPDATE ON public.wishlist_items FOR EACH ROW EXECUTE FUNCTION public.process_wishlist_item_audit();
-
--
-- Name: bans fk_rails_070022cd76; Type: FK CONSTRAINT; Schema: public; Owner: -
--
@@ -2813,6 +2884,14 @@ ALTER TABLE ONLY public.autobiders
ADD CONSTRAINT fk_rails_3d4f798ed7 FOREIGN KEY (user_id) REFERENCES public.users(id);
+--
+-- Name: auto_bids fk_rails_473d19add3; Type: FK CONSTRAINT; Schema: public; Owner: -
+--
+
+ALTER TABLE ONLY public.auto_bids
+ ADD CONSTRAINT fk_rails_473d19add3 FOREIGN KEY (wishlist_item_id) REFERENCES public.wishlist_items(id);
+
+
--
-- Name: wishlist_items fk_rails_5c10acf6bc; Type: FK CONSTRAINT; Schema: public; Owner: -
--
@@ -3006,11 +3085,14 @@ INSERT INTO "schema_migrations" (version) VALUES
('20191025092912'),
('20191028092316'),
('20191121162323'),
+('20191129102035'),
+('20191206123023'),
('20191209073454'),
('20191209083000'),
('20191209085222'),
('20191213082941'),
('20191220131845'),
+('20200109093043'),
('20200110135003'),
('20200115145246'),
('20200205092158'),
@@ -3022,6 +3104,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20220422094307'),
('20220422094556'),
('20220422095751'),
+('20220422121056'),
('20220425103701'),
('20220426082102'),
('20220527064738'),
@@ -3038,5 +3121,8 @@ INSERT INTO "schema_migrations" (version) VALUES
('20230227085236'),
('20230309094132'),
('20230419114412'),
+('20230607092953'),
('20230705192353'),
-('20230607092953');
+('20230925130405');
+
+
diff --git a/public/images/finbite.png b/public/images/finbite.png
new file mode 100644
index 000000000..9521fd2f8
Binary files /dev/null and b/public/images/finbite.png differ
diff --git a/test/fixtures/settings.yml b/test/fixtures/settings.yml
index e0e7d9914..7edc3ea4e 100644
--- a/test/fixtures/settings.yml
+++ b/test/fixtures/settings.yml
@@ -121,9 +121,57 @@ remind_on_domain_registration_everyday:
invoice_issuer:
code: 'invoice_issuer'
description: |
- Text that should appear in invoice as issuer. Usually contains company name, VAT number and
- local court registration number.e which the registration reminder email is sent on. Default: 5
- value: 'Eesti Interneti SA, VAT number EE101286464'
+ Text that should appear in invoice as issuer. Usually contains a company name
+ value: 'Eesti Interneti SA'
+ value_format: string
+
+invoice_issuer_reg_no:
+ code: 'invoice_issuer_reg_no'
+ description: |
+ Invoice issuer registration number
+ value: '90010019'
+ value_format: string
+
+invoice_issuer_vat_no:
+ code: 'invoice_issuer_vat_no'
+ description: |
+ Invoice issuer VAT number
+ value: 'EE101286464'
+ value_format: string
+
+invoice_issuer_street:
+ code: 'invoice_issuer_street'
+ description: |
+ Invoice issuer street name
+ value: 'Paldiski mnt 80'
+ value_format: string
+
+invoice_issuer_state:
+ code: 'invoice_issuer_state'
+ description: |
+ Invoice issuer state name
+ value: 'Harjumaa'
+ value_format: string
+
+invoice_issuer_zip:
+ code: 'invoice_issuer_zip'
+ description: |
+ Invoice issuer zip code
+ value: '10617'
+ value_format: string
+
+invoice_issuer_city:
+ code: 'invoice_issuer_city'
+ description: |
+ Invoice issuer city name
+ value: 'Tallinn'
+ value_format: string
+
+invoice_issuer_country_code:
+ code: 'invoice_issuer_country_code'
+ description: |
+ Invoice issuer country code
+ value: 'EE'
value_format: string
invoice_reminder_in_days:
diff --git a/test/integration/eis_billing/e_invoice_response_test.rb b/test/integration/eis_billing/e_invoice_response_test.rb
new file mode 100644
index 000000000..ce93afe2c
--- /dev/null
+++ b/test/integration/eis_billing/e_invoice_response_test.rb
@@ -0,0 +1,19 @@
+require 'test_helper'
+
+class EInvoiceResponseTest < ActionDispatch::IntegrationTest
+ include Devise::Test::IntegrationHelpers
+
+ setup do
+ sign_in users(:participant)
+ @invoice = invoices(:payable)
+ 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
diff --git a/test/integration/invoices_test.rb b/test/integration/invoices_test.rb
index 5a8178778..4d945d700 100644
--- a/test/integration/invoices_test.rb
+++ b/test/integration/invoices_test.rb
@@ -7,6 +7,7 @@ def setup
@user = users(:participant)
@user_two = users(:second_place_participant)
@auction = auctions(:valid_without_offers)
+ @invoice = invoices(:payable)
@user.reload
sign_in @user
@@ -56,4 +57,30 @@ def test_completely_banned_user_cannot_pay_any_deposit
assert_redirected_to root_path
assert_equal 'You are not authorized to access this page.', flash[:alert]
end
+
+ def test_should_send_e_invoice
+ body = {
+ message: 'Invoice data received',
+ }
+ stub_request(:post, 'http://eis_billing_system:3000/api/v1/e_invoice/e_invoice')
+ .to_return(status: :created, body: body.to_json, headers: {})
+
+ post send_e_invoice_path(uuid: @invoice.uuid), params: nil, headers: {}
+
+ assert_redirected_to invoice_path(@invoice.uuid)
+ assert_equal 'E-Invoice was successfully sent', flash[:notice]
+ end
+
+ def test_send_e_invoice_with_billing_system_error
+ body = {
+ error: 'Internal server error',
+ }
+ stub_request(:post, 'http://eis_billing_system:3000/api/v1/e_invoice/e_invoice')
+ .to_return(status: 500, body: body.to_json, headers: {})
+
+ post send_e_invoice_path(uuid: @invoice.uuid), params: nil, headers: {}
+
+ assert_redirected_to invoice_path(@invoice.uuid)
+ assert_equal body[:error], flash[:alert]
+ end
end
diff --git a/test/system/invoices_test.rb b/test/system/invoices_test.rb
index 52905cad1..259ed3ccf 100644
--- a/test/system/invoices_test.rb
+++ b/test/system/invoices_test.rb
@@ -47,7 +47,7 @@ def test_user_cannot_update_billing_profile_on_paid_invoice
visit edit_invoice_path(@invoice.uuid)
# select_from_dropdown('Joe John Participant', from: 'invoice[billing_profile_id]')
select 'Joe John Participant', from: 'invoice[billing_profile_id]'
-
+
click_link_or_button('Submit')
assert_text('Something went wrong.')
@@ -56,7 +56,7 @@ def test_user_cannot_update_billing_profile_on_paid_invoice
def test_invoice_view_contains_issuer_info
visit invoice_path(@invoice.uuid)
- assert_text('Eesti Interneti SA, VAT number EE101286464')
+ assert_text('Eesti Interneti SA')
setting = settings(:invoice_issuer)
setting.update!(value: 'foo bar baz')