Skip to content

Commit

Permalink
Dont process payment intent success webhooks for wcpay subscription r…
Browse files Browse the repository at this point in the history
…elated intents
  • Loading branch information
james-allan committed Oct 25, 2021
1 parent 93ad1cc commit b4beec9
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions includes/admin/class-wc-rest-payments-webhook-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ private function process_webhook_expired_authorization( $event_body ) {
private function process_webhook_payment_intent_succeeded( $event_body ) {
$event_data = $this->read_rest_property( $event_body, 'data' );
$event_object = $this->read_rest_property( $event_data, 'object' );

$intent_id = $this->read_rest_property( $event_object, 'id' );
$intent_id = $this->read_rest_property( $event_object, 'id' );
$invoice_id = $this->read_rest_property( $event_body, 'invoice' );

// Look up the order related to this charge.
$order = $this->wcpay_db->order_from_intent_id( $intent_id );
Expand All @@ -267,8 +267,14 @@ private function process_webhook_payment_intent_succeeded( $event_body ) {
// Retrieving order with order_id in case intent_id was not properly set.
Logger::debug( 'intent_id not found, using order_id to retrieve order' );
$metadata = $this->read_rest_property( $event_object, 'metadata' );
$order_id = $metadata['order_id'];
$order = $this->wcpay_db->order_from_order_id( $order_id );

if ( isset( $metadata['order_id'] ) ) {
$order_id = $metadata['order_id'];
$order = $this->wcpay_db->order_from_order_id( $order_id );
} elseif ( $invoice_id ) {
// If the payment intent contains an invoice it is a WCPay Subscription-related intent and will be handled by the `invoice.paid` event.
return;
}
}

if ( ! $order ) {
Expand Down

0 comments on commit b4beec9

Please sign in to comment.