/** * The API for operations with orders. * * @package WooCommerce\PayPalCommerce\Api * * @phpcs:disable Squiz.Commenting.FunctionCommentThrowTag */ declare (strict_types=1); namespace WooCommerce\PayPalCommerce\Api; use Exception; use InvalidArgumentException; use RuntimeException; use WC_Order; use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint; use WooCommerce\PayPalCommerce\ApiClient\Entity\Order; use WooCommerce\PayPalCommerce\PPCP; use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway; use WooCommerce\PayPalCommerce\WcGateway\Helper\RefundFeesUpdater; use WooCommerce\PayPalCommerce\WcGateway\Processor\AuthorizedPaymentsProcessor; use WooCommerce\PayPalCommerce\WcGateway\Processor\OrderProcessor; use WooCommerce\PayPalCommerce\WcGateway\Processor\RefundProcessor; /** * Returns the PayPal order. * * @param string|WC_Order $paypal_id_or_wc_order The ID of PayPal order or a WC order (with the ID in meta). * @throws InvalidArgumentException When the argument cannot be used for retrieving the order. * @throws Exception When the operation fails. */ function ppcp_get_paypal_order($paypal_id_or_wc_order): Order { if ($paypal_id_or_wc_order instanceof WC_Order) { $paypal_id_or_wc_order = $paypal_id_or_wc_order->get_meta(PayPalGateway::ORDER_ID_META_KEY); if (!$paypal_id_or_wc_order) { throw new InvalidArgumentException('PayPal order ID not found in meta.'); } } if (!is_string($paypal_id_or_wc_order)) { throw new InvalidArgumentException('Invalid PayPal order ID, string expected.'); } $order_endpoint = PPCP::container()->get('api.endpoint.order'); assert($order_endpoint instanceof OrderEndpoint); return $order_endpoint->order($paypal_id_or_wc_order); } /** * Creates a PayPal order for the given WC order. * * @param WC_Order $wc_order The WC order. * @throws Exception When the operation fails. */ function ppcp_create_paypal_order_for_wc_order(WC_Order $wc_order): Order { $order_processor = PPCP::container()->get('wcgateway.order-processor'); assert($order_processor instanceof OrderProcessor); return $order_processor->create_order($wc_order); } /** * Captures the PayPal order. * * @param WC_Order $wc_order The WC order. * @throws InvalidArgumentException When the order cannot be captured. * @throws Exception When the operation fails. */ function ppcp_capture_order(WC_Order $wc_order): void { $intent = strtoupper((string) $wc_order->get_meta(PayPalGateway::INTENT_META_KEY)); if ($intent !== 'AUTHORIZE') { throw new InvalidArgumentException('Only orders with "authorize" intent can be captured.'); } $captured = wc_string_to_bool($wc_order->get_meta(AuthorizedPaymentsProcessor::CAPTURED_META_KEY)); if ($captured) { throw new InvalidArgumentException('The order is already captured.'); } $authorized_payment_processor = PPCP::container()->get('wcgateway.processor.authorized-payments'); assert($authorized_payment_processor instanceof AuthorizedPaymentsProcessor); if (!$authorized_payment_processor->capture_authorized_payment($wc_order)) { throw new RuntimeException('Capture failed.'); } } /** * Reauthorizes the PayPal order. * * @param WC_Order $wc_order The WC order. * @throws InvalidArgumentException When the order cannot be captured. * @throws Exception When the operation fails. */ function ppcp_reauthorize_order(WC_Order $wc_order): void { $intent = strtoupper((string) $wc_order->get_meta(PayPalGateway::INTENT_META_KEY)); if ($intent !== 'AUTHORIZE') { throw new InvalidArgumentException('Only orders with "authorize" intent can be reauthorized.'); } $captured = wc_string_to_bool($wc_order->get_meta(AuthorizedPaymentsProcessor::CAPTURED_META_KEY)); if ($captured) { throw new InvalidArgumentException('The order is already captured.'); } $authorized_payment_processor = PPCP::container()->get('wcgateway.processor.authorized-payments'); assert($authorized_payment_processor instanceof AuthorizedPaymentsProcessor); if ($authorized_payment_processor->reauthorize_payment($wc_order) !== AuthorizedPaymentsProcessor::SUCCESSFUL) { throw new RuntimeException($authorized_payment_processor->reauthorization_failure_reason() ?: 'Reauthorization failed.'); } } /** * Refunds the PayPal order. * Note that you can use wc_refund_payment() to trigger the refund in WC and PayPal. * * @param WC_Order $wc_order The WC order. * @param float $amount The refund amount. * @param string $reason The reason for the refund. * @return string The PayPal refund ID. * @throws InvalidArgumentException When the order cannot be refunded. * @throws Exception When the operation fails. */ function ppcp_refund_order(WC_Order $wc_order, float $amount, string $reason = ''): string { $order = ppcp_get_paypal_order($wc_order); $refund_processor = PPCP::container()->get('wcgateway.processor.refunds'); assert($refund_processor instanceof RefundProcessor); return $refund_processor->refund($order, $wc_order, $amount, $reason); } /** * Voids the authorization. * * @param WC_Order $wc_order The WC order. * @throws InvalidArgumentException When the order cannot be voided. * @throws Exception When the operation fails. */ function ppcp_void_order(WC_Order $wc_order): void { $order = ppcp_get_paypal_order($wc_order); $refund_processor = PPCP::container()->get('wcgateway.processor.refunds'); assert($refund_processor instanceof RefundProcessor); $refund_processor->void($order); } /** * Updates the PayPal refund fees totals on an order. * * @param WC_Order $wc_order The WC order. */ function ppcp_update_order_refund_fees(WC_Order $wc_order): void { $updater = PPCP::container()->get('wcgateway.helper.refund-fees-updater'); assert($updater instanceof RefundFeesUpdater); $updater->update($wc_order); } Comments for Hostamy – strumenti per strutture a tema affitti brevi https://hostamy.com/en_gb/ Blog e prodotti per host di case vacanze, LT e B&B a diventare più digitali. Cartelli per la casa, contratto di affitto, Libro degli Ospiti etc. Fri, 13 Aug 2021 13:28:05 +0000 hourly 1 https://wordpress.org/?v=6.8.11 Comment on Registrazione sul portale Airbnb by admin https://hostamy.com/en_gb/stm-lessons/registrazione-sul-portale-airbnb/#comment-126 Fri, 13 Aug 2021 13:26:30 +0000 https://hostamy.com/index.php/stm-lessons/registrazione-sul-portale-airbnb/#comment-126 http://www.airbnb.it/r/lorenzoventuri

]]>
Comment on Hello world! by A WordPress Commenter https://hostamy.com/en_gb/hello-world/#comment-1 Sun, 25 Jul 2021 13:41:54 +0000 https://hostamy.com/?p=1#comment-1 Hi, this is a comment.
To get started with moderating, editing, and deleting comments, please visit the Comments screen in the dashboard.
Commenter avatars come from Gravatar.

]]>
Comment on Design and Visualization with Nvidia by Instructor Account https://hostamy.com/en_gb/stm-lessons/design-and-visualization-with-nvidia/#comment-75 Sat, 01 Dec 2018 02:55:26 +0000 http://lmsdemo.loc/lms-white/stm-lessons/design-and-visualization-with-nvidia/#comment-75 In reply to Instructor Account.

I’m too

]]>
Comment on Design and Visualization with Nvidia by Instructor Account https://hostamy.com/en_gb/stm-lessons/design-and-visualization-with-nvidia/#comment-74 Sat, 01 Dec 2018 02:55:17 +0000 http://lmsdemo.loc/lms-white/stm-lessons/design-and-visualization-with-nvidia/#comment-74 Nice feature !

]]>
Comment on Realistic Graphic on UE4 by Instructor Account https://hostamy.com/en_gb/stm-lessons/realistic-graphic-on-ue4/#comment-36 Fri, 30 Nov 2018 14:47:15 +0000 http://lmsdemo.loc/lms-white/stm-lessons/lesson-4/#comment-36 how can use the app ?

]]>
Comment on Realistic Graphic on UE4 by Instructor Account https://hostamy.com/en_gb/stm-lessons/realistic-graphic-on-ue4/#comment-35 Fri, 30 Nov 2018 14:46:43 +0000 http://lmsdemo.loc/lms-white/stm-lessons/lesson-4/#comment-35 In reply to Stylemix Themes.

use the ajaxer sw

]]>
Comment on Realistic Graphic on UE4 by Instructor Account https://hostamy.com/en_gb/stm-lessons/realistic-graphic-on-ue4/#comment-34 Sat, 24 Nov 2018 13:13:13 +0000 http://lmsdemo.loc/lms-white/stm-lessons/lesson-4/#comment-34 In reply to Stylemix Themes.

yES

]]>
Comment on Quiz: Mobile / Native Apps by Instructor Account https://hostamy.com/en_gb/stm-quizzes/quiz-2/#comment-90 Fri, 23 Nov 2018 23:25:44 +0000 http://lmsdemo.loc/lms-white/stm-quizzes/quiz-2/#comment-90 In reply to Instructor Account.

no se

]]>
Comment on Quiz: Mobile / Native Apps by Instructor Account https://hostamy.com/en_gb/stm-quizzes/quiz-2/#comment-89 Fri, 23 Nov 2018 23:25:19 +0000 http://lmsdemo.loc/lms-white/stm-quizzes/quiz-2/#comment-89 hima

]]>
Comment on Realistic Graphic on UE4 by Instructor Account https://hostamy.com/en_gb/stm-lessons/realistic-graphic-on-ue4/#comment-33 Thu, 22 Nov 2018 12:01:59 +0000 http://lmsdemo.loc/lms-white/stm-lessons/lesson-4/#comment-33 In reply to froust.

Test

]]>