-
-
Notifications
You must be signed in to change notification settings - Fork 82
fix(stripe): exclude Klarna from payment methods #1680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -306,13 +306,14 @@ public function run_preflight() { | |
| } | ||
|
|
||
| $subscription_data = [ | ||
| 'payment_method_types' => $allowed_payment_method_types, | ||
| 'success_url' => $redirect_url, | ||
| 'cancel_url' => $this->get_cancel_url(), | ||
| 'billing_address_collection' => 'required', | ||
| 'client_reference_id' => $this->customer->get_id(), | ||
| 'customer' => $s_customer->id, | ||
| 'metadata' => $metadata, | ||
| 'payment_method_types' => $allowed_payment_method_types, | ||
| 'excluded_payment_method_types' => $this->get_excluded_payment_method_types(), | ||
|
Comment on lines
+309
to
+310
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
💡 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.phpRepository: Ultimate-Multisite/ultimate-multisite Length of output: 6181 🌐 Web query:
💡 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 Stripe treats 📍 Affects 3 files
🤖 Prompt for AI Agents |
||
| 'success_url' => $redirect_url, | ||
| 'cancel_url' => $this->get_cancel_url(), | ||
| 'billing_address_collection' => 'required', | ||
| 'client_reference_id' => $this->customer->get_id(), | ||
| 'customer' => $s_customer->id, | ||
| 'metadata' => $metadata, | ||
| ]; | ||
|
|
||
| if ($this->order->should_auto_renew() && $this->order->has_recurring()) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -439,6 +439,16 @@ public function test_run_preflight_subscription_mode_uses_price_ids(): void { | |
| $this->captured_session_args['mode'], | ||
| 'Recurring checkout must use subscription mode' | ||
| ); | ||
| $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' | ||
| ); | ||
|
Comment on lines
+442
to
+451
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 🤖 Prompt for AI Agents |
||
|
|
||
| // Verify line_items exist and use price IDs (not deprecated format) | ||
| $this->assertArrayHasKey( | ||
|
|
||
There was a problem hiding this comment.
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