33namespace Getsolaris \LaravelTossPayments \Attributes ;
44
55use Getsolaris \LaravelTossPayments \Contracts \AttributeInterface ;
6+ use Getsolaris \LaravelTossPayments \Objects \CashReceipt ;
67use Getsolaris \LaravelTossPayments \Objects \RefundReceiveAccount ;
78use Getsolaris \LaravelTossPayments \TossPayments ;
89use 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}
0 commit comments