Skip to content

Handle webhook pattern for payment#4025

Open
Magnusrm wants to merge 5 commits intomainfrom
feat/use-webhook-support-for-payments-if-available
Open

Handle webhook pattern for payment#4025
Magnusrm wants to merge 5 commits intomainfrom
feat/use-webhook-support-for-payments-if-available

Conversation

@Magnusrm
Copy link
Copy Markdown
Contributor

@Magnusrm Magnusrm commented Feb 27, 2026

Description

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
    • Improved payment completion flow: After successful payment, clicking "Next" now intelligently checks for updated task status and navigates to a new task if available, rather than remaining on the current screen.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 27, 2026

📝 Walkthrough

Walkthrough

The PR modifies payment flow handling by removing automatic payment completion logic from PaymentProvider and adding conditional task navigation in PaymentComponent that refetches process state to determine if task position has changed before proceeding.

Changes

Cohort / File(s) Summary
Payment Provider Cleanup
src/features/payment/PaymentProvider.tsx
Removed automatic skipPayment invocation effect and associated paymentCompleted state, simplifying payment state management.
Task Navigation Logic
src/layout/Payment/PaymentComponent.tsx
Added isChecking state, handleNextClick handler that conditionally refetches process state and compares task IDs to determine navigation, and integrated useProcessQuery and useNavigateToTask hooks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The PR description uses the correct template structure but is largely incomplete with critical information missing. Add a detailed description of changes, fill in the related issue number, and complete the verification/QA checklist. Ensure automated tests are addressed and clarify whether documentation updates are needed.
Title check ❓ Inconclusive The title 'Handle webhook pattern for payment' is vague and generic; it lacks specificity about what aspect of webhook handling is being implemented or changed. Clarify the title with concrete details about the specific change, such as 'Stop auto-calling process next on payment completion' or 'Refactor payment status handling to use webhook updates'.

✏️ 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 feat/use-webhook-support-for-payments-if-available

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 added kind/product-feature Pull requests containing new features backport-ignore This PR is a new feature and should not be cherry-picked onto release branches squad/utforming Issues that belongs to the named squad. labels Feb 27, 2026
@Magnusrm Magnusrm marked this pull request as ready for review March 3, 2026 16:23
@Magnusrm
Copy link
Copy Markdown
Contributor Author

Magnusrm commented Mar 3, 2026

/publish

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 3, 2026

PR release:

  • <link rel="stylesheet" type="text/css" href="https://altinncdn.no/toolkits/altinn-app-frontend/4.25.3-pr.4052.use-webhook-support-for-payments-if-available.80ac129b/altinn-app-frontend.css">
  • <script src="https://altinncdn.no/toolkits/altinn-app-frontend/4.25.3-pr.4052.use-webhook-support-for-payments-if-available.80ac129b/altinn-app-frontend.js"></script>

⚙️ Building...
✅ Done!

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/features/payment/PaymentProvider.tsx`:
- Around line 65-67: The component currently treats missing applicationMetadata
as "no webhook" which allows skipPayment() to run prematurely; update the logic
around useApplicationMetadata and supportsPaymentWebhook so auto-advance is
gated until applicationMetadata is resolved — e.g., derive a tri-state
(unknown/true/false) by not calling supportsPaymentWebhook or by returning
undefined when applicationMetadata is undefined, then ensure the code paths that
call skipPayment(), auto-advance, or branches using supportsPaymentWebhook
(references: useApplicationMetadata, applicationMetadata,
supportsPaymentWebhook, skipPayment) explicitly check for metadata being
resolved (applicationMetadata !== undefined) or for supportsPaymentWebhook !==
undefined before proceeding so skipPayment only runs once webhook capability is
known.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1f5b22a and 80ac129.

📒 Files selected for processing (3)
  • src/features/payment/PaymentProvider.tsx
  • src/layout/Payment/PaymentComponent.tsx
  • src/utils/versioning/versions.ts

Comment on lines +65 to +67
const applicationMetadata = useApplicationMetadata();
const supportsPaymentWebhook = appSupportsPaymentWebhook(applicationMetadata?.altinnNugetVersion);

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.

⚠️ Potential issue | 🟠 Major

Gate auto-advance until application metadata is resolved.

Right now, unknown metadata is treated as “no webhook support”, so skipPayment() may still run before webhook capability is known.

Suggested fix
   const applicationMetadata = useApplicationMetadata();
-  const supportsPaymentWebhook = appSupportsPaymentWebhook(applicationMetadata?.altinnNugetVersion);
+  const hasResolvedApplicationMetadata = applicationMetadata !== undefined;
+  const supportsPaymentWebhook = applicationMetadata
+    ? appSupportsPaymentWebhook(applicationMetadata.altinnNugetVersion)
+    : false;
@@
   useEffect(() => {
+    if (!hasResolvedApplicationMetadata) {
+      return;
+    }
     if (isPaymentProcess && paymentCompleted && !isPdf && !supportsPaymentWebhook) {
       skipPayment();
     }
-  }, [isPaymentProcess, paymentCompleted, skipPayment, isPdf, supportsPaymentWebhook]);
+  }, [
+    hasResolvedApplicationMetadata,
+    isPaymentProcess,
+    paymentCompleted,
+    skipPayment,
+    isPdf,
+    supportsPaymentWebhook,
+  ]);

Also applies to: 93-97

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/features/payment/PaymentProvider.tsx` around lines 65 - 67, The component
currently treats missing applicationMetadata as "no webhook" which allows
skipPayment() to run prematurely; update the logic around useApplicationMetadata
and supportsPaymentWebhook so auto-advance is gated until applicationMetadata is
resolved — e.g., derive a tri-state (unknown/true/false) by not calling
supportsPaymentWebhook or by returning undefined when applicationMetadata is
undefined, then ensure the code paths that call skipPayment(), auto-advance, or
branches using supportsPaymentWebhook (references: useApplicationMetadata,
applicationMetadata, supportsPaymentWebhook, skipPayment) explicitly check for
metadata being resolved (applicationMetadata !== undefined) or for
supportsPaymentWebhook !== undefined before proceeding so skipPayment only runs
once webhook capability is known.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Mar 5, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
4.1% Coverage on New Code (required ≥ 45%)
0.0% Condition Coverage on New Code (required ≥ 45%)

See analysis details on SonarQube Cloud

@Magnusrm
Copy link
Copy Markdown
Contributor Author

Magnusrm commented Mar 5, 2026

/publish

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 5, 2026

PR release:

  • <link rel="stylesheet" type="text/css" href="https://altinncdn.no/toolkits/altinn-app-frontend/4.25.3-pr.4083.use-webhook-support-for-payments-if-available.cd3f8eb5/altinn-app-frontend.css">
  • <script src="https://altinncdn.no/toolkits/altinn-app-frontend/4.25.3-pr.4083.use-webhook-support-for-payments-if-available.cd3f8eb5/altinn-app-frontend.js"></script>

⚙️ Building...
✅ Done!

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

Labels

backport-ignore This PR is a new feature and should not be cherry-picked onto release branches kind/product-feature Pull requests containing new features squad/utforming Issues that belongs to the named squad.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant