@bootpay/client-js 5.0.0-beta.6 → 5.0.0-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/dist/package.json +47 -0
  2. package/dist/src/bootpay-environment.js +5 -0
  3. package/dist/src/bootpay-environment.js.map +1 -0
  4. package/dist/src/bootpay-sdk.js +243 -0
  5. package/dist/src/bootpay-sdk.js.map +1 -0
  6. package/dist/src/bootpay-widget.js +83 -0
  7. package/dist/src/bootpay-widget.js.map +1 -0
  8. package/dist/src/bootpay.js +321 -0
  9. package/dist/src/bootpay.js.map +1 -0
  10. package/dist/src/index.js +33 -0
  11. package/dist/src/index.js.map +1 -0
  12. package/dist/src/lib/analytics.js +137 -0
  13. package/dist/src/lib/analytics.js.map +1 -0
  14. package/dist/src/lib/bootpay-widget.js +171 -0
  15. package/dist/src/lib/bootpay-widget.js.map +1 -0
  16. package/dist/src/lib/bootpay.js +496 -0
  17. package/dist/src/lib/bootpay.js.map +1 -0
  18. package/dist/src/lib/event/payment.d.ts +1 -2
  19. package/dist/src/lib/event/payment.js +215 -0
  20. package/dist/src/lib/event/payment.js.map +1 -0
  21. package/dist/src/lib/event/polling.js +42 -0
  22. package/dist/src/lib/event/polling.js.map +1 -0
  23. package/dist/src/lib/event/user-token.js +51 -0
  24. package/dist/src/lib/event/user-token.js.map +1 -0
  25. package/dist/src/lib/event/widget.js +90 -0
  26. package/dist/src/lib/event/widget.js.map +1 -0
  27. package/dist/src/lib/locale/message.js +110 -0
  28. package/dist/src/lib/locale/message.js.map +1 -0
  29. package/dist/src/lib/template/oopay.js +66 -0
  30. package/dist/src/lib/template/oopay.js.map +1 -0
  31. package/dist/src/lib/template/payment.js +488 -0
  32. package/dist/src/lib/template/payment.js.map +1 -0
  33. package/dist/src/lib/template/user-token.js +281 -0
  34. package/dist/src/lib/template/user-token.js.map +1 -0
  35. package/dist/src/lib/template/widget.js +78 -0
  36. package/dist/src/lib/template/widget.js.map +1 -0
  37. package/dist/src/models/bootpay-interface.js +3 -0
  38. package/dist/src/models/bootpay-interface.js.map +1 -0
  39. package/dist/src/models/bootpay-sdk-interface.js +3 -0
  40. package/dist/src/models/bootpay-sdk-interface.js.map +1 -0
  41. package/dist/src/models/bootpay-widget-interface.js +3 -0
  42. package/dist/src/models/bootpay-widget-interface.js.map +1 -0
  43. package/dist/src/models/const.js +15 -0
  44. package/dist/src/models/const.js.map +1 -0
  45. package/dist/src/support/alfred-progress/index.js +64 -0
  46. package/dist/src/support/alfred-progress/index.js.map +1 -0
  47. package/dist/src/support/bootpay-manager.d.ts +2 -2
  48. package/dist/src/support/bootpay-manager.js +39 -0
  49. package/dist/src/support/bootpay-manager.js.map +1 -0
  50. package/dist/src/support/environment.js +89 -0
  51. package/dist/src/support/environment.js.map +1 -0
  52. package/dist/src/support/event.js +133 -0
  53. package/dist/src/support/event.js.map +1 -0
  54. package/dist/src/support/logger.js +130 -0
  55. package/dist/src/support/logger.js.map +1 -0
  56. package/dist/src/support/resource.js +125 -0
  57. package/dist/src/support/resource.js.map +1 -0
  58. package/dist/src/support/storage.js +191 -0
  59. package/dist/src/support/storage.js.map +1 -0
  60. package/dist/src/support/template-manager.js +47 -0
  61. package/dist/src/support/template-manager.js.map +1 -0
  62. package/dist/src/support/util.js +36 -0
  63. package/dist/src/support/util.js.map +1 -0
  64. package/dist/src/support/widget-store.js +73 -0
  65. package/dist/src/support/widget-store.js.map +1 -0
  66. package/package.json +3 -3
  67. package/tsconfig-esnext.json +39 -0
  68. package/dist/bootpay-environment.js +0 -1
  69. package/dist/bootpay-sdk.js +0 -2
  70. package/dist/bootpay-sdk.js.LICENSE.txt +0 -1
  71. package/dist/bootpay-widget.js +0 -2
  72. package/dist/bootpay-widget.js.LICENSE.txt +0 -1
  73. package/dist/bootpay.js +0 -2
  74. package/dist/bootpay.js.LICENSE.txt +0 -1
  75. package/dist/dist/bootpay.d.ts +0 -2
  76. package/dist/index.js +0 -8
  77. package/dist/src/test/index.d.ts +0 -1
  78. package/dist/src/test/moduleRequire.d.ts +0 -1
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.BootpayWidgetWindow = exports.BootpayWidgetWindowManager = void 0;
16
+ const bootpay_manager_1 = require("../support/bootpay-manager");
17
+ const widget_1 = require("./template/widget");
18
+ const widget_2 = require("./event/widget");
19
+ const widget_store_1 = require("../support/widget-store");
20
+ const logger_1 = require("../support/logger");
21
+ const event_1 = require("../support/event");
22
+ const message_1 = require("./locale/message");
23
+ const bootpay_1 = __importDefault(require("../bootpay"));
24
+ class BootpayWidgetWindowManager extends bootpay_manager_1.BootpayManager {
25
+ constructor() {
26
+ super();
27
+ this.message = message_1.BootpayMessage;
28
+ }
29
+ initialize() {
30
+ // 선택된 PG를 초기화한다
31
+ widget_store_1.WidgetStore.setWidgetData({
32
+ el: undefined,
33
+ application_id: undefined,
34
+ price: 0,
35
+ tax_free: 0,
36
+ currency: 'KRW',
37
+ user_token: undefined,
38
+ pg: undefined,
39
+ method: undefined
40
+ });
41
+ }
42
+ render(el, data) {
43
+ if (this.$blank(data === null || data === void 0 ? void 0 : data.price) || data.price < 0) {
44
+ throw new Error('결제금액은 1원 이상을 입력해주세요.');
45
+ }
46
+ if (this.$blank(data === null || data === void 0 ? void 0 : data.application_id)) {
47
+ throw new Error('application_id가 입력되지 않았습니다.');
48
+ }
49
+ this.initialize();
50
+ widget_store_1.WidgetStore.setWidgetData({
51
+ el,
52
+ application_id: data.application_id,
53
+ price: data.price,
54
+ tax_free: data.tax_free,
55
+ currency: data.currency,
56
+ user_token: data.user_token,
57
+ use_only_oopay: data.use_only_oopay,
58
+ external_terms: data.external_terms,
59
+ widget_extra: data.extra,
60
+ use_terms: data.use_terms,
61
+ sandbox: data.sandbox
62
+ });
63
+ widget_1.TemplateWidget.render();
64
+ // 이벤트를 binding 한다
65
+ widget_2.BootpayWidgetEvent.bind();
66
+ }
67
+ update(data) {
68
+ const { price, tax_free, currency, user_token, use_only_oopay, use_terms, sandbox, external_terms } = data;
69
+ widget_store_1.WidgetStore.updateOnProcessing({
70
+ price,
71
+ tax_free,
72
+ currency,
73
+ user_token,
74
+ use_only_oopay,
75
+ use_terms,
76
+ external_terms,
77
+ sandbox
78
+ });
79
+ // user token이 갱신되면 user_token을 업데이트한다
80
+ if (this.$present(user_token) || this.$present(use_only_oopay) || this.$present(use_terms) || this.$present(sandbox)) {
81
+ widget_1.TemplateWidget.postMessage('bootpayWidgetUpdateUserToken', {
82
+ user_token,
83
+ use_only_oopay,
84
+ use_terms,
85
+ external_terms,
86
+ sandbox
87
+ });
88
+ }
89
+ }
90
+ // 결제창을 다시 rendering 한다
91
+ rerender() {
92
+ widget_1.TemplateWidget.rerender();
93
+ }
94
+ destroy() {
95
+ widget_1.TemplateWidget.destroy();
96
+ }
97
+ selectPayment(pg, method, wallet_id, terms = false, select_terms, extra) {
98
+ widget_store_1.WidgetStore.setPayment(pg, method, wallet_id, terms, select_terms, extra);
99
+ logger_1.Logger.debug('selectPayment', `pg: ${pg}, method: ${method}, wallet_id: ${wallet_id}, terms: ${terms}, select_terms: ${JSON.stringify(select_terms)}, extra: ${JSON.stringify(extra)}`);
100
+ }
101
+ currentTermsCondition() {
102
+ return widget_store_1.WidgetStore.selectTerms;
103
+ }
104
+ /**
105
+ * 부트페이 결제 요청을 한다
106
+ * Comment by GOSOMI
107
+ * @date: 2023-06-21
108
+ */
109
+ requestPayment(data) {
110
+ return __awaiter(this, void 0, void 0, function* () {
111
+ if (this.$blank(widget_store_1.WidgetStore.pg) || this.$blank(widget_store_1.WidgetStore.method)) {
112
+ throw new event_1.BootpayEventError({
113
+ event: 'error',
114
+ error_code: 'RC_PG_METHOD_NOT_SELECTED',
115
+ message: this.message.getLocaleMessage('notSelectPayment', 'ko')
116
+ });
117
+ }
118
+ if (!widget_store_1.WidgetStore.termsPassed && widget_store_1.WidgetStore.useTerms) {
119
+ throw new event_1.BootpayEventError({
120
+ event: 'error',
121
+ error_code: 'RC_TERMS_NOT_AGREE',
122
+ message: this.message.getLocaleMessage('termsNotAgree', 'ko')
123
+ });
124
+ }
125
+ if (widget_store_1.WidgetStore.method === 'OOPAY' && widget_store_1.WidgetStore.walletId === undefined) {
126
+ throw new event_1.BootpayEventError({
127
+ event: 'error',
128
+ error_code: 'RC_OOPAY_NEED_SELECT_WALLET',
129
+ message: this.message.getLocaleMessage('notSelectOOPay', 'ko')
130
+ });
131
+ }
132
+ data.application_id = widget_store_1.WidgetStore.applicationId;
133
+ data.price = widget_store_1.WidgetStore.price;
134
+ data.tax_free = widget_store_1.WidgetStore.taxFree;
135
+ data.currency = widget_store_1.WidgetStore.currency;
136
+ data.pg = widget_store_1.WidgetStore.pg;
137
+ data.method = widget_store_1.WidgetStore.method;
138
+ data.wallet_id = widget_store_1.WidgetStore.walletId;
139
+ data.terms = widget_store_1.WidgetStore.selectTerms;
140
+ data.widget_sandbox = widget_store_1.WidgetStore.sandbox;
141
+ data.extra = this.mergeExtraOnStore(data.extra);
142
+ data.widget = 1;
143
+ return bootpay_1.default.requestPayment(data);
144
+ });
145
+ }
146
+ /**
147
+ * Merge Store in Extra Value
148
+ * Comment by GOSOMI
149
+ * @date: 2023-11-17
150
+ */
151
+ mergeExtraOnStore(extra) {
152
+ if (extra === undefined) {
153
+ return widget_store_1.WidgetStore.extra;
154
+ }
155
+ else {
156
+ if (widget_store_1.WidgetStore.extra !== undefined) {
157
+ Object.keys(widget_store_1.WidgetStore.extra).forEach((key) => {
158
+ // @ts-ignore
159
+ extra[key] = widget_store_1.WidgetStore.extra[key];
160
+ });
161
+ }
162
+ return extra;
163
+ }
164
+ }
165
+ isRendered() {
166
+ return widget_1.TemplateWidget.isRendered;
167
+ }
168
+ }
169
+ exports.BootpayWidgetWindowManager = BootpayWidgetWindowManager;
170
+ exports.BootpayWidgetWindow = new BootpayWidgetWindowManager();
171
+ //# sourceMappingURL=bootpay-widget.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootpay-widget.js","sourceRoot":"","sources":["../../../src/lib/bootpay-widget.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,gEAA2D;AAE3D,8CAAkD;AAClD,2CAAmD;AACnD,0DAAqD;AACrD,8CAA0C;AAE1C,4CAAoD;AACpD,8CAAiD;AACjD,yDAAgC;AAEhC,MAAa,0BAA2B,SAAQ,gCAAc;IAG1D;QACI,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,OAAO,GAAG,wBAAc,CAAA;IACjC,CAAC;IAED,UAAU;QACN,gBAAgB;QAChB,0BAAW,CAAC,aAAa,CAAC;YACtB,EAAE,EAAc,SAAS;YACzB,cAAc,EAAE,SAAS;YACzB,KAAK,EAAW,CAAC;YACjB,QAAQ,EAAQ,CAAC;YACjB,QAAQ,EAAQ,KAAK;YACrB,UAAU,EAAM,SAAS;YACzB,EAAE,EAAc,SAAS;YACzB,MAAM,EAAU,SAAS;SAC5B,CAAC,CAAA;IACN,CAAC;IAED,MAAM,CAAC,EAAU,EAAE,IAA+B;QAC9C,IAAI,IAAI,CAAC,MAAM,CAAC,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,CAAC,IAAI,IAAI,CAAC,KAAK,GAAG,CAAC,EAAE;YAC5C,MAAM,IAAI,KAAK,CAAC,sB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0BAAW,CAAC,KAAK,CAAA;SAC3B;aAAM;YACH,IAAI,0BAAW,CAAC,KAAK,KAAK,SAAS,EAAE;gBACjC,MAAM,CAAC,IAAI,CAAC,0BAAW,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,GAAW,EAAE,EAAE;oBACnD,aAAa;oBACb,KAAK,CAAC,GAAG,CAAC,GAAG,0BAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;gBACvC,CAAC,CAAC,CAAA;aACL;YACD,OAAO,KAAK,CAAA;SACf;IACL,CAAC;IAED,UAAU;QACN,OAAO,uBAAc,CAAC,UAAU,CAAA;IACpC,CAAC;CACJ;AAlKD,gEAkKC;AAEY,QAAA,mBAAmB,GAAG,IAAI,0BAA0B,EAAE,CAAA"}
@@ -0,0 +1,496 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.BootpayRequestPayment = exports.BootpayRequestPaymentManager = void 0;
16
+ const bootpay_manager_1 = require("../support/bootpay-manager");
17
+ const storage_1 = require("../support/storage");
18
+ const event_1 = require("../support/event");
19
+ const const_1 = require("../models/const");
20
+ const payment_1 = require("./template/payment");
21
+ const alfred_progress_1 = require("../support/alfred-progress");
22
+ const logger_1 = require("../support/logger");
23
+ const environment_1 = require("../support/environment");
24
+ const util_1 = require("../support/util");
25
+ const package_json_1 = __importDefault(require("../../package.json"));
26
+ class BootpayRequestPaymentManager extends bootpay_manager_1.BootpayManager {
27
+ constructor() {
28
+ super();
29
+ this.$session = storage_1.SessionStorage;
30
+ this.$logger = logger_1.Logger;
31
+ this.$event = logger_1.EventLogger;
32
+ this.platformType = const_1.Const.PLATFORM.JS;
33
+ this.$transactionKey = '';
34
+ this.extra = {};
35
+ this.browserBootpayFilter = {
36
+ instagram: /Instagram/i,
37
+ kakaotalk: /KAKAOTALK/i,
38
+ facebook: /FBAV/i,
39
+ naver: /NAVER/i,
40
+ mobile_safari: /(iPhone|iPad|iPod)/,
41
+ mobile_chrome: [
42
+ /Mobile|iP(hone|od|ad)|Android|BlackBerry|IEMobile|Kindle|NetFront|Silk-Accelerated|(hpw|web)OS|Fennec|Minimo|Opera M(obi|ini)|Blazer|Dolfin|Dolphin|Skyfire|Zune/,
43
+ /Chrome/
44
+ ]
45
+ };
46
+ }
47
+ /**
48
+ * 결제 요청 진행하기
49
+ * Comment by GOSOMI
50
+ * @date: 2021-05-11
51
+ * @param data: RequestPaymentModel
52
+ * @returns Promise<any>
53
+ */
54
+ requestPayment(data) {
55
+ var _a;
56
+ return __awaiter(this, void 0, void 0, function* () {
57
+ if (((_a = data.extra) === null || _a === void 0 ? void 0 : _a.locale) !== undefined && !environment_1.Environment.isSetLocale) {
58
+ environment_1.Environment.setLocale(data.extra.locale);
59
+ }
60
+ this.$event.clearInstance();
61
+ // transaction Key를 만든다
62
+ this.generateTransactionKey();
63
+ data.application_id = environment_1.Environment.currentApplicationId(data.application_id);
64
+ // 로그를 보낼 Key를 설정한다
65
+ this.$event.setTokenKey(this.$transactionKey);
66
+ // Application ID를 설정한다
67
+ this.$event.setApplicationId(data.application_id);
68
+ this.$event.send({
69
+ step: 'start',
70
+ msg: '결제 요청 시작',
71
+ request: data
72
+ });
73
+ data.sdk = true;
74
+ data.platform_type = this.platformType;
75
+ data.ver = package_json_1.default.version;
76
+ data.sdk_version = environment_1.Environment.sdkVersion;
77
+ data.sdk_type = environment_1.Environment.sdkName;
78
+ data.locale = environment_1.Environment.locale;
79
+ data.price = parseFloat(String(data.price));
80
+ data.tax_free = parseFloat(String(data.tax_free));
81
+ BootpayRequestPaymentManager.invalidRequestParamsData(data);
82
+ BootpayRequestPaymentManager.invalidRequestItemsData(data.items, data.price);
83
+ data.uuid = this.$session.currentUserUUID();
84
+ data.sk = this.$session.currentSessionKey();
85
+ data.ti = this.$session.currentTimeTerm();
86
+ data.tk = this.$transactionKey;
87
+ data.env = this.getUserDeviceEnvironment();
88
+ data.extra = this.openTypeFilter(data.extra);
89
+ this.extra = data.extra;
90
+ try {
91
+ const response = yield payment_1.TemplatePayment.start(data);
92
+ logger_1.Logger.debug('confirm ready', response);
93
+ // 결제창을 닫는다
94
+ payment_1.TemplatePayment.hidePaymentiFrame();
95
+ payment_1.TemplatePayment.closePopup();
96
+ // done 이벤트가 아닌 경우 로그를 남긴다
97
+ if (['done', 'issued'].indexOf(response.event) === -1) {
98
+ this.$event.send({
99
+ step: response.event,
100
+ msg: '',
101
+ request: data,
102
+ response: response
103
+ });
104
+ }
105
+ // 승인 Gateway URL을 넣는다
106
+ payment_1.TemplatePayment.setConfirmFormUrl(`${response.gateway_url}/confirm/${response.receipt_id}?application_id=${data.application_id}`);
107
+ return Promise.resolve(response);
108
+ }
109
+ catch (e) {
110
+ this.eventError(e);
111
+ return Promise.reject(e);
112
+ }
113
+ });
114
+ }
115
+ /**
116
+ * 결제 승인
117
+ * Comment by GOSOMI
118
+ * @date: 2021-05-20
119
+ */
120
+ confirm() {
121
+ return __awaiter(this, void 0, void 0, function* () {
122
+ try {
123
+ const response = yield payment_1.TemplatePayment.confirm();
124
+ return Promise.resolve(response);
125
+ }
126
+ catch (e) {
127
+ this.eventError(e);
128
+ return Promise.reject(e);
129
+ }
130
+ });
131
+ }
132
+ /**
133
+ * 이벤트 완료 이벤트
134
+ * Comment by GOSOMI
135
+ * @date: 2021-07-12
136
+ */
137
+ eventDone(response, displaySuccessResult = true) {
138
+ this.$logger.debug(response.event, response);
139
+ this.$event.send({
140
+ step: response.event,
141
+ msg: response.event === 'done' ? '결제완료' : '가상계좌발급완료',
142
+ request: {},
143
+ response: response
144
+ });
145
+ alfred_progress_1.AlfredProgress.hideProgress();
146
+ this.$logger.debug('show result', this.isDisplaySuccessResult());
147
+ if (this.isDisplaySuccessResult() && displaySuccessResult) {
148
+ this.displayResultView(response.data.receipt_id);
149
+ }
150
+ else {
151
+ // view_result가 false인 경우 destroy 한다
152
+ payment_1.TemplatePayment.destroy();
153
+ }
154
+ }
155
+ /**
156
+ * 오류를 처리한다
157
+ * Comment by GOSOMI
158
+ * @date: 2022-01-12
159
+ */
160
+ eventError(e) {
161
+ alfred_progress_1.AlfredProgress.hideProgress();
162
+ payment_1.TemplatePayment.closePopup();
163
+ if (this.isDisplayErrorResult() && e.event === 'error') {
164
+ this.displayResultErrorView(e);
165
+ }
166
+ else {
167
+ payment_1.TemplatePayment.destroy();
168
+ }
169
+ this.$logger.debug('done failed destroy and hide', 'payment');
170
+ this.$event.sendError({
171
+ step: this.$present(e.event) ? e.event : 'error',
172
+ msg: e.message,
173
+ trace: function () {
174
+ try {
175
+ return e.stack;
176
+ }
177
+ catch (e) {
178
+ return false;
179
+ }
180
+ }()
181
+ });
182
+ }
183
+ /**
184
+ * 트랜젝션 키를 만든다
185
+ * Comment by GOSOMI
186
+ * @date: 2021-05-12
187
+ * @returns string
188
+ */
189
+ generateTransactionKey() {
190
+ this.$transactionKey = `${this.$uuid()}-${(new Date()).getTime() * 1000}`;
191
+ return this.$transactionKey;
192
+ }
193
+ requestSubscription(data) {
194
+ return __awaiter(this, void 0, void 0, function* () {
195
+ this.$event.clearInstance();
196
+ // transaction Key를 만든다
197
+ this.generateTransactionKey();
198
+ // 로그를 보낼 Key를 설정한다
199
+ this.$event.setTokenKey(this.$transactionKey);
200
+ // Application ID를 설정한다
201
+ this.$event.setApplicationId(data.application_id);
202
+ this.$event.send({
203
+ step: 'start',
204
+ msg: '정기결제 요청 시작',
205
+ request: data
206
+ });
207
+ data.extra = this.openTypeFilter(data.extra);
208
+ const requestData = {
209
+ application_id: data.application_id,
210
+ subscription_id: data.subscription_id,
211
+ pg: data.pg,
212
+ method: data.method,
213
+ order_name: data.order_name,
214
+ price: data.price,
215
+ tax_free: data.tax_free,
216
+ user_token: data.user_token,
217
+ metadata: data.metadata,
218
+ platform_type: this.platformType,
219
+ ver: package_json_1.default.version,
220
+ sdk_version: environment_1.Environment.sdkVersion,
221
+ sdk_type: environment_1.Environment.sdkName,
222
+ locale: environment_1.Environment.locale,
223
+ sdk: true,
224
+ uuid: this.$session.currentUserUUID(),
225
+ sk: this.$session.currentSessionKey(),
226
+ tk: this.$transactionKey,
227
+ env: this.getUserDeviceEnvironment(),
228
+ user: data.user,
229
+ extra: data.extra
230
+ };
231
+ try {
232
+ const response = yield payment_1.TemplatePayment.start(requestData, 'CARD_SUBSCRIPTION');
233
+ logger_1.Logger.debug('subscription success', response);
234
+ this.$event.send({
235
+ step: 'confirm',
236
+ msg: '결제승인전',
237
+ request: {},
238
+ response: response
239
+ });
240
+ // 결제창을 닫는다
241
+ payment_1.TemplatePayment.hidePaymentiFrame();
242
+ payment_1.TemplatePayment.closePopup();
243
+ switch (response.event) {
244
+ case 'done':
245
+ case 'issued':
246
+ // 결제 완료인 경우 모든 창을 바로 닫는다
247
+ // this.eventDone(response, false)
248
+ break;
249
+ case 'confirm':
250
+ // 승인 전인 경우 승인 URL을 등록한다
251
+ payment_1.TemplatePayment.setConfirmFormUrl(`${response.gateway_url}/confirm/${response.receipt_id}?application_id=${data.application_id}`);
252
+ }
253
+ return Promise.resolve(response);
254
+ }
255
+ catch (e) {
256
+ this.eventError(e);
257
+ return Promise.reject(e);
258
+ }
259
+ });
260
+ }
261
+ /**
262
+ * 본인인증 요청
263
+ * Comment by GOSOMI
264
+ * @date: 2021-12-06
265
+ * @param data: RequestAuthenticationModel
266
+ */
267
+ requestAuthentication(data) {
268
+ return __awaiter(this, void 0, void 0, function* () {
269
+ this.$event.clearInstance();
270
+ // transaction Key를 만든다
271
+ this.generateTransactionKey();
272
+ // 로그를 보낼 Key를 설정한다
273
+ this.$event.setTokenKey(this.$transactionKey);
274
+ // Application ID를 설정한다
275
+ this.$event.setApplicationId(data.application_id);
276
+ this.$event.send({
277
+ step: 'start',
278
+ msg: '본인인증 요청 시작',
279
+ request: data
280
+ });
281
+ data.extra = this.openTypeFilter(data.extra);
282
+ const requestData = {
283
+ application_id: data.application_id,
284
+ authentication_id: data.authentication_id,
285
+ pg: data.pg,
286
+ method: this.$present(data.method) ? data.method : 'auth',
287
+ order_name: data.order_name,
288
+ platform_type: this.platformType,
289
+ ver: package_json_1.default.version,
290
+ sdk_version: environment_1.Environment.sdkVersion,
291
+ sdk_type: environment_1.Environment.sdkName,
292
+ locale: environment_1.Environment.locale,
293
+ metadata: data.metadata,
294
+ sdk: true,
295
+ uuid: this.$session.currentUserUUID(),
296
+ sk: this.$session.currentSessionKey(),
297
+ tk: this.$transactionKey,
298
+ env: this.getUserDeviceEnvironment(),
299
+ user: data.user,
300
+ extra: data.extra
301
+ };
302
+ try {
303
+ const response = yield payment_1.TemplatePayment.start(requestData, 'AUTH');
304
+ logger_1.Logger.debug('authentication success', response);
305
+ this.$event.send({
306
+ step: 'confirm',
307
+ msg: '본인인증 승인전',
308
+ request: {},
309
+ response: response
310
+ });
311
+ // 결제창을 닫는다
312
+ payment_1.TemplatePayment.hidePaymentiFrame();
313
+ payment_1.TemplatePayment.closePopup();
314
+ switch (response.event) {
315
+ case 'done':
316
+ case 'issued':
317
+ // 결제 완료인 경우 모든 창을 바로 닫는다
318
+ // this.eventDone(response, false)
319
+ break;
320
+ case 'confirm':
321
+ // 승인 전인 경우 승인 URL을 등록한다
322
+ payment_1.TemplatePayment.setConfirmFormUrl(`${response.gateway_url}/confirm/${response.receipt_id}?application_id=${data.application_id}`);
323
+ }
324
+ return Promise.resolve(response);
325
+ }
326
+ catch (e) {
327
+ this.eventError(e);
328
+ return Promise.reject(e);
329
+ }
330
+ });
331
+ }
332
+ requestPaymentUrl(data) {
333
+ return __awaiter(this, void 0, void 0, function* () {
334
+ try {
335
+ const response = yield payment_1.TemplatePayment.startPaymentUrl(data.url);
336
+ if (['done', 'issued'].indexOf(response.event) === -1) {
337
+ this.$event.send({
338
+ step: response.event,
339
+ msg: '',
340
+ request: {
341
+ url: data.url
342
+ },
343
+ response: response
344
+ });
345
+ }
346
+ // 승인 Gateway URL을 넣는다
347
+ payment_1.TemplatePayment.setConfirmFormUrl(`${response.gateway_url}/confirm/${response.receipt_id}?application_id=${data.application_id}`);
348
+ return Promise.resolve(response);
349
+ }
350
+ catch (e) {
351
+ this.eventError(e);
352
+ return Promise.reject(e);
353
+ }
354
+ });
355
+ }
356
+ getUserDeviceEnvironment() {
357
+ return {
358
+ width: window.innerWidth,
359
+ height: window.innerHeight
360
+ };
361
+ }
362
+ /**
363
+ * display result
364
+ * Comment by GOSOMI
365
+ * @date: 2022-01-12
366
+ */
367
+ isDisplaySuccessResult() {
368
+ return this.extra !== undefined && this.extra.display_success_result !== undefined && this.extra.display_success_result;
369
+ }
370
+ isDisplayErrorResult() {
371
+ return this.extra !== undefined && this.extra.display_error_result !== undefined && this.extra.display_error_result;
372
+ }
373
+ /**
374
+ * Result View를 호출한다
375
+ * Comment by GOSOMI
376
+ * @date: 2022-01-12
377
+ */
378
+ displayResultView(receiptId) {
379
+ payment_1.TemplatePayment.moveToUrl(environment_1.Environment.toDoor(`result/${receiptId}`));
380
+ }
381
+ /**
382
+ * Result Error View를 보여준다
383
+ * Comment by GOSOMI
384
+ * @date: 2022-01-12
385
+ */
386
+ displayResultErrorView(e) {
387
+ payment_1.TemplatePayment.moveToUrl(environment_1.Environment.toDoor(`error?error_code=${e.error_code}&pg_error_code=${e.pg_error_code}&message=${e.message}`));
388
+ }
389
+ /**
390
+ * OpenTypeUserAgent Filter
391
+ * Comment by GOSOMI
392
+ * @date: 2022-05-09
393
+ */
394
+ openTypeFilter(extra) {
395
+ if (this.$present(extra) && extra.browser_open_type !== undefined) {
396
+ const userAgent = this.getUserAgent();
397
+ for (let i in extra.browser_open_type) {
398
+ const browser = extra.browser_open_type[i];
399
+ const filter = this.$present(this.browserBootpayFilter[browser.browser]) ?
400
+ this.browserBootpayFilter[browser.browser] :
401
+ new RegExp(`${browser.browser}`);
402
+ if (userAgent.match(filter)) {
403
+ extra.open_type = browser.open_type;
404
+ break;
405
+ }
406
+ }
407
+ }
408
+ return extra;
409
+ }
410
+ /**
411
+ * 요청 데이터 필수 값 체크
412
+ * Comment by GOSOMI
413
+ * @date: 2021-05-12
414
+ * @param data: RequestPaymentModel
415
+ */
416
+ static invalidRequestParamsData(data) {
417
+ if ((0, util_1.isBlank)(data)) {
418
+ throw new event_1.BootpayEventError({
419
+ event: 'error',
420
+ error_code: 'NEED_MORE_PARAMS',
421
+ message: '결제 요청을 위한 최소한의 결제 정보를 입력해주세요.'
422
+ });
423
+ }
424
+ Object.keys(BootpayRequestPaymentManager.invalidRequestParams).forEach((key) => {
425
+ const value = data[key];
426
+ if ((0, util_1.isBlank)(value)) {
427
+ throw new event_1.BootpayEventError({
428
+ event: 'error',
429
+ error_code: 'INVALID_REQUEST_PARAMS',
430
+ message: BootpayRequestPaymentManager.invalidRequestParams[key]
431
+ });
432
+ }
433
+ });
434
+ }
435
+ /**
436
+ * 첨부된 item data invalidate
437
+ * Comment by GOSOMI
438
+ * @date: 2021-05-12
439
+ * @param items: Array<ItemModel>
440
+ * @param price: number
441
+ */
442
+ static invalidRequestItemsData(items, price) {
443
+ if (items !== undefined && (0, util_1.isPresent)(items)) {
444
+ let totalPrice = 0;
445
+ items.forEach((item, index) => {
446
+ if ((0, util_1.isBlank)(item.id)) {
447
+ throw new event_1.BootpayEventError({
448
+ event: 'error',
449
+ error_code: 'NEED_ITEM_ID',
450
+ message: `${index + 1}번째 상품 고유 ID를 입력해주세요. [ key: id ]`
451
+ });
452
+ }
453
+ if ((0, util_1.isBlank)(item.name)) {
454
+ throw new event_1.BootpayEventError({
455
+ event: 'error',
456
+ error_code: 'NEED_ITEM_NAME',
457
+ message: `${index + 1}번째 상품명을 입력해주세요. [ key: name ]`
458
+ });
459
+ }
460
+ if ((0, util_1.isBlank)(item.qty)) {
461
+ throw new event_1.BootpayEventError({
462
+ event: 'error',
463
+ error_code: 'NEED_ITEM_QTY',
464
+ message: `${index + 1}번째 상품수량을 입력해주세요. [ key: qty ]`
465
+ });
466
+ }
467
+ if ((0, util_1.isBlank)(item.price)) {
468
+ throw new event_1.BootpayEventError({
469
+ event: 'error',
470
+ error_code: 'NEED_ITEM_PRICE',
471
+ message: `${index + 1}번째 상품금액을 입력해주세요. [ key: price ]`
472
+ });
473
+ }
474
+ items[index].price = parseFloat(String(items[index].price));
475
+ items[index].qty = parseFloat(String(items[index].qty));
476
+ totalPrice += items[index].price * items[index].qty;
477
+ });
478
+ if (totalPrice !== price) {
479
+ throw new event_1.BootpayEventError({
480
+ event: 'error',
481
+ error_code: 'NEED_ITEM_TOTAL_PRICE_NOT_MATCH',
482
+ message: `결제 금액과 상품 수량 및 상품 금액의 총합과 일치하지 않습니다. [ 요청금액: ${price} ${(typeof price)}, 상품 총합계 금액: ${totalPrice} ${typeof totalPrice} ]`
483
+ });
484
+ }
485
+ }
486
+ }
487
+ }
488
+ exports.BootpayRequestPaymentManager = BootpayRequestPaymentManager;
489
+ BootpayRequestPaymentManager.invalidRequestParams = {
490
+ application_id: 'application_id를 입력해주세요. [ key: application_id ]',
491
+ order_name: '판매할 상품명을 입력해주세요. [ key: order_name ]',
492
+ price: '판매할 상품의 금액을 입력해주세요. [ key: price ]',
493
+ order_id: '가맹점에서 설정할 주문 ID를 입력해주세요. [ key: order_id ]'
494
+ };
495
+ exports.BootpayRequestPayment = new BootpayRequestPaymentManager();
496
+ //# sourceMappingURL=bootpay.js.map