Skip to content

Commit 038e6c6

Browse files
committed
카드 번호 결제 구현
1 parent 44aec85 commit 038e6c6

File tree

2 files changed

+154
-0
lines changed

2 files changed

+154
-0
lines changed

src/Attributes/Payment.php

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Getsolaris\LaravelTossPayments\Contracts\AttributeInterface;
66
use Getsolaris\LaravelTossPayments\Objects\CashReceipt;
77
use Getsolaris\LaravelTossPayments\Objects\RefundReceiveAccount;
8+
use Getsolaris\LaravelTossPayments\Objects\Vbv;
89
use Getsolaris\LaravelTossPayments\TossPayments;
910
use GuzzleHttp\Promise\PromiseInterface;
1011
use Illuminate\Http\Client\Response;
@@ -46,6 +47,27 @@ class Payment extends TossPayments implements AttributeInterface
4647
*/
4748
protected string $bank;
4849

50+
/**
51+
* @var string
52+
*/
53+
protected string $cardNumber;
54+
55+
/**
56+
* @var string
57+
*/
58+
protected string $cardExpirationYear;
59+
60+
/**
61+
* @var string
62+
*/
63+
protected string $cardExpirationMonth;
64+
65+
/**
66+
* @var string
67+
*/
68+
protected string $customerIdentityNumber;
69+
70+
4971
/**
5072
* @var int
5173
*/
@@ -288,4 +310,108 @@ public function virtualAccounts(
288310
'bank' => $this->bank,
289311
] + $parameters);
290312
}
313+
314+
/**
315+
* @param string $cardNumber
316+
* @return $this
317+
*/
318+
public function cardNumber(string $cardNumber): static
319+
{
320+
$this->cardNumber = $cardNumber;
321+
322+
return $this;
323+
}
324+
325+
/**
326+
* @param string $cardExpirationYear
327+
* @return $this
328+
*/
329+
public function cardExpirationYear(string $cardExpirationYear): static
330+
{
331+
$this->cardExpirationYear = $cardExpirationYear;
332+
333+
return $this;
334+
}
335+
336+
/**
337+
* @param string $cardExpirationMonth
338+
* @return $this
339+
*/
340+
public function cardExpirationMonth(string $cardExpirationMonth): static
341+
{
342+
$this->cardExpirationMonth = $cardExpirationMonth;
343+
344+
return $this;
345+
}
346+
347+
/**
348+
* @param string $customerIdentityNumber
349+
* @return $this
350+
*/
351+
public function customerIdentityNumber(string $customerIdentityNumber)
352+
{
353+
$this->customerIdentityNumber = $customerIdentityNumber;
354+
355+
return $this;
356+
}
357+
358+
/**
359+
* @param string|null $cardPassword
360+
* @param int|null $cardInstallmentPlan
361+
* @param bool|null $useFreeInstallmentPlan
362+
* @param int|null $taxFreeAmount
363+
* @param string|null $customerEmail
364+
* @param string|null $customerName
365+
* @param Vbv|null $vbv
366+
* @return PromiseInterface|Response
367+
*/
368+
public function keyIn(
369+
?string $cardPassword = null,
370+
?int $cardInstallmentPlan = null,
371+
?bool $useFreeInstallmentPlan = null,
372+
?int $taxFreeAmount = null,
373+
?string $customerEmail = null,
374+
?string $customerName = null,
375+
?Vbv $vbv = null
376+
): PromiseInterface|Response
377+
{
378+
$parameters = [];
379+
if ($cardPassword) {
380+
$parameters['cardPassword'] = $cardPassword;
381+
}
382+
383+
if ($cardInstallmentPlan) {
384+
$parameters['cardInstallmentPlan'] = $cardInstallmentPlan;
385+
}
386+
387+
if ($useFreeInstallmentPlan) {
388+
$parameters['useFreeInstallmentPlan'] = $useFreeInstallmentPlan;
389+
}
390+
391+
if ($taxFreeAmount) {
392+
$parameters['taxFreeAmount'] = $taxFreeAmount;
393+
}
394+
395+
if ($customerEmail) {
396+
$parameters['customerEmail'] = $customerEmail;
397+
}
398+
399+
if ($customerName) {
400+
$parameters['customerName'] = $customerName;
401+
}
402+
403+
if ($vbv) {
404+
$parameters['vbv'] = (array) $vbv;
405+
}
406+
407+
return $this->client->post($this->createEndpoint('/key-in'), [
408+
'amount' => $this->amount,
409+
'orderId' => $this->orderId,
410+
'orderName' => $this->orderName,
411+
'cardNumber' => $this->cardNumber,
412+
'cardExpirationYear' => $this->cardExpirationYear,
413+
'cardExpirationMonth' => $this->cardExpirationMonth,
414+
'customerIdentityNumber' => $this->customerIdentityNumber,
415+
] + $parameters);
416+
}
291417
}

src/Objects/Vbv.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Getsolaris\LaravelTossPayments\Objects;
4+
5+
class Vbv
6+
{
7+
/**
8+
* @var string
9+
*/
10+
public string $cavv;
11+
12+
/**
13+
* @var string
14+
*/
15+
public string $xid;
16+
17+
/**
18+
* @var string
19+
*/
20+
public string $eci;
21+
22+
public function __construct(string $cavv, string $xid, string $eci)
23+
{
24+
$this->cavv = $cavv;
25+
$this->xid = $xid;
26+
$this->eci = $eci;
27+
}
28+
}

0 commit comments

Comments
 (0)