Skip to content

✨ server: show friendly decline reasons#1141

Open
aguxez wants to merge 2 commits into
mainfrom
notifications
Open

✨ server: show friendly decline reasons#1141
aguxez wants to merge 2 commits into
mainfrom
notifications

Conversation

@aguxez

@aguxez aguxez commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features
    • Added clearer, normalized decline reasons for declined transactions.
    • Added localized decline reason translations in Spanish and Portuguese.
    • Added friendly push notification messages for supported decline reasons.
  • Bug Fixes
    • Improved handling of varied decline reason formats and unknown errors.
    • Prevented duplicate decline notifications for previously recorded transactions.
  • Tests
    • Expanded coverage for normalized reasons, translations, transaction events, and notifications.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Decline handling now normalizes mapped reasons, stores canonical text, conditionally sends localized push notifications, adds Spanish and Portuguese translations, expands coverage in server tests, and declares patch releases for the server and mobile packages.

Changes

Decline reason mapping and notifications

Layer / File(s) Summary
Decline reason mapping and notification trigger logic
server/hooks/panda.ts
Decline inputs are lowercased and mapped to canonical reasons, unknown values default to transaction declined, and notifications use mapped push reasons only for newly inserted records.
Server-side decline reason tests
server/test/hooks/panda.test.ts
Parameterized tests verify stored reasons, merchant-blocked normalization, localized notification contents, and randomized transaction identifiers.
Decline reason translations
server/i18n/*.json, src/i18n/*.json
Spanish and Portuguese translations are added for card, PIN, merchant, and transaction decline states.
Package release metadata
.changeset/*.md
Patch release changesets are added for @exactly/server and @exactly/mobile.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant reject
  participant TransactionStore
  participant sendPushNotification
  reject->>reject: Normalize and resolve declineReason
  reject->>TransactionStore: Upsert declined transaction
  TransactionStore-->>reject: Return isNew
  reject->>sendPushNotification: Send localized mapped reason when eligible
Loading

Possibly related PRs

  • exactly/exa#622: Both changes update decline-reason mapping and declined push-notification behavior in the Panda hook and its tests.

Suggested reviewers: cruzdanilo, nfmelendez, dieguezguille, franm91

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: server-side handling now shows friendlier decline reasons.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch notifications
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch notifications

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request expands the transaction decline reasons in the Panda webhook hook, normalizing the reasons to lowercase and introducing a pushReason property for customized push notifications. It also adds corresponding translations in Spanish and Portuguese, along with comprehensive test coverage. The review feedback suggests sorting the newly added translation keys alphabetically across all modified translation files to maintain consistency and avoid future merge conflicts.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread server/i18n/es.json Outdated
Comment thread server/i18n/pt.json Outdated
Comment thread src/i18n/es.json
Comment thread src/i18n/pt.json
Comment thread src/i18n/es.json
Comment thread src/i18n/pt.json
Comment thread src/i18n/es.json
Comment thread src/i18n/pt.json

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6291fb3f-2f5c-4a79-a30a-64e1f0121a1c

📥 Commits

Reviewing files that changed from the base of the PR and between f0f3659 and f8e112c.

📒 Files selected for processing (7)
  • .changeset/tall-geese-share.md
  • server/hooks/panda.ts
  • server/i18n/es.json
  • server/i18n/pt.json
  • server/test/hooks/panda.test.ts
  • src/i18n/es.json
  • src/i18n/pt.json

Comment thread server/hooks/panda.ts Outdated
Comment thread server/test/hooks/panda.test.ts Outdated
@changeset-bot

changeset-bot Bot commented Jul 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9021d2e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@exactly/mobile Patch
@exactly/server Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@aguxez
aguxez marked this pull request as ready for review July 13, 2026 11:22

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 749b81ae-a65e-4523-9d53-6b64758891c4

📥 Commits

Reviewing files that changed from the base of the PR and between 1c53e77 and 5e2e44a.

📒 Files selected for processing (9)
  • .changeset/calm-wolves-translate.md
  • .changeset/tall-geese-share.md
  • cspell.json
  • server/hooks/panda.ts
  • server/i18n/es.json
  • server/i18n/pt.json
  • server/test/hooks/panda.test.ts
  • src/i18n/es.json
  • src/i18n/pt.json

Comment thread server/hooks/panda.ts Outdated
Comment thread server/test/hooks/panda.test.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5e2e44a14e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread server/hooks/panda.ts Outdated
Comment thread cspell.json Outdated
@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 55.73770% with 27 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.70%. Comparing base (76a9dc4) to head (9021d2e).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
server/hooks/panda.ts 47.61% 17 Missing and 5 partials ⚠️
server/api/activity.ts 73.68% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1141      +/-   ##
==========================================
- Coverage   73.27%   72.70%   -0.58%     
==========================================
  Files         254      254              
  Lines       10839    11279     +440     
  Branches     3598     3791     +193     
==========================================
+ Hits         7942     8200     +258     
- Misses       2613     2788     +175     
- Partials      284      291       +7     
Flag Coverage Δ
e2e 72.70% <55.73%> (-0.55%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

♻️ Duplicate comments (1)
server/test/hooks/panda.test.ts (1)

3086-3092: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Test expectation should match implementation's .trim() on merchantName.

The implementation at server/hooks/panda.ts uses spend.merchantName.trim(), but the test expectation here passes authorization.json.body.spend.merchantName without .trim(). If the test fixture's merchant name has leading or trailing whitespace, the notification contents won't match and the test will fail.

💚 Proposed fix
-          merchantName: authorization.json.body.spend.merchantName,
+          merchantName: authorization.json.body.spend.merchantName.trim(),

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9cb9ce8a-2122-47bd-9d17-b616e557fa34

📥 Commits

Reviewing files that changed from the base of the PR and between db89620 and f4e8500.

📒 Files selected for processing (8)
  • .changeset/calm-wolves-translate.md
  • .changeset/tall-geese-share.md
  • server/hooks/panda.ts
  • server/i18n/es.json
  • server/i18n/pt.json
  • server/test/hooks/panda.test.ts
  • src/i18n/es.json
  • src/i18n/pt.json

@aguxez
aguxez force-pushed the notifications branch 2 times, most recently from 98fc94a to e872dc9 Compare July 15, 2026 14:48

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e872dc9e11

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread server/hooks/panda.ts Outdated
@aguxez
aguxez force-pushed the notifications branch 2 times, most recently from d0403ef to e9aaf57 Compare July 15, 2026 17:18

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e9aaf5730c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread server/utils/panda.ts Outdated
@aguxez
aguxez force-pushed the notifications branch 2 times, most recently from ab83b45 to 42af7ac Compare July 16, 2026 09:01

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 42af7ac6a5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread server/utils/panda.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 163eac8daf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread server/utils/panda.ts Outdated
Comment thread server/utils/panda.ts Outdated
@aguxez
aguxez force-pushed the notifications branch 2 times, most recently from d99b701 to a610a7e Compare July 16, 2026 11:44

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1e7067bd41

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread server/utils/panda.ts Outdated
@aguxez
aguxez force-pushed the notifications branch 3 times, most recently from 7e8f6da to 8f4cd30 Compare July 16, 2026 13:08

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8f4cd309da

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread server/api/activity.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9021d2eb02

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread server/hooks/panda.ts
COALESCE(${transactions.payload}::jsonb->'bodies', '[]'::jsonb) || ${JSON.stringify([declinedBody])}::jsonb
)`,
},
...(payload.action === "created" && {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Deduplicate declined updated webhooks

When Panda retries a declined updated webhook, the case "updated" path falls through into this same declined reject call, but this guard is only installed for created events. Each retry with the same webhook id therefore appends another body, returns true from .returning(), and the caller sends another declined push notification; apply the event-id setWhere guard to declined updated events as well.

Useful? React with 👍 / 👎.

Comment thread server/hooks/panda.ts
await reject(account, payload, jsonBody, payload.body.spend.declinedReason ?? "transaction declined");
const requestedReason =
payload.body.spend.declinedReason?.toLowerCase() === "webhook declined"
? await getRequestedDeclineReason(payload.body.id, payload.body.spend.cardId)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep local reasons when requested id is absent

When a locally rejected requested authorization omits body.id (still accepted by the requested schema), reject stores that declined row under the webhook payload.id, but a later created webhook with declinedReason: "webhook declined" looks up the saved reason by the created transaction id here. Fresh evidence after the earlier local-decline thread: the schema still makes requested body.id optional, so this lookup misses those rows and falls back to a generic transaction declined notification/activity instead of the saved frozenCard or InsufficientAccountLiquidity reason.

Useful? React with 👍 / 👎.

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.

1 participant