Skip to content

Add retry for fetching paymentInformation#4259

Merged
Magnusrm merged 1 commit into
mainfrom
fix/retry-fetching-payment-info-when-webhook-temporarily-locks-instance-data
Jun 11, 2026
Merged

Add retry for fetching paymentInformation#4259
Magnusrm merged 1 commit into
mainfrom
fix/retry-fetching-payment-info-when-webhook-temporarily-locks-instance-data

Conversation

@Magnusrm

@Magnusrm Magnusrm commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Description

Adds retry with exponential backoff to the payment information query (GET …/payment), mirroring the existing instance-data query policy (retry: 3).

Returning from the hosted payment page races with the payment webhook that advances the process. In that window the endpoint can briefly fail (a momentarily locked data element, or a transient 5xx/network blip). With no retry, a single bad response immediately rendered the DisplayError page and stranded the user after a completed payment. Retrying a few times lets the backend settle before any error surfaces.

Related Issue(s)

  • closes #{issue number}

Verification/QA

  • Manual functionality testing
    • I have tested these changes manually
    • Creator of the original issue (or service owner) has been contacted for manual testing (or will be contacted when released in alpha)
    • No testing done/necessary
  • Automated tests
    • Unit test(s) have been added/updated
    • Cypress E2E test(s) have been added/updated
    • No automatic tests are needed here (no functional changes/additions)
    • I want someone to help me make some tests
  • UU/WCAG (follow these guidelines until we have our own)
    • I have tested with a screen reader/keyboard navigation/automated wcag validator
    • No testing done/necessary (no DOM/visual changes)
    • I want someone to help me perform accessibility testing
  • User documentation @ altinn-studio-docs
    • Has been added/updated
    • No functionality has been changed/added, so no documentation is needed
    • I will do that later/have created an issue
  • Support in Altinn Studio
    • Issue(s) created for support in Studio
    • This change/feature does not require any changes to Altinn Studio
  • Sprint board
    • The original issue (or this PR itself) has been added to the Team Apps project and to the current sprint board
    • I don't have permissions to do that, please help me out
  • Labels
    • I have added a kind/* and backport* label to this PR for proper release notes grouping
    • I don't have permissions to add labels, please help me out

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced payment processing reliability by implementing automatic retry logic to handle temporary service disruptions without interrupting transactions.

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This pull request adds retry logic with exponential backoff to the payment information query in PaymentInformationProvider.tsx. The change applies consistent retry semantics (up to 3 retries with capped delay) to both the webhooks-enabled and non-webhooks code paths, including comments on the race condition between payment returns and webhook progression.

Changes

Payment Query Retry Configuration

Layer / File(s) Summary
Payment information query retry with exponential backoff
src/features/payment/PaymentInformationProvider.tsx
Added retry configuration to usePaymentInformationQueryDef with exponential backoff and capped delay for both webhooks-supported and non-webhooks query paths. Includes inline documentation of the race condition between hosted payment return and webhook advancement, and the rationale for retrying transient failures.

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and clearly summarizes the main change: adding retry logic to payment information fetching.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.
Description check ✅ Passed The pull request description is comprehensive and complete, addressing all required sections including description, related issues, and verification/QA with appropriate selections.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/retry-fetching-payment-info-when-webhook-temporarily-locks-instance-data

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 and usage tips.

@Magnusrm Magnusrm changed the title add retry for fetching instandeInformation Add retry for fetching paymentInformation Jun 10, 2026
@Magnusrm Magnusrm added backport This PR should be cherry-picked onto older release branches kind/bug Something isn't working labels Jun 10, 2026
@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/features/payment/PaymentInformationProvider.tsx (1)

34-49: ⚡ Quick win

Use queryOptions + object-managed query key for both payment query branches.

Both branches still return raw option objects directly. To match repo guidance and keep retry/query config centrally composable, wrap these definitions with TanStack queryOptions and use object segments in query keys consistently.

♻️ Suggested refactor
+import { queryOptions, skipToken, useQuery } from '`@tanstack/react-query`';
...
   if (appSupportsPaymentWebhooks(altinnNugetVersion)) {
-    return {
-      queryKey: ['fetchPaymentInfoForTask', instanceId, selectedLanguage],
+    return queryOptions({
+      queryKey: ['fetchPaymentInfoForTask', { instanceId, selectedLanguage, taskId }] as const,
       queryFn: instanceId ? () => fetchPaymentInformationForTask(instanceId, selectedLanguage, taskId) : skipToken,
       enabled: enabled && !!instanceId,
       retry: 3,
       retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 30000),
-    };
+    });
   } else {
-    return {
-      queryKey: ['fetchPaymentInfo'],
+    return queryOptions({
+      queryKey: ['fetchPaymentInfo', { instanceId, selectedLanguage }] as const,
       queryFn: instanceId ? () => fetchPaymentInformation(instanceId, selectedLanguage) : skipToken,
       enabled: enabled && !!instanceId,
       gcTime: 0,
       retry: 3,
       retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 30000),
-    };
+    });
   }

As per coding guidelines, "Use objects for managing query keys and functions with queryOptions for sharing TanStack Query configuration across the system for central management".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/features/payment/PaymentInformationProvider.tsx` around lines 34 - 49,
Replace the raw option objects returned in PaymentInformationProvider with
TanStack queryOptions and use object-based query keys: build an object key
(e.g., { scope: 'fetchPaymentInfoForTask', instanceId, selectedLanguage, taskId
} or { scope: 'fetchPaymentInfo', instanceId, selectedLanguage }) and return
queryOptions({ queryKey: thatObject, queryFn: instanceId ? () =>
fetchPaymentInformationForTask(instanceId, selectedLanguage, taskId) :
skipToken, enabled: enabled && !!instanceId, retry: 3, retryDelay:
(attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 30000) }) for the task
branch and similarly use queryOptions with the fetchPaymentInformation queryFn
for the other branch (preserve gcTime: 0 on the non-task branch inside
queryOptions).

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/features/payment/PaymentInformationProvider.tsx`:
- Around line 34-49: Replace the raw option objects returned in
PaymentInformationProvider with TanStack queryOptions and use object-based query
keys: build an object key (e.g., { scope: 'fetchPaymentInfoForTask', instanceId,
selectedLanguage, taskId } or { scope: 'fetchPaymentInfo', instanceId,
selectedLanguage }) and return queryOptions({ queryKey: thatObject, queryFn:
instanceId ? () => fetchPaymentInformationForTask(instanceId, selectedLanguage,
taskId) : skipToken, enabled: enabled && !!instanceId, retry: 3, retryDelay:
(attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 30000) }) for the task
branch and similarly use queryOptions with the fetchPaymentInformation queryFn
for the other branch (preserve gcTime: 0 on the non-task branch inside
queryOptions).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e14916df-b0a0-4fc9-9834-e81ca6b5f486

📥 Commits

Reviewing files that changed from the base of the PR and between 4ac8801 and fe52199.

📒 Files selected for processing (1)
  • src/features/payment/PaymentInformationProvider.tsx

@Magnusrm Magnusrm moved this to 🔎 In review in Team Altinn Studio Jun 11, 2026

@olemartinorg olemartinorg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🙌

@Magnusrm Magnusrm merged commit a24e3e0 into main Jun 11, 2026
20 of 25 checks passed
@Magnusrm Magnusrm deleted the fix/retry-fetching-payment-info-when-webhook-temporarily-locks-instance-data branch June 11, 2026 11:01
@github-project-automation github-project-automation Bot moved this from 🔎 In review to ✅ Done in Team Altinn Studio Jun 11, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Automatic backport successful!

A backport PR has been automatically created for the release/v4.31 release branch.

The release branch release/v4.31 already existed and was updated.

The cherry-pick was clean with no conflicts. Please review the backport PR when it appears.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR should be cherry-picked onto older release branches kind/bug Something isn't working

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

2 participants