-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBootpayExample.java
More file actions
286 lines (254 loc) · 10.2 KB
/
BootpayExample.java
File metadata and controls
286 lines (254 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
import kr.co.bootpay.Bootpay;
import kr.co.bootpay.model.request.*;
import kr.co.bootpay.model.response.ResDefault;
import kr.co.bootpay.model.response.data.*;
//import kr.co.bootpay.*
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.TimeZone;
public class BootpayExample {
static Bootpay bootpay;
public static void main(String[] args) {
bootpay = new Bootpay("5b8f6a4d396fa665fdc2b5ea", "rm6EYECr6aroQVG2ntW0A6LpWnkTgP4uQ3H18sDDUYw=");
goGetToken();
// getReceipt();
// receiptCancel();
// getBillingKey();
requestSubscribe();
// reserveSubscribe();
// reserveCancelSubscribe();
// destroyBillingKey();
// getUserToken();
// requestLink();
// confirm();
// certificate();
// shippingStart();
}
public static void goGetToken() {
try {
HashMap<String, Object> res = bootpay.getAccessToken();
if(res.get("error_code") == null) { //success
System.out.println("goGetToken success: " + res);
} else {
System.out.println("goGetToken false: " + res);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void getBillingKey() {
Subscribe subscribe = new Subscribe();
subscribe.orderName = "정기결제 테스트 아이템";
subscribe.subscriptionId = "" + (System.currentTimeMillis() / 1000);
subscribe.pg = "welcome";
subscribe.cardNo = "5570**********1074"; //실제 테스트시에는 *** 마스크처리가 아닌 숫자여야 함
subscribe.cardPw = "**"; //실제 테스트시에는 *** 마스크처리가 아닌 숫자여야 함
subscribe.cardExpireYear = "**"; //실제 테스트시에는 *** 마스크처리가 아닌 숫자여야 함
subscribe.cardExpireMonth = "**"; //실제 테스트시에는 *** 마스크처리가 아닌 숫자여야 함
subscribe.cardIdentityNo = ""; //생년월일 또는 사업자 등록번호 (- 없이 입력)
subscribe.user = new User();
subscribe.user.username = "홍길동";
subscribe.user.phone = "01011112222";
subscribe.extra = new SubscribeExtra();
subscribe.extra.subscribeTestPayment = 1;
try {
HashMap<String, Object> res = bootpay.getBillingKey(subscribe);
if(res.get("error_code") == null) { //success
System.out.println("getBillingKey success: " + res);
} else {
System.out.println("getBillingKey false: " + res);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void destroyBillingKey() {
String receiptId = "628b2644d01c7e00209b6092";
try {
HashMap<String, Object> res = bootpay.destroyBillingKey(receiptId);
if(res.get("error_code") == null) { //success
System.out.println("destroyBillingKey success: " + res);
} else {
System.out.println("destroyBillingKey false: " + res);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void requestSubscribe() {
SubscribePayload payload = new SubscribePayload();
payload.billingKey = "66f9da41e1afdbe0495e6526";
payload.orderName = "아이템01";
payload.price = 1000;
payload.user = new User();
payload.user.phone = "01012345678";
payload.orderId = "" + (System.currentTimeMillis() / 1000);
try {
HashMap<String, Object> res = bootpay.requestSubscribe(payload);
if(res.get("error_code") == null) { //success
System.out.println("requestSubscribe success: " + res);
} else {
System.out.println("requestSubscribe false: " + res);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void reserveSubscribe() {
SubscribePayload payload = new SubscribePayload();
payload.billingKey = "628b2644d01c7e00209b6092";
payload.orderName = "아이템01";
payload.price = 1000;
payload.orderId = "" + (System.currentTimeMillis() / 1000);
Date now = new Date();
now.setTime(now.getTime() + 10 * 1000); //10초 뒤 결제
//
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss XXX");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
payload.reserveExecuteAt = sdf.format(now); // 결제 승인 시점
try {
HashMap<String, Object> res = bootpay.reserveSubscribe(payload);
if(res.get("error_code") == null) { //success
System.out.println("reserveSubscribe success: " + res);
} else {
System.out.println("reserveSubscribe false: " + res);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void reserveCancelSubscribe() {
String receiptId = "628b316cd01c7e00219b6081";
try {
HashMap<String, Object> res = bootpay.reserveCancelSubscribe(receiptId);
if(res.get("error_code") == null) { //success
System.out.println("reserveCancelSubscribe success: " + res);
} else {
System.out.println("reserveCancelSubscribe false: " + res);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void receiptCancel() {
Cancel cancel = new Cancel();
cancel.receiptId = "664ae6621a10a75af2b4b085";
cancel.cancelUsername = "관리자3";
cancel.cancelMessage = "테스트 결제3";
// cancel.price = 1000.0; //부분취소 요청시
// cancel.cancelId = "12342134"; //부분취소 요청시, 중복 부분취소 요청하는 실수를 방지하고자 할때 지정
// RefundData refund = new RefundData(); // 가상계좌 환불 요청시, 단 CMS 특약이 되어있어야만 환불요청이 가능하다.
// refund.account = "675601012341234"; //환불계좌
// refund.accountholder = "홍길동"; //환불계좌주
// refund.bankcode = BankCode.getCode("국민은행");//은행코드
// cancel.refund = refund;
try {
// ResDefault
HashMap<String, Object> res = bootpay.receiptCancel(cancel);
if(res.get("error_code") == null) { //success
System.out.println("receiptCancel success: " + res);
} else {
System.out.println("receiptCancel false: " + res);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void getUserToken() {
UserToken userToken = new UserToken();
userToken.userId = "1234"; // 개발사에서 관리하는 회원 고유 번호
try {
HashMap<String, Object> res = bootpay.getUserToken(userToken);
if(res.get("error_code") == null) { //success
System.out.println("getUserToken success: " + res);
} else {
System.out.println("getUserToken false: " + res);
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Deprecated
public static void requestLink() {
Payload payload = new Payload();
payload.orderId = "1234";
payload.price = 1000d;
payload.orderName = "테스트 결제";
payload.pg = "payapp";
// payload.method = "vbank";
User user = new User();
user.username = "홍길동";
user.phone = "01012341234";
payload.user = user;
Extra extra = new Extra();
payload.extra = extra;
try {
ResDefault res = bootpay.requestLink(payload);
System.out.println("requestLink:" + res.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
public static void confirm() {
String receiptId = "62876963d01c7e00209b6028";
try {
HashMap<String, Object> res = bootpay.confirm(receiptId);
if(res.get("error_code") == null) { //success
System.out.println("confirm success: " + res);
} else {
System.out.println("confirm false: " + res);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void getReceipt() {
String receiptId = "62b12f4b6262500007629fec";
try {
HashMap<String, Object> res = bootpay.getReceipt(receiptId);
if(res.get("error_code") == null) { //success
System.out.println("getReceipt success: " + res);
} else {
System.out.println("getReceipt false: " + res);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void certificate() {
String receiptId = "628ae7ffd01c7e001e9b6066";
try {
HashMap<String, Object> res = bootpay.certificate(receiptId);
if(res.get("error_code") == null) { //success
System.out.println("certificate success: " + res);
} else {
System.out.println("certificate false: " + res);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void shippingStart() {
Shipping shipping = new Shipping();
shipping.receiptId = "628ae7ffd01c7e001e9b6066";
shipping.trackingNumber = "123456";
shipping.deliveryCorp = "CJ대한통운";
ShippingUser user = new ShippingUser();
user.username = "홍길동";
user.phone = "01000000000";
user.address = "서울특별시 종로구";
user.zipcode = "08490";
shipping.user = user;
try {
HashMap<String, Object> res = bootpay.shippingStart(shipping);
if(res.get("error_code") == null) { //success
System.out.println("certificate success: " + res);
} else {
System.out.println("certificate false: " + res);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}