Skip to content

Commit 494341e

Browse files
wjrosaMayishadaledupreez
authored
Handling more Stripe metas with the order helper class (#4705)
* Introducing a Stripe order helper class * Order meta keys as constants * Adding deprecation annotation * Additional methods * Replacing occurrences * Unit test class * Including class * Tests update * Tests update * Replace meta key reference * Changelog and readme entries * Fix test class name * Fix test class name * validate_minimum_order_amount * Fix tests * Order lock updates * Order lock updates * Order lock updates * Payment awaiting action methods * Fix tests * Revert unnecessary changes * Revert unnecessary changes * Fix merge * Update deprecated comments * Update includes/abstracts/abstract-wc-stripe-payment-gateway.php Co-authored-by: Mayisha <[email protected]> * Update includes/class-wc-stripe-order-helper.php Co-authored-by: Mayisha <[email protected]> * Update includes/class-wc-stripe-order-helper.php Co-authored-by: Mayisha <[email protected]> * Update includes/class-wc-stripe-order-helper.php Co-authored-by: Mayisha <[email protected]> * Removing invalid tests * Revert invalid method calls * Update @SInCE comment * Update includes/class-wc-stripe-order-helper.php Co-authored-by: Mayisha <[email protected]> * Update includes/class-wc-stripe-order-helper.php Co-authored-by: Mayisha <[email protected]> * Removing unused order lock param * Minor improvements to the refund lock code * Adding typed params and return values + singleton pattern * Implementing the new singleton pattern * Fix tests * Adding missing type declarations to constants * Fix static implementations * Fix wrong lock method call * Fix static implementations * Fix static implementations * Fix tests * Fix remaining static calls * Fix tests * Fix tests * Fix tests * Handling source ID meta in the order helper * Handling payment intent, setup intent and refund * Unit tests * Changelog and readme entries * Changelog and readme entries * Fix tests * Fix changelog and readme entries * Minor test improvement * Handling more Stripe metas with the order helper class * Card ID meta * UPE payment type * UPE waiting for redirect * UPE redirect processed * Fix tests * Fix method implementation + remove unused method * Changelog and readme entries * Update includes/class-wc-stripe-order-helper.php Co-authored-by: daledupreez <[email protected]> * Fix implementation after method renaming + renaming the card_id method and implementations * Update includes/class-wc-stripe-order-helper.php Co-authored-by: daledupreez <[email protected]> * Changing null check * New protected method to handle meta update * Helper for meta data deletion * Update includes/class-wc-stripe-order-helper.php Co-authored-by: daledupreez <[email protected]> * Doc update * Update includes/class-wc-stripe-order-helper.php Co-authored-by: daledupreez <[email protected]> --------- Co-authored-by: Mayisha <[email protected]> Co-authored-by: daledupreez <[email protected]>
1 parent 1a5d825 commit 494341e

21 files changed

+352
-134
lines changed

changelog.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
*** Changelog ***
22

33
= 10.1.0 - xxxx-xx-xx =
4-
4+
* Dev - Expands the Stripe Order Helper class to handle customer ID, card ID, UPE payment type, and UPE redirect status metas
55

66
= 10.0.0 - 2025-10-14 =
77
* Update - Removes frontend code related to Payment Request Buttons in the checkout page

includes/abstracts/abstract-wc-stripe-payment-gateway-voucher.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,13 @@ public function process_payment( $order_id, $retry = true, $force_save_save = fa
264264

265265
$intent = $this->create_or_update_payment_intent( $order );
266266

267-
$order->update_meta_data( '_stripe_upe_payment_type', $this->stripe_id );
267+
$order_helper = WC_Stripe_Order_Helper::get_instance();
268+
269+
$order_helper->update_stripe_upe_payment_type( $order, $this->stripe_id );
268270
$order->update_status( OrderStatus::PENDING, __( 'Awaiting payment.', 'woocommerce-gateway-stripe' ) );
269271
$order->save();
270272

271-
WC_Stripe_Order_Helper::get_instance()->add_payment_intent_to_order( $intent->id, $order );
273+
$order_helper->add_payment_intent_to_order( $intent->id, $order );
272274

273275
return [
274276
'result' => 'success',
@@ -386,7 +388,7 @@ public function update_payment_intent_ajax() {
386388
$intent = $this->create_or_update_payment_intent( $order );
387389

388390
$order->update_status( OrderStatus::PENDING, __( 'Awaiting payment.', 'woocommerce-gateway-stripe' ) );
389-
$order->update_meta_data( '_stripe_upe_payment_type', $this->stripe_id );
391+
WC_Stripe_Order_Helper::get_instance()->update_stripe_upe_payment_type( $order, $this->stripe_id );
390392
$order->save();
391393

392394
wp_send_json(

includes/abstracts/abstract-wc-stripe-payment-gateway.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ public function maybe_remove_non_existent_customer( $error, $order ) {
330330
}
331331

332332
delete_user_option( $order->get_customer_id(), '_stripe_customer_id' );
333-
$order->delete_meta_data( '_stripe_customer_id' );
333+
WC_Stripe_Order_Helper::get_instance()->delete_stripe_customer_id( $order );
334334
$order->save();
335335

336336
return true;
@@ -410,7 +410,7 @@ public function get_transaction_url( $order ) {
410410
*/
411411
public function get_stripe_customer_id( $order ) {
412412
// Try to get it via the order first.
413-
$customer = $order->get_meta( '_stripe_customer_id', true );
413+
$customer = WC_Stripe_Order_Helper::get_instance()->get_stripe_customer_id( $order );
414414

415415
if ( empty( $customer ) ) {
416416
$customer = get_user_option( '_stripe_customer_id', $order->get_customer_id() );
@@ -1025,7 +1025,7 @@ public function prepare_order_source( $order = null ) {
10251025

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

10301030
// Take this opportunity to update the key name.
10311031
$order_helper->update_stripe_source( $order, $source_id );
@@ -1079,13 +1079,15 @@ public function check_source( $prepared_source ) {
10791079
* @param stdClass $source Source information.
10801080
*/
10811081
public function save_source_to_order( $order, $source ) {
1082+
$order_helper = WC_Stripe_Order_Helper::get_instance();
1083+
10821084
// Store source in the order.
10831085
if ( $source->customer ) {
1084-
$order->update_meta_data( '_stripe_customer_id', $source->customer );
1086+
$order_helper->update_stripe_customer_id( $order, $source->customer );
10851087
}
10861088

10871089
if ( $source->source ) {
1088-
WC_Stripe_Order_Helper::get_instance()->update_stripe_source( $order, $source->source );
1090+
$order_helper->update_stripe_source( $order, $source->source );
10891091
}
10901092

10911093
if ( is_callable( [ $order, 'save' ] ) ) {

includes/admin/class-wc-rest-stripe-orders-controller.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,10 @@ public function create_customer( $request ) {
125125
}
126126
$customer = new WC_Stripe_Customer( $order_user->ID );
127127

128+
$order_helper = WC_Stripe_Order_Helper::get_instance();
129+
128130
// Set the customer ID if known but not already set.
129-
$customer_id = $order->get_meta( '_stripe_customer_id', true );
131+
$customer_id = $order_helper->get_stripe_customer_id( $order );
130132
if ( ! $customer->get_id() && $customer_id ) {
131133
$customer->set_id( $customer_id );
132134
}
@@ -143,7 +145,7 @@ public function create_customer( $request ) {
143145
return new WP_Error( 'stripe_error', $e->getMessage() );
144146
}
145147

146-
$order->update_meta_data( '_stripe_customer_id', $customer_id );
148+
$order_helper->update_stripe_customer_id( $order, $customer_id );
147149
$order->save();
148150

149151
return rest_ensure_response( [ 'id' => $customer_id ] );

includes/admin/class-wc-stripe-privacy.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public function order_data_exporter( $email_address, $page = 1 ) {
120120
$done = false;
121121
$data_to_export = [];
122122
$orders = $this->get_stripe_orders( $email_address, (int) $page );
123+
$order_helper = WC_Stripe_Order_Helper::get_instance();
123124
$done = true;
124125
if ( 0 < count( $orders ) ) {
125126
foreach ( $orders as $order ) {
@@ -130,11 +131,11 @@ public function order_data_exporter( $email_address, $page = 1 ) {
130131
'data' => [
131132
[
132133
'name' => __( 'Stripe payment id', 'woocommerce-gateway-stripe' ),
133-
'value' => WC_Stripe_Order_Helper::get_instance()->get_stripe_source( $order ),
134+
'value' => $order_helper->get_stripe_source( $order ),
134135
],
135136
[
136137
'name' => __( 'Stripe customer id', 'woocommerce-gateway-stripe' ),
137-
'value' => $order->get_meta( '_stripe_customer_id', true ),
138+
'value' => $order_helper->get_stripe_customer_id( $order ),
138139
],
139140
],
140141
];
@@ -368,7 +369,7 @@ protected function maybe_handle_subscription( $order ) {
368369
$order_helper = WC_Stripe_Order_Helper::get_instance();
369370
$order_helper->delete_stripe_source( $renewal_order );
370371
$order_helper->delete_stripe_refund( $renewal_order );
371-
$renewal_order->delete_meta_data( '_stripe_customer_id' );
372+
$order_helper->delete_stripe_customer_id( $renewal_order );
372373
}
373374

374375
$subscription->delete_meta_data( '_stripe_source_id' );
@@ -388,7 +389,7 @@ protected function maybe_handle_order( $order ) {
388389
$order_helper = WC_Stripe_Order_Helper::get_instance();
389390
$stripe_source_id = $order_helper->get_stripe_source( $order );
390391
$stripe_refund_id = $order_helper->get_stripe_refund( $order );
391-
$stripe_customer_id = $order->get_meta( '_stripe_customer_id', true );
392+
$stripe_customer_id = $order_helper->get_stripe_customer_id( $order );
392393

393394
if ( ! $this->is_retention_expired( $order->get_date_created()->getTimestamp() ) ) {
394395
/* translators: %d Order ID */
@@ -401,7 +402,7 @@ protected function maybe_handle_order( $order ) {
401402

402403
$order_helper->delete_stripe_source( $order );
403404
$order_helper->delete_stripe_refund( $order );
404-
$order->delete_meta_data( '_stripe_customer_id' );
405+
$order_helper->delete_stripe_customer_id( $order );
405406

406407
return [ true, false, [ __( 'Stripe personal data erased.', 'woocommerce-gateway-stripe' ) ] ];
407408
}

includes/class-wc-stripe-helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1968,7 +1968,7 @@ public static function validate_intent_for_order( $order, $intent, ?string $sele
19681968
}
19691969

19701970
if ( null === $selected_payment_type ) {
1971-
$selected_payment_type = $order->get_meta( '_stripe_upe_payment_type', true );
1971+
$selected_payment_type = WC_Stripe_Order_Helper::get_instance()->get_stripe_upe_payment_type( $order );
19721972
}
19731973

19741974
// If we don't have a selected payment type, that implies we have no stored value and a new payment type is permitted.

includes/class-wc-stripe-intent-controller.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ public function update_intent( $intent_id = '', $order_id = null, $save_payment_
525525
WC_Stripe_UPE_Payment_Method_Link::STRIPE_ID,
526526
];
527527
}
528-
$order->update_meta_data( '_stripe_upe_payment_type', $selected_upe_payment_type );
528+
$order_helper->update_stripe_upe_payment_type( $order, $selected_upe_payment_type );
529529
}
530530
if ( ! empty( $customer ) && $customer->get_id() ) {
531531
$request['customer'] = $customer->get_id();
@@ -886,7 +886,7 @@ public function create_and_confirm_payment_intent( $payment_information ) {
886886

887887
// Only update the payment_type if we have a reference to the payment type the customer selected.
888888
if ( '' !== $selected_payment_type ) {
889-
$order->update_meta_data( '_stripe_upe_payment_type', $selected_payment_type );
889+
WC_Stripe_Order_Helper::get_instance()->update_stripe_upe_payment_type( $order, $selected_payment_type );
890890
}
891891

892892
return $payment_intent;

includes/class-wc-stripe-order-handler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public function process_redirect_payment( $order_id, $retry = true, $previous_er
170170
// Customer param wrong? The user may have been deleted on stripe's end. Remove customer_id. Can be retried without.
171171
if ( $this->is_no_such_customer_error( $response->error ) ) {
172172
delete_user_option( $order->get_customer_id(), '_stripe_customer_id' );
173-
$order->delete_meta_data( '_stripe_customer_id' );
173+
$order_helper->delete_stripe_customer_id( $order );
174174
$order->save();
175175
}
176176

0 commit comments

Comments
 (0)