Skip to content
Merged
Show file tree
Hide file tree
Changes from 64 commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
fad88d6
Introducing a Stripe order helper class
wjrosa Aug 21, 2025
2ff8bac
Order meta keys as constants
wjrosa Aug 21, 2025
2f73d5e
Adding deprecation annotation
wjrosa Aug 21, 2025
2d376f5
Additional methods
wjrosa Aug 21, 2025
ce7f7ff
Replacing occurrences
wjrosa Aug 21, 2025
c8a4fa8
Unit test class
wjrosa Aug 21, 2025
ac3638b
Including class
wjrosa Aug 21, 2025
603aeab
Tests update
wjrosa Aug 21, 2025
1bf7c57
Tests update
wjrosa Aug 21, 2025
c68f45b
Replace meta key reference
wjrosa Aug 21, 2025
a754c88
Changelog and readme entries
wjrosa Aug 21, 2025
5748edc
Fix test class name
wjrosa Aug 21, 2025
bd49443
Fix test class name
wjrosa Aug 21, 2025
bff2519
validate_minimum_order_amount
wjrosa Aug 21, 2025
3875e7c
Fix tests
wjrosa Aug 22, 2025
a29267f
Order lock updates
wjrosa Aug 22, 2025
29abdf3
Order lock updates
wjrosa Aug 22, 2025
c38e781
Order lock updates
wjrosa Aug 22, 2025
8fe231c
Payment awaiting action methods
wjrosa Aug 22, 2025
e4844ee
Fix tests
wjrosa Aug 22, 2025
a9ceb2a
Merge branch 'develop' into dev/order-helper-class
wjrosa Sep 15, 2025
d750e3b
Revert unnecessary changes
wjrosa Sep 15, 2025
d69d56c
Revert unnecessary changes
wjrosa Sep 15, 2025
df37c49
Fix merge
wjrosa Sep 15, 2025
67c79d6
Update deprecated comments
wjrosa Sep 15, 2025
e7b670e
Merge branch 'develop' into dev/order-helper-class
wjrosa Sep 17, 2025
fa19b8e
Update includes/abstracts/abstract-wc-stripe-payment-gateway.php
wjrosa Sep 17, 2025
26df456
Update includes/class-wc-stripe-order-helper.php
wjrosa Sep 17, 2025
a222bca
Update includes/class-wc-stripe-order-helper.php
wjrosa Sep 17, 2025
cfe10bb
Update includes/class-wc-stripe-order-helper.php
wjrosa Sep 17, 2025
357fa89
Removing invalid tests
wjrosa Sep 17, 2025
297762c
Revert invalid method calls
wjrosa Sep 17, 2025
0ffe7b3
Update @since comment
wjrosa Sep 17, 2025
b636c2b
Update includes/class-wc-stripe-order-helper.php
wjrosa Sep 17, 2025
cf2c42d
Update includes/class-wc-stripe-order-helper.php
wjrosa Sep 17, 2025
655c2f9
Removing unused order lock param
wjrosa Sep 17, 2025
66bd3f3
Minor improvements to the refund lock code
wjrosa Sep 17, 2025
cf2546c
Adding typed params and return values + singleton pattern
wjrosa Sep 18, 2025
fd604fb
Implementing the new singleton pattern
wjrosa Sep 18, 2025
f5d10a8
Fix tests
wjrosa Sep 18, 2025
ba27b2b
Adding missing type declarations to constants
wjrosa Sep 18, 2025
9706579
Fix static implementations
wjrosa Sep 18, 2025
2aeebbd
Fix wrong lock method call
wjrosa Sep 18, 2025
9ed95f5
Merge branch 'develop' into dev/order-helper-class
wjrosa Sep 18, 2025
463fd2a
Fix static implementations
wjrosa Sep 18, 2025
7670d31
Fix static implementations
wjrosa Sep 18, 2025
305e0cb
Fix tests
wjrosa Sep 18, 2025
8d1a722
Fix remaining static calls
wjrosa Sep 18, 2025
a871fdf
Fix tests
wjrosa Sep 18, 2025
fb5c599
Fix tests
wjrosa Sep 18, 2025
7dd4763
Fix tests
wjrosa Sep 18, 2025
1dfe73e
Merge branch 'develop' into dev/order-helper-class
wjrosa Sep 18, 2025
1726d81
Merge branch 'develop' into dev/order-helper-class
wjrosa Sep 23, 2025
1f9feae
Handling source ID meta in the order helper
wjrosa Sep 23, 2025
bac9ef1
Merge branch 'develop' into dev/handling-source-id-meta
wjrosa Sep 23, 2025
8b5bbac
Handling payment intent, setup intent and refund
wjrosa Sep 23, 2025
d3797fa
Unit tests
wjrosa Sep 23, 2025
e942cb5
Changelog and readme entries
wjrosa Sep 23, 2025
e3631f3
Merge branch 'develop' into dev/handling-source-id-meta
wjrosa Sep 26, 2025
206be4f
Changelog and readme entries
wjrosa Sep 26, 2025
c095e96
Merge branch 'dev/handling-source-id-meta' of https://github.com/wooc…
wjrosa Sep 26, 2025
f683c88
Fix tests
wjrosa Sep 26, 2025
5511198
Fix changelog and readme entries
wjrosa Sep 26, 2025
a63d493
Minor test improvement
wjrosa Sep 26, 2025
8a6f634
Add missing params to update calls
wjrosa Sep 30, 2025
9d38f8b
Fix missing instantiations
wjrosa Sep 30, 2025
7e72073
Merge branch 'develop' into dev/handling-source-id-meta
wjrosa Sep 30, 2025
aece2f6
Merge branch 'develop' into dev/handling-source-id-meta
Oct 1, 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
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*** Changelog ***

= 10.0.0 - xxxx-xx-xx =
* Dev - Expands the Stripe Order Helper class to handle source ID, refund ID, intent ID, and setup intent ID metas
* Update - Removing the `wc_stripe_is_upe_checkout_enabled` filter, as Legacy Checkout is no longer supported
* Dev - Upgrades `jest` to version 29.7.0, `@wordpress/scripts` to 26.19.0, and adds `axios`(version 1.12.2) to the JavaScript development dependencies
* Update - Shows the Stripe account connection modal in settings when the merchant did not connect via OAuth along with a new notice
Expand Down
23 changes: 12 additions & 11 deletions includes/abstracts/abstract-wc-stripe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -1020,14 +1020,15 @@ public function prepare_order_source( $order = null ) {
$stripe_customer->set_id( $stripe_customer_id );
}

$source_id = $order->get_meta( '_stripe_source_id', true );
$order_helper = WC_Stripe_Order_Helper::get_instance();
$source_id = $order_helper->get_stripe_source( $order );

// Since 4.0.0, we changed card to source so we need to account for that.
if ( empty( $source_id ) ) {
$source_id = $order->get_meta( '_stripe_card_id', true );

// Take this opportunity to update the key name.
$order->update_meta_data( '_stripe_source_id', $source_id );
$order_helper->update_stripe_source( $order, $source_id );

if ( is_callable( [ $order, 'save' ] ) ) {
$order->save();
Expand Down Expand Up @@ -1084,7 +1085,7 @@ public function save_source_to_order( $order, $source ) {
}

if ( $source->source ) {
$order->update_meta_data( '_stripe_source_id', $source->source );
WC_Stripe_Order_Helper::get_instance()->update_stripe_source( $order, $source->source );
}

if ( is_callable( [ $order, 'save' ] ) ) {
Expand Down Expand Up @@ -1278,7 +1279,7 @@ public function process_refund( $order_id, $amount = null, $reason = '' ) {
}
}

$order->update_meta_data( '_stripe_refund_id', $response->id );
$order_helper->update_stripe_refund( $order, $response->id );

if ( isset( $response->balance_transaction ) ) {
$this->update_fees( $order, $response->balance_transaction );
Expand Down Expand Up @@ -1686,8 +1687,9 @@ public function save_intent_to_order( $order, $intent ) {
return;
}

$order_helper = WC_Stripe_Order_Helper::get_instance();
if ( 'payment_intent' === $intent->object ) {
WC_Stripe_Order_Helper::get_instance()->add_payment_intent_to_order( $intent->id, $order );
$order_helper->add_payment_intent_to_order( $intent->id, $order );

// TODO: Refactor and add mandate ID support for other payment methods, if necessary.
// The mandate ID is not available for the intent object, so we need to fetch the charge.
Expand All @@ -1700,7 +1702,7 @@ public function save_intent_to_order( $order, $intent ) {
$order->update_meta_data( '_stripe_mandate_id', $charge->payment_method_details->acss_debit->mandate );
}
} elseif ( 'setup_intent' === $intent->object ) {
$order->update_meta_data( '_stripe_setup_intent', $intent->id );
$order_helper->update_stripe_setup_intent( $order );

// Add mandate for free trial subscriptions.
if ( isset( $intent->mandate ) ) {
Expand All @@ -1721,15 +1723,14 @@ public function save_intent_to_order( $order, $intent ) {
* @return obect|bool Either the intent object or `false`.
*/
public function get_intent_from_order( $order ) {
$intent_id = $order->get_meta( '_stripe_intent_id' );

$order_helper = WC_Stripe_Order_Helper::get_instance();
$intent_id = $order_helper->get_stripe_intent( $order );
if ( $intent_id ) {
return $this->get_intent( 'payment_intents', $intent_id );
}

// The order doesn't have a payment intent, but it may have a setup intent.
$intent_id = $order->get_meta( '_stripe_setup_intent' );

$intent_id = $order_helper->get_stripe_setup_intent( $order );
if ( $intent_id ) {
return $this->get_intent( 'setup_intents', $intent_id );
}
Expand Down Expand Up @@ -1918,7 +1919,7 @@ public function setup_intent( $order, $prepared_source ) {
if ( is_wp_error( $setup_intent ) ) {
WC_Stripe_Logger::log( "Unable to create SetupIntent for Order #$order_id: " . print_r( $setup_intent, true ) );
} elseif ( WC_Stripe_Intent_Status::REQUIRES_ACTION === $setup_intent->status ) {
$order->update_meta_data( '_stripe_setup_intent', $setup_intent->id );
WC_Stripe_Order_Helper::get_instance()->update_stripe_setup_intent( $setup_intent->id );
$order->save();

return $setup_intent->client_secret;
Expand Down
24 changes: 11 additions & 13 deletions includes/admin/class-wc-stripe-privacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,8 @@ public function get_privacy_message() {
public function order_data_exporter( $email_address, $page = 1 ) {
$done = false;
$data_to_export = [];

$orders = $this->get_stripe_orders( $email_address, (int) $page );

$done = true;

$orders = $this->get_stripe_orders( $email_address, (int) $page );
$done = true;
if ( 0 < count( $orders ) ) {
foreach ( $orders as $order ) {
$data_to_export[] = [
Expand All @@ -133,7 +130,7 @@ public function order_data_exporter( $email_address, $page = 1 ) {
'data' => [
[
'name' => __( 'Stripe payment id', 'woocommerce-gateway-stripe' ),
'value' => $order->get_meta( '_stripe_source_id', true ),
'value' => WC_Stripe_Order_Helper::get_instance()->get_stripe_source( $order ),
],
[
'name' => __( 'Stripe customer id', 'woocommerce-gateway-stripe' ),
Expand Down Expand Up @@ -367,10 +364,10 @@ protected function maybe_handle_subscription( $order ) {
}

$renewal_orders = class_exists( 'WC_Subscriptions_Renewal_Order' ) ? WC_Subscriptions_Renewal_Order::get_renewal_orders( $order->get_id(), 'WC_Order' ) : [];

foreach ( $renewal_orders as $renewal_order ) {
$renewal_order->delete_meta_data( '_stripe_source_id' );
$renewal_order->delete_meta_data( '_stripe_refund_id' );
$order_helper = WC_Stripe_Order_Helper::get_instance();
$order_helper->delete_stripe_source( $renewal_order );
$order_helper->delete_stripe_refund( $renewal_order );
$renewal_order->delete_meta_data( '_stripe_customer_id' );
}

Expand All @@ -388,8 +385,9 @@ protected function maybe_handle_subscription( $order ) {
* @return array
*/
protected function maybe_handle_order( $order ) {
$stripe_source_id = $order->get_meta( '_stripe_source_id', true );
$stripe_refund_id = $order->get_meta( '_stripe_refund_id', true );
$order_helper = WC_Stripe_Order_Helper::get_instance();
$stripe_source_id = $order_helper->get_stripe_source( $order );
$stripe_refund_id = $order_helper->get_stripe_refund( $order );
$stripe_customer_id = $order->get_meta( '_stripe_customer_id', true );

if ( ! $this->is_retention_expired( $order->get_date_created()->getTimestamp() ) ) {
Expand All @@ -401,8 +399,8 @@ protected function maybe_handle_order( $order ) {
return [ false, false, [] ];
}

$order->delete_meta_data( '_stripe_source_id' );
$order->delete_meta_data( '_stripe_refund_id' );
$order_helper->delete_stripe_source( $order );
$order_helper->delete_stripe_refund( $order );
$order->delete_meta_data( '_stripe_customer_id' );

return [ true, false, [ __( 'Stripe personal data erased.', 'woocommerce-gateway-stripe' ) ] ];
Expand Down
13 changes: 6 additions & 7 deletions includes/class-wc-stripe-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1304,9 +1304,8 @@ private static function should_load_scripts_for_prb_location( $location ) {
* @deprecated 10.0.0 Use WC_Stripe_Order_Helper::add_payment_intent_to_order() instead.
*/
public static function add_payment_intent_to_order( $payment_intent_id, $order ) {

$old_intent_id = $order->get_meta( '_stripe_intent_id' );

$order_helper = WC_Stripe_Order_Helper::get_instance();
$old_intent_id = $order_helper->get_stripe_intent( $order );
if ( $old_intent_id === $payment_intent_id ) {
return;
}
Expand All @@ -1319,7 +1318,7 @@ public static function add_payment_intent_to_order( $payment_intent_id, $order )
)
);

$order->update_meta_data( '_stripe_intent_id', $payment_intent_id );
$order_helper->update_stripe_intent( $order );
$order->save();
}

Expand Down Expand Up @@ -1421,10 +1420,10 @@ public static function get_payment_method_from_intent( $intent ) {
* @deprecated 10.0.0 Use WC_Stripe_Order_Helper::get_intent_id_from_order() instead.
*/
public static function get_intent_id_from_order( $order ) {
$intent_id = $order->get_meta( '_stripe_intent_id' );

$order_helper = WC_Stripe_Order_Helper::get_instance();
$intent_id = $order_helper->get_stripe_intent( $order );
if ( ! $intent_id ) {
$intent_id = $order->get_meta( '_stripe_setup_intent' );
$intent_id = $order_helper->get_stripe_setup_intent( $order );
}

return $intent_id ?? false;
Expand Down
2 changes: 1 addition & 1 deletion includes/class-wc-stripe-intent-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function verify_intent() {
}

// Validate the intent being verified.
$order_intent_id = $order->get_meta( '_stripe_intent_id', true );
$order_intent_id = WC_Stripe_Order_Helper::get_instance()->get_stripe_intent( $order );
if ( ! $order_intent_id || ! isset( $_GET['intent_id'] ) || $order_intent_id !== $_GET['intent_id'] ) {
throw new WC_Stripe_Exception( 'invalid_intent', __( "We're not able to process this payment. Please try again later.", 'woocommerce-gateway-stripe' ) );
}
Expand Down
187 changes: 180 additions & 7 deletions includes/class-wc-stripe-order-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ class WC_Stripe_Order_Helper {
*/
private const META_STRIPE_SOURCE_ID = '_stripe_source_id';

/**
* Meta key for Stripe charge ID.
*
* @var string
*/
private const META_STRIPE_CHARGE_ID = '_stripe_charge_id';

/**
* Meta key for Stripe refund ID.
*
Expand Down Expand Up @@ -267,6 +260,186 @@ public function delete_stripe_net( ?WC_Order $order = null ) {
$order->delete_meta_data( self::LEGACY_META_STRIPE_NET );
}

/**
* Gets the Stripe source for order.
*
* @since 10.0.0
*
* @param WC_Order|null $order
* @return false|string|null
*/
public function get_stripe_source( ?WC_Order $order = null ) {
if ( is_null( $order ) ) {
return false;
}

return $order->get_meta( self::META_STRIPE_SOURCE_ID, true );
}

/**
* Updates the Stripe source for order.
*
* @since 10.0.0
*
* @param WC_Order|null $order
* @param string $source_id
* @return false|void
*/
public function update_stripe_source( ?WC_Order $order = null, string $source_id = '' ) {
if ( is_null( $order ) ) {
return false;
}

$order->update_meta_data( self::META_STRIPE_SOURCE_ID, $source_id );
}

/**
* Deletes the Stripe source for order.
*
* @since 10.0.0
*
* @param WC_Order|null $order
* @return false|void
*/
public function delete_stripe_source( ?WC_Order $order = null ) {
if ( is_null( $order ) ) {
return false;
}

$order->delete_meta_data( self::META_STRIPE_SOURCE_ID );
}

/**
* Updates the Stripe refund for order.
*
* @since 10.0.0
*
* @param WC_Order|null $order
* @return false|string|null
*/
public function get_stripe_refund( ?WC_Order $order = null ) {
if ( is_null( $order ) ) {
return false;
}

return $order->get_meta( self::META_STRIPE_REFUND_ID, true );
}

/**
* Updates the Stripe refund for order.
*
* @since 10.0.0
*
* @param WC_Order|null $order
* @param string $refund_id
* @return false|void
*/
public function update_stripe_refund( ?WC_Order $order = null, string $refund_id = '' ) {
if ( is_null( $order ) ) {
return false;
}

$order->update_meta_data( self::META_STRIPE_REFUND_ID, $refund_id );
}

/**
* Deletes the Stripe refund for order.
*
* @since 10.0.0
*
* @param WC_Order|null $order
* @return false|void
*/
public function delete_stripe_refund( ?WC_Order $order = null ) {
if ( is_null( $order ) ) {
return false;
}

$order->delete_meta_data( self::META_STRIPE_REFUND_ID );
}

/**
* Gets the Stripe intent for order.
*
* @since 10.0.0
*
* @param WC_Order|null $order
* @return false|string|null
*/
public function get_stripe_intent( ?WC_Order $order = null ) {
if ( is_null( $order ) ) {
return false;
}

return $order->get_meta( self::META_STRIPE_INTENT_ID, true );
}

/**
* Updates the Stripe intent for order.
*
* @since 10.0.0
*
* @param WC_Order|null $order
* @param string $intent_id
* @return false|void
*/
public function update_stripe_intent( ?WC_Order $order = null, string $intent_id = '' ) {
if ( is_null( $order ) ) {
return false;
}

$order->update_meta_data( self::META_STRIPE_INTENT_ID, $intent_id );
}

/**
* Deletes the Stripe intent for order.
*
* @since 10.0.0
*
* @param WC_Order|null $order
* @return false|void
*/
public function delete_stripe_intent( ?WC_Order $order = null ) {
if ( is_null( $order ) ) {
return false;
}

$order->delete_meta_data( self::META_STRIPE_INTENT_ID );
}

/**
* Gets the Stripe setup intent for order.
*
* @since 10.0.0
*
* @param WC_Order|null $order
* @return false|string|null
*/
public function get_stripe_setup_intent( ?WC_Order $order = null ) {
if ( is_null( $order ) ) {
return false;
}

return $order->get_meta( self::META_STRIPE_SETUP_INTENT, true );
}

/**
* Updates the Stripe setup intent for order.
*
* @since 10.0.0
*
* @param WC_Order|null $order
* @param string $intent_id
* @return false|void
*/
public function update_stripe_setup_intent( ?WC_Order $order = null, string $intent_id = '' ) {
if ( is_null( $order ) ) {
return false;
}

$order->update_meta_data( self::META_STRIPE_SETUP_INTENT, $intent_id );
}

/**
* Adds payment intent id and order note to order if payment intent is not already saved
*
Expand Down
Loading
Loading