Skip to content

Commit 44aec85

Browse files
committed
가상계좌 발급 요청 구현
1 parent 8832fd5 commit 44aec85

File tree

5 files changed

+189
-15
lines changed

5 files changed

+189
-15
lines changed

src/Attributes/Payment.php

Lines changed: 155 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Getsolaris\LaravelTossPayments\Attributes;
44

55
use Getsolaris\LaravelTossPayments\Contracts\AttributeInterface;
6+
use Getsolaris\LaravelTossPayments\Objects\CashReceipt;
67
use Getsolaris\LaravelTossPayments\Objects\RefundReceiveAccount;
78
use Getsolaris\LaravelTossPayments\TossPayments;
89
use GuzzleHttp\Promise\PromiseInterface;
@@ -16,14 +17,34 @@ class Payment extends TossPayments implements AttributeInterface
1617
protected string $uri;
1718

1819
/**
19-
* @var string|null
20+
* @var string
21+
*/
22+
protected string $paymentKey;
23+
24+
/**
25+
* @var string
26+
*/
27+
protected string $orderId;
28+
29+
/**
30+
* @var string
31+
*/
32+
protected string $cancelReason;
33+
34+
/**
35+
* @var string
2036
*/
21-
protected ?string $paymentKey = null;
37+
protected string $orderName;
2238

2339
/**
24-
* @var string|null
40+
* @var string
2541
*/
26-
protected ?string $orderId = null;
42+
protected string $customerName;
43+
44+
/**
45+
* @var string
46+
*/
47+
protected string $bank;
2748

2849
/**
2950
* @var int
@@ -48,11 +69,16 @@ public function initializeUri(): static
4869

4970
/**
5071
* @param string|null $endpoint
72+
* @param bool $withUri
5173
* @return string
5274
*/
53-
public function createEndpoint(?string $endpoint): string
75+
public function createEndpoint(?string $endpoint, bool $withUri = true): string
5476
{
55-
return $this->url.$this->uri.$this->start($endpoint);
77+
if ($withUri) {
78+
return $this->url.$this->uri.$this->start($endpoint);
79+
}
80+
81+
return $this->url.$this->start($endpoint);
5682
}
5783

5884
/**
@@ -110,23 +136,29 @@ public function get(): PromiseInterface|Response
110136

111137
/**
112138
* @param string $cancelReason
139+
* @return $this
140+
*/
141+
public function cancelReason(string $cancelReason): static
142+
{
143+
$this->cancelReason = $cancelReason;
144+
145+
return $this;
146+
}
147+
148+
/**
113149
* @param int|null $cancelAmount
114150
* @param RefundReceiveAccount|null $refundReceiveAccount
115151
* @param int|null $taxFreeAmount
116152
* @param int|null $refundableAmount
117153
* @return PromiseInterface|Response
118154
*/
119155
public function cancel(
120-
string $cancelReason,
121156
?int $cancelAmount = null,
122157
?RefundReceiveAccount $refundReceiveAccount = null,
123158
?int $taxFreeAmount = null,
124159
?int $refundableAmount = null
125160
): PromiseInterface|Response {
126-
$parameters = [
127-
'cancelReason' => $cancelReason,
128-
];
129-
161+
$parameters = [];
130162
if ($cancelAmount) {
131163
$parameters['cancelAmount'] = $cancelAmount;
132164
}
@@ -143,6 +175,117 @@ public function cancel(
143175
$parameters['refundableAmount'] = $refundableAmount;
144176
}
145177

146-
return $this->client->post($this->createEndpoint('/'.$this->paymentKey.'/cancel'), $parameters);
178+
return $this->client->post($this->createEndpoint('/'.$this->paymentKey.'/cancel'), [
179+
'cancelReason' => $this->cancelReason,
180+
] + $parameters);
181+
}
182+
183+
/**
184+
* @param string $orderName
185+
* @return $this
186+
*/
187+
public function orderName(string $orderName): static
188+
{
189+
$this->orderName = $orderName;
190+
191+
return $this;
192+
}
193+
194+
/**
195+
* @param string $customerName
196+
* @return $this
197+
*/
198+
public function customerName(string $customerName): static
199+
{
200+
$this->customerName = $customerName;
201+
202+
return $this;
203+
}
204+
205+
/**
206+
* @param string $bank
207+
* @return $this
208+
*/
209+
public function bank(string $bank): static
210+
{
211+
$this->bank = $bank;
212+
213+
return $this;
214+
}
215+
216+
/**
217+
* @param string|null $accountType
218+
* @param string|null $accountKey
219+
* @param int|null $validHours
220+
* @param string|null $dueDate
221+
* @param string|null $customerEmail
222+
* @param string|null $customerMobilePhone
223+
* @param int|null $taxFreeAmount
224+
* @param bool|null $useEscrow
225+
* @param CashReceipt|null $cashReceipt
226+
* @param array|null $escrowProducts
227+
* @return PromiseInterface|Response
228+
*/
229+
public function virtualAccounts(
230+
?string $accountType = null,
231+
?string $accountKey = null,
232+
?int $validHours = null,
233+
?string $dueDate = null,
234+
?string $customerEmail = null,
235+
?string $customerMobilePhone = null,
236+
?int $taxFreeAmount = null,
237+
?bool $useEscrow = null,
238+
?CashReceipt $cashReceipt = null,
239+
?array $escrowProducts = null
240+
): PromiseInterface|Response
241+
{
242+
$parameters = [];
243+
if ($accountType) {
244+
$parameters['accountType'] = $accountType;
245+
}
246+
247+
if ($accountKey) {
248+
$parameters['accountKey'] = $accountKey;
249+
}
250+
251+
if ($validHours) {
252+
$parameters['validHours'] = $validHours;
253+
}
254+
255+
if ($dueDate) {
256+
$parameters['dueDate'] = $dueDate;
257+
}
258+
259+
if ($customerEmail) {
260+
$parameters['customerEmail'] = $customerEmail;
261+
}
262+
263+
if ($customerMobilePhone) {
264+
$parameters['customerMobilePhone'] = $customerMobilePhone;
265+
}
266+
267+
if ($taxFreeAmount) {
268+
$parameters['taxFreeAmount'] = $taxFreeAmount;
269+
}
270+
271+
if ($useEscrow) {
272+
$parameters['useEscrow'] = $useEscrow;
273+
}
274+
275+
if ($cashReceipt) {
276+
$parameters['cashReceipt'] = (array) $cashReceipt;
277+
}
278+
279+
if ($escrowProducts) {
280+
$parameters['escrowProducts'] = $escrowProducts;
281+
}
282+
283+
return $this->client->post($this->createEndpoint('/virtual-accounts', false), [
284+
'amount' => $this->amount,
285+
'orderId' => $this->orderId,
286+
'orderName' => $this->orderName,
287+
'customerName' => $this->customerName,
288+
'bank' => $this->bank,
289+
] + $parameters);
147290
}
148291
}

src/Attributes/Transaction.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,16 @@ public function initializeUri(): static
5151

5252
/**
5353
* @param string|null $endpoint
54+
* @param bool $withUri
5455
* @return string
5556
*/
56-
public function createEndpoint(?string $endpoint): string
57+
public function createEndpoint(?string $endpoint, bool $withUri = true): string
5758
{
58-
return $this->url.$this->uri.$this->start($endpoint);
59+
if ($withUri) {
60+
return $this->url.$this->uri.$this->start($endpoint);
61+
}
62+
63+
return $this->url.$this->start($endpoint);
5964
}
6065

6166
/**

src/Contracts/AttributeInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ public function __construct();
88

99
public function initializeUri(): static;
1010

11-
public function createEndpoint(?string $endpoint, bool $hasUri): string;
11+
public function createEndpoint(?string $endpoint, bool $withUri): string;
1212
}

src/Objects/CashReceipt.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,25 @@
44

55
class CashReceipt
66
{
7+
/**
8+
* @var string
9+
*/
10+
public string $type;
711

12+
/**
13+
* @var string
14+
*/
15+
public string $registrationNumber;
16+
17+
/**
18+
* @var string
19+
*/
20+
public string $businessNumber;
21+
22+
public function __construct(string $type, string $registrationNumber, string $businessNumber)
23+
{
24+
$this->type = $type;
25+
$this->registrationNumber = $registrationNumber;
26+
$this->businessNumber = $businessNumber;
27+
}
828
}

src/Objects/RefundReceiveAccount.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ class RefundReceiveAccount
99
*/
1010
public string $bank;
1111

12+
/**
13+
* @var string
14+
*/
1215
public string $accountNumber;
1316

17+
/**
18+
* @var string
19+
*/
1420
public string $holderName;
1521

1622
public function __construct(string $bank, string $accountNumber, string $holderName)

0 commit comments

Comments
 (0)