Skip to content

fix(stripe): exclude Klarna from payment methods - #1680

Open
superdav42 wants to merge 2 commits into
mainfrom
feature/auto-20260728-173416
Open

fix(stripe): exclude Klarna from payment methods#1680
superdav42 wants to merge 2 commits into
mainfrom
feature/auto-20260728-173416

Conversation

@superdav42

@superdav42 superdav42 commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Upgrade stripe/stripe-php to v21 so PaymentIntent and SetupIntent support Klarna exclusions.
  • Exclude Klarna in Stripe Elements, PaymentIntents, SetupIntents, and Stripe Checkout sessions.
  • Preserve existing payment-method configuration and card-only Checkout defaults.

Verification

  • vendor/bin/phpunit --filter 'WP_Ultimo\\Gateways\\Stripe_Gateway_Test|WP_Ultimo\\Gateways\\Stripe_Checkout_Gateway_Run_Preflight_Test'
  • vendor/bin/phpcs inc/gateways/class-base-stripe-gateway.php inc/gateways/class-stripe-gateway.php inc/gateways/class-stripe-checkout-gateway.php tests/WP_Ultimo/Gateways/Stripe_Gateway_Test.php tests/WP_Ultimo/Gateways/Stripe_Checkout_Gateway_Run_Preflight_Test.php
  • node_modules/.bin/eslint assets/js/gateways/stripe.js
  • composer validate --no-check-publish --no-interaction

aidevops.sh v3.32.192 plugin for OpenCode v1.18.5 with gpt-5.6-terra

Summary by CodeRabbit

  • New Features

    • Stripe payment forms now hide Klarna by default.
    • Payment method exclusions are applied consistently across payment, checkout, subscription setup, and the billing portal “change payment method” experience.
    • Excluded payment methods can be customized via the existing configuration hook.
  • Bug Fixes

    • Prevented excluded payment methods from showing in Stripe’s payment selection UI.
  • Tests

    • Added/updated tests to verify default behavior and customization of excluded payment method types.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 876b5d41-8e77-4765-8a0f-d30ff35a096b

📥 Commits

Reviewing files that changed from the base of the PR and between 04aa927 and 2bd5a74.

📒 Files selected for processing (1)
  • assets/js/gateways/stripe.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • assets/js/gateways/stripe.js

📝 Walkthrough

Walkthrough

Stripe payment flows now exclude configurable payment method types, defaulting to Klarna. The exclusion list is passed through Checkout, PaymentIntent, SetupIntent, Billing Portal, and Payment Element initialization, with tests covering defaults and customization.

Changes

Stripe payment method exclusions

Layer / File(s) Summary
Exclusion contract and exposure
inc/gateways/class-base-stripe-gateway.php
Adds a filterable Klarna exclusion list and exposes it to Billing Portal and frontend Stripe configuration.
Stripe API payload propagation
inc/gateways/class-stripe-checkout-gateway.php, inc/gateways/class-stripe-gateway.php, composer.json
Adds excluded payment method types to Checkout, PaymentIntent, and SetupIntent payloads, and updates the Stripe PHP constraint.
Frontend configuration and validation
assets/js/gateways/stripe.js, tests/WP_Ultimo/Gateways/*Stripe*Test.php
Configures the Payment Element exclusion list and tests default, filtered, Checkout, PaymentIntent, and SetupIntent arguments.

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

Suggested labels: status:in-review, origin:interactive, type:bug

Sequence Diagram(s)

sequenceDiagram
  participant StripeGateway
  participant StripeCheckoutGateway
  participant StripeAPI
  participant PaymentElement
  StripeGateway->>StripeAPI: Create PaymentIntent or SetupIntent with Klarna excluded
  StripeCheckoutGateway->>StripeAPI: Create Checkout session with Klarna excluded
  StripeGateway->>PaymentElement: Provide excluded payment method types
  PaymentElement->>StripeAPI: Initialize with excludedPaymentMethodTypes
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 summarizes the main change: excluding Klarna from Stripe payment methods.
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 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/auto-20260728-173416

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.

@github-actions

Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@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.

Actionable comments posted: 3

🤖 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.

Inline comments:
In `@inc/gateways/class-base-stripe-gateway.php`:
- Line 923: Update the excluded_payment_method_types assignment in the relevant
Stripe gateway handler to call get_excluded_payment_method_types() on the
membership’s $gateway instance instead of $this, matching how the allowed list
is resolved and preserving gateway-specific filter context.

In `@inc/gateways/class-stripe-checkout-gateway.php`:
- Around line 309-310: Remove the explicit payment_method_types array when
excluded_payment_method_types is supplied at both Checkout session sites:
inc/gateways/class-stripe-checkout-gateway.php lines 309-310 and
inc/gateways/class-base-stripe-gateway.php lines 922-923, preserving the dynamic
exclusion behavior. In
tests/WP_Ultimo/Gateways/Stripe_Checkout_Gateway_Run_Preflight_Test.php lines
442-451, drop excluded_payment_method_types or update the assertion to match the
reconciled session parameters.

In `@tests/WP_Ultimo/Gateways/Stripe_Checkout_Gateway_Run_Preflight_Test.php`:
- Around line 442-451: Update the assertions in the Stripe Checkout preflight
test around captured_session_args to match the supported Checkout contract:
verify either the filtered explicit payment_method_types allow-list or the
Dashboard-managed dynamic payment-method path, rather than requiring both
payment_method_types and excluded_payment_method_types. Reconcile the production
payload first, then adjust the test and mock expectations so they validate the
chosen contract.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f51b191e-80b8-4d5b-8607-ec1cfb45d303

📥 Commits

Reviewing files that changed from the base of the PR and between cde1920 and 04aa927.

⛔ Files ignored due to path filters (1)
  • composer.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • assets/js/gateways/stripe.js
  • composer.json
  • inc/gateways/class-base-stripe-gateway.php
  • inc/gateways/class-stripe-checkout-gateway.php
  • inc/gateways/class-stripe-gateway.php
  • tests/WP_Ultimo/Gateways/Stripe_Checkout_Gateway_Run_Preflight_Test.php
  • tests/WP_Ultimo/Gateways/Stripe_Gateway_Test.php

'client_reference_id' => $customer_id,
'customer' => $s_customer_id,
'payment_method_types' => $allowed_payment_method_types,
'excluded_payment_method_types' => $this->get_excluded_payment_method_types(),

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Resolve exclusions from the membership gateway instance.

The allowed list is resolved from $gateway, but the new exclusion list is resolved from $this. If this handler runs on a different Stripe gateway instance than the membership’s gateway, gateway-specific filters receive the wrong object. Use $gateway->get_excluded_payment_method_types() here.

🤖 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 `@inc/gateways/class-base-stripe-gateway.php` at line 923, Update the
excluded_payment_method_types assignment in the relevant Stripe gateway handler
to call get_excluded_payment_method_types() on the membership’s $gateway
instance instead of $this, matching how the allowed list is resolved and
preserving gateway-specific filter context.

Comment on lines +309 to +310
'payment_method_types' => $allowed_payment_method_types,
'excluded_payment_method_types' => $this->get_excluded_payment_method_types(),

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.

🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail
curl -fsSL 'https://docs.stripe.com/api/checkout/sessions/create' |
  grep -Fq 'This should only be used when payment methods for this Checkout Session are managed through the Stripe Dashboard.'

Repository: Ultimate-Multisite/ultimate-multisite

Length of output: 175


🌐 Web query:

Stripe Checkout sessions create payment_method_types excluded_payment_method_types documentation

💡 Result:

In the Stripe Checkout API, payment_method_types and excluded_payment_method_types are distinct parameters used to control which payment methods are presented to the customer. payment_method_types This parameter is used to explicitly define the list of payment method types (e.g., ['card', 'acss_debit']) to be accepted for a specific Checkout Session [1][2]. If you provide this parameter, Stripe will only offer the payment methods explicitly listed, overriding your default settings in the Stripe Dashboard [3]. If you prefer to manage your payment methods centrally via the Stripe Dashboard (Dynamic Payment Methods), you should omit this parameter [3]. excluded_payment_method_types This parameter is an optional array of payment method types that should be excluded from a Checkout Session [1][4]. It is intended to be used in conjunction with dynamic payment method management [3][5]. When you use this parameter, you can dynamically remove specific methods for a single transaction without having to update your global dashboard settings [3][5]. Key considerations: - Use cases: excluded_payment_method_types is useful when you need granular, per-transaction control that is impractical to manage via global configurations (e.g., excluding certain methods based on the specific items in a cart) [5]. - Exclusions limitations: You cannot use excluded_payment_method_types to hide wallets such as Apple Pay, Google Pay, or Link [3][5]. To control the visibility of these specific methods on a per-transaction basis, you must use the appropriate wallets hash parameters for your integration [3][5]. - Interaction: You can use excluded_payment_method_types alongside your configured payment methods to further refine availability on a case-by-case basis [5].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'Relevant source snippets:\n'
for f in \
  inc/gateways/class-stripe-checkout-gateway.php \
  inc/gateways/class-base-stripe-gateway.php \
  tests/WP_Ultimo/Gateways/Stripe_Checkout_Gateway_Run_Preflight_Test.php
do
  echo "--- $f"
  rg -n "payment_method_types|excluded_payment_method_types|create_checkout_session|get_excluded_payment_method_types|get_allowed_payment_method" "$f" || true
done

printf '\nSurrounding contexts:\n'
sed -n '280,325p' inc/gateways/class-stripe-checkout-gateway.php
printf '\n---\n'
sed -n '880,945p' inc/gateways/class-base-stripe-gateway.php
printf '\n---\n'
sed -n '420,458p' tests/WP_Ultimo/Gateways/Stripe_Checkout_Gateway_Run_Preflight_Test.php

Repository: Ultimate-Multisite/ultimate-multisite

Length of output: 6181


🌐 Web query:

Stripe API Checkout Session excluded_payment_method_types payment_method_types relationship

💡 Result:

In the Stripe API for Checkout Sessions, payment_method_types and excluded_payment_method_types serve different purposes and operate under different management models [1][2][3]. payment_method_types This parameter is used to explicitly define which payment methods to accept for a Checkout Session [2]. When you provide this list, you are manually controlling the availability of payment methods [1][4]. If you choose to manage your payment methods dynamically through the Stripe Dashboard (the recommended approach for most modern integrations), you should avoid passing this parameter in your integration code, as it overrides the dynamic settings [1][4]. excluded_payment_method_types This parameter is used to remove specific payment methods from a transaction on a per-session basis [2][3]. It is intended for use when you are otherwise managing your payment methods dynamically through the Stripe Dashboard [2][5][3]. By using this parameter, you can exclude specific methods (e.g., "affirm" or "acss_debit") while allowing the Dashboard settings to continue determining the availability of all other enabled methods [1][3]. Key Distinctions and Usage: - Relationship: They are largely mutually exclusive in terms of best practices. You should generally rely on either manual specification (payment_method_types) or dynamic dashboard management combined with per-transaction exclusions (excluded_payment_method_types) [1][2][3]. - Exclusions: The excluded_payment_method_types parameter cannot be used to exclude certain wallet-based payment methods such as Apple Pay, Google Pay, or Link [4][3]. To control the visibility of these specific methods for an individual transaction, you must use the appropriate wallets hash parameters within your integration [4][3]. - Flexibility: Using excluded_payment_method_types offers more granular control than simple dashboard configuration, allowing you to tailor payment options based on specific transaction attributes like the items being purchased [3].

Citations:


Don’t send explicit payment_method_types together with exclusions.

Stripe treats payment_method_types as an explicit allow-list and excluded_payment_method_types as a refinement for dynamically configured Checkout methods. Sending both makes the exclusions unreliable. Reconcile this at both Checkout session sites, or drop excluded_payment_method_types from this test and update the assertion.

📍 Affects 3 files
  • inc/gateways/class-stripe-checkout-gateway.php#L309-L310 (this comment)
  • inc/gateways/class-base-stripe-gateway.php#L922-L923
  • tests/WP_Ultimo/Gateways/Stripe_Checkout_Gateway_Run_Preflight_Test.php#L442-L451
🤖 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 `@inc/gateways/class-stripe-checkout-gateway.php` around lines 309 - 310,
Remove the explicit payment_method_types array when
excluded_payment_method_types is supplied at both Checkout session sites:
inc/gateways/class-stripe-checkout-gateway.php lines 309-310 and
inc/gateways/class-base-stripe-gateway.php lines 922-923, preserving the dynamic
exclusion behavior. In
tests/WP_Ultimo/Gateways/Stripe_Checkout_Gateway_Run_Preflight_Test.php lines
442-451, drop excluded_payment_method_types or update the assertion to match the
reconciled session parameters.

Comment on lines +442 to +451
$this->assertSame(
['card'],
$this->captured_session_args['payment_method_types'],
'Stripe Checkout must preserve its card-only default'
);
$this->assertSame(
['klarna'],
$this->captured_session_args['excluded_payment_method_types'],
'Stripe Checkout must exclude Klarna'
);

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.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Align this assertion with the supported Checkout contract.

The test currently requires both payment_method_types and excluded_payment_method_types. Update it after the production payload is reconciled so it verifies either the filtered explicit allow-list or the Dashboard-managed dynamic-method path; the mock cannot catch this API contract issue.

🤖 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 `@tests/WP_Ultimo/Gateways/Stripe_Checkout_Gateway_Run_Preflight_Test.php`
around lines 442 - 451, Update the assertions in the Stripe Checkout preflight
test around captured_session_args to match the supported Checkout contract:
verify either the filtered explicit payment_method_types allow-list or the
Dashboard-managed dynamic payment-method path, rather than requiring both
payment_method_types and excluded_payment_method_types. Reconcile the production
payload first, then adjust the test and mock expectations so they validate the
chosen contract.

@github-actions

Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

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