Skip to content

Commit

Permalink
feat: add status and update callback URL for domain reservations
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
OlegPhenomenon committed Nov 8, 2024
1 parent 02fec75 commit 815d627
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module EisBilling
class BusinessRegistryCallbackController < ApplicationController
skip_authorization_check

def callback

result = EisBilling::SendCallbackService.call(reference_number: params[:payment_reference])

invoice_number = params[:order_reference]

puts '----'
puts result.body
puts result.code
puts invoice_number
puts '----'

if result.code == '200'
reserve_domain_invoice = ReserveDomainInvoice.find_by(number: invoice_number)
filtered_domains = BusinessRegistry::DomainAvailabilityCheckerService.filter_available(reserve_domain_invoice.domain_names)

reserved_domains = []

# TODO:
# - create reservied domains
# - somehow bind them to the current invoice, maybe need to add some field there
# - find invoices where are the same domains

filtered_domains.each do |domain|
reserved_domains << ReservedDomain.create(name: domain)
end

reserve_domain_invoice.paid!

pending_invoices = ReserveDomainInvoice.pending.where('domain_names && ARRAY[?]::varchar[]', reserve_domain_invoice.domain_names)

# - cancel them or recreate and change the price ?!?!


render status: :ok, json: { message: 'Callback received' }
else
render status: :internal_server_error, json: { message: 'Callback failed' }
end

end
end
end
5 changes: 4 additions & 1 deletion app/models/reserve_domain_invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ class InvoiceResponseStruct < Struct.new(:status_code_success, :oneoff_payment_l
HTTP_OK = '200'
HTTP_CREATED = '201'
DEFAULT_AMOUNT = '10.00'
ONE_OFF_CUSTOMER_URL = 'https://registry.test'
ONE_OFF_CUSTOMER_URL = 'https://registry.test/eis_billing/callback'


enum status: { pending: 0, paid: 1, cancelled: 2, failed: 3 }

class << self
def create_list_of_domains(domain_names, success_business_registry_customer_url, failed_business_registry_customer_url)
Expand Down
29 changes: 29 additions & 0 deletions app/services/eis_billing/send_callback_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module EisBilling
class SendCallbackService < EisBilling::Base

attr_reader :reference_number

def initialize(reference_number:)
@reference_number = reference_number
end

def self.call(reference_number:)
new(reference_number: reference_number).call
end

def call
send_request
end

private

def send_request
http = EisBilling::Base.base_request
http.get(billing_callback_url)
end

def billing_callback_url
"/api/v1/callback_handler/callback?payment_reference=#{reference_number}"
end
end
end
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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'
get 'callback', to: 'business_registry_callback#callback', as: 'callback'
resource :invoices, only: [:update]
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ class AddCallbackUrlsToReserveDomainInvoices < ActiveRecord::Migration[6.1]
def change
add_column :reserve_domain_invoices, :success_business_registry_customer_url, :string
add_column :reserve_domain_invoices, :failed_business_registry_customer_url, :string
add_column :reserve_domain_invoices, :status, :integer, default: 0
end
end
3 changes: 2 additions & 1 deletion db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2637,7 +2637,8 @@ CREATE TABLE public.reserve_domain_invoices (
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL,
success_business_registry_customer_url character varying,
failed_business_registry_customer_url character varying
failed_business_registry_customer_url character varying,
status integer DEFAULT 0
);


Expand Down

0 comments on commit 815d627

Please sign in to comment.