diff --git a/modules/ppcp-wc-subscriptions/src/Helper/SubscriptionHelper.php b/modules/ppcp-wc-subscriptions/src/Helper/SubscriptionHelper.php index 45e4817287..1853bc69cd 100644 --- a/modules/ppcp-wc-subscriptions/src/Helper/SubscriptionHelper.php +++ b/modules/ppcp-wc-subscriptions/src/Helper/SubscriptionHelper.php @@ -19,8 +19,6 @@ use WC_Subscriptions_Product; use WCS_Manual_Renewal_Manager; use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException; -use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway; -use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway; /** * Class SubscriptionHelper @@ -295,18 +293,19 @@ public function previous_transaction( WC_Subscription $subscription ): string { return ''; } - // Sort orders by key descending. - krsort( $orders ); - - // Removes first order (the current processing order). - unset( $orders[ array_key_first( $orders ) ] ); + // Sort orders by oder ID descending. + rsort( $orders ); + $current_order = wc_get_order( array_shift( $orders ) ); + if ( ! $current_order instanceof WC_Order ) { + return ''; + } foreach ( $orders as $order_id ) { $order = wc_get_order( $order_id ); if ( is_a( $order, WC_Order::class ) && in_array( $order->get_status(), array( 'processing', 'completed' ), true ) - && in_array( $order->get_payment_method(), array( PayPalGateway::ID, CreditCardGateway::ID ), true ) + && $current_order->get_payment_method() === $order->get_payment_method() ) { $transaction_id = $order->get_transaction_id(); if ( $transaction_id ) { diff --git a/modules/ppcp-wc-subscriptions/src/RenewalHandler.php b/modules/ppcp-wc-subscriptions/src/RenewalHandler.php index f0900881dd..82341fc8d9 100644 --- a/modules/ppcp-wc-subscriptions/src/RenewalHandler.php +++ b/modules/ppcp-wc-subscriptions/src/RenewalHandler.php @@ -556,7 +556,11 @@ private function card_payment_source( string $token, WC_Order $wc_order ): Payme 'usage' => 'SUBSEQUENT', 'previous_transaction_reference' => $transaction, ); + } else { + $this->logger->debug( sprintf( 'Previous transaction not found for subscription %s', $subscription->get_id() ) ); } + } else { + $this->logger->debug( sprintf( 'Subscription not found for renewal order %s', $wc_order->get_id() ) ); } return new PaymentSource(