generated from pricelees/issue-pr-template
test: 토스페이 계좌이체 클라이언트 테스트 추가
This commit is contained in:
parent
211edcaffd
commit
1cb1a97703
@ -8,9 +8,18 @@ object SampleTosspayConstant {
|
||||
const val AMOUNT: Int = 100_000
|
||||
const val CANCEL_REASON: String = "테스트 결제 취소"
|
||||
|
||||
val confirmRequestJson: String = """
|
||||
{
|
||||
"paymentKey": "$PAYMENT_KEY",
|
||||
"orderId": "$ORDER_ID",
|
||||
"amount": "$AMOUNT"
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
val cancelRequestJson: String = """
|
||||
{
|
||||
"cancelReason": "$CANCEL_REASON"
|
||||
"cancelReason": "$CANCEL_REASON",
|
||||
"cancelAmount": "$AMOUNT"
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
@ -21,7 +30,7 @@ object SampleTosspayConstant {
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
val confirmJson: String = """
|
||||
val easypayCardConfirmJson: String = """
|
||||
{
|
||||
"mId": "tgen_docs",
|
||||
"lastTransactionKey": "txrd_a01k4mtanmyx0hm6hmmbvfvmhky",
|
||||
@ -84,7 +93,7 @@ object SampleTosspayConstant {
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
val cancelJson: String = """
|
||||
val easypayCardCancelJson: String = """
|
||||
{
|
||||
"mId": "tgen_docs",
|
||||
"lastTransactionKey": "txrd_a01k4mtgh26vgrn1evbdckyqmdr",
|
||||
@ -162,4 +171,118 @@ object SampleTosspayConstant {
|
||||
"metadata": null
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
val transferConfirmJson: String = """
|
||||
{
|
||||
"mId": "tgen_docs",
|
||||
"lastTransactionKey": "txrd_a01k4mtanmyx0hm6hmmbvfvmhky",
|
||||
"paymentKey": "$PAYMENT_KEY",
|
||||
"orderId": "$ORDER_ID",
|
||||
"orderName": "Sonya Aguirre 예약 결제",
|
||||
"taxExemptionAmount": 0,
|
||||
"status": "DONE",
|
||||
"requestedAt": "${OffsetDateTime.now()}",
|
||||
"approvedAt": "${OffsetDateTime.now().plusSeconds(5)}",
|
||||
"useEscrow": false,
|
||||
"cultureExpense": false,
|
||||
"card": null,
|
||||
"virtualAccount": null,
|
||||
"transfer": {
|
||||
"bankCode": "92",
|
||||
"settlementStatus": "COMPLETED"
|
||||
},
|
||||
"mobilePhone": null,
|
||||
"giftCertificate": null,
|
||||
"cashReceipt": null,
|
||||
"cashReceipts": null,
|
||||
"discount": null,
|
||||
"cancels": null,
|
||||
"secret": "ps_6BYq7GWPVvGNAwZeRBDLrNE5vbo1",
|
||||
"type": "NORMAL",
|
||||
"easyPay": null,
|
||||
"country": "KR",
|
||||
"failure": null,
|
||||
"isPartialCancelable": true,
|
||||
"receipt": {
|
||||
"url": "https://dashboard-sandbox.tosspayments.com/receipt/redirection?transactionId=tgen_20250908230510v2rY2&ref=PX"
|
||||
},
|
||||
"checkout": {
|
||||
"url": "https://api.tosspayments.com/v1/payments/tgen_20250908230510v2rY2/checkout"
|
||||
},
|
||||
"currency": "KRW",
|
||||
"totalAmount": $AMOUNT,
|
||||
"balanceAmount": $AMOUNT,
|
||||
"suppliedAmount": ${(AMOUNT * 0.9).toInt()},
|
||||
"vat": ${(AMOUNT * 0.1).toInt()},
|
||||
"taxFreeAmount": 0,
|
||||
"method": "간편결제",
|
||||
"version": "2022-11-16",
|
||||
"metadata": null
|
||||
}
|
||||
""".trimIndent()
|
||||
|
||||
val transferCancelJson: String = """
|
||||
{
|
||||
"mId": "tgen_docs",
|
||||
"lastTransactionKey": "txrd_a01k4mtanmyx0hm6hmmbvfvmhky",
|
||||
"paymentKey": "$PAYMENT_KEY",
|
||||
"orderId": "$ORDER_ID",
|
||||
"orderName": "Sonya Aguirre 예약 결제",
|
||||
"taxExemptionAmount": 0,
|
||||
"status": "DONE",
|
||||
"requestedAt": "${OffsetDateTime.now()}",
|
||||
"approvedAt": "${OffsetDateTime.now().plusSeconds(5)}",
|
||||
"useEscrow": false,
|
||||
"cultureExpense": false,
|
||||
"card": null,
|
||||
"virtualAccount": null,
|
||||
"transfer": {
|
||||
"bankCode": "92",
|
||||
"settlementStatus": "COMPLETED"
|
||||
},
|
||||
"mobilePhone": null,
|
||||
"giftCertificate": null,
|
||||
"cashReceipt": null,
|
||||
"cashReceipts": null,
|
||||
"discount": null,
|
||||
"cancels": [
|
||||
{
|
||||
"transactionKey": "txrd_a01k4mtgh26vgrn1evbdckyqmdr",
|
||||
"cancelReason": "$CANCEL_REASON",
|
||||
"taxExemptionAmount": 0,
|
||||
"canceledAt": "${OffsetDateTime.now().plusMinutes(1)}",
|
||||
"cardDiscountAmount": 0,
|
||||
"transferDiscountAmount": 0,
|
||||
"easyPayDiscountAmount": 0,
|
||||
"receiptKey": null,
|
||||
"cancelStatus": "DONE",
|
||||
"cancelRequestId": null,
|
||||
"cancelAmount": $AMOUNT,
|
||||
"taxFreeAmount": 0,
|
||||
"refundableAmount": 0
|
||||
}
|
||||
],
|
||||
"secret": "ps_6BYq7GWPVvGNAwZeRBDLrNE5vbo1",
|
||||
"type": "NORMAL",
|
||||
"easyPay": null,
|
||||
"country": "KR",
|
||||
"failure": null,
|
||||
"isPartialCancelable": true,
|
||||
"receipt": {
|
||||
"url": "https://dashboard-sandbox.tosspayments.com/receipt/redirection?transactionId=tgen_20250908230510v2rY2&ref=PX"
|
||||
},
|
||||
"checkout": {
|
||||
"url": "https://api.tosspayments.com/v1/payments/tgen_20250908230510v2rY2/checkout"
|
||||
},
|
||||
"currency": "KRW",
|
||||
"totalAmount": $AMOUNT,
|
||||
"balanceAmount": $AMOUNT,
|
||||
"suppliedAmount": ${(AMOUNT * 0.9).toInt()},
|
||||
"vat": ${(AMOUNT * 0.1).toInt()},
|
||||
"taxFreeAmount": 0,
|
||||
"method": "간편결제",
|
||||
"version": "2022-11-16",
|
||||
"metadata": null
|
||||
}
|
||||
""".trimIndent()
|
||||
}
|
||||
|
||||
@ -39,26 +39,30 @@ class TosspayClientTest(
|
||||
}.andExpect {
|
||||
content().contentType(MediaType.APPLICATION_JSON)
|
||||
}.andExpect {
|
||||
content().json(SampleTosspayConstant.confirmJson)
|
||||
content().json(SampleTosspayConstant.confirmRequestJson)
|
||||
}
|
||||
|
||||
test("성공 응답") {
|
||||
commonAction().andRespond {
|
||||
withSuccess()
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.body(SampleTosspayConstant.confirmJson)
|
||||
.createResponse(it)
|
||||
context("성공 응답") {
|
||||
test("간편결제 + 카드") {
|
||||
commonAction().andRespond {
|
||||
withSuccess()
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.body(SampleTosspayConstant.easypayCardConfirmJson)
|
||||
.createResponse(it)
|
||||
}
|
||||
|
||||
runConfirmTest()
|
||||
}
|
||||
|
||||
val paymentResponse: PaymentClientConfirmResponse = client.confirm(
|
||||
SampleTosspayConstant.PAYMENT_KEY,
|
||||
SampleTosspayConstant.ORDER_ID,
|
||||
SampleTosspayConstant.AMOUNT
|
||||
)
|
||||
test("계좌이체") {
|
||||
commonAction().andRespond {
|
||||
withSuccess()
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.body(SampleTosspayConstant.transferConfirmJson)
|
||||
.createResponse(it)
|
||||
}
|
||||
|
||||
assertSoftly(paymentResponse) {
|
||||
this.paymentKey shouldBe SampleTosspayConstant.PAYMENT_KEY
|
||||
this.totalAmount shouldBe SampleTosspayConstant.AMOUNT
|
||||
runConfirmTest()
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,7 +111,7 @@ class TosspayClientTest(
|
||||
commonAction().andRespond {
|
||||
withSuccess()
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.body(SampleTosspayConstant.cancelJson)
|
||||
.body(SampleTosspayConstant.easypayCardCancelJson)
|
||||
.createResponse(it)
|
||||
}
|
||||
|
||||
@ -155,4 +159,17 @@ class TosspayClientTest(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun runConfirmTest() {
|
||||
val paymentResponse: PaymentClientConfirmResponse = client.confirm(
|
||||
SampleTosspayConstant.PAYMENT_KEY,
|
||||
SampleTosspayConstant.ORDER_ID,
|
||||
SampleTosspayConstant.AMOUNT
|
||||
)
|
||||
|
||||
assertSoftly(paymentResponse) {
|
||||
this.paymentKey shouldBe SampleTosspayConstant.PAYMENT_KEY
|
||||
this.totalAmount shouldBe SampleTosspayConstant.AMOUNT
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user