Skip to content

Commit 815d627

Browse files
feat: add status and update callback URL for domain reservations
Add status tracking and update callback handling for domain reservations: - Add status enum to ReserveDomainInvoice (pending, paid, cancelled, failed) - Add status column to reserve_domain_invoices table with default 'pending' - Update ONE_OFF_CUSTOMER_URL to include callback path - Add callback route for EIS billing system - Update database structure for new status column This change enables tracking reservation payment status and proper callback handling for the business registry domain reservation process.
1 parent 02fec75 commit 815d627

6 files changed

+83
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
module EisBilling
2+
class BusinessRegistryCallbackController < ApplicationController
3+
skip_authorization_check
4+
5+
def callback
6+
7+
result = EisBilling::SendCallbackService.call(reference_number: params[:payment_reference])
8+
9+
invoice_number = params[:order_reference]
10+
11+
puts '----'
12+
puts result.body
13+
puts result.code
14+
puts invoice_number
15+
puts '----'
16+
17+
if result.code == '200'
18+
reserve_domain_invoice = ReserveDomainInvoice.find_by(number: invoice_number)
19+
filtered_domains = BusinessRegistry::DomainAvailabilityCheckerService.filter_available(reserve_domain_invoice.domain_names)
20+
21+
reserved_domains = []
22+
23+
# TODO:
24+
# - create reservied domains
25+
# - somehow bind them to the current invoice, maybe need to add some field there
26+
# - find invoices where are the same domains
27+
28+
filtered_domains.each do |domain|
29+
reserved_domains << ReservedDomain.create(name: domain)
30+
end
31+
32+
reserve_domain_invoice.paid!
33+
34+
pending_invoices = ReserveDomainInvoice.pending.where('domain_names && ARRAY[?]::varchar[]', reserve_domain_invoice.domain_names)
35+
36+
# - cancel them or recreate and change the price ?!?!
37+
38+
39+
render status: :ok, json: { message: 'Callback received' }
40+
else
41+
render status: :internal_server_error, json: { message: 'Callback failed' }
42+
end
43+
44+
end
45+
end
46+
end

app/models/reserve_domain_invoice.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ class InvoiceResponseStruct < Struct.new(:status_code_success, :oneoff_payment_l
1414
HTTP_OK = '200'
1515
HTTP_CREATED = '201'
1616
DEFAULT_AMOUNT = '10.00'
17-
ONE_OFF_CUSTOMER_URL = 'https://registry.test'
17+
ONE_OFF_CUSTOMER_URL = 'https://registry.test/eis_billing/callback'
18+
19+
20+
enum status: { pending: 0, paid: 1, cancelled: 2, failed: 3 }
1821

1922
class << self
2023
def create_list_of_domains(domain_names, success_business_registry_customer_url, failed_business_registry_customer_url)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
module EisBilling
2+
class SendCallbackService < EisBilling::Base
3+
4+
attr_reader :reference_number
5+
6+
def initialize(reference_number:)
7+
@reference_number = reference_number
8+
end
9+
10+
def self.call(reference_number:)
11+
new(reference_number: reference_number).call
12+
end
13+
14+
def call
15+
send_request
16+
end
17+
18+
private
19+
20+
def send_request
21+
http = EisBilling::Base.base_request
22+
http.get(billing_callback_url)
23+
end
24+
25+
def billing_callback_url
26+
"/api/v1/callback_handler/callback?payment_reference=#{reference_number}"
27+
end
28+
end
29+
end

config/routes.rb

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
put '/directo_response', to: 'directo_response#update', as: 'directo_response'
1717
put '/e_invoice_response', to: 'e_invoice_response#update', as: 'e_invoice_response'
1818
post '/lhv_connect_transactions', to: 'lhv_connect_transactions#create', as: 'lhv_connect_transactions'
19+
get 'callback', to: 'business_registry_callback#callback', as: 'callback'
1920
resource :invoices, only: [:update]
2021
end
2122

db/migrate/20241104104620_add_callback_urls_to_reserve_domain_invoices.rb

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ class AddCallbackUrlsToReserveDomainInvoices < ActiveRecord::Migration[6.1]
22
def change
33
add_column :reserve_domain_invoices, :success_business_registry_customer_url, :string
44
add_column :reserve_domain_invoices, :failed_business_registry_customer_url, :string
5+
add_column :reserve_domain_invoices, :status, :integer, default: 0
56
end
67
end

db/structure.sql

+2-1
Original file line numberDiff line numberDiff line change
@@ -2637,7 +2637,8 @@ CREATE TABLE public.reserve_domain_invoices (
26372637
created_at timestamp(6) without time zone NOT NULL,
26382638
updated_at timestamp(6) without time zone NOT NULL,
26392639
success_business_registry_customer_url character varying,
2640-
failed_business_registry_customer_url character varying
2640+
failed_business_registry_customer_url character varying,
2641+
status integer DEFAULT 0
26412642
);
26422643

26432644

0 commit comments

Comments
 (0)