Skip to content

feat(bank-accounts): self-serve add/update/delete/set-default for ERPNext bank accounts - #513

Merged
islandbitcoin merged 4 commits into
mainfrom
feat/bank-accounts-self-serve
Sep 23, 2026
Merged

islandbitcoin merged 4 commits into
mainfrom
feat/bank-accounts-self-serve

Conversation

@islandbitcoin

Copy link
Copy Markdown
Contributor

What

Customers manage their own Jamaican (ERPNext) bank accounts: add, edit, delete, set default. All changes apply instantly (product decision; ops still reviews every Cashout before paying it). Bridge external accounts already had this and are untouched.

Depends on lnflash/frappe-flash-admin#78, which adds the delete_bank_account endpoint. Deploy that first.

GraphQL

bankAccountAdd(input: BankAccountAddInput!): BankAccountPayload!
bankAccountUpdate(input: BankAccountUpdateInput!): BankAccountPayload!
bankAccountSetDefault(input: BankAccountSetDefaultInput!): BankAccountPayload!
bankAccountDelete(input: BankAccountDeleteInput!): SuccessPayload!

bankAccountUpdateRequest is marked @deprecated and keeps working for older app versions. New error codes: BANK_ACCOUNT_UPGRADE_REQUIRED, BANK_ACCOUNT_NOT_FOUND, BANK_ACCOUNT_DUPLICATE_NUMBER, BANK_ACCOUNT_INVALID.

schema.graphql and dev/apollo-federation/supergraph.graphql are both regenerated and both carry the new fields (the router rejected pendingUpdate in the past because only the subgraph SDL was updated).

Behavior

  • erpParty comes only from the authenticated account, never from input. Update, delete and set-default also check the id is in the caller's own account list before calling ERPNext (the Frappe side checks again).
  • ERPNext service methods call /api/method/admin_panel.api.banking.{add,update,set_default,delete}_bank_account.
  • getBankAccountsByCustomer filters disabled=0 and no longer stops at Frappe's default 20 rows. Cashout ownership checks use the same method, so a removed account cannot be cashed out to.
  • Validation: bank must be in listBanks() (the Frappe endpoint would otherwise create a Bank master from free text), account type Chequing or Savings, currency JMD or USD on add and immutable after, length limits, control / zero-width / bidi characters rejected in text ops reads off a Cashout. At most 10 accounts per customer.
  • ERPNext error text is matched against an allowlist and mapped to our own messages, not forwarded to the customer.
  • A successful add is not reported as a failure when the follow-up read fails.
  • A successful instant update closes any open Bank Account Update Request for that account so a stale approval cannot overwrite it (best effort, logged on failure).
  • Shared per-account rate limit bankAccountManage: 20 writes per hour. New mutations are blocked for API keys, like their sibling.
  • listBanks now requests every bank instead of the first 20.
  • Logs carry the last 4 digits of an account number, never the raw axios error (its request body holds the full number).

Not verified

Nothing here has run against a live ERPNext. The 417 / _server_messages error shape is from Frappe conventions and the sibling branch's source, and needs confirming on TEST.

Tests

4 new spec files plus updates (service methods with mocked axios, app layer, error map, rate limit config). yarn tsc-check, yarn eslint-check, yarn madge-check, yarn check-yaml, yarn check:sdl, typos and lockfile prettier all pass. Full unit suite was green on the feature commit (3241 passed); after the review fixes the touched specs, lint and typecheck were re-run and pass.

🤖 Generated with Claude Code

bobodread876 and others added 4 commits September 20, 2026 20:47
…Next bank accounts

Customers can now manage their ERPNext (Jamaican) cashout bank accounts
instantly, with no admin review:

- ErpNext service: createBankAccount / updateBankAccount / deleteBankAccount /
  setDefaultBankAccount over the admin_panel.api.banking endpoints, with
  duplicate-number, not-owned and validation refusals told apart from generic
  failures. Full account numbers are never logged.
- getBankAccountsByCustomer filters disabled=0, so a soft-deleted account
  vanishes from the app and from the cashout ownership checks.
- App layer: erpParty only from the authenticated account, ownership verified
  before every write, currency locked on update, bank must be a supported
  bank, open update requests closed after an instant edit, shared per-account
  rate limit.
- GraphQL: bankAccountAdd / bankAccountUpdate / bankAccountSetDefault /
  bankAccountDelete (blocked for API keys); bankAccountUpdateRequest deprecated.
- error-map: all new errors plus the previously unmapped bank account errors.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
bankAccountAdd/Update validate bankName against listBanks, so a
truncated list would reject valid banks once ERPNext has more than 20.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
- getBankAccountsByCustomer asks for every row (limit_page_length=0) and
  addBankAccount caps a customer at 10 enabled accounts, so an account can
  no longer land past Frappe's default page of 20 and become invisible.
- ERPNext refusals are allowlisted: only the banking.py refusals map to
  BankAccountValidationError, with flash-owned text; "Unknown ERP customer"
  maps to BankAccountUpgradeRequiredError; any other 417 (missing method,
  Frappe-internal checks) is a generic failure. The error map only shows
  allowlisted BANK_ACCOUNT_INVALID messages.
- validateDetails enforces an account-number format, length limits on
  branch and account name, and rejects control characters and <>.
- BANK_ACCOUNT_DUPLICATE_NUMBER is only returned for a number on the
  customer's own visible accounts (checked locally). An ERPNext duplicate
  refusal for a number the customer cannot see becomes the generic
  BANK_ACCOUNT_INVALID, removing the cross-customer probe. Decision
  recorded in the module header.
- A failed re-read after a committed add/update/set-default logs and
  returns the written values instead of failing the mutation.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…d account name

UNSAFE_TEXT_REGEX only covered C0 controls, DEL and angle brackets, so
zero-width, bidi-override, line-separator, BOM and C1 code points passed
validation. A holder name could display reordered in the ERPNext desk,
where ops compares it against KYC on payout.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants