mirror of
https://github.com/we-promise/sure.git
synced 2026-08-05 16:42:18 +00:00
* feat(sync): allow EnableBanking credit card balances to be parsed as available credit * feat(ui): expose Enable Banking balance interpretation toggle on credit card form Adds a toggle to the credit card edit dialog, shown only when the account is linked to an Enable Banking provider account. Toggling persists treat_balance_as_available_credit and enqueues an item sync so the balance is reinterpreted immediately. * fix(sync): keep existing balance when credit limit is missing for available-credit cards When treat_balance_as_available_credit is on and the API omits credit_limit, the reported balance is known to be available credit, so recording it as debt fabricates a liability. Skip the balance write in that case and only update the available credit metadata. Also extract the credit card branching into a helper and include provider_key, account_provider and metadata in the debug log entries so support can filter /settings/debug by the affected connection. * refactor(ui): move provider lookup to Account and label the toggle for assistive tech Adds Account#provider_account_for so the view no longer queries account_providers directly, and wires aria-labelledby from the toggle to its visible label. * fix(ui): apply Enable Banking setting only after a successful account update Runs the provider flag update after super and only on the redirect path, so a failed account save no longer persists the flag or enqueues a sync. Also permits the enable_banking params so malformed input is filtered instead of raising. * test(sync): extract relink helper in Enable Banking processor test * feat(sync): fall back to manually set available credit as the credit limit When the toggle is on, the accountable's available_credit field now holds the credit limit (API-provided, or user-entered when the API omits it) and is never overwritten with the reported balance. This lets users whose bank reports available credit without a credit limit compute the outstanding debt by entering their limit in the Available credit field, while keeping the field stable across syncs so a stale reported balance can never be mistaken for a limit. --------- Signed-off-by: Juan José Mata <juanjo.mata@gmail.com> Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
52 lines
2.6 KiB
Plaintext
52 lines
2.6 KiB
Plaintext
<%# locals: (account:, url:) %>
|
|
|
|
<%= render "accounts/form", account: account, url: url do |form| %>
|
|
<%= render "shared/ruler", classes: "my-4" %>
|
|
|
|
<div class="space-y-2">
|
|
<%= form.fields_for :accountable do |credit_card_form| %>
|
|
<div class="flex items-center gap-2">
|
|
<%= credit_card_form.number_field :available_credit,
|
|
label: t("credit_cards.form.available_credit"),
|
|
placeholder: t("credit_cards.form.available_credit_placeholder"),
|
|
min: 0 %>
|
|
</div>
|
|
|
|
<div class="flex items-center gap-2">
|
|
<%= credit_card_form.money_field :minimum_payment,
|
|
label: t("credit_cards.form.minimum_payment"),
|
|
placeholder: t("credit_cards.form.minimum_payment_placeholder"),
|
|
default_currency: Current.family.currency %>
|
|
|
|
<%= credit_card_form.number_field :apr,
|
|
label: t("credit_cards.form.apr"),
|
|
placeholder: t("credit_cards.form.apr_placeholder"),
|
|
min: 0,
|
|
step: 0.01 %>
|
|
</div>
|
|
|
|
<div class="flex items-center gap-2">
|
|
<%= credit_card_form.date_field :expiration_date,
|
|
label: t("credit_cards.form.expiration_date") %>
|
|
<%= credit_card_form.number_field :annual_fee,
|
|
label: t("credit_cards.form.annual_fee"),
|
|
placeholder: t("credit_cards.form.annual_fee_placeholder"),
|
|
min: 0 %>
|
|
</div>
|
|
<% end %>
|
|
|
|
<% enable_banking_account = account.provider_account_for("EnableBankingAccount") if account.persisted? %>
|
|
<% if enable_banking_account %>
|
|
<div class="flex items-center justify-between gap-2">
|
|
<div class="space-y-1">
|
|
<p class="text-sm" id="enable_banking_balance_toggle_label"><%= t("credit_cards.form.treat_balance_as_available_credit_label") %></p>
|
|
<p class="text-secondary text-xs"><%= t("credit_cards.form.treat_balance_as_available_credit_description") %></p>
|
|
</div>
|
|
<%= form.fields_for :enable_banking, enable_banking_account do |eb_form| %>
|
|
<%= eb_form.toggle :treat_balance_as_available_credit, "aria-labelledby": "enable_banking_balance_toggle_label" %>
|
|
<% end %>
|
|
</div>
|
|
<% end %>
|
|
</div>
|
|
<% end %>
|