Skip to content

Commit

Permalink
Don't process payment intent success webhooks for WCPay subscriptions…
Browse files Browse the repository at this point in the history
… related intents (#3199)

* Dont process payment intent success webhooks for wcpay subscription related intents

* Get the invoiceID from the event['data']['object']

* Dont assume the invoice param will always be set in the request

Co-authored-by: mattallan <matt.allan@automattic.com>
  • Loading branch information
james-allan and mattallan authored Oct 25, 2021
1 parent bb0e5f5 commit 89766ab
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 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,7 @@ 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' );

// Look up the order related to this charge.
$order = $this->wcpay_db->order_from_intent_id( $intent_id );
Expand All @@ -267,8 +266,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 ( ! empty( $event_object['invoice'] ) ) {
// 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 89766ab

Please sign in to comment.