mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Refactor PayPal order retrieval
This commit is contained in:
parent
fda789228c
commit
a25eca53bb
2 changed files with 20 additions and 20 deletions
|
@ -443,14 +443,8 @@ class OrderEndpoint {
|
||||||
$error = new RuntimeException(
|
$error = new RuntimeException(
|
||||||
__( 'Could not retrieve order.', 'woocommerce-paypal-payments' )
|
__( 'Could not retrieve order.', 'woocommerce-paypal-payments' )
|
||||||
);
|
);
|
||||||
$this->logger->log(
|
$this->logger->warning($error->getMessage());
|
||||||
'warning',
|
|
||||||
$error->getMessage(),
|
|
||||||
array(
|
|
||||||
'args' => $args,
|
|
||||||
'response' => $response,
|
|
||||||
)
|
|
||||||
);
|
|
||||||
throw $error;
|
throw $error;
|
||||||
}
|
}
|
||||||
$json = json_decode( $response['body'] );
|
$json = json_decode( $response['body'] );
|
||||||
|
@ -485,8 +479,8 @@ class OrderEndpoint {
|
||||||
);
|
);
|
||||||
throw $error;
|
throw $error;
|
||||||
}
|
}
|
||||||
$order = $this->order_factory->from_paypal_response( $json );
|
|
||||||
return $order;
|
return $this->order_factory->from_paypal_response( $json );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -10,9 +10,11 @@ declare(strict_types=1);
|
||||||
namespace WooCommerce\PayPalCommerce\WcGateway\Processor;
|
namespace WooCommerce\PayPalCommerce\WcGateway\Processor;
|
||||||
|
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use WC_Order;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
|
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\Order;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
|
use WooCommerce\PayPalCommerce\ApiClient\Entity\OrderStatus;
|
||||||
|
use WooCommerce\PayPalCommerce\ApiClient\Exception\RuntimeException;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Factory\OrderFactory;
|
use WooCommerce\PayPalCommerce\ApiClient\Factory\OrderFactory;
|
||||||
use WooCommerce\PayPalCommerce\ApiClient\Helper\OrderHelper;
|
use WooCommerce\PayPalCommerce\ApiClient\Helper\OrderHelper;
|
||||||
use WooCommerce\PayPalCommerce\Button\Helper\ThreeDSecure;
|
use WooCommerce\PayPalCommerce\Button\Helper\ThreeDSecure;
|
||||||
|
@ -160,17 +162,21 @@ class OrderProcessor {
|
||||||
*
|
*
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function process( \WC_Order $wc_order ): bool {
|
public function process( WC_Order $wc_order ): bool {
|
||||||
$order_id = $wc_order->get_meta( PayPalGateway::ORDER_ID_META_KEY );
|
$order = $this->session_handler->order();
|
||||||
if ( ! $order_id ) {
|
|
||||||
$this->last_error = __( 'No PayPal order ID found in the current WooCommerce session.', 'woocommerce-paypal-payments' );
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$order = $this->session_handler->order() ?? $this->order_endpoint->order( $order_id );
|
|
||||||
if ( ! $order ) {
|
if ( ! $order ) {
|
||||||
$this->last_error = __( 'No PayPal order found in the current WooCommerce session.', 'woocommerce-paypal-payments' );
|
$order_id = $wc_order->get_meta( PayPalGateway::ORDER_ID_META_KEY );
|
||||||
return false;
|
if ( ! $order_id ) {
|
||||||
|
$this->last_error = __( 'No PayPal order ID found in order meta.', 'woocommerce-paypal-payments' );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$order = $this->order_endpoint->order( $order_id );
|
||||||
|
} catch ( RuntimeException $exception ) {
|
||||||
|
$this->last_error = __( 'Could not retrieve PayPal order.', 'woocommerce-paypal-payments' );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->add_paypal_meta( $wc_order, $order, $this->environment );
|
$this->add_paypal_meta( $wc_order, $order, $this->environment );
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue