@jetthai/cuora 1.1.66 → 1.1.67

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.
@@ -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: {
@@ -53,7 +59,7 @@ export default function (request) {
53
59
  actions: ['setInitialization', 'setPreviousOrder'],
54
60
  cond: 'hasPreviousOrder',
55
61
  },
56
- { target: '#vpay.loaded', actions: 'setInitialization' },
62
+ { target: '#vpay.checking', actions: 'setInitialization' },
57
63
  ],
58
64
  onError: {
59
65
  target: '#vpay.unavailable',
@@ -62,6 +68,31 @@ export default function (request) {
62
68
  },
63
69
  },
64
70
  },
71
+ checking: {
72
+ always: [
73
+ {
74
+ target: 'fetching',
75
+ cond: (context, event) => {
76
+ const { siteConfig = {}, promotion = {} } = context
77
+ const { walletMode = '', bonusPreviewEnable = '0' } = siteConfig
78
+ return walletMode === '4' && bonusPreviewEnable === '1' && promotion.activityNo != 'none'
79
+ },
80
+ },
81
+ { target: 'loaded' },
82
+ ],
83
+ },
84
+ fetching: {
85
+ invoke: {
86
+ src: 'fetchBonusPreview',
87
+ onDone: {
88
+ target: 'loaded',
89
+ actions: 'setBonusPreview',
90
+ },
91
+ onError: {
92
+ target: 'loaded',
93
+ },
94
+ },
95
+ },
65
96
  loaded: {
66
97
  entry: 'reset',
67
98
  on: {
@@ -69,7 +100,7 @@ export default function (request) {
69
100
  {
70
101
  target: 'debouncing',
71
102
  actions: 'addAmount',
72
- cond: (context, event) => context.grandTotalEnable === 1,
103
+ cond: 'isGrandTotalEnable',
73
104
  },
74
105
  {
75
106
  target: 'debouncing',
@@ -80,6 +111,10 @@ export default function (request) {
80
111
  target: 'calculating',
81
112
  actions: 'setAmount',
82
113
  },
114
+ CLEAR_CALCULATION: {
115
+ target: 'debouncing',
116
+ actions: 'clearCalculation',
117
+ },
83
118
  },
84
119
  },
85
120
  debouncing: {
@@ -88,7 +123,7 @@ export default function (request) {
88
123
  {
89
124
  target: 'debouncing',
90
125
  actions: 'addAmount',
91
- cond: (context, event) => context.grandTotalEnable === 1,
126
+ cond: 'isGrandTotalEnable',
92
127
  },
93
128
  {
94
129
  target: 'debouncing',
@@ -99,9 +134,6 @@ export default function (request) {
99
134
  target: 'debouncing',
100
135
  actions: 'setAmount',
101
136
  },
102
- BACK: {
103
- target: 'loaded',
104
- },
105
137
  },
106
138
  after: {
107
139
  1000: {
@@ -116,7 +148,7 @@ export default function (request) {
116
148
  {
117
149
  target: 'debouncing',
118
150
  actions: 'addAmount',
119
- cond: (context, event) => context.grandTotalEnable === 1,
151
+ cond: 'isGrandTotalEnable',
120
152
  },
121
153
  {
122
154
  target: 'debouncing',
@@ -127,11 +159,12 @@ export default function (request) {
127
159
  target: 'debouncing',
128
160
  actions: 'setAmount',
129
161
  },
130
- CALCULATE: {
162
+ CLEAR_CALCULATION: {
131
163
  target: 'debouncing',
164
+ actions: 'clearCalculation',
132
165
  },
133
- BACK: {
134
- target: 'loaded',
166
+ CLEAR: {
167
+ actions: 'setAmount',
135
168
  },
136
169
  },
137
170
  },
@@ -153,7 +186,7 @@ export default function (request) {
153
186
  {
154
187
  target: 'debouncing',
155
188
  actions: 'addAmount',
156
- cond: (context, event) => context.grandTotalEnable === 1,
189
+ cond: 'isGrandTotalEnable',
157
190
  },
158
191
  {
159
192
  target: 'debouncing',
@@ -167,19 +200,22 @@ export default function (request) {
167
200
  CONFIRM: {
168
201
  target: 'submitting',
169
202
  },
170
- BACK: {
171
- target: 'loaded',
172
- },
173
203
  CLEAR_CALCULATION: {
174
204
  target: 'debouncing',
175
205
  actions: 'clearCalculation',
176
206
  },
207
+ CLEAR: {
208
+ actions: 'setAmount',
209
+ },
177
210
  },
178
211
  },
179
212
  submitting: {
180
213
  invoke: {
181
214
  src: 'submitDeposit',
182
- onDone: { target: 'submitted', actions: 'setOrder' },
215
+ onDone: {
216
+ target: 'submitted',
217
+ actions: 'setOrder',
218
+ },
183
219
  onError: {
184
220
  target: 'calculated',
185
221
  },
@@ -189,6 +225,11 @@ export default function (request) {
189
225
  accountUnbound: {},
190
226
  unavailable: {},
191
227
  },
228
+ on: {
229
+ SET_PROMOTION: {
230
+ actions: 'setPromotion',
231
+ },
232
+ },
192
233
  },
193
234
  {
194
235
  actions: {
@@ -197,6 +238,11 @@ export default function (request) {
197
238
  userAccount: event.data.bankInfo?.[0],
198
239
  }
199
240
  }),
241
+ setBonusPreview: assign((context, event) => {
242
+ return {
243
+ bonusPreviewData: event.data.bonus,
244
+ }
245
+ }),
200
246
  setOrder: assign((context, event) => {
201
247
  const { amount, qrcode, vpayId } = event.data
202
248
  return {
@@ -214,9 +260,10 @@ export default function (request) {
214
260
  }
215
261
  }),
216
262
  setInitialization: assign((context, event) => {
217
- const { housePayment, bankList } = event.data
263
+ const { siteConfig, housePayment, bankList } = event.data
218
264
  const { optional, minimum, maximum, grandTotalEnable } = housePayment
219
265
  return {
266
+ siteConfig,
220
267
  options: optional,
221
268
  minimum,
222
269
  maximum,
@@ -224,6 +271,12 @@ export default function (request) {
224
271
  grandTotalEnable,
225
272
  }
226
273
  }),
274
+ setPromotion: assign((context, event) => {
275
+ const promotion = event.data
276
+ return {
277
+ promotion,
278
+ }
279
+ }),
227
280
  addAmount: assign((context, event) => {
228
281
  const { amount, maximum } = context
229
282
  return {
@@ -233,11 +286,6 @@ export default function (request) {
233
286
  setAmount: assign((context, event) => {
234
287
  return { amount: event.data }
235
288
  }),
236
- clear: assign((context, event) => {
237
- return {
238
- amount: 0,
239
- }
240
- }),
241
289
  setCalculation: assign((context, event) => {
242
290
  return {
243
291
  calculation: event.data,
@@ -256,33 +304,48 @@ export default function (request) {
256
304
  hasPreviousOrder: (context, event) => {
257
305
  return event.data.order?.qrcode
258
306
  },
307
+ isGrandTotalEnable: (context, event) => {
308
+ return context.grandTotalEnable === 1
309
+ },
259
310
  },
260
311
  services: {
261
312
  fetchPaymentInfo: async (context, event) => {
262
313
  return await request.send(payment.getPaymentInfo())
263
314
  },
264
315
  initialize: async (context, event) => {
265
- const [payments, bankList, order] = await Promise.all([
316
+ const [{ config }, payments, bankList, order] = await Promise.all([
317
+ request.send(common.getConfig({ appSecret })),
266
318
  request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' })),
267
319
  request.send(payment.getBankList('amb')),
268
320
  request.send(payment.checkTransaction(context.method)),
269
321
  ])
270
- return { housePayment: payments.find((payment) => payment.method === context.method), bankList, order }
322
+ const siteConfig = JSON.parse(window.atob(config))
323
+ return { siteConfig, housePayment: payments.find((payment) => payment.method === context.method), bankList, order }
324
+ },
325
+ fetchBonusPreview: async (context, event) => {
326
+ const { method, promotion } = context
327
+ return await request.send({
328
+ paymentMethod: method,
329
+ promotionsNo: promotion?.activityNo,
330
+ })
271
331
  },
272
332
  submitDeposit: async (context, event) => {
273
- const { method, amount } = context
333
+ const { method, amount, promotion } = context
274
334
  return await request.send(
275
335
  payment.submitDepositTransaction({
276
336
  method,
277
337
  amount,
338
+ promotionsNo: promotion?.activityNo,
278
339
  })
279
340
  )
280
341
  },
281
342
  fetchCalculation: async (context, event) => {
343
+ const { method, amount, promotion } = context
282
344
  return await request.send(
283
345
  payment.getDepositExpectedResult({
284
- method: context.method,
285
- amount: context.amount,
346
+ method,
347
+ amount,
348
+ promotionsNo: promotion?.activityNo,
286
349
  })
287
350
  )
288
351
  },
@@ -111,7 +111,7 @@ export default function (request) {
111
111
  }
112
112
  return {
113
113
  promotionsList,
114
- selectedPromo: noBonus,
114
+ selectedPromo: siteConfig?.walletMode === '4' ? promotionsList[0] : noBonus,
115
115
  }
116
116
  }),
117
117
  setSelectedPromo: assign((context, event) => {