Skip to content

Commit b6ced45

Browse files
authored
Merge pull request #223 from prgrms-web-devcourse-final-project/fix#217
[Fix]: 카드 등록 오류 수정
2 parents 7d2382d + 45f5511 commit b6ced45

File tree

6 files changed

+24
-8
lines changed

6 files changed

+24
-8
lines changed

src/main/java/com/backend/domain/payment/dto/request/PaymentMethodCreateRequest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,5 @@ public class PaymentMethodCreateRequest {
2929
private String bankName; // 예: KB국민은행
3030
private String acctLast4; // "5678"
3131

32-
@NotBlank
33-
private String provider; // "toss", "iamport" 등..
32+
private String provider; // "toss"
3433
}

src/main/java/com/backend/domain/payment/dto/response/TossIssueBillingKeyResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class TossIssueBillingKeyResponse {
1313
private String provider; // "toss"
1414

1515
@Schema(description = "카드 브랜드/발급사", example = "SHINHAN")
16-
private String cardBrand; // 선택: 스냅샷에 쓰려면
16+
private String brand; // 선택: 스냅샷에 쓰려면
1717

1818
@Schema(description = "카드 끝 4자리", example = "1234")
1919
private String last4; // 선택

src/main/java/com/backend/domain/payment/entity/PaymentMethod.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class PaymentMethod extends BaseEntity {
5959
private String acctLast4; // 계좌번호 끝 4자리(예: 5678)..
6060

6161
@Column(length = 32, nullable = false)
62-
private String provider; // 어떤 PG를 통해 결제하는지(예: "toss", "iamport")..
62+
private String provider; // 어떤 PG를 통해 결제하는지(예: "toss")..
6363

6464
@Column(nullable = false)
6565
@Builder.Default

src/main/java/com/backend/domain/payment/service/PaymentMethodService.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ public PaymentMethodResponse create(Long memberId, PaymentMethodCreateRequest re
7777
if (isBlank(req.getBrand()) || isBlank(req.getLast4())){
7878
throw new IllegalArgumentException("CARD는 brand, last4가 필요합니다. (expMonth/expYear는 선택)");
7979
}
80+
81+
String normalizedLast4 = req.getLast4().replaceAll("\\D", "");
82+
if (normalizedLast4.length() < 4) {
83+
throw new IllegalArgumentException("last4는 카드번호 끝 4자리여야 합니다.");
84+
}
85+
last4 = normalizedLast4.substring(normalizedLast4.length() - 4);
86+
8087
// 카드 필드 채우기..
8188
brand = req.getBrand();
8289
last4 = req.getLast4();
@@ -105,6 +112,13 @@ public PaymentMethodResponse create(Long memberId, PaymentMethodCreateRequest re
105112
}
106113
}
107114

115+
String provider = req.getProvider();
116+
if (provider == null || provider.isBlank()) {
117+
provider = "toss";
118+
} else {
119+
provider = provider.trim().toLowerCase();
120+
}
121+
108122
PaymentMethod entity = PaymentMethod.builder()
109123
.member(member)
110124
.methodType(type)
@@ -120,7 +134,7 @@ public PaymentMethodResponse create(Long memberId, PaymentMethodCreateRequest re
120134
.bankCode(bankCode)
121135
.bankName(bankName)
122136
.acctLast4(acctLast4)
123-
.provider( nvlBlankToNull(req.getProvider()) )
137+
.provider(provider)
124138
.active(true)
125139
.deleted(false)
126140
.build();

src/main/java/com/backend/domain/payment/service/TossBillingClientService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public TossIssueBillingKeyResponse issueBillingKey(String customerKey, String au
8989

9090
return TossIssueBillingKeyResponse.builder()
9191
.billingKey(billingKey)
92-
.cardBrand(cardBrand)
92+
.brand(cardBrand)
9393
.last4(cardNumber)
9494
.expMonth(expMonth)
9595
.expYear(expYear)

src/main/resources/static/payments/toss/billing-success.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,11 @@ <h2>빌링키 발급 완료</h2>
3636
log(`✓ 교환 성공 → billingKey=${billingKey}`);
3737

3838
// 카드 정보(있으면) 보조로 사용
39-
const brand = d.cardBrand ?? null;
40-
const last4 = d.cardNumber ? String(d.cardNumber).slice(-4) : null;
39+
const brand = d.brand ?? d.cardBrand ?? null;
40+
const rawLast4 = d.last4 ?? d.cardNumber ?? null;
41+
const last4 = rawLast4
42+
? String(rawLast4).replace(/\D/g, '').slice(-4) // 숫자만 남기고 끝 4자리
43+
: null;
4144
const expMon = d.expMonth ?? null;
4245
const expYear = d.expYear ?? null;
4346

0 commit comments

Comments
 (0)