♻️ Refactor OrderFactory to consolidate 3DS and regular response handling

This commit is contained in:
Daniel Dudzic 2025-07-03 00:16:42 +02:00
parent 8fee8c330f
commit 59503b29b3
No known key found for this signature in database
GPG key ID: 31B40D33E3465483
2 changed files with 3 additions and 37 deletions

View file

@ -265,12 +265,7 @@ class OrderEndpoint {
throw $error;
}
// Check if this is a PAYER_ACTION_REQUIRED response (3DS).
$is_3ds_response = isset( $json->status ) && $json->status === 'PAYER_ACTION_REQUIRED';
$order = $is_3ds_response
? $this->order_factory->from_paypal_response_with_3ds( $json )
: $this->order_factory->from_paypal_response( $json );
$order = $this->order_factory->from_paypal_response( $json );
do_action( 'woocommerce_paypal_payments_paypal_order_created', $order );

View file

@ -68,7 +68,8 @@ class OrderFactory {
$order->payer(),
$order->intent(),
$order->create_time(),
$order->update_time()
$order->update_time(),
$order->links()
);
}
@ -83,36 +84,6 @@ class OrderFactory {
public function from_paypal_response( \stdClass $order_data ): Order {
$this->validate_order_id( $order_data );
$purchase_units = $this->create_purchase_units( $order_data );
$status = $this->create_order_status( $order_data );
$intent = $this->get_intent( $order_data );
$timestamps = $this->create_timestamps( $order_data );
$payer = $this->create_payer( $order_data );
$payment_source = $this->create_payment_source( $order_data );
return new Order(
$order_data->id,
$purchase_units,
$status,
$payment_source,
$payer,
$intent,
$timestamps['create_time'],
$timestamps['update_time']
);
}
/**
* Returns an Order object based off a PayPal 3DS Response.
*
* @param \stdClass $order_data The JSON object.
*
* @return Order
* @throws RuntimeException When JSON object is malformed.
*/
public function from_paypal_response_with_3ds( \stdClass $order_data ): Order {
$this->validate_order_id( $order_data );
$purchase_units = $this->create_purchase_units( $order_data );
$status = $this->create_order_status( $order_data );
$intent = $this->get_intent( $order_data );