## Linear ticket - https://linear.app/chatwoot/issue/CW-7253/billing-brl-pix-new-users ## Description New accounts that sign up in Brazilian Portuguese are now billed in BRL instead of USD. Their Stripe customer is created with a Brazil address and Portuguese locale (so the Stripe portal offers Real prices and PIX), and the AI credit top-up flow shows packages priced in the account's billing currency. Currency support is config-driven, so adding another currency later is a configuration change rather than a code change. ## Type of change - [ ] New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - https://www.loom.com/share/c8d3d08c1b844ed6b820438d4209491a ## Screenshot <img width="904" height="440" alt="image" src="https://github.com/user-attachments/assets/6f19fad8-e6af-46ea-b99f-b0265bb9eeec" /> ## Checklist: - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my code - [ ] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules
38 lines
1.1 KiB
Ruby
38 lines
1.1 KiB
Ruby
module BillingHelper
|
|
private
|
|
|
|
def default_plan?(account)
|
|
installation_config = InstallationConfig.find_by(name: 'CHATWOOT_CLOUD_PLANS')
|
|
default_plan = installation_config&.value&.first
|
|
|
|
# Return false if not plans are configured, so that no checks are enforced
|
|
return false if default_plan.blank?
|
|
|
|
account.custom_attributes['plan_name'].nil? || account.custom_attributes['plan_name'] == default_plan['name']
|
|
end
|
|
|
|
def conversations_this_month(account)
|
|
account.conversations.where('created_at > ?', 30.days.ago).count
|
|
end
|
|
|
|
def non_web_inboxes(account)
|
|
account.inboxes.where.not(channel_type: Channel::WebWidget.to_s).count
|
|
end
|
|
|
|
def agents(account)
|
|
account.users.count
|
|
end
|
|
|
|
# current_period_end moved to the subscription item in newer Stripe API versions; read both.
|
|
def subscription_period_end(subscription)
|
|
subscription['current_period_end'] || subscription['items']['data'].first&.[]('current_period_end')
|
|
end
|
|
|
|
def subscription_ends_on(subscription)
|
|
period_end = subscription_period_end(subscription)
|
|
return if period_end.blank?
|
|
|
|
Time.zone.at(period_end)
|
|
end
|
|
end
|