Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit b2ebb35

Browse files
committed
feat: add shipping information post endpoint
1 parent 6475e78 commit b2ebb35

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

src/Api/Carts.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,17 @@ public function totalsInformation($body = [])
4141

4242
return $this->post('/carts/mine/totals-information', $body);
4343
}
44+
45+
/**
46+
* Save the total shipping information.
47+
*
48+
* @param array $body
49+
* @return array
50+
*/
51+
public function shippingInformation($body = [])
52+
{
53+
$this->validateSingleStoreCode();
54+
55+
return $this->post('/carts/mine/shipping-information', $body);
56+
}
4457
}

src/Api/GuestCarts.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,16 @@ public function totalsInformation($cartId, $body = [])
8686
{
8787
return $this->post('/guest-carts/'.$cartId.'/totals-information', $body);
8888
}
89+
90+
/**
91+
* Save the total shipping information.
92+
*
93+
* @param string $cartId
94+
* @param array $body
95+
* @return array
96+
*/
97+
public function shippingInformation($cartId, $body = [])
98+
{
99+
return $this->post('/guest-carts/'.$cartId.'/shipping-information', $body);
100+
}
89101
}

tests/Api/CartsTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,26 @@ public function test_must_pass_a_single_store_code_to_totals_information()
7878
$magento = new Magento();
7979
$magento->api('carts')->totalsInformation([]);
8080
}
81+
82+
public function test_can_call_carts_shipping_information()
83+
{
84+
Http::fake([
85+
'*rest/default/V1/carts/mine/shipping-information' => Http::response([], 200),
86+
]);
87+
88+
$magento = new Magento();
89+
$magento->storeCode = 'default';
90+
91+
$api = $magento->api('carts')->shippingInformation([]);
92+
93+
$this->assertTrue($api->ok());
94+
}
95+
96+
public function test_must_pass_a_single_store_code_to_shipping_information()
97+
{
98+
$this->expectException('exception');
99+
100+
$magento = new Magento();
101+
$magento->api('carts')->shippingInformation([]);
102+
}
81103
}

tests/Api/GuestCartsTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,17 @@ public function test_can_call_guest_carts_totals_information()
9595

9696
$this->assertTrue($api->ok());
9797
}
98+
99+
public function test_can_call_guest_carts_shipping_information()
100+
{
101+
Http::fake([
102+
'*rest/all/V1/guest-carts/foo/shipping-information' => Http::response([], 200),
103+
]);
104+
105+
$magento = new Magento();
106+
107+
$api = $magento->api('guestCarts')->shippingInformation('foo');
108+
109+
$this->assertTrue($api->ok());
110+
}
98111
}

0 commit comments

Comments
 (0)