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

Commit 126e7cf

Browse files
authored
Merge pull request #32 from grayloon/payment-information
Payment Information Endpoint
2 parents f4b991f + e83cb0b commit 126e7cf

File tree

4 files changed

+61
-1
lines changed

4 files changed

+61
-1
lines changed

src/Api/Carts.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ public function shippingInformation($body = [])
5858
/**
5959
* Lists available payment methods for a specified shopping cart. This call returns an array of objects, but detailed information about each object’s attributes might not be included.
6060
*
61-
* @param array $body
6261
* @return array
6362
*/
6463
public function paymentMethods()
@@ -67,4 +66,17 @@ public function paymentMethods()
6766

6867
return $this->get('/carts/mine/payment-methods');
6968
}
69+
70+
/**
71+
* Set payment information and place order for a specified cart.
72+
*
73+
* @param array $body
74+
* @return array
75+
*/
76+
public function paymentInformation($body = [])
77+
{
78+
$this->validateSingleStoreCode();
79+
80+
return $this->post('/carts/mine/payment-information', $body);
81+
}
7082
}

src/Api/GuestCarts.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,23 @@ public function shippingInformation($cartId, $body = [])
102102
/**
103103
* List available payment methods for a specified shopping cart. This call returns an array of objects, but detailed information about each object’s attributes might not be included.
104104
*
105+
* @param string $cartId
105106
* @return array
106107
*/
107108
public function paymentMethods($cartId)
108109
{
109110
return $this->get('/guest-carts/'.$cartId.'/payment-methods');
110111
}
112+
113+
/**
114+
* Set payment information and place order for a specified cart.
115+
*
116+
* @param string $cartId
117+
* @param array $body
118+
* @return array
119+
*/
120+
public function paymentInformation($cartId, $body = [])
121+
{
122+
return $this->post('/guest-carts/'.$cartId.'/payment-information', $body);
123+
}
111124
}

tests/Api/CartsTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,26 @@ public function test_must_pass_a_single_store_code_to_payment_methods()
122122
$magento = new Magento();
123123
$magento->api('carts')->paymentMethods([]);
124124
}
125+
126+
public function test_can_call_carts_payment_information()
127+
{
128+
Http::fake([
129+
'*rest/default/V1/carts/mine/payment-information' => Http::response([], 200),
130+
]);
131+
132+
$magento = new Magento();
133+
$magento->storeCode = 'default';
134+
135+
$api = $magento->api('carts')->paymentInformation([]);
136+
137+
$this->assertTrue($api->ok());
138+
}
139+
140+
public function test_must_pass_a_single_store_code_to_payment_information()
141+
{
142+
$this->expectException('exception');
143+
144+
$magento = new Magento();
145+
$magento->api('carts')->paymentInformation([]);
146+
}
125147
}

tests/Api/GuestCartsTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,17 @@ public function test_can_call_guest_carts_payment_methods()
121121

122122
$this->assertTrue($api->ok());
123123
}
124+
125+
public function test_can_call_guest_carts_payment_information()
126+
{
127+
Http::fake([
128+
'*rest/all/V1/guest-carts/foo/payment-information' => Http::response([], 200),
129+
]);
130+
131+
$magento = new Magento();
132+
133+
$api = $magento->api('guestCarts')->paymentInformation('foo', ['bar']);
134+
135+
$this->assertTrue($api->ok());
136+
}
124137
}

0 commit comments

Comments
 (0)