Skip to content

Commit b4beec9

Browse files
committed
Dont process payment intent success webhooks for wcpay subscription related intents
1 parent 93ad1cc commit b4beec9

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

includes/admin/class-wc-rest-payments-webhook-controller.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,8 @@ private function process_webhook_expired_authorization( $event_body ) {
257257
private function process_webhook_payment_intent_succeeded( $event_body ) {
258258
$event_data = $this->read_rest_property( $event_body, 'data' );
259259
$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' );
262262

263263
// Look up the order related to this charge.
264264
$order = $this->wcpay_db->order_from_intent_id( $intent_id );
@@ -267,8 +267,14 @@ private function process_webhook_payment_intent_succeeded( $event_body ) {
267267
// Retrieving order with order_id in case intent_id was not properly set.
268268
Logger::debug( 'intent_id not found, using order_id to retrieve order' );
269269
$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+
}
272278
}
273279

274280
if ( ! $order ) {

0 commit comments

Comments
 (0)