mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
store data to create PP order in class properties
This commit is contained in:
parent
8f00894080
commit
91adee26e4
1 changed files with 23 additions and 10 deletions
|
@ -95,6 +95,20 @@ class CreateOrderEndpoint implements EndpointInterface {
|
||||||
*/
|
*/
|
||||||
private $order;
|
private $order;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data from the request.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $parsed_request_data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The array of purchase units for order.
|
||||||
|
*
|
||||||
|
* @var PurchaseUnit[]
|
||||||
|
*/
|
||||||
|
private $purchase_units;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CreateOrderEndpoint constructor.
|
* CreateOrderEndpoint constructor.
|
||||||
*
|
*
|
||||||
|
@ -145,6 +159,7 @@ class CreateOrderEndpoint implements EndpointInterface {
|
||||||
public function handle_request(): bool {
|
public function handle_request(): bool {
|
||||||
try {
|
try {
|
||||||
$data = $this->request_data->read_request( $this->nonce() );
|
$data = $this->request_data->read_request( $this->nonce() );
|
||||||
|
$this->parsed_request_data = $data;
|
||||||
$wc_order = null;
|
$wc_order = null;
|
||||||
if ( 'pay-now' === $data['context'] ) {
|
if ( 'pay-now' === $data['context'] ) {
|
||||||
$wc_order = wc_get_order( (int) $data['order_id'] );
|
$wc_order = wc_get_order( (int) $data['order_id'] );
|
||||||
|
@ -158,14 +173,14 @@ class CreateOrderEndpoint implements EndpointInterface {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$purchase_units = array( $this->purchase_unit_factory->from_wc_order( $wc_order ) );
|
$this->purchase_units = array( $this->purchase_unit_factory->from_wc_order( $wc_order ) );
|
||||||
} else {
|
} else {
|
||||||
$purchase_units = $this->cart_repository->all();
|
$this->purchase_units = $this->cart_repository->all();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->set_bn_code( $data );
|
$this->set_bn_code( $data );
|
||||||
|
|
||||||
$order = $this->create_paypal_order($data, $purchase_units, $wc_order);
|
$order = $this->create_paypal_order($wc_order);
|
||||||
|
|
||||||
if ( 'checkout' === $data['context'] ) {
|
if ( 'checkout' === $data['context'] ) {
|
||||||
$this->process_checkout_form( $data['form'], $order );
|
$this->process_checkout_form( $data['form'], $order );
|
||||||
|
@ -192,21 +207,19 @@ class CreateOrderEndpoint implements EndpointInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $request_data Parsed data of the checkout or pay now form.
|
* @param \WC_Order|null $wc_order WC order to get data from.
|
||||||
* @param PurchaseUnit[] $purchase_units The list of order items.
|
|
||||||
* @param \WC_Order $wc_order The respective WC order to get data from.
|
|
||||||
*
|
*
|
||||||
* @return Order Created PayPal order.
|
* @return Order Created PayPal order.
|
||||||
*
|
*
|
||||||
* @throws RuntimeException If create order request fails.
|
* @throws RuntimeException If create order request fails.
|
||||||
*/
|
*/
|
||||||
private function create_paypal_order(array $request_data, array $purchase_units, \WC_Order $wc_order): Order {
|
private function create_paypal_order(\WC_Order $wc_order = null): Order {
|
||||||
$needs_shipping = WC()->cart && WC()->cart->needs_shipping();
|
$needs_shipping = WC()->cart && WC()->cart->needs_shipping();
|
||||||
$shipping_address_is_fix = $needs_shipping && 'checkout' === $request_data['context'];
|
$shipping_address_is_fix = $needs_shipping && 'checkout' === $this->parsed_request_data['context'];
|
||||||
|
|
||||||
return $this->api_endpoint->create(
|
return $this->api_endpoint->create(
|
||||||
$purchase_units,
|
$this->purchase_units,
|
||||||
$this->payer( $request_data, $wc_order ),
|
$this->payer( $this->parsed_request_data, $wc_order ),
|
||||||
null,
|
null,
|
||||||
$this->payment_method(),
|
$this->payment_method(),
|
||||||
'',
|
'',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue