mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
♻️ Fix the GetOrderEndpoint handler
We use the new `::raw_order()` method to return the plain object. The `Order` object could not be serialized in a meaningful way.
This commit is contained in:
parent
4f4905af96
commit
2591cf444e
2 changed files with 19 additions and 22 deletions
|
@ -284,7 +284,7 @@ return array(
|
|||
$container->get( 'wcgateway.paypal-gateway' )
|
||||
);
|
||||
},
|
||||
'button.endpoint.get-order' => static function( ContainerInterface $container ): GetOrderEndpoint {
|
||||
'button.endpoint.get-order' => static function( ContainerInterface $container ): GetOrderEndpoint {
|
||||
return new GetOrderEndpoint(
|
||||
$container->get( 'button.request-data' ),
|
||||
$container->get( 'api.endpoint.order' )
|
||||
|
|
|
@ -5,50 +5,47 @@
|
|||
* @package WooCommerce\PayPalCommerce\Button\Endpoint
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types = 1 );
|
||||
|
||||
namespace WooCommerce\PayPalCommerce\Button\Endpoint;
|
||||
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Endpoint\OrderEndpoint;
|
||||
use WooCommerce\PayPalCommerce\Button\Exception\RuntimeException;
|
||||
use WooCommerce\PayPalCommerce\Button\Helper\ContextTrait;
|
||||
|
||||
/**
|
||||
* Class ApproveSubscriptionEndpoint
|
||||
*/
|
||||
class GetOrderEndpoint implements EndpointInterface {
|
||||
|
||||
use ContextTrait;
|
||||
|
||||
const ENDPOINT = 'ppc-get-order';
|
||||
public const ENDPOINT = 'ppc-get-order';
|
||||
|
||||
/**
|
||||
* The request data helper.
|
||||
*
|
||||
* @var RequestData
|
||||
*/
|
||||
private $request_data;
|
||||
private RequestData $request_data;
|
||||
|
||||
/**
|
||||
* The order endpoint.
|
||||
*
|
||||
* @var OrderEndpoint
|
||||
*/
|
||||
private $order_endpoint;
|
||||
private OrderEndpoint $order_endpoint;
|
||||
|
||||
|
||||
/**
|
||||
* ApproveSubscriptionEndpoint constructor.
|
||||
* Constructor.
|
||||
*
|
||||
* @param RequestData $request_data The request data helper.
|
||||
* @param OrderEndpoint $order_endpoint The order endpoint.
|
||||
* @param RequestData $request_data The request data helper.
|
||||
* @param OrderEndpoint $order_endpoint The order endpoint.
|
||||
*/
|
||||
public function __construct(
|
||||
RequestData $request_data,
|
||||
OrderEndpoint $order_endpoint
|
||||
) {
|
||||
$this->request_data = $request_data;
|
||||
$this->order_endpoint = $order_endpoint;
|
||||
$this->request_data = $request_data;
|
||||
$this->order_endpoint = $order_endpoint;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -56,29 +53,29 @@ class GetOrderEndpoint implements EndpointInterface {
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function nonce(): string {
|
||||
public static function nonce() : string {
|
||||
return self::ENDPOINT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the request.
|
||||
* Handles the request responds with the PayPal order details.
|
||||
*
|
||||
* @return bool
|
||||
* @return bool This method never returns a value, but we must implement the interface.
|
||||
* @throws RuntimeException When order not found or handling failed.
|
||||
*/
|
||||
public function handle_request(): bool {
|
||||
$data = $this->request_data->read_request( $this->nonce() );
|
||||
public function handle_request() : bool {
|
||||
$data = $this->request_data->read_request( self::nonce() );
|
||||
|
||||
if ( ! isset( $data['order_id'] ) ) {
|
||||
throw new RuntimeException(
|
||||
__( 'No order id given', 'woocommerce-paypal-payments' )
|
||||
);
|
||||
}
|
||||
|
||||
$order = $this->order_endpoint->order( $data['order_id'] );
|
||||
$order = $this->order_endpoint->raw_order( $data['order_id'] );
|
||||
|
||||
wp_send_json_success( $order );
|
||||
|
||||
wp_send_json_success(array(
|
||||
'order' => $order
|
||||
));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue