Skip to content

Show payment methods available in the PMC on settings page #4252

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

Merged
merged 30 commits into from
May 7, 2025
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4dc5a76
Add caching for Stripe payment method configuration
daledupreez Apr 17, 2025
9c95977
Fix the correct method signature
daledupreez Apr 17, 2025
7d19a5a
More method signature fixes
daledupreez Apr 17, 2025
e691516
Move static cache var to get_primary_configuration_from_cache and rem…
diegocurbelo Apr 17, 2025
c945bec
Unify var/func names for all PMC related functions
diegocurbelo Apr 17, 2025
bd79e91
Update PMC function in test mocks
diegocurbelo Apr 17, 2025
2d1c6cd
Merge branch 'develop' into fix/add-caching-for-stripe-configuration
diegocurbelo Apr 21, 2025
987d11f
Fix merge conflicts with renamed constants
diegocurbelo Apr 21, 2025
b095438
Add changelog entry
diegocurbelo Apr 21, 2025
5a3b24c
Revert var/func renames
diegocurbelo Apr 22, 2025
76f3398
Use different transients for live and test mode
diegocurbelo Apr 22, 2025
df468d2
Merge branch 'develop' into fix/add-caching-for-stripe-configuration
diegocurbelo Apr 22, 2025
bdcfae0
Add log if update payment methods configurations fails
diegocurbelo Apr 22, 2025
d1d0655
get available payment methods list from pmc
Mayisha Apr 23, 2025
eadd2e6
move if condition to the gateway class function
Mayisha Apr 23, 2025
91fc00a
Merge branch 'develop' into task/show-pmc-available-methods
Mayisha Apr 24, 2025
a238905
Merge branch 'develop' into task/show-pmc-available-methods
Mayisha Apr 29, 2025
05481fe
rename method
Mayisha Apr 30, 2025
9ed996c
add changelog
Mayisha Apr 30, 2025
b31f59e
Merge branch 'develop' into task/show-pmc-available-methods
Mayisha Apr 30, 2025
e77520b
Merge branch 'develop' into task/show-pmc-available-methods
Mayisha May 5, 2025
d1453bf
force fetch pmc only once
Mayisha May 5, 2025
51e1cc3
revert cleanup
Mayisha May 5, 2025
236025d
add sepa_debit in list of upe available methods
Mayisha May 5, 2025
ec4e43d
fix settings controller tests
Mayisha May 5, 2025
fc0e7b2
remove sepa duplicate entry
Mayisha May 5, 2025
9e37a75
mock configuration and fix tests
Mayisha May 5, 2025
f632a30
remove unused param
Mayisha May 5, 2025
e046a3b
add comments
Mayisha May 6, 2025
72ce5c2
bail if pmc is not enabled
Mayisha May 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion includes/abstracts/abstract-wc-stripe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function get_upe_enabled_payment_method_ids( $force_refresh = false ) {
*
* @return string[]
*/
public function get_upe_available_payment_methods() {
public function get_upe_available_payment_methods( $force_refresh = false ) {
return [ WC_Stripe_Payment_Methods::CARD ];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public function register_routes() {
*/
public function get_settings() {
$is_upe_enabled = WC_Stripe_Feature_Flags::is_upe_checkout_enabled();
$available_payment_method_ids = $is_upe_enabled ? $this->gateway->get_upe_available_payment_methods() : WC_Stripe_Helper::get_legacy_available_payment_method_ids();
$available_payment_method_ids = $is_upe_enabled ? $this->gateway->get_upe_available_payment_methods( true ) : WC_Stripe_Helper::get_legacy_available_payment_method_ids();
$ordered_payment_method_ids = $is_upe_enabled ? WC_Stripe_Helper::get_upe_ordered_payment_method_ids( $this->gateway ) : $available_payment_method_ids;
$enabled_payment_method_ids = $is_upe_enabled ? $this->gateway->get_upe_enabled_payment_method_ids( true ) : WC_Stripe_Helper::get_legacy_enabled_payment_method_ids();

Expand Down
21 changes: 21 additions & 0 deletions includes/class-wc-stripe-payment-method-configurations.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,27 @@ public static function get_parent_configuration_id() {
return self::get_primary_configuration()->parent ?? null;
}

/**
* Get the UPE available payment method IDs.
*
* @param bool $force_refresh Whether to force a refresh of the payment method configuration from Stripe.
* @return array
*/
public static function get_upe_available_payment_methods( $force_refresh = false ) {
$available_payment_method_ids = [];
$merchant_payment_method_configuration = self::get_primary_configuration( $force_refresh );

if ( $merchant_payment_method_configuration ) {
foreach ( $merchant_payment_method_configuration as $payment_method_id => $payment_method ) {
if ( isset( $payment_method->display_preference->value ) && isset( WC_Stripe_UPE_Payment_Gateway::UPE_AVAILABLE_METHODS[ $payment_method_id ] ) ) {
$available_payment_method_ids[] = $payment_method_id;
}
}
}

return $available_payment_method_ids;
}

/**
* Get the UPE enabled payment method IDs.
*
Expand Down
20 changes: 11 additions & 9 deletions includes/payment-methods/class-wc-stripe-upe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class WC_Stripe_UPE_Payment_Gateway extends WC_Gateway_Stripe {
WC_Stripe_Payment_Methods::ALIPAY => WC_Stripe_UPE_Payment_Method_Alipay::class,
WC_Stripe_Payment_Methods::AMAZON_PAY => WC_Stripe_UPE_Payment_Method_Amazon_Pay::class,
WC_Stripe_Payment_Methods::BLIK => WC_Stripe_UPE_Payment_Method_BLIK::class,
WC_Stripe_Payment_Methods::GIROPAY => WC_Stripe_UPE_Payment_Method_Giropay::class,
WC_Stripe_Payment_Methods::KLARNA => WC_Stripe_UPE_Payment_Method_Klarna::class,
WC_Stripe_Payment_Methods::AFFIRM => WC_Stripe_UPE_Payment_Method_Affirm::class,
WC_Stripe_Payment_Methods::AFTERPAY_CLEARPAY => WC_Stripe_UPE_Payment_Method_Afterpay_Clearpay::class,
Expand All @@ -39,7 +38,6 @@ class WC_Stripe_UPE_Payment_Gateway extends WC_Gateway_Stripe {
WC_Stripe_Payment_Methods::OXXO => WC_Stripe_UPE_Payment_Method_Oxxo::class,
WC_Stripe_Payment_Methods::SEPA => WC_Stripe_UPE_Payment_Method_Sepa::class,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this change intentionally part of this PR? I just want to make sure, because it's a minor thing that could have unexpected consequences!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change is intentional. Initially, I changed it to fix some tests. But looking into it deeper, I found that sepa_debit is the right attribute to use here. This array was changed from a plain array to an associative array in this PR #4152. What I missed during the review is WC_Stripe_Payment_Methods::SEPA is associated with WC_Stripe_UPE_Payment_Method_Sepa::class. But if you check the WC_Stripe_UPE_Payment_Method_Sepa class notice that the payment method ID is WC_Stripe_Payment_Methods::SEPA_DEBIT. So WC_Stripe_Payment_Methods::SEPA_DEBIT should be safe and the correct attribute.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough. I wasn't sure whether it should be included in this PR or pushed into its own PR, as it's technically its own fix that may be worth documenting.

WC_Stripe_Payment_Methods::P24 => WC_Stripe_UPE_Payment_Method_P24::class,
WC_Stripe_Payment_Methods::SOFORT => WC_Stripe_UPE_Payment_Method_Sofort::class,
WC_Stripe_Payment_Methods::MULTIBANCO => WC_Stripe_UPE_Payment_Method_Multibanco::class,
WC_Stripe_Payment_Methods::LINK => WC_Stripe_UPE_Payment_Method_Link::class,
WC_Stripe_Payment_Methods::WECHAT_PAY => WC_Stripe_UPE_Payment_Method_Wechat_Pay::class,
Expand Down Expand Up @@ -671,17 +669,21 @@ public function get_upe_enabled_at_checkout_payment_method_ids( $order_id = null
*
* @return string[]
*/
public function get_upe_available_payment_methods() {
$available_payment_methods = [];
public function get_upe_available_payment_methods( $force_refresh = false ) {
// If the payment method configurations API is not enabled, we fallback to the enabled payment methods in the plugin.
if ( ! WC_Stripe_Payment_Method_Configurations::is_enabled() ) {
$available_payment_methods = [];

foreach ( $this->payment_methods as $payment_method ) {
if ( is_callable( [ $payment_method, 'is_available_for_account_country' ] ) && ! $payment_method->is_available_for_account_country() ) {
continue;
foreach ( $this->payment_methods as $payment_method ) {
if ( is_callable( [ $payment_method, 'is_available_for_account_country' ] ) && ! $payment_method->is_available_for_account_country() ) {
continue;
}
$available_payment_methods[] = $payment_method->get_id();
}
$available_payment_methods[] = $payment_method->get_id();
return $available_payment_methods;
}

return $available_payment_methods;
return WC_Stripe_Payment_Method_Configurations::get_upe_available_payment_methods( $force_refresh );
}

/**
Expand Down
Loading