Skip to content

Commit 02ad93e

Browse files
committed
Merge remote-tracking branch 'origin/release/7.0.2' into trunk
2 parents 7f3cbdd + ce1846d commit 02ad93e

8 files changed

+99
-23
lines changed

changelog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
*** Changelog ***
22

3+
= 7.0.2 - 2023-01-11 =
4+
* Fix - Expand charges object from incoming webhooks using Stripe API version 2022-11-15.
5+
* Fix - Expand refunds on charge object from incoming webhooks using Stripe API version 2022-11-15.
6+
* Fix - Fix critical error on PHP 8+ when php_uname() is disabled
7+
38
= 7.0.1 - 2022-11-11 =
49
* Fix - Issue where subscription renewal payments were being charged twice no longer present.
510

includes/abstracts/abstract-wc-stripe-payment-gateway.php

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,10 +621,13 @@ public function get_owner_details( $order ) {
621621
}
622622

623623
/**
624-
* Get source object by source id.
624+
* Get source object by source ID.
625625
*
626626
* @since 4.0.3
627627
* @param string $source_id The source ID to get source object for.
628+
*
629+
* @throws WC_Stripe_Exception Error while retrieving source object.
630+
* @return string|object
628631
*/
629632
public function get_source_object( $source_id = '' ) {
630633
if ( empty( $source_id ) ) {
@@ -640,6 +643,49 @@ public function get_source_object( $source_id = '' ) {
640643
return $source_object;
641644
}
642645

646+
/**
647+
* Get charge object by charge ID.
648+
*
649+
* @since 7.0.2
650+
* @param string $charge_id The charge ID to get charge object for.
651+
* @param array $params The parameters to pass to the request.
652+
*
653+
* @throws WC_Stripe_Exception Error while retrieving charge object.
654+
* @return string|object
655+
*/
656+
public function get_charge_object( $charge_id = '', $params = [] ) {
657+
if ( empty( $charge_id ) ) {
658+
return '';
659+
}
660+
661+
$charge_object = WC_Stripe_API::request( $params, 'charges/' . $charge_id, 'GET' );
662+
663+
if ( ! empty( $charge_object->error ) ) {
664+
throw new WC_Stripe_Exception( print_r( $charge_object, true ), $charge_object->error->message );
665+
}
666+
667+
return $charge_object;
668+
}
669+
670+
/**
671+
* Get latest charge object from payment intent.
672+
*
673+
* Since API version 2022-11-15, the `charges` property was replaced with `latest_charge`.
674+
* We can remove this method once we drop support for API versions prior to 2022-11-15.
675+
*
676+
* @since 7.0.2
677+
* @param object $intent Stripe API Payment Intent object response.
678+
*
679+
* @return object
680+
*/
681+
public function get_latest_charge_from_intent( $intent ) {
682+
if ( ! empty( $intent->charges->data ) ) {
683+
return end( $intent->charges->data );
684+
} else {
685+
return $this->get_charge_object( $intent->latest_charge );
686+
}
687+
}
688+
643689
/**
644690
* Checks if card is a prepaid card.
645691
*

includes/class-wc-stripe-api.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static function get_user_agent() {
6969
'lang' => 'php',
7070
'lang_version' => phpversion(),
7171
'publisher' => 'woocommerce',
72-
'uname' => php_uname(),
72+
'uname' => function_exists( 'php_uname' ) ? php_uname() : PHP_OS,
7373
'application' => $app_info,
7474
];
7575
}

includes/class-wc-stripe-webhook-handler.php

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@ public function process_webhook_capture( $notification ) {
402402
if ( $this->is_partial_capture( $notification ) ) {
403403
$partial_amount = $this->get_partial_amount_to_charge( $notification );
404404
$order->set_total( $partial_amount );
405-
$this->update_fees( $order, $notification->data->object->refunds->data[0]->balance_transaction );
405+
$refund_object = $this->get_refund_object( $notification );
406+
$this->update_fees( $order, $refund_object->balance_transaction );
406407
/* translators: partial captured amount */
407408
$order->add_order_note( sprintf( __( 'This charge was partially captured via Stripe Dashboard in the amount of: %s', 'woocommerce-gateway-stripe' ), $partial_amount ) );
408409
} else {
@@ -554,11 +555,12 @@ public function process_webhook_refund( $notification ) {
554555
$order_id = $order->get_id();
555556

556557
if ( 'stripe' === $order->get_payment_method() ) {
557-
$charge = $order->get_transaction_id();
558-
$captured = $order->get_meta( '_stripe_charge_captured' );
559-
$refund_id = $order->get_meta( '_stripe_refund_id' );
560-
$currency = $order->get_currency();
561-
$raw_amount = $notification->data->object->refunds->data[0]->amount;
558+
$charge = $order->get_transaction_id();
559+
$captured = $order->get_meta( '_stripe_charge_captured' );
560+
$refund_id = $order->get_meta( '_stripe_refund_id' );
561+
$currency = $order->get_currency();
562+
$refund_object = $this->get_refund_object( $notification );
563+
$raw_amount = $refund_object->amount;
562564

563565
if ( ! in_array( strtolower( $currency ), WC_Stripe_Helper::no_decimal_currencies(), true ) ) {
564566
$raw_amount /= 100;
@@ -580,7 +582,7 @@ public function process_webhook_refund( $notification ) {
580582
}
581583

582584
// If the refund ID matches, don't continue to prevent double refunding.
583-
if ( $notification->data->object->refunds->data[0]->id === $refund_id ) {
585+
if ( $refund_object->id === $refund_id ) {
584586
return;
585587
}
586588

@@ -600,14 +602,14 @@ public function process_webhook_refund( $notification ) {
600602
WC_Stripe_Logger::log( $refund->get_error_message() );
601603
}
602604

603-
$order->update_meta_data( '_stripe_refund_id', $notification->data->object->refunds->data[0]->id );
605+
$order->update_meta_data( '_stripe_refund_id', $refund_object->id );
604606

605-
if ( isset( $notification->data->object->refunds->data[0]->balance_transaction ) ) {
606-
$this->update_fees( $order, $notification->data->object->refunds->data[0]->balance_transaction );
607+
if ( isset( $refund_object->balance_transaction ) ) {
608+
$this->update_fees( $order, $refund_object->balance_transaction );
607609
}
608610

609611
/* translators: 1) amount (including currency symbol) 2) transaction id 3) refund message */
610-
$order->add_order_note( sprintf( __( 'Refunded %1$s - Refund ID: %2$s - %3$s', 'woocommerce-gateway-stripe' ), $amount, $notification->data->object->refunds->data[0]->id, $reason ) );
612+
$order->add_order_note( sprintf( __( 'Refunded %1$s - Refund ID: %2$s - %3$s', 'woocommerce-gateway-stripe' ), $amount, $refund_object->id, $reason ) );
611613
}
612614
}
613615
}
@@ -768,6 +770,25 @@ public function is_partial_capture( $notification ) {
768770
return 0 < $notification->data->object->amount_refunded;
769771
}
770772

773+
/**
774+
* Gets the first refund object from charge notification.
775+
*
776+
* @since 7.0.2
777+
* @param object $notification
778+
*
779+
* @return object
780+
*/
781+
public function get_refund_object( $notification ) {
782+
// Since API version 2022-11-15, the Charge object no longer expands `refunds` by default.
783+
// We can remove this once we drop support for API versions prior to 2022-11-15.
784+
if ( ! empty( $notification->data->object->refunds->data[0] ) ) {
785+
return $notification->data->object->refunds->data[0];
786+
}
787+
788+
$charge = $this->get_charge_object( $notification->data->object->id, [ 'expand' => [ 'refunds' ] ] );
789+
return $charge->refunds->data[0];
790+
}
791+
771792
/**
772793
* Gets the amount refunded.
773794
*
@@ -777,10 +798,11 @@ public function is_partial_capture( $notification ) {
777798
*/
778799
public function get_refund_amount( $notification ) {
779800
if ( $this->is_partial_capture( $notification ) ) {
780-
$amount = $notification->data->object->refunds->data[0]->amount / 100;
801+
$refund_object = $this->get_refund_object( $notification );
802+
$amount = $refund_object->amount / 100;
781803

782804
if ( in_array( strtolower( $notification->data->object->currency ), WC_Stripe_Helper::no_decimal_currencies() ) ) {
783-
$amount = $notification->data->object->refunds->data[0]->amount;
805+
$amount = $refund_object->amount;
784806
}
785807

786808
return $amount;
@@ -845,7 +867,8 @@ public function process_payment_intent_success( $notification ) {
845867
break;
846868
case 'payment_intent.succeeded':
847869
case 'payment_intent.amount_capturable_updated':
848-
$charge = end( $intent->charges->data );
870+
$charge = $this->get_latest_charge_from_intent( $intent );
871+
849872
WC_Stripe_Logger::log( "Stripe PaymentIntent $intent->id succeeded for order $order_id" );
850873

851874
do_action( 'wc_gateway_stripe_process_payment', $charge, $order );

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "woocommerce-gateway-stripe",
33
"title": "WooCommerce Gateway Stripe",
4-
"version": "7.0.1",
4+
"version": "7.0.2",
55
"license": "GPL-3.0",
66
"homepage": "http://wordpress.org/plugins/woocommerce-gateway-stripe/",
77
"repository": {

readme.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Tags: credit card, stripe, apple pay, payment request, google pay, sepa, sofort,
44
Requires at least: 5.7
55
Tested up to: 6.0
66
Requires PHP: 7.0
7-
Stable tag: 7.0.1
7+
Stable tag: 7.0.2
88
License: GPLv3
99
License URI: https://www.gnu.org/licenses/gpl-3.0.html
1010
Attributions: thorsten-stripe
@@ -128,7 +128,9 @@ If you get stuck, you can ask for help in the Plugin Forum.
128128

129129
== Changelog ==
130130

131-
= 7.0.1 - 2022-11-11 =
132-
* Fix - Issue where subscription renewal payments were being charged twice no longer present.
131+
= 7.0.2 - 2023-01-11 =
132+
* Fix - Expand charges object from incoming webhooks using Stripe API version 2022-11-15.
133+
* Fix - Expand refunds on charge object from incoming webhooks using Stripe API version 2022-11-15.
134+
* Fix - Fix critical error on PHP 8+ when php_uname() is disabled
133135

134136
[See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt).

woocommerce-gateway-stripe.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Description: Take credit card payments on your store using Stripe.
66
* Author: WooCommerce
77
* Author URI: https://woocommerce.com/
8-
* Version: 7.0.1
8+
* Version: 7.0.2
99
* Requires at least: 5.8
1010
* Tested up to: 6.0
1111
* WC requires at least: 6.8
@@ -21,7 +21,7 @@
2121
/**
2222
* Required minimums and constants
2323
*/
24-
define( 'WC_STRIPE_VERSION', '7.0.1' ); // WRCS: DEFINED_VERSION.
24+
define( 'WC_STRIPE_VERSION', '7.0.2' ); // WRCS: DEFINED_VERSION.
2525
define( 'WC_STRIPE_MIN_PHP_VER', '7.3.0' );
2626
define( 'WC_STRIPE_MIN_WC_VER', '6.8' );
2727
define( 'WC_STRIPE_FUTURE_MIN_WC_VER', '6.9' );

0 commit comments

Comments
 (0)