69
69
use WCPay \Payment_Methods \UPE_Payment_Method ;
70
70
use WCPay \Payment_Methods \Multibanco_Payment_Method ;
71
71
use WCPay \Payment_Methods \Grabpay_Payment_Method ;
72
- use WCPay \Payment_Methods \Wechatpay_Payment_Method ;
73
72
use WCPay \PaymentMethods \Configs \Registry \PaymentMethodDefinitionRegistry ;
74
73
75
74
/**
@@ -1777,6 +1776,34 @@ public function process_payment_for_order( $cart, $payment_information, $schedul
1777
1776
1778
1777
$ this ->maybe_add_customer_notification_note ( $ order , $ processing );
1779
1778
1779
+ // ensuring the payment method title is set before any early return paths to avoid incomplete order data.
1780
+ if ( empty ( $ _POST ['payment_request_type ' ] ) && empty ( $ _POST ['express_payment_type ' ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
1781
+ // Extract payment method details for setting the payment method title.
1782
+ if ( $ payment_needed ) {
1783
+ $ charge = $ intent ? $ intent ->get_charge () : null ;
1784
+ $ payment_method_details = $ charge ? $ charge ->get_payment_method_details () : [];
1785
+ // For payment intents, get payment method type from the intent itself, fallback to charge details.
1786
+ $ payment_method_type = $ intent ? $ intent ->get_payment_method_type () : null ;
1787
+ if ( ! $ payment_method_type && $ payment_method_details ) {
1788
+ $ payment_method_type = $ payment_method_details ['type ' ] ?? null ;
1789
+ }
1790
+
1791
+ if ( 'card ' === $ payment_method_type && isset ( $ payment_method_details ['card ' ]['last4 ' ] ) ) {
1792
+ $ order ->add_meta_data ( 'last4 ' , $ payment_method_details ['card ' ]['last4 ' ], true );
1793
+ if ( isset ( $ payment_method_details ['card ' ]['brand ' ] ) ) {
1794
+ $ order ->add_meta_data ( '_card_brand ' , $ payment_method_details ['card ' ]['brand ' ], true );
1795
+ }
1796
+ $ order ->save_meta_data ();
1797
+ }
1798
+ } else {
1799
+ $ payment_method_details = false ;
1800
+ $ token = $ payment_information ->is_using_saved_payment_method () ? $ payment_information ->get_payment_token () : null ;
1801
+ $ payment_method_type = $ token ? $ this ->get_payment_method_type_for_setup_intent ( $ intent , $ token ) : null ;
1802
+ }
1803
+
1804
+ $ this ->set_payment_method_title_for_order ( $ order , $ payment_method_type , $ payment_method_details );
1805
+ }
1806
+
1780
1807
if ( isset ( $ status ) && Intent_Status::REQUIRES_ACTION === $ status && $ this ->is_changing_payment_method_for_subscription () ) {
1781
1808
// Because we're filtering woocommerce_subscriptions_update_payment_via_pay_shortcode, we need to manually set this delayed update all flag here.
1782
1809
if ( isset ( $ _POST ['update_all_subscriptions_payment_method ' ] ) && wc_clean ( wp_unslash ( $ _POST ['update_all_subscriptions_payment_method ' ] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
@@ -1797,27 +1824,6 @@ public function process_payment_for_order( $cart, $payment_information, $schedul
1797
1824
$ cart ->empty_cart ();
1798
1825
}
1799
1826
1800
- if ( $ payment_needed ) {
1801
- $ charge = $ intent ? $ intent ->get_charge () : null ;
1802
- $ payment_method_details = $ charge ? $ charge ->get_payment_method_details () : [];
1803
- $ payment_method_type = $ payment_method_details ? $ payment_method_details ['type ' ] : null ;
1804
-
1805
- if ( 'card ' === $ payment_method_type && isset ( $ payment_method_details ['card ' ]['last4 ' ] ) ) {
1806
- $ order ->add_meta_data ( 'last4 ' , $ payment_method_details ['card ' ]['last4 ' ], true );
1807
- if ( isset ( $ payment_method_details ['card ' ]['brand ' ] ) ) {
1808
- $ order ->add_meta_data ( '_card_brand ' , $ payment_method_details ['card ' ]['brand ' ], true );
1809
- }
1810
- $ order ->save_meta_data ();
1811
- }
1812
- } else {
1813
- $ payment_method_details = false ;
1814
- $ payment_method_type = $ this ->get_payment_method_type_for_setup_intent ( $ intent , $ token );
1815
- }
1816
-
1817
- if ( empty ( $ _POST ['payment_request_type ' ] ) && empty ( $ _POST ['express_payment_type ' ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
1818
- $ this ->set_payment_method_title_for_order ( $ order , $ payment_method_type , $ payment_method_details );
1819
- }
1820
-
1821
1827
return [
1822
1828
'result ' => 'success ' ,
1823
1829
'redirect ' => $ this ->get_return_url ( $ order ),
@@ -4106,7 +4112,6 @@ public function get_upe_available_payment_methods() {
4106
4112
$ available_methods [] = Klarna_Payment_Method::PAYMENT_METHOD_STRIPE_ID ;
4107
4113
$ available_methods [] = Multibanco_Payment_Method::PAYMENT_METHOD_STRIPE_ID ;
4108
4114
$ available_methods [] = Grabpay_Payment_Method::PAYMENT_METHOD_STRIPE_ID ;
4109
- $ available_methods [] = Wechatpay_Payment_Method::PAYMENT_METHOD_STRIPE_ID ;
4110
4115
4111
4116
// This gets all the registered payment method definitions. As new payment methods are converted from the legacy style, they need to be removed from the list above.
4112
4117
$ payment_method_definitions = PaymentMethodDefinitionRegistry::instance ()->get_all_payment_method_definitions ();
0 commit comments