Skip to content

Commit 96f4db8

Browse files
committed
wip
1 parent d0aaa0a commit 96f4db8

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

includes/class-wc-payment-gateway-wcpay.php

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,8 +883,12 @@ public function needs_https_setup() {
883883
* @return bool Whether the gateway is enabled and ready to accept payments.
884884
*/
885885
public function is_available() {
886-
// some payment methods should not be available in the payment methods list if they're "express checkout".
886+
// Some payment methods should not be available in the payment methods list if they're "express checkout".
887+
// However, if the user has saved tokens for this express checkout method, we should allow it.
887888
if ( $this->payment_method->is_express_checkout() && ! is_admin() ) {
889+
if ( is_user_logged_in() && ! empty( \WC_Payment_Tokens::get_customer_tokens( get_current_user_id(), $this->id ) ) ) {
890+
return $this->check_base_availability_for_saved_tokens();
891+
}
888892
return false;
889893
}
890894

@@ -950,6 +954,44 @@ protected function check_base_availability() {
950954
return parent::is_available() && ! $this->needs_setup();
951955
}
952956

957+
/**
958+
* Checks availability for express checkout payment methods when used with saved tokens.
959+
* Similar to check_base_availability() but skips the check for payment methods
960+
* enabled at checkout, since express checkout methods like Amazon Pay are not
961+
* in that list but should still be available when the user has saved tokens.
962+
*
963+
* @return bool
964+
*/
965+
protected function check_base_availability_for_saved_tokens() {
966+
if ( ! WC_Payments::get_gateway()->is_enabled() ) {
967+
return false;
968+
}
969+
970+
$payment_method_id = $this->payment_method->get_id();
971+
$processing_payment_method = $this->payment_methods[ $payment_method_id ];
972+
if ( ! $processing_payment_method->is_enabled_at_checkout( $this->get_account_country() ) ) {
973+
return false;
974+
}
975+
976+
$payment_method_statuses = $this->get_upe_enabled_payment_method_statuses();
977+
$stripe_key = $this->get_payment_method_capability_key_map()[ $payment_method_id ] ?? null;
978+
$is_payment_method_active = array_key_exists( $stripe_key, $payment_method_statuses ) && 'active' === $payment_method_statuses[ $stripe_key ]['status'];
979+
if ( false === $is_payment_method_active ) {
980+
return false;
981+
}
982+
983+
// Disable the gateway if using live mode without HTTPS set up or the currency is not
984+
// available in the country of the account.
985+
if ( $this->needs_https_setup() || ! $this->is_available_for_current_currency() ) {
986+
return false;
987+
}
988+
989+
// Skip the check for get_payment_method_ids_enabled_at_checkout() since express checkout
990+
// methods like Amazon Pay are not in that list but should be available for saved tokens.
991+
992+
return parent::is_available() && ! $this->needs_setup();
993+
}
994+
953995
/**
954996
* Checks if the gateway is available for express checkout.
955997
* This bypasses checkout-page-specific restrictions for payment methods

0 commit comments

Comments
 (0)