@@ -257,8 +257,8 @@ private function process_webhook_expired_authorization( $event_body ) {
257
257
private function process_webhook_payment_intent_succeeded ( $ event_body ) {
258
258
$ event_data = $ this ->read_rest_property ( $ event_body , 'data ' );
259
259
$ event_object = $ this ->read_rest_property ( $ event_data , 'object ' );
260
-
261
- $ intent_id = $ this ->read_rest_property ( $ event_object , 'id ' );
260
+ $ intent_id = $ this -> read_rest_property ( $ event_object , ' id ' );
261
+ $ invoice_id = $ this ->read_rest_property ( $ event_body , 'invoice ' );
262
262
263
263
// Look up the order related to this charge.
264
264
$ order = $ this ->wcpay_db ->order_from_intent_id ( $ intent_id );
@@ -267,8 +267,14 @@ private function process_webhook_payment_intent_succeeded( $event_body ) {
267
267
// Retrieving order with order_id in case intent_id was not properly set.
268
268
Logger::debug ( 'intent_id not found, using order_id to retrieve order ' );
269
269
$ metadata = $ this ->read_rest_property ( $ event_object , 'metadata ' );
270
- $ order_id = $ metadata ['order_id ' ];
271
- $ order = $ this ->wcpay_db ->order_from_order_id ( $ order_id );
270
+
271
+ if ( isset ( $ metadata ['order_id ' ] ) ) {
272
+ $ order_id = $ metadata ['order_id ' ];
273
+ $ order = $ this ->wcpay_db ->order_from_order_id ( $ order_id );
274
+ } elseif ( $ invoice_id ) {
275
+ // If the payment intent contains an invoice it is a WCPay Subscription-related intent and will be handled by the `invoice.paid` event.
276
+ return ;
277
+ }
272
278
}
273
279
274
280
if ( ! $ order ) {
0 commit comments