Skip to content

Commit

Permalink
fix(subscription): raise error in BillSubscription
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-pochet committed Sep 12, 2024
1 parent 8908742 commit 6deec93
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/jobs/bill_subscription_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ def perform(subscriptions, timestamp, invoicing_reason:, invoice: nil, skip_char
def tax_error?(result)
return false unless result.error.is_a?(BaseService::ValidationFailure)

result.error&.messages&.dig(:tax_error)
result.error&.messages&.dig(:tax_error)&.present?
end
end
2 changes: 1 addition & 1 deletion app/jobs/fees/create_pay_in_advance_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def perform(charge:, event:, billing_at: nil)
def tax_error?(result)
return false unless result.error.is_a?(BaseService::ValidationFailure)

result.error&.messages&.dig(:tax_error)
result.error&.messages&.dig(:tax_error).present?
end
end
end
2 changes: 1 addition & 1 deletion app/jobs/invoices/create_pay_in_advance_charge_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def perform(charge:, event:, timestamp:, invoice: nil)
def tax_error?(result)
return false unless result.error.is_a?(BaseService::ValidationFailure)

result.error&.messages&.dig(:tax_error)
result.error&.messages&.dig(:tax_error).present?
end
end
end
2 changes: 1 addition & 1 deletion app/jobs/invoices/finalize_all_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def perform(organization:, invoice_ids:)
def tax_error?(result)
return false unless result.error.is_a?(BaseService::ValidationFailure)

result.error&.messages&.dig(:tax_error)
result.error&.messages&.dig(:tax_error).present?
end
end
end
6 changes: 4 additions & 2 deletions app/services/invoices/create_pay_in_advance_charge_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,10 @@ def refresh_amounts(credit_amount_cents:)
invoice.total_amount_cents -= credit_amount_cents
end

def tax_error?(fee_result)
!fee_result.success? && fee_result.error.messages.dig(:tax_error)
def tax_error?(result)
return false unless result.error.is_a?(BaseService::ValidationFailure)

result.error&.messages&.dig(:tax_error).present?
end

def create_error_detail(code)
Expand Down
4 changes: 3 additions & 1 deletion app/services/invoices/refresh_draft_and_finalize_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def should_deliver_email?
end

def tax_error?(error)
error&.messages&.dig(:tax_error)
return false unless error.is_a?(BaseService::ValidationFailure)

error&.messages&.dig(:tax_error).present?
end
end
end
2 changes: 2 additions & 0 deletions app/services/invoices/refresh_draft_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ def flag_lifetime_usage_for_refresh
end

def tax_error?(error)
return false unless error.is_a?(BaseService::ValidationFailure)

error&.code == 'tax_error'
end

Expand Down
6 changes: 4 additions & 2 deletions app/services/lifetime_usages/recalculate_and_check_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ def progressive_billed_amount
result.progressive_billed_amount
end

def tax_error?(fee_result)
!fee_result.success? && fee_result&.error&.code == 'tax_error'
def tax_error?(result)
return false unless result.error.is_a?(BaseService::ValidationFailure)

result.error&.messages&.dig(:tax_error).present?
end
end
end

0 comments on commit 6deec93

Please sign in to comment.