@@ -928,22 +928,20 @@ public function process_payment_intent_success( $notification ) {
928
928
break ;
929
929
case 'payment_intent.succeeded ' :
930
930
case 'payment_intent.amount_capturable_updated ' :
931
- $ charge = $ this ->get_latest_charge_from_intent ( $ intent );
932
-
933
931
WC_Stripe_Logger::log ( "Stripe PaymentIntent $ intent ->id succeeded for order $ order_id " );
934
932
935
- /**
936
- * Check if the order is awaiting further action from the customer. If so, do not process the payment via the webhook, let the redirect handle it.
937
- *
938
- * This is a stop-gap to fix a critical issue, see https://github.com/woocommerce/woocommerce-gateway-stripe/issues/2536. It would
939
- * be better if we removed the need for additional meta data in favor of refactoring this part of the payment processing.
940
- */
941
- $ is_awaiting_action = $ order ->get_meta ( '_stripe_upe_waiting_for_redirect ' ) ?? false ;
933
+ $ process_webhook_async = apply_filters ( 'wc_stripe_process_payment_intent_webhook_async ' , true , $ order , $ intent , $ notification );
934
+ $ is_awaiting_action = $ order ->get_meta ( '_stripe_upe_waiting_for_redirect ' ) ?? false ;
935
+
936
+ // Process the webhook now if it's for a voucher or wallet payment , or if filtered to process immediately and order is not awaiting action.
937
+ if ( $ is_voucher_payment || $ is_wallet_payment || ( ! $ process_webhook_async && ! $ is_awaiting_action ) ) {
938
+ $ charge = $ this ->get_latest_charge_from_intent ( $ intent );
942
939
943
- // Voucher payments are only processed via the webhook so are excluded from the above check.
944
- // Wallets are also processed via the webhook, not redirection.
945
- if ( ! $ is_voucher_payment && ! $ is_wallet_payment && $ is_awaiting_action ) {
946
- WC_Stripe_Logger::log ( "Stripe UPE waiting for redirect. Scheduled deferred webhook processing. The status for order $ order_id might need manual adjustment. " );
940
+ do_action ( 'wc_gateway_stripe_process_payment ' , $ charge , $ order );
941
+
942
+ $ this ->process_response ( $ charge , $ order );
943
+ } else {
944
+ WC_Stripe_Logger::log ( "Processing $ notification ->type ( $ intent ->id ) asynchronously for order $ order_id. " );
947
945
948
946
// Schedule a job to check on the status of this intent.
949
947
$ this ->defer_webhook_processing (
@@ -954,14 +952,11 @@ public function process_payment_intent_success( $notification ) {
954
952
]
955
953
);
956
954
957
- do_action ( 'wc_gateway_stripe_process_payment_intent_incomplete ' , $ order );
958
- return ;
955
+ if ( $ is_awaiting_action ) {
956
+ do_action ( 'wc_gateway_stripe_process_payment_intent_incomplete ' , $ order );
957
+ }
959
958
}
960
959
961
- do_action ( 'wc_gateway_stripe_process_payment ' , $ charge , $ order );
962
-
963
- // Process valid response.
964
- $ this ->process_response ( $ charge , $ order );
965
960
break ;
966
961
default :
967
962
if ( $ is_voucher_payment && 'payment_intent.payment_failed ' === $ notification ->type ) {
@@ -1123,6 +1118,11 @@ protected function handle_deferred_payment_intent_succeeded( $order, $intent_id
1123
1118
1124
1119
$ charge = $ this ->get_latest_charge_from_intent ( $ intent );
1125
1120
1121
+ if ( ! $ charge ) {
1122
+ WC_Stripe_Logger::log ( "Skipped processing deferred webhook for Stripe PaymentIntent {$ intent_id } for order {$ order ->get_id ()} - no charge found. " );
1123
+ return ;
1124
+ }
1125
+
1126
1126
WC_Stripe_Logger::log ( "Processing Stripe PaymentIntent {$ intent_id } for order {$ order ->get_id ()} via deferred webhook. " );
1127
1127
1128
1128
do_action ( 'wc_gateway_stripe_process_payment ' , $ charge , $ order );
0 commit comments