@jetthai/cuora 1.1.63 → 1.1.65-doubleWallet

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.
@@ -26,8 +26,9 @@ export default function (request) {
26
26
 
27
27
  grandTotalEnable: 1,
28
28
 
29
- // use for wallet mode 3
29
+ // use for wallet mode 3 & 4
30
30
  promotion: null,
31
+ bonusPreviewData: [],
31
32
  },
32
33
  states: {
33
34
  loading: {
@@ -35,7 +36,7 @@ export default function (request) {
35
36
  src: 'fetchInitData',
36
37
  onDone: {
37
38
  target: 'checking',
38
- actions: ['setInitData', 'preset'],
39
+ actions: 'setInitData',
39
40
  },
40
41
  onError: {
41
42
  target: 'fail',
@@ -44,178 +45,121 @@ export default function (request) {
44
45
  },
45
46
  checking: {
46
47
  always: [
47
- { target: 'newWalletMode', cond: 'isNewWalletMode' },
48
+ {
49
+ target: 'loaded',
50
+ cond: 'isDoubleWalletMode',
51
+ },
48
52
  {
49
53
  target: 'debouncing',
50
54
  actions: 'setPromotionDefaultAmount',
51
55
  cond: 'hasMinPromotionDeposit',
52
56
  },
53
- { target: 'defaultMode' },
57
+ { target: 'loaded' },
54
58
  ],
55
59
  },
56
- newWalletMode: {
57
- initial: 'loaded',
60
+ fail: {},
61
+ loaded: {
62
+ type: 'parallel',
63
+ entry: 'reset',
58
64
  states: {
59
- loaded: {
60
- entry: 'reset',
61
- on: {
62
- SELECT_QRCODE: {
63
- actions: 'setQrcode',
65
+ bonusPreview: {
66
+ initial: 'checking',
67
+ states: {
68
+ checking: {
69
+ always: [
70
+ {
71
+ target: 'fetching',
72
+ cond: (context, event) => {
73
+ const { siteConfig = {}, promotion = {} } = context
74
+ return siteConfig.bonusPreviewEnable === '1' && promotion.activityNo != 'none'
75
+ },
76
+ },
77
+ { target: 'end' },
78
+ ],
64
79
  },
65
- SELECT_AMOUNT: [
66
- {
67
- target: 'pending',
68
- actions: 'addAmount',
69
- cond: (context, event) => context.grandTotalEnable === 1,
70
- },
71
- {
72
- target: 'pending',
73
- actions: 'setAmount',
80
+ fetching: {
81
+ invoke: {
82
+ src: 'fetchBonusPreview',
83
+ onDone: {
84
+ target: 'end',
85
+ actions: 'setBonusPreview',
86
+ },
87
+ onError: {
88
+ target: 'end',
89
+ },
74
90
  },
75
- ],
76
- KEY_IN: {
77
- target: 'pending',
78
- actions: 'setAmount',
79
91
  },
92
+ end: {},
80
93
  },
81
94
  },
82
- pending: {
95
+ idle: {
83
96
  on: {
97
+ SELECT_QRCODE: [
98
+ {
99
+ target: '#qrcode.debouncing',
100
+ actions: ['setQrcode', 'setPromotionDefaultAmount'],
101
+ cond: (context, event) => context.siteConfig?.walletMode === '3' && context.promotion?.minimumAmount,
102
+ },
103
+ {
104
+ actions: 'setQrcode',
105
+ },
106
+ ],
84
107
  SELECT_AMOUNT: [
85
108
  {
109
+ target: '#qrcode.pending',
86
110
  actions: 'addAmount',
87
- cond: (context, event) => context.grandTotalEnable === 1,
111
+ cond: (context, event) => context.siteConfig?.walletMode === '2' && context.grandTotalEnable === 1,
88
112
  },
89
113
  {
114
+ target: '#qrcode.pending',
90
115
  actions: 'setAmount',
116
+ cond: 'isFreeWalletMode',
91
117
  },
92
- ],
93
- KEY_IN: {
94
- actions: 'setAmount',
95
- },
96
- CONFIRM: {
97
- target: 'debouncing',
98
- },
99
- BACK: {
100
- target: 'loaded',
101
- },
102
- },
103
- },
104
- debouncing: {
105
- on: {
106
- SELECT_AMOUNT: [
107
118
  {
108
- target: 'debouncing',
119
+ target: '#qrcode.debouncing',
109
120
  actions: 'addAmount',
110
- cond: (context, event) => context.grandTotalEnable === 1,
121
+ cond: 'isGrandTotalEnable',
111
122
  },
112
123
  {
113
- target: 'debouncing',
124
+ target: '#qrcode.debouncing',
114
125
  actions: 'setAmount',
115
126
  },
116
127
  ],
117
- KEY_IN: {
118
- target: 'debouncing',
119
- actions: 'setAmount',
120
- },
121
- BACK: {
122
- target: 'loaded',
123
- },
124
- },
125
- after: {
126
- 1000: {
127
- target: 'calculating',
128
- },
129
- },
130
- },
131
- calculable: {
132
- entry: 'clearCalculation',
133
- on: {
134
- SELECT_AMOUNT: [
128
+ KEY_IN: [
135
129
  {
136
- target: 'debouncing',
137
- actions: 'addAmount',
138
- cond: (context, event) => context.grandTotalEnable === 1,
130
+ target: '#qrcode.pending',
131
+ actions: 'setAmount',
132
+ cond: 'isFreeWalletMode',
139
133
  },
140
134
  {
141
- target: 'debouncing',
135
+ target: '#qrcode.calculating',
142
136
  actions: 'setAmount',
143
137
  },
144
138
  ],
145
- KEY_IN: {
146
- target: 'debouncing',
147
- actions: 'setAmount',
148
- },
149
- CALCULATE: {
150
- target: 'debouncing',
151
- },
152
- BACK: {
153
- target: 'loaded',
154
- },
155
- },
156
- },
157
- calculating: {
158
- invoke: {
159
- src: 'fetchCalculation',
160
- onDone: {
161
- target: 'submitting',
162
- actions: 'setCalculation',
163
- },
164
- onError: {
165
- target: 'calculable',
166
- },
167
- },
168
- },
169
- submitting: {
170
- invoke: {
171
- src: 'submitDeposit',
172
- onDone: {
173
- target: 'submitted',
174
- actions: 'setResult',
175
- },
176
- onError: {
177
- target: 'pending',
178
- },
179
- },
180
- },
181
- submitted: {
182
- on: {
183
- SELECT_QRCODE: {
184
- target: 'loaded',
185
- actions: 'setQrcode',
186
- },
187
139
  },
188
140
  },
189
141
  },
190
142
  },
191
- defaultMode: {
192
- entry: 'reset',
143
+ pending: {
193
144
  on: {
194
- SELECT_QRCODE: [
195
- {
196
- target: 'debouncing',
197
- actions: ['setQrcode', 'setPromotionDefaultAmount'],
198
- cond: 'hasMinPromotionDeposit',
199
- },
200
- {
201
- actions: 'setQrcode',
202
- },
203
- ],
204
145
  SELECT_AMOUNT: [
205
146
  {
206
- target: 'debouncing',
207
147
  actions: 'addAmount',
208
- cond: (context, event) => context.grandTotalEnable === 1,
148
+ cond: 'isGrandTotalEnable',
209
149
  },
210
150
  {
211
- target: 'debouncing',
212
151
  actions: 'setAmount',
213
152
  },
214
153
  ],
215
154
  KEY_IN: {
216
- target: 'calculating',
217
155
  actions: 'setAmount',
218
156
  },
157
+ CONFIRM: {
158
+ target: 'calculating',
159
+ },
160
+ BACK: {
161
+ target: 'loaded',
162
+ },
219
163
  },
220
164
  },
221
165
  debouncing: {
@@ -224,19 +168,25 @@ export default function (request) {
224
168
  {
225
169
  target: 'debouncing',
226
170
  actions: 'addAmount',
227
- cond: (context, event) => context.grandTotalEnable === 1,
171
+ cond: (context, event) => context.siteConfig?.walletMode === '2' && context.grandTotalEnable === 1,
172
+ },
173
+ {
174
+ target: 'debouncing',
175
+ actions: 'setAmount',
176
+ cond: 'isFreeWalletMode',
177
+ },
178
+ {
179
+ target: 'debouncing',
180
+ actions: 'addAmount',
181
+ cond: 'isGrandTotalEnable',
228
182
  },
229
183
  {
230
184
  target: 'debouncing',
231
185
  actions: 'setAmount',
232
186
  },
233
187
  ],
234
- KEY_IN: {
235
- target: 'debouncing',
236
- actions: 'setAmount',
237
- },
238
188
  BACK: {
239
- target: 'defaultMode',
189
+ target: 'loaded',
240
190
  },
241
191
  },
242
192
  after: {
@@ -245,15 +195,24 @@ export default function (request) {
245
195
  },
246
196
  },
247
197
  },
248
- fail: {},
249
198
  calculable: {
250
199
  entry: 'clearCalculation',
251
200
  on: {
252
201
  SELECT_AMOUNT: [
202
+ {
203
+ target: 'pending',
204
+ actions: 'addAmount',
205
+ cond: (context, event) => context.siteConfig?.walletMode === '2' && context.grandTotalEnable === 1,
206
+ },
207
+ {
208
+ target: 'pending',
209
+ actions: 'setAmount',
210
+ cond: 'isFreeWalletMode',
211
+ },
253
212
  {
254
213
  target: 'debouncing',
255
214
  actions: 'addAmount',
256
- cond: (context, event) => context.grandTotalEnable === 1,
215
+ cond: 'isGrandTotalEnable',
257
216
  },
258
217
  {
259
218
  target: 'debouncing',
@@ -261,24 +220,28 @@ export default function (request) {
261
220
  },
262
221
  ],
263
222
  KEY_IN: {
264
- target: 'debouncing',
223
+ target: 'calculating',
265
224
  actions: 'setAmount',
266
225
  },
267
- CALCULATE: {
268
- target: 'debouncing',
269
- },
270
226
  BACK: {
271
- target: 'defaultMode',
227
+ target: 'loaded',
272
228
  },
273
229
  },
274
230
  },
275
231
  calculating: {
276
232
  invoke: {
277
233
  src: 'fetchCalculation',
278
- onDone: {
279
- target: 'calculated',
280
- actions: 'setCalculation',
281
- },
234
+ onDone: [
235
+ {
236
+ target: 'submitting',
237
+ actions: 'setCalculation',
238
+ cond: 'isFreeWalletMode',
239
+ },
240
+ {
241
+ target: 'calculated',
242
+ actions: 'setCalculation',
243
+ },
244
+ ],
282
245
  onError: {
283
246
  target: 'calculable',
284
247
  },
@@ -287,10 +250,20 @@ export default function (request) {
287
250
  calculated: {
288
251
  on: {
289
252
  SELECT_AMOUNT: [
253
+ {
254
+ target: 'pending',
255
+ actions: 'addAmount',
256
+ cond: (context, event) => context.siteConfig?.walletMode === '2' && context.grandTotalEnable === 1,
257
+ },
258
+ {
259
+ target: 'pending',
260
+ actions: 'setAmount',
261
+ cond: 'isFreeWalletMode',
262
+ },
290
263
  {
291
264
  target: 'debouncing',
292
265
  actions: 'addAmount',
293
- cond: (context, event) => context.grandTotalEnable === 1,
266
+ cond: 'isGrandTotalEnable',
294
267
  },
295
268
  {
296
269
  target: 'debouncing',
@@ -298,14 +271,14 @@ export default function (request) {
298
271
  },
299
272
  ],
300
273
  KEY_IN: {
301
- target: 'debouncing',
274
+ target: 'calculating',
302
275
  actions: 'setAmount',
303
276
  },
304
277
  CONFIRM: {
305
278
  target: 'submitting',
306
279
  },
307
280
  BACK: {
308
- target: 'defaultMode',
281
+ target: 'loaded',
309
282
  },
310
283
  CLEAR_CALCULATION: {
311
284
  target: 'debouncing',
@@ -328,7 +301,7 @@ export default function (request) {
328
301
  submitted: {
329
302
  on: {
330
303
  SELECT_QRCODE: {
331
- target: 'defaultMode',
304
+ target: 'loaded',
332
305
  actions: 'setQrcode',
333
306
  },
334
307
  },
@@ -349,10 +322,11 @@ export default function (request) {
349
322
  }
350
323
  }),
351
324
  setInitData: assign((context, event) => {
352
- const { paymentDetail } = event.data
325
+ const { siteConfig, paymentDetail } = event.data
353
326
  const qrcodes = paymentDetail.filter((element) => element.category === context.currentCategory)
354
327
 
355
328
  return {
329
+ siteConfig,
356
330
  paymentDetail,
357
331
  qrcodes,
358
332
  selectedQrcode: qrcodes[0],
@@ -361,10 +335,9 @@ export default function (request) {
361
335
  grandTotalEnable: qrcodes[0].grandTotalEnable,
362
336
  }
363
337
  }),
364
- preset: assign((context, event) => {
365
- const { siteConfig } = event.data
338
+ setBonusPreview: assign((context, event) => {
366
339
  return {
367
- siteConfig,
340
+ bonusPreviewData: event.data.bonus,
368
341
  }
369
342
  }),
370
343
  setQrcode: assign((context, event) => {
@@ -409,9 +382,15 @@ export default function (request) {
409
382
  }),
410
383
  },
411
384
  guards: {
412
- isNewWalletMode: (context, event) => {
385
+ isFreeWalletMode: (context, event) => {
413
386
  return context.siteConfig?.walletMode === '2'
414
387
  },
388
+ isDoubleWalletMode: (context, event) => {
389
+ return context.siteConfig?.walletMode === '4'
390
+ },
391
+ isGrandTotalEnable: (context, event) => {
392
+ return context.grandTotalEnable === 1
393
+ },
415
394
  hasMinPromotionDeposit: (context, event) => {
416
395
  return context.promotion?.minimumAmount
417
396
  },
@@ -425,6 +404,13 @@ export default function (request) {
425
404
  const siteConfig = JSON.parse(window.atob(config))
426
405
  return { siteConfig, paymentDetail }
427
406
  },
407
+ fetchBonusPreview: async (context, event) => {
408
+ const { currentMethod, promotion } = context
409
+ return await request.send({
410
+ paymentMethod: currentMethod,
411
+ promotionsNo: promotion?.activityNo,
412
+ })
413
+ },
428
414
  fetchCalculation: async (context, event) => {
429
415
  const { currentMethod, selectedAmount, promotion } = context
430
416
  return await request.send(
@@ -1,7 +1,9 @@
1
1
  import { assign, createMachine } from 'xstate'
2
2
  import payment from '../../api/payment.js'
3
+ import common from '../../api/common.js'
3
4
 
4
5
  export default function (request) {
6
+ const { appSecret } = request.config
5
7
  return createMachine(
6
8
  {
7
9
  id: 'vpay',
@@ -9,6 +11,7 @@ export default function (request) {
9
11
  context: {
10
12
  method: 'vpay',
11
13
  userAccount: {},
14
+ siteConfig: null,
12
15
  amount: 0,
13
16
 
14
17
  bankList: [],
@@ -23,6 +26,9 @@ export default function (request) {
23
26
  calculatedAmount: 0,
24
27
 
25
28
  grandTotalEnable: 1,
29
+
30
+ promotion: null,
31
+ bonusPreviewData: [],
26
32
  },
27
33
  states: {
28
34
  loading: {
@@ -63,22 +69,57 @@ export default function (request) {
63
69
  },
64
70
  },
65
71
  loaded: {
72
+ type: 'parallel',
66
73
  entry: 'reset',
67
- on: {
68
- SELECT_AMOUNT: [
69
- {
70
- target: 'debouncing',
71
- actions: 'addAmount',
72
- cond: (context, event) => context.grandTotalEnable === 1,
74
+ states: {
75
+ bonusPreview: {
76
+ initial: 'checking',
77
+ states: {
78
+ checking: {
79
+ always: [
80
+ {
81
+ target: 'fetching',
82
+ cond: (context, event) => {
83
+ const { siteConfig = {}, promotion = {} } = context
84
+ return siteConfig.bonusPreviewEnable === '1' && promotion.activityNo != 'none'
85
+ },
86
+ },
87
+ { target: 'end' },
88
+ ],
89
+ },
90
+ fetching: {
91
+ invoke: {
92
+ src: 'fetchBonusPreview',
93
+ onDone: {
94
+ target: 'end',
95
+ actions: 'setBonusPreview',
96
+ },
97
+ onError: {
98
+ target: 'end',
99
+ },
100
+ },
101
+ },
102
+ end: {},
73
103
  },
74
- {
75
- target: 'debouncing',
76
- actions: 'setAmount',
104
+ },
105
+ idle: {
106
+ on: {
107
+ SELECT_AMOUNT: [
108
+ {
109
+ target: '#vpay.debouncing',
110
+ actions: 'addAmount',
111
+ cond: (context, event) => context.grandTotalEnable === 1,
112
+ },
113
+ {
114
+ target: '#vpay.debouncing',
115
+ actions: 'setAmount',
116
+ },
117
+ ],
118
+ KEY_IN: {
119
+ target: '#vpay.calculating',
120
+ actions: 'setAmount',
121
+ },
77
122
  },
78
- ],
79
- KEY_IN: {
80
- target: 'calculating',
81
- actions: 'setAmount',
82
123
  },
83
124
  },
84
125
  },
@@ -189,6 +230,11 @@ export default function (request) {
189
230
  accountUnbound: {},
190
231
  unavailable: {},
191
232
  },
233
+ on: {
234
+ SET_PROMOTION: {
235
+ actions: 'setPromotion',
236
+ },
237
+ },
192
238
  },
193
239
  {
194
240
  actions: {
@@ -197,6 +243,11 @@ export default function (request) {
197
243
  userAccount: event.data.bankInfo?.[0],
198
244
  }
199
245
  }),
246
+ setBonusPreview: assign((context, event) => {
247
+ return {
248
+ bonusPreviewData: event.data.bonus,
249
+ }
250
+ }),
200
251
  setOrder: assign((context, event) => {
201
252
  const { amount, qrcode, vpayId } = event.data
202
253
  return {
@@ -214,9 +265,10 @@ export default function (request) {
214
265
  }
215
266
  }),
216
267
  setInitialization: assign((context, event) => {
217
- const { housePayment, bankList } = event.data
268
+ const { siteConfig, housePayment, bankList } = event.data
218
269
  const { optional, minimum, maximum, grandTotalEnable } = housePayment
219
270
  return {
271
+ siteConfig,
220
272
  options: optional,
221
273
  minimum,
222
274
  maximum,
@@ -224,6 +276,12 @@ export default function (request) {
224
276
  grandTotalEnable,
225
277
  }
226
278
  }),
279
+ setPromotion: assign((context, event) => {
280
+ const promotion = event.data
281
+ return {
282
+ promotion,
283
+ }
284
+ }),
227
285
  addAmount: assign((context, event) => {
228
286
  const { amount, maximum } = context
229
287
  return {
@@ -233,11 +291,6 @@ export default function (request) {
233
291
  setAmount: assign((context, event) => {
234
292
  return { amount: event.data }
235
293
  }),
236
- clear: assign((context, event) => {
237
- return {
238
- amount: 0,
239
- }
240
- }),
241
294
  setCalculation: assign((context, event) => {
242
295
  return {
243
296
  calculation: event.data,
@@ -262,27 +315,39 @@ export default function (request) {
262
315
  return await request.send(payment.getPaymentInfo())
263
316
  },
264
317
  initialize: async (context, event) => {
265
- const [payments, bankList, order] = await Promise.all([
318
+ const [{ config }, payments, bankList, order] = await Promise.all([
319
+ request.send(common.getConfig({ appSecret })),
266
320
  request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' })),
267
321
  request.send(payment.getBankList('amb')),
268
322
  request.send(payment.checkTransaction(context.method)),
269
323
  ])
270
- return { housePayment: payments.find((payment) => payment.method === context.method), bankList, order }
324
+ const siteConfig = JSON.parse(window.atob(config))
325
+ return { siteConfig, housePayment: payments.find((payment) => payment.method === context.method), bankList, order }
326
+ },
327
+ fetchBonusPreview: async (context, event) => {
328
+ const { method, promotion } = context
329
+ return await request.send({
330
+ paymentMethod: method,
331
+ promotionsNo: promotion?.activityNo,
332
+ })
271
333
  },
272
334
  submitDeposit: async (context, event) => {
273
- const { method, amount } = context
335
+ const { method, amount, promotion } = context
274
336
  return await request.send(
275
337
  payment.submitDepositTransaction({
276
338
  method,
277
339
  amount,
340
+ promotionsNo: promotion?.activityNo,
278
341
  })
279
342
  )
280
343
  },
281
344
  fetchCalculation: async (context, event) => {
345
+ const { method, amount, promotion } = context
282
346
  return await request.send(
283
347
  payment.getDepositExpectedResult({
284
- method: context.method,
285
- amount: context.amount,
348
+ method,
349
+ amount,
350
+ promotionsNo: promotion?.activityNo,
286
351
  })
287
352
  )
288
353
  },