Skip to content

Commit 49fb803

Browse files
author
이용홍
committed
🎉 init
1 parent 6b2a8e8 commit 49fb803

16 files changed

+780
-21
lines changed

.gitignore

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
1-
# Compiled class file
2-
*.class
1+
HELP.md
2+
.gradle
3+
build/
4+
!gradle/wrapper/gradle-wrapper.jar
5+
!**/src/main/**/build/
6+
!**/src/test/**/build/
37

4-
# Log file
5-
*.log
8+
### STS ###
9+
.apt_generated
10+
.classpath
11+
.factorypath
12+
.project
13+
.settings
14+
.springBeans
15+
.sts4-cache
16+
bin/
17+
!**/src/main/**/bin/
18+
!**/src/test/**/bin/
619

7-
# BlueJ files
8-
*.ctxt
20+
### IntelliJ IDEA ###
21+
.idea
22+
*.iws
23+
*.iml
24+
*.ipr
25+
out/
26+
!**/src/main/**/out/
27+
!**/src/test/**/out/
928

10-
# Mobile Tools for Java (J2ME)
11-
.mtj.tmp/
29+
### NetBeans ###
30+
/nbproject/private/
31+
/nbbuild/
32+
/dist/
33+
/nbdist/
34+
/.nb-gradle/
1235

13-
# Package Files #
14-
*.jar
15-
*.war
16-
*.nar
17-
*.ear
18-
*.zip
19-
*.tar.gz
20-
*.rar
21-
22-
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23-
hs_err_pid*
36+
### VS Code ###
37+
.vscode/

README.md

Lines changed: 144 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,144 @@
1-
# spring-boot-starter-xss
2-
spring boot starter xss filter
1+
# spring-boot-starter-toss-payments
2+
spring boot starter toss payments
3+
4+
토스페이먼츠 API 버전 2022-11-16 으로 작성되었습니다.
5+
6+
## How to
7+
To get a Git project into your build:
8+
9+
*Step 1*. Add the JitPack repository to your build file
10+
11+
Add it in your root build.gradle at the end of repositories:
12+
13+
```groovy
14+
allprojects {
15+
repositories {
16+
...
17+
maven { url 'https://jitpack.io' }
18+
}
19+
}
20+
```
21+
22+
*Step 2*. Add the dependency
23+
24+
```groovy
25+
dependencies {
26+
implementation 'com.github.herbaccara:spring-boot-starter-toss-payments:Tag'
27+
}
28+
```
29+
30+
## application.yml 설정
31+
```yaml
32+
toss:
33+
payments:
34+
enabled: true
35+
client-key: 클라이언트 키
36+
client-secret: 클라이언트 시크릿
37+
webhook:
38+
enabled: true
39+
path: /toss/payments/webhook
40+
```
41+
42+
## 사용하기
43+
```kotlin
44+
class SpringComponent (
45+
private val tossPaymentsService: TossPaymentsService
46+
)
47+
48+
```
49+
50+
## RestTemplate 커스텀 설정
51+
아래 2개의 인터페이스를 상속받은 class 를 만들고 bean 으로 등록
52+
53+
```kotlin
54+
interface TossPaymentsRestTemplateBuilderCustomizer {
55+
fun customize(restTemplateBuilder: RestTemplateBuilder)
56+
}
57+
58+
interface TossPaymentsClientHttpRequestInterceptor : ClientHttpRequestInterceptor
59+
```
60+
61+
62+
## Webhook controller
63+
toss.webhook.enabled 값이 true 인 경우 자동으로
64+
[TossPaymentsWebhookController](src%2Fmain%2Fkotlin%2Fherbaccara%2Ftoss%2Fpayments%2FTossPaymentsWebhookController.kt)
65+
가 bean 으로 등록됩니다.
66+
67+
webhook event 는 applicationEventPublisher 에 즉시 publishEvent 됩니다.
68+
69+
직접 TossPaymentsWebhookController 를 상속받은 component 를 등록해서 사용 하실 수 있습니다.
70+
71+
```kotlin
72+
@RestController
73+
@RequestMapping("\${toss.payments.webhook.path:${TossPaymentsProperties.DEFAULT_WEBHOOK_PATH}}")
74+
class TossPaymentsWebhookController(
75+
private val applicationEventPublisher: ApplicationEventPublisher
76+
) {
77+
/***
78+
* 가상계좌 결제 상태를 알려주는 웹훅
79+
*/
80+
@RequestMapping("/deposit-callback")
81+
fun onDepositCallback(depositCallback: DepositCallback) {
82+
applicationEventPublisher.publishEvent(depositCallback)
83+
}
84+
85+
/***
86+
* 카드, 계좌이체, 휴대폰, 상품권 결제 상태를 알려주는 웹훅입니다.
87+
*/
88+
@RequestMapping("/payment-status-changed")
89+
fun onPaymentStatusChanged(paymentStatusChangedEvent: Event<PaymentStatusChanged>) {
90+
applicationEventPublisher.publishEvent(paymentStatusChangedEvent)
91+
}
92+
93+
/***
94+
* 지급대행 요청 상태가 COMPLETED, FAILED로 변경되면 웹훅이 전송됩니다. 자세한 상태 설명은 status에서 확인하세요.
95+
*/
96+
@RequestMapping("/payout-status-changed")
97+
fun onPayoutStatusChanged(payoutStatusChangedEvent: Event<PayoutStatusChanged>) {
98+
applicationEventPublisher.publishEvent(payoutStatusChangedEvent)
99+
}
100+
101+
/***
102+
* 브랜드페이 고객의 결제 수단이 변경되면 웹훅이 전송됩니다.
103+
*/
104+
@RequestMapping("/method-updated")
105+
fun onMethodUpdated(methodUpdatedEvent: Event<MethodUpdated>) {
106+
applicationEventPublisher.publishEvent(methodUpdatedEvent)
107+
}
108+
109+
/***
110+
* 브랜드페이 고객의 상태가 변경되면 웹훅이 전송됩니다.
111+
*/
112+
@RequestMapping("/customer-status-changed")
113+
fun onCustomerStatusChanged(customerStatusChangedEvent: Event<CustomerStatusChanged>) {
114+
applicationEventPublisher.publishEvent(customerStatusChangedEvent)
115+
}
116+
}
117+
118+
```
119+
120+
## Webhook event
121+
122+
[AbstractTossPaymentsEventListener.kt](src%2Fmain%2Fkotlin%2Fherbaccara%2Ftoss%2Fpayments%2FAbstractTossPaymentsEventListener.kt)
123+
를 상속받은 component 를 bean 으로 등록해서 webhook event 를 처리 할 수 있습니다.
124+
125+
```kotlin
126+
abstract class AbstractTossPaymentsEventListener {
127+
128+
@EventListener
129+
abstract fun onDepositCallback(depositCallback: DepositCallback)
130+
131+
@EventListener
132+
abstract fun onPaymentStatusChanged(paymentStatusChangedEvent: Event<PaymentStatusChanged>)
133+
134+
@EventListener
135+
abstract fun onPayoutStatusChanged(payoutStatusChangedEvent: Event<PayoutStatusChanged>)
136+
137+
@EventListener
138+
abstract fun onMethodUpdated(methodUpdatedEvent: Event<MethodUpdated>)
139+
140+
@EventListener
141+
abstract fun onCustomerStatusChanged(customerStatusChangedEvent: Event<CustomerStatusChanged>)
142+
}
143+
144+
```

build.gradle

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2+
3+
plugins {
4+
id 'java'
5+
id 'java-library'
6+
id 'maven-publish'
7+
id 'org.jetbrains.kotlin.jvm' version '1.8.10'
8+
id 'org.jetbrains.kotlin.plugin.spring' version '1.8.10'
9+
id "org.jmailen.kotlinter" version "3.13.0"
10+
}
11+
12+
group = 'herbaccara'
13+
version = '0.0.1'
14+
sourceCompatibility = '17'
15+
16+
publishing {
17+
publications {
18+
shadow(MavenPublication) {
19+
from components.java
20+
21+
version = version
22+
artifactId = project.name
23+
groupId = rootProject.group
24+
}
25+
}
26+
}
27+
28+
kotlinter {
29+
disabledRules = ["no-wildcard-imports", "enum-entry-name-case"]
30+
}
31+
32+
repositories {
33+
mavenCentral()
34+
}
35+
36+
dependencies {
37+
implementation 'org.jetbrains.kotlin:kotlin-reflect'
38+
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8'
39+
40+
implementation 'org.springframework:spring-context:6.0.2'
41+
implementation 'org.springframework:spring-webmvc:6.0.2'
42+
implementation 'org.springframework:spring-webmvc:6.0.2'
43+
44+
implementation 'jakarta.servlet:jakarta.servlet-api:6.0.0'
45+
46+
implementation 'org.jsoup:jsoup:1.15.4'
47+
48+
implementation 'org.springframework.boot:spring-boot:3.0.0'
49+
implementation 'org.springframework.boot:spring-boot-autoconfigure:3.0.0'
50+
testImplementation 'org.springframework.boot:spring-boot-starter-test:3.0.0'
51+
}
52+
53+
tasks.withType(KotlinCompile) {
54+
kotlinOptions {
55+
freeCompilerArgs = ['-Xjsr305=strict']
56+
jvmTarget = '17'
57+
}
58+
}
59+
60+
tasks.named('test') {
61+
useJUnitPlatform()
62+
}

gradle/wrapper/gradle-wrapper.jar

60.1 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip
4+
networkTimeout=10000
5+
zipStoreBase=GRADLE_USER_HOME
6+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)