Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 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.9.0 - xxxx-xx-xx =
* Dev - Introduces a new helper method to identify Stripe orders
* Fix - Removes the credit card payment method requirement for the Optimized Checkout feature
* Fix - Payment method test instructions not showing up for the Optimized Checkout payment element
* Add - Includes a new notice to highlight the Optimized Checkout feature above the payment methods list in the Stripe settings page
Expand Down
10 changes: 10 additions & 0 deletions includes/class-wc-stripe-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2003,4 +2003,14 @@ public static function is_connected( $mode = null ) {
return isset( $options['publishable_key'], $options['secret_key'] ) && trim( $options['publishable_key'] ) && trim( $options['secret_key'] );
}
}

/**
* Checks if the order is using a Stripe payment method.
*
* @param $order WC_Order The order to check.
* @return bool
*/
public static function is_stripe_gateway_order( $order ) {
return WC_Gateway_Stripe::ID === substr( (string) $order->get_payment_method(), 0, 6 );
}
}
2 changes: 1 addition & 1 deletion includes/class-wc-stripe-order-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ public function prevent_cancelling_orders_awaiting_action( $cancel_order, $order
}

// Bail if payment method is not stripe or `stripe_{apm_method}` or doesn't have an intent yet.
if ( substr( (string) $order->get_payment_method(), 0, 6 ) !== 'stripe' || ! $this->get_intent_from_order( $order ) ) {
if ( ! WC_Stripe_Helper::is_stripe_gateway_order( $order ) || ! $this->get_intent_from_order( $order ) ) {
return $cancel_order;
}

Expand Down
4 changes: 2 additions & 2 deletions includes/class-wc-stripe-webhook-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ public function process_webhook_refund( $notification ) {

$order_id = $order->get_id();

if ( 'stripe' === substr( (string) $order->get_payment_method(), 0, 6 ) ) {
if ( WC_Stripe_Helper::is_stripe_gateway_order( $order ) ) {
$charge = $order->get_transaction_id();
$captured = $order->get_meta( '_stripe_charge_captured' );
$refund_id = $order->get_meta( '_stripe_refund_id' );
Expand Down Expand Up @@ -821,7 +821,7 @@ public function process_webhook_refund_updated( $notification ) {

$order_id = $order->get_id();

if ( 'stripe' === substr( (string) $order->get_payment_method(), 0, 6 ) ) {
if ( WC_Stripe_Helper::is_stripe_gateway_order( $order ) ) {
$charge = $order->get_transaction_id();
$refund_id = $order->get_meta( '_stripe_refund_id' );
$currency = $order->get_currency();
Expand Down
2 changes: 1 addition & 1 deletion includes/compat/class-wc-stripe-subscriptions-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public static function is_subscription_payment_method_detached( $subscription )
return false;
}

if ( 'stripe' !== substr( (string) $subscription->get_payment_method(), 0, 6 ) ) {
if ( ! WC_Stripe_Helper::is_stripe_gateway_order( $subscription ) ) {
// If the payment method is not a Stripe method, we don't need to check further.
return false;
}
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.9.0 - xxxx-xx-xx =
* Dev - Introduces a new helper method to identify Stripe orders
* Fix - Removes the credit card payment method requirement for the Optimized Checkout feature
* Fix - Payment method test instructions not showing up for the Optimized Checkout payment element
* Add - Includes a new notice to highlight the Optimized Checkout feature above the payment methods list in the Stripe settings page
Expand Down
21 changes: 21 additions & 0 deletions tests/phpunit/WC_Stripe_Helper_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -895,4 +895,25 @@ public function is_webhook_url_provider() {
'webhook URL with extra parameters should match' => [ 'https://example.com/test/?wc-api=wc_stripe&foo=bar', 'https://example.com/test/?wc-api=wc_stripe', true ],
];
}

/**
* Tests for `is_stripe_gateway_order`.
*
* @return void
*/
public function test_is_stripe_gateway_order() {
// Test with a Stripe order (Klarna).
$order = WC_Helper_Order::create_order();
$order->set_payment_method( 'stripe_klarna' );
$this->assertTrue( WC_Stripe_Helper::is_stripe_gateway_order( $order ) );

// Test with a non-Stripe order.
$order = WC_Helper_Order::create_order();
$order->set_payment_method( 'cod' );
$this->assertFalse( WC_Stripe_Helper::is_stripe_gateway_order( $order ) );

// Test with an empty order.
$order = new WC_Order();
$this->assertFalse( WC_Stripe_Helper::is_stripe_gateway_order( $order ) );
}
}
Loading