der->set_status( 'refunded' ); $wc_order->save(); break; default: throw new RuntimeException( 'Nothing to refund/void.' ); } return true; } catch ( Exception $error ) { $this->logger->error( 'Refund failed: ' . $error->getMessage() ); return false; } } /** * Adds a refund to the PayPal order. * * @param Order $order The PayPal order. * @param WC_Order $wc_order The WooCommerce order. * @param float $amount The refund amount. * @param string $reason The reason for the refund. * * @throws RuntimeException When operation fails. * @return string The PayPal refund ID. */ public function refund( Order $order, WC_Order $wc_order, float $amount, string $reason = '' ): string { $payments = $this->get_payments( $order ); $captures = $payments->captures(); if ( ! $captures ) { throw new RuntimeException( 'No capture.' ); } $capture = $captures[0]; $refund = new RefundCapture( $capture, $capture->invoice_id() ?: $this->prefix . $wc_order->get_order_number(), $reason, new Amount( new Money( $amount, $wc_order->get_currency() ) ) ); return $this->payments_endpoint->refund( $refund ); } /** * Voids the authorization. * * @param Order $order The PayPal order. * @throws RuntimeException When operation fails. */ public function void( Order $order ): void { $payments = $this->get_payments( $order ); $voidable_authorizations = array_filter( $payments->authorizations(), function ( Authorization $authorization ): bool { return $authorization->is_voidable(); } ); if ( ! $voidable_authorizations ) { throw new RuntimeException( 'No voidable authorizations.' ); } foreach ( $voidable_authorizations as $authorization ) { $this->payments_endpoint->void( $authorization ); } } /** * Determines the refunding mode. * * @param Order $order The order. * * @return string One of the REFUND_MODE_ constants. */ public function determine_refund_mode( Order $order ): string { $payments = $this->get_payments( $order ); $authorizations = $payments->authorizations(); if ( $authorizations ) { foreach ( $authorizations as $authorization ) { if ( $authorization->is_voidable() ) { return self::REFUND_MODE_VOID; } } } if ( $payments->captures() ) { return self::REFUND_MODE_REFUND; } return self::REFUND_MODE_UNKNOWN; } /** * Returns the payments object or throws. * * @param Order $order The order. * @throws RuntimeException When payment not available. */ protected function get_payments( Order $order ): Payments { $purchase_units = $order->purchase_units(); if ( ! $purchase_units ) { throw new RuntimeException( 'No purchase units.' ); } $payments = $purchase_units[0]->payments(); if ( ! $payments ) { throw new RuntimeException( 'No payments.' ); } return $payments; } }
Fatal error: Uncaught Error: Class "WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor" not found in /htdocs/wp-content/plugins/woocommerce-paypal-payments/modules/ppcp-wc-gateway/services.php:630 Stack trace: #0 /htdocs/wp-content/plugins/woocommerce-paypal-payments/lib/packages/Inpsyde/Modularity/Container/ReadOnlyContainer.php(71): WooCommerce\PayPalCommerce\WcGateway\WCGatewayModule::WooCommerce\PayPalCommerce\WcGateway\{closure}(Object(WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Container\ReadOnlyContainer)) #1 /htdocs/wp-content/plugins/woocommerce-paypal-payments/modules/ppcp-wc-gateway/services.php(95): WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Container\ReadOnlyContainer->get('wcgateway.proce...') #2 /htdocs/wp-content/plugins/woocommerce-paypal-payments/lib/packages/Inpsyde/Modularity/Container/ReadOnlyContainer.php(71): WooCommerce\PayPalCommerce\WcGateway\WCGatewayModule::WooCommerce\PayPalCommerce\WcGateway\{closure}(Object(WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Container\ReadOnlyContainer)) #3 /htdocs/wp-content/plugins/woocommerce-paypal-payments/modules/ppcp-blocks/services.php(46): WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Container\ReadOnlyContainer->get('wcgateway.paypa...') #4 /htdocs/wp-content/plugins/woocommerce-paypal-payments/lib/packages/Inpsyde/Modularity/Container/ReadOnlyContainer.php(71): WooCommerce\PayPalCommerce\Blocks\BlocksModule::WooCommerce\PayPalCommerce\Blocks\{closure}(Object(WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Container\ReadOnlyContainer)) #5 /htdocs/wp-content/plugins/woocommerce-paypal-payments/modules/ppcp-blocks/src/BlocksModule.php(72): WooCommerce\PayPalCommerce\Vendor\Inpsyde\Modularity\Container\ReadOnlyContainer->get('blocks.method') #6 /htdocs/wp-includes/class-wp-hook.php(324): WooCommerce\PayPalCommerce\Blocks\BlocksModule->WooCommerce\PayPalCommerce\Blocks\{closure}(Object(Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry)) #7 /htdocs/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters('', Array) #8 /htdocs/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #9 /htdocs/wp-content/plugins/woocommerce/src/Blocks/Integrations/IntegrationRegistry.php(50): do_action('woocommerce_blo...', Object(Automattic\WooCommerce\Blocks\Payments\PaymentMethodRegistry)) #10 /htdocs/wp-includes/class-wp-hook.php(324): Automattic\WooCommerce\Blocks\Integrations\IntegrationRegistry->initialize('') #11 /htdocs/wp-includes/class-wp-hook.php(348): WP_Hook->apply_filters(NULL, Array) #12 /htdocs/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #13 /htdocs/wp-settings.php(643): do_action('init') #14 /htdocs/wp-config.php(106): require_once('/htdocs/wp-sett...') #15 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #16 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #17 /htdocs/index.php(17): require('/htdocs/wp-blog...') #18 {main} thrown in /htdocs/wp-content/plugins/woocommerce-paypal-payments/modules/ppcp-wc-gateway/services.php on line 630