Skip to content

Commit

Permalink
Merge pull request #398 from tungleduyxyz/issue_397_sync_with_killbil…
Browse files Browse the repository at this point in the history
…l_client

Issue 397 Sync with killbill-client
  • Loading branch information
reshmabidikar authored Apr 30, 2024
2 parents 841e6fa + ca32dda commit 4944870
Show file tree
Hide file tree
Showing 21 changed files with 62 additions and 64 deletions.
6 changes: 3 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ gem 'kenui'
# gem 'killbill-assets-ui', path: '../killbill-assets-ui'
gem 'killbill-assets-ui'

# gem 'killbill-client', :path => '../killbill-client-ruby'
# gem 'killbill-client', git: 'https://github.com/killbill/killbill-client-ruby.git', branch: 'master'
gem 'killbill-client'
# gem 'killbill-client', path: '../killbill-client-ruby'
gem 'killbill-client', git: 'https://github.com/killbill/killbill-client-ruby.git', branch: 'master'
# gem 'killbill-client'
11 changes: 5 additions & 6 deletions app/controllers/kaui/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,9 @@ def show
end

fetch_payment_methods_with_details = fetch_payment_methods.then do |pms|
ops = []
pms.each do |pm|
ops << promise do
Kaui::PaymentMethod.find_by_id(pm.payment_method_id, true, cached_options_for_klient)
ops = pms.map do |pm|
promise do
Kaui::PaymentMethod.find_by_id(pm.payment_method_id, false, true, [], 'NONE', cached_options_for_klient)
rescue StandardError => e
# Maybe the plugin is not registered or the plugin threw an exception
Rails.logger.warn(e)
Expand Down Expand Up @@ -182,7 +181,7 @@ def trigger_invoice
invoice = nil
begin
invoice = if dry_run
Kaui::Invoice.trigger_invoice_dry_run(account_id, target_date, false, options_for_klient)
Kaui::Invoice.trigger_invoice_dry_run(account_id, target_date, false, [], current_user.kb_username, params[:reason], params[:comment], options_for_klient)
else
Kaui::Invoice.trigger_invoice(account_id, target_date, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
end
Expand All @@ -209,7 +208,7 @@ def trigger_invoice
# Fetched asynchronously, as it takes time. This also helps with enforcing permissions.
def next_invoice_date
json_response do
next_invoice = Kaui::Invoice.trigger_invoice_dry_run(params.require(:account_id), nil, true, options_for_klient)
next_invoice = Kaui::Invoice.trigger_invoice_dry_run(params.require(:account_id), nil, true, [], current_user.kb_username, params[:reason], params[:comment], options_for_klient)
next_invoice ? next_invoice.target_date.to_json : nil
end
end
Expand Down
5 changes: 2 additions & 3 deletions app/controllers/kaui/admin_tenants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,8 @@ def catalog_by_effective_date

# convert result to a full hash since dynamic attributes of a class are ignored when converting to json
result.each do |data|
plans = []
data[:plans].each do |plan|
plans << plan.instance_variables.each_with_object({}) { |var, hash_plan| hash_plan[var.to_s.delete('@')] = plan.instance_variable_get(var) }
plans = data[:plans].map do |plan|
plan.instance_variables.each_with_object({}) { |var, hash_plan| hash_plan[var.to_s.delete('@')] = plan.instance_variable_get(var) }
end

catalog << { version_date: data[:version_date],
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/kaui/audit_logs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def history
when 'CUSTOM_FIELD'
audit_logs_with_history = Kaui::CustomField.new({ custom_field_id: object_id }).audit_logs_with_history(cached_options_for_klient)
when 'INVOICE'
invoice = Kaui::Invoice.find_by_id(object_id, 'NONE', cached_options_for_klient)
invoice = Kaui::Invoice.find_by_id(object_id, false, 'NONE', cached_options_for_klient)
audit_logs_with_history = invoice.audit_logs_with_history(cached_options_for_klient)
when 'INVOICE_ITEM'
invoice_item = Kaui::InvoiceItem.new
Expand All @@ -84,10 +84,10 @@ def history
payment = Kaui::Payment.find_by_id(object_id, false, false, cached_options_for_klient)
audit_logs_with_history = payment.audit_logs_with_history(cached_options_for_klient)
when 'PAYMENT_METHOD'
payment_method = Kaui::PaymentMethod.find_by_id(object_id, false, cached_options_for_klient)
payment_method = Kaui::PaymentMethod.find_by_id(object_id, false, false, [], 'NONE', cached_options_for_klient)
audit_logs_with_history = payment_method.audit_logs_with_history(cached_options_for_klient)
when 'SUBSCRIPTION'
subscription = Kaui::Subscription.find_by_id(object_id, cached_options_for_klient)
subscription = Kaui::Subscription.find_by_id(object_id, 'NONE', cached_options_for_klient)
audit_logs_with_history = subscription.audit_logs_with_history(cached_options_for_klient)
when 'SUBSCRIPTION_EVENT'
audit_logs_with_history = Kaui::Subscription.event_audit_logs_with_history(object_id, cached_options_for_klient)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/kaui/charges_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def new
amount = params[:amount]

if invoice_id.present?
@invoice = Kaui::Invoice.find_by_id(invoice_id, 'NONE', options_for_klient)
@invoice = Kaui::Invoice.find_by_id(invoice_id, false, 'NONE', options_for_klient)
amount ||= @invoice.balance
currency = @invoice.currency
else
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/kaui/credits_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def new
amount = params[:amount]

if invoice_id.present?
@invoice = Kaui::Invoice.find_by_id(invoice_id, 'NONE', options_for_klient)
@invoice = Kaui::Invoice.find_by_id(invoice_id, false, 'NONE', options_for_klient)
amount ||= @invoice.balance
currency = @invoice.currency
else
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/kaui/custom_fields_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def create
end
when :SUBSCRIPTION
begin
test_uuid = Kaui::Subscription.find_by_id(param_uuid, options_for_klient)
test_uuid = Kaui::Subscription.find_by_id(param_uuid, 'NONE', options_for_klient)
rescue StandardError
# Ignore
end
Expand Down Expand Up @@ -163,7 +163,7 @@ def _check_object_exist(uuid, object_type)
end
when 'SUBSCRIPTION'
begin
test_uuid = Kaui::Subscription.find_by_id(param_uuid, options_for_klient)
test_uuid = Kaui::Subscription.find_by_id(param_uuid, 'NONE', options_for_klient)
rescue StandardError
# Ignore
ensure
Expand All @@ -172,7 +172,7 @@ def _check_object_exist(uuid, object_type)
when 'INVOICE'
begin
cached_options_for_klient = options_for_klient
test_uuid = Kaui::Invoice.find_by_id(param_uuid, 'FULL', cached_options_for_klient)
test_uuid = Kaui::Invoice.find_by_id(param_uuid, false, 'FULL', cached_options_for_klient)
rescue StandardError
# Ignore
ensure
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/kaui/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def invoice_search(search_query, search_by = nil, fast = 0, options = {})
case search_by
when 'ID'
begin
invoice = Kaui::Invoice.find_by_id(search_query, 'NONE', options)
invoice = Kaui::Invoice.find_by_id(search_query, false, 'NONE', options)
redirect_to account_invoice_path(invoice.account_id, invoice.invoice_id) and return
rescue KillBillClient::API::NotFound => _e
search_error("No invoice matches \"#{search_query}\"")
Expand All @@ -64,7 +64,7 @@ def invoice_search(search_query, search_by = nil, fast = 0, options = {})
unsupported_search_field('INVOICE', search_by)
when 'NUMBER'
begin
invoice = Kaui::Invoice.find_by_number(search_query, 'NONE', options)
invoice = Kaui::Invoice.find_by_number(search_query, false, 'NONE', options)
redirect_to account_invoice_path(invoice.account_id, invoice.invoice_id) and return
rescue KillBillClient::API::NotFound, KillBillClient::API::BadRequest => _e
search_error("No invoice matches \"#{search_query}\"")
Expand Down Expand Up @@ -116,14 +116,14 @@ def payment_search(search_query, search_by = nil, fast = 0, options = {})
def transaction_search(search_query, search_by = nil, _fast = 0, options = {})
if search_by.blank? || search_by == 'ID'
begin
payment = Kaui::Payment.find_by_transaction_id(search_query, false, true, options)
payment = Kaui::Payment.find_by_transaction_id(search_query, false, true, [], 'NONE', options)
redirect_to account_payment_path(payment.account_id, payment.payment_id) and return
rescue KillBillClient::API::NotFound => _e
search_error("No transaction matches \"#{search_query}\"")
end
else
begin
payment = Kaui::Payment.find_by_transaction_external_key(search_query, false, true, 'NONE', options)
payment = Kaui::Payment.find_by_transaction_external_key(search_query, false, true, [], 'NONE', options)
redirect_to account_payment_path(payment.account_id, payment.payment_id) and return
rescue KillBillClient::API::NotFound => _e
search_error("No transaction matches \"#{search_query}\"")
Expand Down Expand Up @@ -198,7 +198,7 @@ def invoice_payment_search(search_query, search_by = nil, _fast = 0, options = {
def subscription_search(search_query, search_by = nil, _fast = 0, options = {})
if search_by.blank? || search_by == 'ID'
begin
subscription = Kaui::Subscription.find_by_id(search_query, options)
subscription = Kaui::Subscription.find_by_id(search_query, 'NONE', options)
redirect_to account_bundles_path(subscription.account_id) and return
rescue KillBillClient::API::NotFound => _e
search_error("No subscription matches \"#{search_query}\"")
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/kaui/invoice_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def edit
invoice_id = params.require(:invoice_id)

# See https://github.com/killbill/killbill/issues/7
invoice = Kaui::Invoice.find_by_id(invoice_id, 'NONE', options_for_klient)
invoice = Kaui::Invoice.find_by_id(invoice_id, false, 'NONE', options_for_klient)
@invoice_item = invoice.items.find { |ii| ii.invoice_item_id == invoice_item_id }

return unless @invoice_item.nil?
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/kaui/invoices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def show
# Go to the database once
cached_options_for_klient = options_for_klient

@invoice = Kaui::Invoice.find_by_id(params.require(:id), 'FULL', cached_options_for_klient)
@invoice = Kaui::Invoice.find_by_id(params.require(:id), false, 'FULL', cached_options_for_klient)
# This will put the TAX items at the bottom
precedence = {
'EXTERNAL_CHARGE' => 0,
Expand Down Expand Up @@ -132,7 +132,7 @@ def show

def void_invoice
cached_options_for_klient = options_for_klient
invoice = KillBillClient::Model::Invoice.find_by_id(params.require(:id), 'NONE', cached_options_for_klient)
invoice = KillBillClient::Model::Invoice.find_by_id(params.require(:id), false, 'NONE', cached_options_for_klient)
begin
invoice.void(current_user.kb_username, params[:reason], params[:comment], cached_options_for_klient)
redirect_to account_invoice_path(invoice.account_id, invoice.invoice_id), notice: 'Invoice successfully voided'
Expand All @@ -143,12 +143,12 @@ def void_invoice
end

def restful_show
invoice = Kaui::Invoice.find_by_id(params.require(:id), 'NONE', options_for_klient)
invoice = Kaui::Invoice.find_by_id(params.require(:id), false, 'NONE', options_for_klient)
redirect_to account_invoice_path(invoice.account_id, invoice.invoice_id)
end

def restful_show_by_number
invoice = Kaui::Invoice.find_by_number(params.require(:number), 'NONE', options_for_klient)
invoice = Kaui::Invoice.find_by_number(params.require(:number), false, 'NONE', options_for_klient)
redirect_to account_invoice_path(invoice.account_id, invoice.invoice_id)
end

Expand All @@ -158,7 +158,7 @@ def show_html

def commit_invoice
cached_options_for_klient = options_for_klient
invoice = KillBillClient::Model::Invoice.find_by_id(params.require(:id), 'NONE', cached_options_for_klient)
invoice = KillBillClient::Model::Invoice.find_by_id(params.require(:id), false, 'NONE', cached_options_for_klient)
invoice.commit(current_user.kb_username, params[:reason], params[:comment], cached_options_for_klient)
redirect_to account_invoice_path(invoice.account_id, invoice.invoice_id), notice: 'Invoice successfully committed'
end
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/kaui/payment_methods_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def create
def destroy
payment_method_id = params[:id]

payment_method = Kaui::PaymentMethod.find_by_id(payment_method_id, false, options_for_klient)
payment_method = Kaui::PaymentMethod.find_by_id(payment_method_id, false, false, [], 'NONE', options_for_klient)
begin
Kaui::PaymentMethod.destroy(payment_method_id, params[:set_auto_pay_off], false, current_user.kb_username, params[:reason], params[:comment], options_for_klient)
redirect_to kaui_engine.account_path(payment_method.account_id), notice: "Payment method #{payment_method_id} successfully deleted"
Expand All @@ -89,7 +89,7 @@ def show
end

def restful_show
payment_method = Kaui::PaymentMethod.find_by_id(params.require(:id), false, options_for_klient)
payment_method = Kaui::PaymentMethod.find_by_id(params.require(:id), false, false, [], 'NONE', options_for_klient)
redirect_to kaui_engine.account_path(payment_method.account_id)
end

Expand All @@ -98,7 +98,7 @@ def validate_external_key
external_key = params.require(:external_key)

begin
payment_methods = Kaui::PaymentMethod.find_by_external_key(external_key, false, false, 'NONE', options_for_klient)
payment_methods = Kaui::PaymentMethod.find_by_external_key(external_key, false, false, [], 'NONE', options_for_klient)
rescue KillBillClient::API::NotFound
payment_methods = nil
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/kaui/payments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def pagination

def new
cached_options_for_klient = options_for_klient
fetch_invoice = promise { Kaui::Invoice.find_by_id(params.require(:invoice_id), 'NONE', cached_options_for_klient) }
fetch_invoice = promise { Kaui::Invoice.find_by_id(params.require(:invoice_id), false, 'NONE', cached_options_for_klient) }
fetch_payment_methods = promise { Kaui::PaymentMethod.find_all_by_account_id(params.require(:account_id), false, cached_options_for_klient) }

@invoice = wait(fetch_invoice)
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/kaui/refunds_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ class RefundsController < Kaui::EngineController
def new
cached_options_for_klient = options_for_klient

fetch_invoice = promise { Kaui::Invoice.find_by_id(params.require(:invoice_id), 'NONE', cached_options_for_klient) }
fetch_invoice = promise { Kaui::Invoice.find_by_id(params.require(:invoice_id), false, 'NONE', cached_options_for_klient) }
fetch_payment = promise { Kaui::InvoicePayment.find_by_id(params.require(:payment_id), false, false, cached_options_for_klient) }

fetch_bundles = promise { @account.bundles(cached_options_for_klient) }

@invoice = wait(fetch_invoice)
Expand All @@ -18,7 +19,7 @@ def new

# rubocop:disable Lint/FloatComparison
def create
invoice = Kaui::Invoice.find_by_id(params.require(:invoice_id), 'NONE', options_for_klient)
invoice = Kaui::Invoice.find_by_id(params.require(:invoice_id), false, 'NONE', options_for_klient)

if params[:adjustment_type] == 'invoiceItemAdjustment'
items = []
Expand Down
16 changes: 8 additions & 8 deletions app/controllers/kaui/subscriptions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def create
end

def edit
@subscription = Kaui::Subscription.find_by_id(params.require(:id), options_for_klient)
@subscription = Kaui::Subscription.find_by_id(params.require(:id), 'NONE', options_for_klient)
_, plans_details = lookup_bundle_and_plan_details(@subscription)
# Use a Set to deal with multiple pricelists
@plans = Set.new.merge(plans_details.map(&:plan))
Expand All @@ -86,7 +86,7 @@ def update

wait_for_completion = params[:wait_for_completion] == '1'

subscription = Kaui::Subscription.find_by_id(params.require(:id), options_for_klient)
subscription = Kaui::Subscription.find_by_id(params.require(:id), 'NONE', options_for_klient)

input = { planName: plan_name }

Expand Down Expand Up @@ -124,21 +124,21 @@ def destroy
else
nil
end
subscription = Kaui::Subscription.find_by_id(params.require(:id), options_for_klient)
subscription = Kaui::Subscription.find_by_id(params.require(:id), 'NONE', options_for_klient)
subscription.cancel(current_user.kb_username, params[:reason], params[:comment], requested_date, entitlement_policy, billing_policy, use_requested_date_for_billing, options_for_klient)
redirect_to kaui_engine.account_bundles_path(subscription.account_id), notice: 'Subscription was successfully cancelled'
end

def reinstate
subscription = Kaui::Subscription.find_by_id(params.require(:id), options_for_klient)
subscription = Kaui::Subscription.find_by_id(params.require(:id), 'NONE', options_for_klient)

subscription.uncancel(current_user.kb_username, params[:reason], params[:comment], options_for_klient)

redirect_to kaui_engine.account_bundles_path(subscription.account_id), notice: 'Subscription was successfully reinstated'
end

def edit_bcd
@subscription = Kaui::Subscription.find_by_id(params.require(:id), options_for_klient)
@subscription = Kaui::Subscription.find_by_id(params.require(:id), 'NONE', options_for_klient)
end

def update_bcd
Expand All @@ -158,7 +158,7 @@ def show
end

def restful_show
subscription = Kaui::Subscription.find_by_id(params.require(:id), options_for_klient)
subscription = Kaui::Subscription.find_by_id(params.require(:id), 'NONE', options_for_klient)
redirect_to kaui_engine.account_bundles_path(subscription.account_id)
end

Expand All @@ -181,7 +181,7 @@ def validate_external_key
external_key = params.require(:external_key)

begin
subscription = Kaui::Subscription.find_by_external_key(external_key, options_for_klient)
subscription = Kaui::Subscription.find_by_external_key(external_key, 'NONE', options_for_klient)
rescue KillBillClient::API::NotFound
subscription = nil
end
Expand All @@ -192,7 +192,7 @@ def validate_external_key

def update_tags
subscription_id = params.require(:id)
subscription = Kaui::Subscription.find_by_id(subscription_id, options_for_klient)
subscription = Kaui::Subscription.find_by_id(subscription_id, 'NONE', options_for_klient)
tags = []
params.each_key do |key|
next unless key.include? 'tag'
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/kaui/transactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Kaui
class TransactionsController < Kaui::EngineController
def restful_show
payment = Kaui::Payment.find_by_transaction_id(params.require(:id), false, true, options_for_klient)
payment = Kaui::Payment.find_by_transaction_id(params.require(:id), false, true, [], 'NONE', options_for_klient)
redirect_to account_payment_path(payment.account_id, payment.payment_id)
end

Expand All @@ -18,7 +18,7 @@ def new
currency: params[:currency],
transaction_type: params[:transaction_type])
else
payment = Kaui::Payment.find_by_transaction_id(transaction_id, false, false, options_for_klient)
payment = Kaui::Payment.find_by_transaction_id(transaction_id, false, false, [], 'NONE', options_for_klient)
@transaction = Kaui::Transaction.build_from_raw_transaction(payment.transactions.find { |tx| tx.transaction_id == transaction_id })
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/kaui/custom_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def self.list_or_search(search_key = nil, offset = 0, limit = 10, options = {})
if search_key.present?
find_in_batches_by_search_key(search_key, offset, limit, options)
else
find_in_batches(offset, limit, options)
find_in_batches(offset, limit, 'NONE', options)
end
end
end
Expand Down
Loading

0 comments on commit 4944870

Please sign in to comment.