Skip to content
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

Introducing express methods constants #3845

Open
wants to merge 5 commits into
base: dev/improving-handling-of-ece-method-titles
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*** Changelog ***

= 9.2.0 - xxxx-xx-xx =
* Dev - Introduces new payment method constants for the express methods: Google Pay, Apple Pay, Link, and Amazon Pay (backend version).
* Dev - Improves how we handle express payment method titles by introducing new constants and methods to replace duplicate code.
* Fix - Hides "pay" and "cancel" buttons on the order received page when an Amazon Pay order is pending, since it may take a while to be confirmed.
* Dev - Introduces new payment method constants for the express methods: Google Pay, Apple Pay, Link, and Amazon Pay.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public function set_account_keys( WP_REST_Request $request ) {
}
} else {
$upe_gateway = new WC_Stripe_UPE_Payment_Gateway();
$upe_gateway->update_option( 'upe_checkout_experience_accepted_payments', [ WC_Stripe_Payment_Methods::CARD, WC_Stripe_Payment_Methods::LINK ] );
$upe_gateway->update_option( 'upe_checkout_experience_accepted_payments', [ WC_Stripe_Payment_Methods::CARD, WC_Stripe_Express_Payment_Methods::LINK ] );

// Handle Multibanco separately as it is a non UPE method but it is part of the same settings page.
$multibanco = WC_Stripe_Helper::get_legacy_payment_method( 'stripe_multibanco' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public function get_settings() {
/* Settings > Payments accepted on checkout */
'enabled_payment_method_ids' => array_values( array_intersect( $enabled_payment_method_ids, $available_payment_method_ids ) ), // only fetch enabled payment methods that are available.
'available_payment_method_ids' => $available_payment_method_ids,
'ordered_payment_method_ids' => array_values( array_diff( $ordered_payment_method_ids, [ WC_Stripe_Payment_Methods::LINK ] ) ), // exclude Link from this list as it is a express methods.
'ordered_payment_method_ids' => array_values( array_diff( $ordered_payment_method_ids, [ WC_Stripe_Express_Payment_Methods::LINK ] ) ), // exclude Link from this list as it is a express methods.
'individual_payment_method_settings' => $is_upe_enabled ? WC_Stripe_Helper::get_upe_individual_payment_method_settings( $this->gateway ) : WC_Stripe_Helper::get_legacy_individual_payment_method_settings(),

/* Settings > Express checkouts */
Expand Down
2 changes: 1 addition & 1 deletion includes/admin/stripe-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@
$upe_settings['upe_checkout_experience_accepted_payments'] = [
'title' => __( 'Payments accepted on checkout (Early access)', 'woocommerce-gateway-stripe' ),
'type' => 'upe_checkout_experience_accepted_payments',
'default' => [ WC_Stripe_Payment_Methods::CARD, WC_Stripe_Payment_Methods::LINK ],
'default' => [ WC_Stripe_Payment_Methods::CARD, WC_Stripe_Express_Payment_Methods::LINK ],
];
}
// Insert UPE options below the 'logging' setting.
Expand Down
4 changes: 2 additions & 2 deletions includes/class-wc-stripe-blocks-support.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,10 @@ public function add_stripe_intents( PaymentContext $context, PaymentResult &$res
*/
private function add_order_meta( \WC_Order $order, $payment_request_type ) {
$payment_method_suffix = WC_Stripe_Express_Checkout_Helper::get_payment_method_title_suffix();
if ( 'apple_pay' === $payment_request_type ) {
if ( WC_Stripe_Express_Payment_Methods::APPLE_PAY === $payment_request_type ) {
$order->set_payment_method_title( WC_Stripe_Express_Payment_Titles::APPLE_PAY . $payment_method_suffix );
$order->save();
} elseif ( 'google_pay' === $payment_request_type ) {
} elseif ( WC_Stripe_Express_Payment_Methods::GOOGLE_PAY === $payment_request_type ) {
$order->set_payment_method_title( WC_Stripe_Express_Payment_Titles::GOOGLE_PAY . $payment_method_suffix );
$order->save();
} elseif ( 'payment_request_api' === $payment_request_type ) {
Expand Down
4 changes: 2 additions & 2 deletions includes/class-wc-stripe-intent-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -988,13 +988,13 @@ public function is_mandate_data_required( $selected_payment_type, $is_using_save
WC_Stripe_Payment_Methods::BANCONTACT,
WC_Stripe_Payment_Methods::IDEAL,
WC_Stripe_Payment_Methods::SOFORT,
WC_Stripe_Payment_Methods::LINK,
WC_Stripe_Express_Payment_Methods::LINK,
];
if ( in_array( $selected_payment_type, $payment_methods_with_mandates, true ) ) {
return true;
}

return WC_Stripe_Payment_Methods::CARD === $selected_payment_type && in_array( WC_Stripe_Payment_Methods::LINK, $this->get_upe_gateway()->get_upe_enabled_payment_method_ids(), true );
return WC_Stripe_Payment_Methods::CARD === $selected_payment_type && in_array( WC_Stripe_Express_Payment_Methods::LINK, $this->get_upe_gateway()->get_upe_enabled_payment_method_ids(), true );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion includes/compat/trait-wc-stripe-subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -983,7 +983,7 @@ public function maybe_render_subscription_payment_method( $payment_method_to_dis
/* translators: 1) Cash App Cashtag */
$payment_method_to_display = sprintf( __( 'Via Cash App Pay (%1$s)', 'woocommerce-gateway-stripe' ), $source->cashapp->cashtag );
break 3;
case WC_Stripe_Payment_Methods::LINK:
case WC_Stripe_Express_Payment_Methods::LINK:
/* translators: 1) email address associated with the Stripe Link payment method */
$payment_method_to_display = sprintf( __( 'Via Stripe Link (%1$s)', 'woocommerce-gateway-stripe' ), $source->link->email );
break 3;
Expand Down
2 changes: 1 addition & 1 deletion includes/connect/class-wc-stripe-connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ private function get_default_stripe_config() {
}

$result['upe_checkout_experience_enabled'] = 'yes';
$result['upe_checkout_experience_accepted_payments'][] = WC_Stripe_Payment_Methods::LINK;
$result['upe_checkout_experience_accepted_payments'][] = WC_Stripe_Express_Payment_Methods::LINK;

return $result;
}
Expand Down
37 changes: 37 additions & 0 deletions includes/constants/class-wc-stripe-express-payment-methods.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}

/**
* Class WC_Stripe_Express_Payment_Methods
*/
class WC_Stripe_Express_Payment_Methods {
/**
* Amazon Pay payment method.
*
* @string
*/
const AMAZON_PAY = 'amazon_pay';

/**
* Google Pay payment method.
*
* @string
*/
const GOOGLE_PAY = 'google_pay';

/**
* Apple Pay payment method.
*
* @string
*/
const APPLE_PAY = 'apple_pay';

/**
* Link payment method.
*
* @string
*/
const LINK = 'link';
}
20 changes: 18 additions & 2 deletions includes/constants/class-wc-stripe-payment-methods.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}

/**
* Class WC_Stripe_Payment_Methods
*/
Expand All @@ -17,7 +21,6 @@ class WC_Stripe_Payment_Methods {
const GIROPAY = 'giropay';
const IDEAL = 'ideal';
const KLARNA = 'klarna';
const LINK = 'link';
const MULTIBANCO = 'multibanco';
const OXXO = 'oxxo';
const P24 = 'p24';
Expand All @@ -27,7 +30,20 @@ class WC_Stripe_Payment_Methods {
const WECHAT_PAY = 'wechat_pay';
const CARD_PRESENT = 'card_present';
const BACS_DEBIT = 'bacs_debit';
const AMAZON_PAY = 'amazon_pay';

/**
* Use WC_Stripe_Express_Payment_Methods::LINK instead.
*
* @deprecated 9.2.0
*/
const LINK = 'link';

/**
* Use WC_Stripe_Express_Payment_Methods::AMAZON_PAY instead.
*
* @deprecated 9.2.0
*/
const AMAZON_PAY = 'amazon_pay';

/**
* Payment methods that are considered as voucher payment methods.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,10 @@ public function add_order_meta( $order_id, $posted_data ) {

$express_checkout_type = wc_clean( wp_unslash( $_POST['express_checkout_type'] ) );
$payment_method_suffix = WC_Stripe_Express_Checkout_Helper::get_payment_method_title_suffix();
if ( 'apple_pay' === $express_checkout_type ) {
if ( WC_Stripe_Express_Payment_Methods::APPLE_PAY === $express_checkout_type ) {
$order->set_payment_method_title( WC_Stripe_Express_Payment_Titles::APPLE_PAY . $payment_method_suffix );
$order->save();
} elseif ( 'google_pay' === $express_checkout_type ) {
} elseif ( WC_Stripe_Express_Payment_Methods::GOOGLE_PAY === $express_checkout_type ) {
$order->set_payment_method_title( WC_Stripe_Express_Payment_Titles::GOOGLE_PAY . $payment_method_suffix );
$order->save();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ public function __construct() {
*/
public static function get_payment_method_titles( $include_link = false ) {
$titles = [
'apple_pay' => WC_Stripe_Express_Payment_Titles::APPLE_PAY,
'google_pay' => WC_Stripe_Express_Payment_Titles::GOOGLE_PAY,
WC_Stripe_Payment_Methods::AMAZON_PAY => WC_Stripe_Express_Payment_Titles::AMAZON_PAY,
WC_Stripe_Express_Payment_Methods::APPLE_PAY => WC_Stripe_Express_Payment_Titles::APPLE_PAY,
WC_Stripe_Express_Payment_Methods::GOOGLE_PAY => WC_Stripe_Express_Payment_Titles::GOOGLE_PAY,
WC_Stripe_Express_Payment_Methods::AMAZON_PAY => WC_Stripe_Express_Payment_Titles::AMAZON_PAY,
];
if ( $include_link ) {
$titles[ WC_Stripe_Payment_Methods::LINK ] = WC_Stripe_Express_Payment_Titles::LINK;
$titles[ WC_Stripe_Express_Payment_Methods::LINK ] = WC_Stripe_Express_Payment_Titles::LINK;
}
return $titles;
}
Expand Down
20 changes: 10 additions & 10 deletions includes/payment-methods/class-wc-stripe-upe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -1745,13 +1745,13 @@ public function set_payment_method_title_for_order( $order, $payment_method_type

$payment_method = $this->payment_methods[ $payment_method_type ];
$payment_method_id = $payment_method instanceof WC_Stripe_UPE_Payment_Method_CC ? $this->id : $payment_method->id;
$is_stripe_link = WC_Stripe_Payment_Methods::LINK === $payment_method_type ||
( isset( $stripe_payment_method->type ) && WC_Stripe_Payment_Methods::LINK === $stripe_payment_method->type );
$is_stripe_link = WC_Stripe_Express_Payment_Methods::LINK === $payment_method_type ||
( isset( $stripe_payment_method->type ) && WC_Stripe_Express_Payment_Methods::LINK === $stripe_payment_method->type );

// Stripe Link uses the main gateway to process payments, however Link payments should use the title of the Link payment method.
if ( $is_stripe_link && isset( $this->payment_methods[ WC_Stripe_Payment_Methods::LINK ] ) ) {
if ( $is_stripe_link && isset( $this->payment_methods[ WC_Stripe_Express_Payment_Methods::LINK ] ) ) {
$payment_method_id = $this->id;
$payment_method_title = $this->payment_methods[ WC_Stripe_Payment_Methods::LINK ]->get_title( $stripe_payment_method );
$payment_method_title = $this->payment_methods[ WC_Stripe_Express_Payment_Methods::LINK ]->get_title( $stripe_payment_method );
} else {
$payment_method_title = $payment_method->get_title( $stripe_payment_method );
}
Expand Down Expand Up @@ -2394,7 +2394,7 @@ protected function handle_saving_payment_method( WC_Order $order, $payment_metho
$customer->clear_cache();

// If the payment method object is a Link payment method, use the Link payment method instance to create the payment token.
if ( isset( $payment_method_object->type ) && WC_Stripe_Payment_Methods::LINK === $payment_method_object->type ) {
if ( isset( $payment_method_object->type ) && WC_Stripe_Express_Payment_Methods::LINK === $payment_method_object->type ) {
$payment_method_instance = $this->payment_methods['link'];
} else {
$payment_method_instance = $this->payment_methods[ $payment_method_type ];
Expand Down Expand Up @@ -2675,10 +2675,10 @@ private function get_payment_method_types_for_intent_creation(
switch ( $express_payment_type ) {
case WC_Stripe_UPE_Payment_Method_Link::STRIPE_ID:
return [ WC_Stripe_UPE_Payment_Method_CC::STRIPE_ID, WC_Stripe_UPE_Payment_Method_Link::STRIPE_ID ];
case WC_Stripe_Payment_Methods::AMAZON_PAY:
return [ WC_Stripe_Payment_Methods::AMAZON_PAY ];
case 'google_pay':
case 'apple_pay':
case WC_Stripe_Express_Payment_Methods::AMAZON_PAY:
return [ WC_Stripe_Express_Payment_Methods::AMAZON_PAY ];
case WC_Stripe_Express_Payment_Methods::GOOGLE_PAY:
case WC_Stripe_Express_Payment_Methods::APPLE_PAY:
default:
return [ WC_Stripe_UPE_Payment_Method_CC::STRIPE_ID ];
}
Expand Down Expand Up @@ -2732,7 +2732,7 @@ protected function get_upe_gateway_id_for_order( $payment_method ) {
$token_gateway_type = $payment_method->get_retrievable_type();

if ( WC_Stripe_Payment_Methods::CARD === $token_gateway_type ||
WC_Stripe_Payment_Methods::LINK === $token_gateway_type ) {
WC_Stripe_Express_Payment_Methods::LINK === $token_gateway_type ) {
return $this->id;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function __construct() {
* @return string
*/
public function get_title( $payment_details = false ) {
if ( WC_Stripe_Payment_Methods::AMAZON_PAY === ( $payment_details->type ?? null ) ) {
return $this->get_card_wallet_type_title( WC_Stripe_Payment_Methods::AMAZON_PAY );
if ( WC_Stripe_Express_Payment_Methods::AMAZON_PAY === ( $payment_details->type ?? null ) ) {
return $this->get_card_wallet_type_title( WC_Stripe_Express_Payment_Methods::AMAZON_PAY );
}

$wallet_type = $payment_details->card->wallet->type ?? null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class WC_Payment_Token_Link extends WC_Payment_Token implements WC_Stripe_Paymen
*
* @var string
*/
protected $type = WC_Stripe_Payment_Methods::LINK;
protected $type = WC_Stripe_Express_Payment_Methods::LINK;

/**
* Stores Link payment token data.
Expand Down Expand Up @@ -98,7 +98,7 @@ public function set_email( $email ) {
* @inheritDoc
*/
public function is_equal_payment_method( $payment_method ): bool {
if ( WC_Stripe_Payment_Methods::LINK === $payment_method->type
if ( WC_Stripe_Express_Payment_Methods::LINK === $payment_method->type
&& ( $payment_method->link->email ?? null ) === $this->get_email() ) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion includes/payment-tokens/class-wc-stripe-payment-tokens.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public function get_account_saved_payment_methods_list_item( $item, $payment_tok
case WC_Stripe_Payment_Methods::CASHAPP_PAY:
$item['method']['brand'] = esc_html__( 'Cash App Pay', 'woocommerce-gateway-stripe' );
break;
case WC_Stripe_Payment_Methods::LINK:
case WC_Stripe_Express_Payment_Methods::LINK:
$item['method']['brand'] = sprintf(
/* translators: customer email */
esc_html__( 'Stripe Link (%s)', 'woocommerce-gateway-stripe' ),
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
== Changelog ==

= 9.2.0 - xxxx-xx-xx =
* Dev - Introduces new payment method constants for the express methods: Google Pay, Apple Pay, Link, and Amazon Pay (backend version).
* Dev - Improves how we handle express payment method titles by introducing new constants and methods to replace duplicate code.
* Fix - Hides "pay" and "cancel" buttons on the order received page when an Amazon Pay order is pending, since it may take a while to be confirmed.
* Dev - Introduces new payment method constants for the express methods: Google Pay, Apple Pay, Link, and Amazon Pay.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function provide_test_get_title() {
'Amazon Pay' => [
'settings' => [],
'payment details' => [
'type' => WC_Stripe_Payment_Methods::AMAZON_PAY,
'type' => WC_Stripe_Express_Payment_Methods::AMAZON_PAY,
],
'expected' => 'Amazon Pay (Stripe)',
],
Expand All @@ -44,7 +44,7 @@ public function provide_test_get_title() {
'payment details' => [
'card' => [
'wallet' => [
'type' => 'google_pay',
'type' => WC_Stripe_Express_Payment_Methods::GOOGLE_PAY,
],
],
],
Expand Down
1 change: 1 addition & 0 deletions woocommerce-gateway-stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ public function init() {
require_once __DIR__ . '/includes/class-wc-gateway-stripe.php';
require_once __DIR__ . '/includes/constants/class-wc-stripe-currency-code.php';
require_once __DIR__ . '/includes/constants/class-wc-stripe-payment-methods.php';
require_once __DIR__ . '/includes/constants/class-wc-stripe-express-payment-methods.php';
require_once __DIR__ . '/includes/constants/class-wc-stripe-intent-status.php';
require_once __DIR__ . '/includes/constants/class-wc-stripe-express-payment-titles.php';
require_once __DIR__ . '/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php';
Expand Down
Loading