@jetthai/cuora 1.0.69 → 1.0.70

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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ### [1.0.70](https://github.com/jetthai/cuora-module/compare/v1.0.69...v1.0.70) (2022-01-02)
6
+
5
7
  ### [1.0.69](https://github.com/jetthai/cuora-module/compare/v1.0.68...v1.0.69) (2021-12-29)
6
8
 
7
9
  ### [1.0.68](https://github.com/jetthai/cuora-module/compare/v1.0.67...v1.0.68) (2021-12-28)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetthai/cuora",
3
- "version": "1.0.69",
3
+ "version": "1.0.70",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
@@ -52,6 +52,36 @@ export default {
52
52
  method: 'post',
53
53
  params: { transferType: 'DEPOSIT', amount, card_type, card_code, card_seri },
54
54
  }),
55
+ submitDepositTransactionBank: ({
56
+ method,
57
+ amount,
58
+ applyerBankCode,
59
+ applyerAccountNumber,
60
+ applyerHolderName,
61
+ targetBankCode,
62
+ targetAccountNumber,
63
+ depositTime = '1234567890',
64
+ receipt,
65
+ }) => ({
66
+ url: `payment/v2/${method}/transaction`,
67
+ method: 'post',
68
+ params: {
69
+ transferType: 'DEPOSIT',
70
+ amount,
71
+ applyerBankCode,
72
+ applyerAccountNumber,
73
+ applyerHolderName,
74
+ targetBankCode,
75
+ targetAccountNumber,
76
+ depositTime,
77
+ receipt,
78
+ },
79
+ }),
80
+ submitDepositTransactionQrcode: ({ method, amount }) => ({
81
+ url: `payment/v2/${method}/transaction`,
82
+ method: 'post',
83
+ params: { transferType: 'DEPOSIT', amount },
84
+ }),
55
85
  submitWithdrawTransaction: ({ method, amount, cryptoCurrency, cryptoNetwork, targetAddress }) => ({
56
86
  url: `payment/v2/${method}/transaction`,
57
87
  method: 'post',
@@ -1,5 +1,6 @@
1
+ import manual_vn from './manual_vn'
1
2
  import loadcard_vn from './loadcard_vn'
2
3
  import qrcode_vn from './qrcode_vn'
3
4
  import deposit_fc from './deposit_fc'
4
5
 
5
- export default { loadcard_vn, qrcode_vn, deposit_fc }
6
+ export default { manual_vn, loadcard_vn, qrcode_vn, deposit_fc }
@@ -0,0 +1,320 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import payment from '../../api/payment'
3
+
4
+ export default function (request) {
5
+ return createMachine(
6
+ {
7
+ id: 'manual',
8
+ initial: 'loading',
9
+ context: {
10
+ paymentDetails: [],
11
+
12
+ houseBanks: [],
13
+ playerBanks: [],
14
+ banks: [],
15
+
16
+ amount: null,
17
+ selectedHouseBank: null,
18
+ selectedUserBank: null,
19
+ userAccountNumber: null,
20
+ userAccountName: null,
21
+ depositTime: null,
22
+ receipt: null,
23
+
24
+ currentMethodType: 'manual',
25
+ method: null,
26
+ currentPayment: null,
27
+ currentApplyerBank: null,
28
+
29
+ calculation: null,
30
+ processing: null,
31
+ },
32
+ states: {
33
+ loading: {
34
+ initial: 'init1',
35
+ states: {
36
+ init1: {
37
+ invoke: {
38
+ src: 'fetchInitData',
39
+ onDone: {
40
+ target: 'init2',
41
+ actions: 'setInitData',
42
+ },
43
+ onError: {
44
+ target: '#manual.fail',
45
+ },
46
+ },
47
+ },
48
+ init2: {
49
+ always: [
50
+ {
51
+ target: '#manual.processing',
52
+ cond: 'isProcessing',
53
+ },
54
+ ],
55
+ invoke: {
56
+ src: 'fetchBanksList',
57
+ onDone: {
58
+ target: '#manual.step1',
59
+ actions: 'setBanks',
60
+ },
61
+ onError: {
62
+ target: '#manual.fail',
63
+ },
64
+ },
65
+ },
66
+ },
67
+ },
68
+ step1: {
69
+ initial: 'idle',
70
+ states: {
71
+ idle: {
72
+ on: {
73
+ SET_AMOUNT: {
74
+ actions: ['setAmount', 'clearCalculation'],
75
+ },
76
+ CALCULATE: {
77
+ target: 'calculating',
78
+ cond: 'isCalculable',
79
+ },
80
+ SELECT_HOUSE_BANK: {
81
+ actions: 'setHouseBank',
82
+ },
83
+ CLEAR_CALCULATION: {
84
+ actions: 'clearCalculation',
85
+ },
86
+ TRANSACT: {
87
+ target: '#manual.step2',
88
+ cond: 'isCalculated',
89
+ },
90
+ },
91
+ },
92
+ calculating: {
93
+ invoke: {
94
+ src: 'fetchCalculation',
95
+ onDone: {
96
+ target: 'idle',
97
+ actions: 'setCalculation',
98
+ },
99
+ onError: {
100
+ target: 'idle',
101
+ },
102
+ },
103
+ },
104
+ },
105
+ },
106
+ step2: {
107
+ initial: 'idle',
108
+ states: {
109
+ idle: {
110
+ on: {
111
+ SET_AMOUNT: {
112
+ actions: ['setAmount', 'clearCalculation'],
113
+ },
114
+ CALCULATE: {
115
+ target: 'calculating',
116
+ cond: 'isCalculable',
117
+ },
118
+ SELECT_HOUSE_BANK: {
119
+ actions: 'setHouseBank',
120
+ },
121
+ SELECT_USER_BANK: {
122
+ actions: 'setUserBank',
123
+ },
124
+ INPUT_USER_ACCOUNT_NUMBER: {
125
+ actions: 'setUserAccountNumber',
126
+ },
127
+ INPUT_USER_ACCOUNT_NAME: {
128
+ actions: 'setUserAccountName',
129
+ },
130
+ SET_DEPOSIT_TIME: {
131
+ actions: 'setDepositTime',
132
+ },
133
+ SET_RECEIPT: {
134
+ actions: 'setReceipt',
135
+ },
136
+ CLEAR_CALCULATION: {
137
+ actions: 'clearCalculation',
138
+ },
139
+ SUBMIT: {
140
+ target: 'submitting',
141
+ cond: 'isSubmittable',
142
+ },
143
+ },
144
+ },
145
+ calculating: {
146
+ invoke: {
147
+ src: 'fetchCalculation',
148
+ onDone: {
149
+ target: 'idle',
150
+ actions: 'setCalculation',
151
+ },
152
+ onError: {
153
+ target: 'idle',
154
+ },
155
+ },
156
+ },
157
+ submitting: {
158
+ invoke: {
159
+ src: 'submitDeposit',
160
+ onDone: {
161
+ target: '#manual.submitted',
162
+ actions: 'setProcessing',
163
+ },
164
+ onError: {
165
+ target: 'idle',
166
+ },
167
+ },
168
+ },
169
+ },
170
+ },
171
+ processing: {},
172
+ submitted: {},
173
+ fail: {},
174
+ },
175
+ },
176
+ {
177
+ actions: {
178
+ setInitData: assign((context, event) => {
179
+ const { paymentInfo, paymentDetails } = event.data
180
+ const bankInfoList = paymentInfo?.bankInfo || []
181
+ const currentPayment = paymentDetails.find((element) => element.methodType === context.currentMethodType)
182
+ const houseBanks = currentPayment.banks.map((item) => {
183
+ item.bankCode = item.bankName
184
+ return item
185
+ })
186
+ return {
187
+ paymentDetails,
188
+ currentPayment,
189
+ method: currentPayment.method,
190
+ houseBanks,
191
+ selectedHouseBank: houseBanks[0],
192
+ playerBanks: bankInfoList,
193
+ processing: currentPayment.processing?.[0],
194
+ }
195
+ }),
196
+ setBanks: assign((context, event) => {
197
+ const { playerBanks } = context
198
+
199
+ const formattedPlayerBanks = playerBanks.map((bank) => {
200
+ bank.shortName = `${bank.bankCode} ${bank.accountNumber.slice(-5)}`
201
+ return bank
202
+ })
203
+
204
+ const banks = [...formattedPlayerBanks, ...event.data]
205
+
206
+ return {
207
+ banks,
208
+ selectedUserBank: banks[0],
209
+ userAccountNumber: banks[0].accountNumber,
210
+ userAccountName: banks[0].holderName,
211
+ }
212
+ }),
213
+ setHouseBank: assign((context, event) => {
214
+ return {
215
+ selectedHouseBank: event.data,
216
+ }
217
+ }),
218
+ setAmount: assign((context, event) => {
219
+ return {
220
+ amount: event.data,
221
+ }
222
+ }),
223
+ setCalculation: assign((context, event) => {
224
+ return {
225
+ calculation: event.data,
226
+ }
227
+ }),
228
+ setProcessing: assign((context, event) => {
229
+ return {
230
+ processing: event.data,
231
+ }
232
+ }),
233
+ clearCalculation: assign((context, event) => {
234
+ return {
235
+ calculation: null,
236
+ }
237
+ }),
238
+ setUserBank: assign((context, event) => {
239
+ const { accountNumber, holderName } = event.data
240
+ return {
241
+ selectedUserBank: event.data,
242
+ userAccountNumber: accountNumber,
243
+ userAccountName: holderName,
244
+ }
245
+ }),
246
+ setUserAccountNumber: assign((context, event) => {
247
+ return {
248
+ userAccountNumber: event.data,
249
+ }
250
+ }),
251
+ setUserAccountName: assign((context, event) => {
252
+ return {
253
+ userAccountName: event.data,
254
+ }
255
+ }),
256
+ setDepositTime: assign((context, event) => {
257
+ return {
258
+ depositTime: event.data,
259
+ }
260
+ }),
261
+ setReceipt: assign((context, event) => {
262
+ return {
263
+ receipt: event.data,
264
+ }
265
+ }),
266
+ },
267
+ guards: {
268
+ isCalculable: (context, event) => {
269
+ return context.amount
270
+ },
271
+ isCalculated: (context, event) => {
272
+ return context.calculation
273
+ },
274
+ isSubmittable: (context, event) => {
275
+ const { amount, userAccountNumber, userAccountName, depositTime, receipt } = context
276
+ return amount && userAccountNumber && userAccountName && depositTime && receipt
277
+ },
278
+ isProcessing: (context, event) => {
279
+ return context.processing
280
+ },
281
+ },
282
+ services: {
283
+ fetchInitData: async (context, event) => {
284
+ const [paymentInfo, paymentDetails] = await Promise.all([
285
+ request.send(payment.getPaymentInfo()),
286
+ request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' })),
287
+ ])
288
+ return {
289
+ paymentInfo,
290
+ paymentDetails,
291
+ }
292
+ },
293
+ fetchBanksList: async (context, event) => {
294
+ const { method } = context
295
+ return await request.send(payment.getBankList(method))
296
+ },
297
+ fetchCalculation: async (context, event) => {
298
+ const { method, amount } = context
299
+ return await request.send(payment.getDepositExpectedResult({ method, amount }))
300
+ },
301
+ submitDeposit: async (context, event) => {
302
+ const { method, amount, selectedHouseBank, selectedUserBank, userAccountNumber, userAccountName, depositTime, receipt } = context
303
+ return await request.send(
304
+ payment.submitDepositTransactionBank({
305
+ method,
306
+ amount,
307
+ targetBankCode: selectedHouseBank.bankName,
308
+ targetAccountNumber: selectedHouseBank.accountNumber,
309
+ applyerBankCode: selectedUserBank.bankCode,
310
+ applyerAccountNumber: userAccountNumber,
311
+ applyerHolderName: userAccountName,
312
+ depositTime,
313
+ receipt,
314
+ })
315
+ )
316
+ },
317
+ },
318
+ }
319
+ )
320
+ }
@@ -183,7 +183,7 @@ export default function (request) {
183
183
  submitDeposit: async (context, event) => {
184
184
  const { currentMethod, selectedAmount } = context
185
185
  return await request.send(
186
- payment.submitDepositTransaction({
186
+ payment.submitDepositTransactionQrcode({
187
187
  method: currentMethod,
188
188
  amount: selectedAmount,
189
189
  })