@@ -25,8 +25,8 @@ class ResponseFactory {
2525 /**
2626 * Constructor.
2727 *
28- * @param AgenticCartBuilder $cart_builder Cart builder service.
29- * @param AppliedCouponsBuilder $applied_coupons_builder Applied coupons builder service.
28+ * @param AgenticCartBuilder $cart_builder Cart builder service.
29+ * @param AppliedCouponsBuilder $applied_coupons_builder Applied coupons builder service.
3030 * @param ShippingOptionsBuilder $shipping_options_builder Shipping options builder service.
3131 */
3232 public function __construct (
@@ -42,42 +42,51 @@ public function __construct(
4242 /**
4343 * Create a new cart response (status: CREATED).
4444 *
45- * @param PayPalCart $cart The cart object.
45+ * @param PayPalCart $cart The cart object.
4646 * @param string $cart_id The cart ID.
47- * @param string $token The payment token.
48- * @return NewCartResponse The response object.
47+ * @param string $token The payment token.
48+ * @return CartResponse The response object.
4949 */
50- public function new_cart ( PayPalCart $ cart , string $ cart_id , string $ token ): NewCartResponse {
51- $ wc_cart = $ this ->build_wc_cart_or_null ( $ cart );
52- $ applied_coupons = $ this ->build_applied_coupons ( $ cart );
53- return new NewCartResponse ( $ cart , $ cart_id , $ token , $ applied_coupons , $ wc_cart );
50+ public function new_cart ( PayPalCart $ cart , string $ cart_id , string $ token ): CartResponse {
51+ $ wc_cart = $ this ->build_wc_cart_or_null ( $ cart );
52+
53+ return CartResponse::create_new ( $ cart , $ cart_id , $ token )
54+ ->wc_cart ( $ wc_cart )
55+ ->applied_coupons ( $ this ->build_applied_coupons ( $ cart ) )
56+ ->shipping_options ( $ this ->shipping_options_builder ->build ( $ wc_cart ) );
5457 }
5558
5659 /**
5760 * Create a paid cart response.
5861 *
59- * @param WC_Order $order The WooCommerce order.
60- * @param PayPalCart $cart The cart object.
62+ * @param WC_Order $order The WooCommerce order.
63+ * @param PayPalCart $cart The cart object.
6164 * @param string $cart_id The cart ID.
62- * @return PaidCartResponse The response object.
65+ * @return CartResponse The response object.
6366 */
64- public function from_order ( WC_Order $ order , PayPalCart $ cart , string $ cart_id ): PaidCartResponse {
65- $ wc_cart = $ this ->build_wc_cart_or_null ( $ cart );
66- $ applied_coupons = $ this ->build_applied_coupons ( $ cart );
67- return new PaidCartResponse ( $ cart , $ cart_id , $ order , $ applied_coupons , $ wc_cart );
67+ public function from_order ( WC_Order $ order , PayPalCart $ cart , string $ cart_id ): CartResponse {
68+ $ wc_cart = $ this ->build_wc_cart_or_null ( $ cart );
69+
70+ return CartResponse::create_completed ( $ cart , $ cart_id , $ order )
71+ ->wc_cart ( $ wc_cart )
72+ ->applied_coupons ( $ this ->build_applied_coupons ( $ cart ) )
73+ ->shipping_options ( $ this ->shipping_options_builder ->build ( $ wc_cart ) );
6874 }
6975
7076 /**
7177 * Create a basic cart response.
7278 *
73- * @param PayPalCart $cart The cart object.
79+ * @param PayPalCart $cart The cart object.
7480 * @param string $cart_id The cart ID.
7581 * @return CartResponse The response object.
7682 */
7783 public function from_cart ( PayPalCart $ cart , string $ cart_id ): CartResponse {
78- $ wc_cart = $ this ->build_wc_cart_or_null ( $ cart );
79- $ applied_coupons = $ this ->build_applied_coupons ( $ cart );
80- return new CartResponse ( $ cart , $ applied_coupons , $ cart_id , $ wc_cart );
84+ $ wc_cart = $ this ->build_wc_cart_or_null ( $ cart );
85+
86+ return CartResponse::create ( $ cart , $ cart_id )
87+ ->wc_cart ( $ wc_cart )
88+ ->applied_coupons ( $ this ->build_applied_coupons ( $ cart ) )
89+ ->shipping_options ( $ this ->shipping_options_builder ->build ( $ wc_cart ) );
8190 }
8291
8392 /**
@@ -104,6 +113,7 @@ private function build_wc_cart_or_null( PayPalCart $cart ): ?WC_Cart {
104113 */
105114 private function build_applied_coupons ( PayPalCart $ cart ): array {
106115 $ validation_status = $ cart ->issues () ? 'INVALID ' : 'VALID ' ;
116+
107117 return $ this ->applied_coupons_builder ->build_applied_coupons_array ( $ cart , $ validation_status );
108118 }
109119}
0 commit comments