@jetthai/cuora 1.1.94-cash-2 → 1.1.94-cash-3
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.1.94-cash-3](https://github.com/jetthai/cuora-module/compare/v1.1.94-cash-2...v1.1.94-cash-3) (2023-05-11)
|
|
6
|
+
|
|
5
7
|
### [1.1.94-cash-2](https://github.com/jetthai/cuora-module/compare/v1.1.94-cash-1...v1.1.94-cash-2) (2023-05-11)
|
|
6
8
|
|
|
7
9
|
### [1.1.94-cash-1](https://github.com/jetthai/cuora-module/compare/v1.1.94-cash...v1.1.94-cash-1) (2023-05-11)
|
package/package.json
CHANGED
package/src/api/payment.js
CHANGED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { assign, createMachine } from 'xstate'
|
|
2
|
+
import payment from '../../api/payment.js'
|
|
3
|
+
import { max } from '../../util/index.js'
|
|
4
|
+
|
|
5
|
+
export default function (request, context) {
|
|
6
|
+
const { paymentDetail = [], promotion, selectedAmount } = context || {}
|
|
7
|
+
|
|
8
|
+
return createMachine(
|
|
9
|
+
{
|
|
10
|
+
id: 'direct_cash',
|
|
11
|
+
initial: 'loading',
|
|
12
|
+
context: {
|
|
13
|
+
paymentDetail,
|
|
14
|
+
promotion,
|
|
15
|
+
selectedAmount,
|
|
16
|
+
|
|
17
|
+
directs: [],
|
|
18
|
+
selectedDirect: null,
|
|
19
|
+
bankMap: {},
|
|
20
|
+
userBanks: [],
|
|
21
|
+
selectedUserBank: null,
|
|
22
|
+
calculation: null,
|
|
23
|
+
currentCategory: 'direct',
|
|
24
|
+
result: null,
|
|
25
|
+
},
|
|
26
|
+
states: {
|
|
27
|
+
loading: {
|
|
28
|
+
always: [
|
|
29
|
+
{
|
|
30
|
+
target: 'checking',
|
|
31
|
+
actions: 'setInitData',
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
},
|
|
35
|
+
checking: {
|
|
36
|
+
invoke: {
|
|
37
|
+
src: 'fetchBanksList',
|
|
38
|
+
onDone: {
|
|
39
|
+
target: 'debouncing',
|
|
40
|
+
actions: 'setBanks',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
loaded: {},
|
|
45
|
+
debouncing: {
|
|
46
|
+
after: {
|
|
47
|
+
1000: [{ target: 'calculating', cond: 'isCalculable' }, { target: 'loaded' }],
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
calculating: {
|
|
51
|
+
invoke: {
|
|
52
|
+
src: 'fetchCalculation',
|
|
53
|
+
onDone: {
|
|
54
|
+
target: 'calculated',
|
|
55
|
+
actions: 'setCalculation',
|
|
56
|
+
},
|
|
57
|
+
onError: {
|
|
58
|
+
target: 'loaded',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
calculated: {
|
|
63
|
+
on: {
|
|
64
|
+
SUBMIT: {
|
|
65
|
+
target: 'submitting',
|
|
66
|
+
cond: 'isSubmittable',
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
submitting: {
|
|
71
|
+
invoke: {
|
|
72
|
+
src: 'submitDeposit',
|
|
73
|
+
onDone: {
|
|
74
|
+
target: 'submitted',
|
|
75
|
+
actions: 'setResult',
|
|
76
|
+
},
|
|
77
|
+
onError: {
|
|
78
|
+
target: 'calculated',
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
submitted: {},
|
|
83
|
+
fail: {},
|
|
84
|
+
},
|
|
85
|
+
on: {
|
|
86
|
+
SET_PROMOTION: {
|
|
87
|
+
target: '.loading',
|
|
88
|
+
actions: 'setPromotion',
|
|
89
|
+
internal: false,
|
|
90
|
+
},
|
|
91
|
+
SELECT_DIRECT: {
|
|
92
|
+
target: 'debouncing',
|
|
93
|
+
actions: 'setDirect',
|
|
94
|
+
internal: false,
|
|
95
|
+
},
|
|
96
|
+
SELECT_USER_BANK: {
|
|
97
|
+
actions: 'setUserBank',
|
|
98
|
+
internal: false,
|
|
99
|
+
},
|
|
100
|
+
SET_AMOUNT: {
|
|
101
|
+
target: 'debouncing',
|
|
102
|
+
actions: 'setAmount',
|
|
103
|
+
internal: false,
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
actions: {
|
|
109
|
+
reset: assign((context, event) => {
|
|
110
|
+
const { userBanks } = context
|
|
111
|
+
return {
|
|
112
|
+
selectedAmount: null,
|
|
113
|
+
selectedUserBank: userBanks[0],
|
|
114
|
+
calculation: null,
|
|
115
|
+
}
|
|
116
|
+
}),
|
|
117
|
+
setInitData: assign((context, event) => {
|
|
118
|
+
const { paymentDetail, selectedAmount, promotion } = context
|
|
119
|
+
const directs = paymentDetail
|
|
120
|
+
.filter((element) => element.category === context.currentCategory && element.transferType === 'deposit')
|
|
121
|
+
.map((direct) => {
|
|
122
|
+
direct.disabled = promotion?.promotionsNo !== 'none' && direct.charge > 0
|
|
123
|
+
return direct
|
|
124
|
+
})
|
|
125
|
+
const selectedDirect = directs.find((direct) => !direct.disabled)
|
|
126
|
+
|
|
127
|
+
return {
|
|
128
|
+
directs,
|
|
129
|
+
selectedDirect,
|
|
130
|
+
selectedAmount: max(promotion?.minimumAmount, selectedDirect?.minimum, selectedAmount, 0),
|
|
131
|
+
}
|
|
132
|
+
}),
|
|
133
|
+
setBanks: assign((context, event) => {
|
|
134
|
+
const { selectedDirect, bankMap } = context
|
|
135
|
+
const userBanks = event.data
|
|
136
|
+
|
|
137
|
+
if (selectedDirect)
|
|
138
|
+
return {
|
|
139
|
+
bankMap: { ...bankMap, [selectedDirect.method]: userBanks },
|
|
140
|
+
userBanks,
|
|
141
|
+
selectedUserBank: userBanks[0],
|
|
142
|
+
}
|
|
143
|
+
}),
|
|
144
|
+
setDirect: assign((context, event) => {
|
|
145
|
+
return {
|
|
146
|
+
selectedDirect: event.data,
|
|
147
|
+
}
|
|
148
|
+
}),
|
|
149
|
+
setUserBank: assign((context, event) => {
|
|
150
|
+
return {
|
|
151
|
+
selectedUserBank: event.data,
|
|
152
|
+
}
|
|
153
|
+
}),
|
|
154
|
+
setAmount: assign((context, event) => {
|
|
155
|
+
return {
|
|
156
|
+
selectedAmount: event.data,
|
|
157
|
+
}
|
|
158
|
+
}),
|
|
159
|
+
setCalculation: assign((context, event) => {
|
|
160
|
+
return {
|
|
161
|
+
calculation: event.data,
|
|
162
|
+
}
|
|
163
|
+
}),
|
|
164
|
+
clearCalculation: assign((context, event) => {
|
|
165
|
+
return {
|
|
166
|
+
calculation: null,
|
|
167
|
+
}
|
|
168
|
+
}),
|
|
169
|
+
setResult: assign((context, event) => {
|
|
170
|
+
return {
|
|
171
|
+
result: event.data,
|
|
172
|
+
}
|
|
173
|
+
}),
|
|
174
|
+
setPromotion: assign((context, event) => {
|
|
175
|
+
return {
|
|
176
|
+
promotion: event.data,
|
|
177
|
+
}
|
|
178
|
+
}),
|
|
179
|
+
},
|
|
180
|
+
guards: {
|
|
181
|
+
isCalculable: (context, event) => {
|
|
182
|
+
const {
|
|
183
|
+
selectedAmount,
|
|
184
|
+
selectedDirect: { maximum, minimum },
|
|
185
|
+
} = context
|
|
186
|
+
|
|
187
|
+
return selectedAmount && minimum <= +selectedAmount && +selectedAmount <= maximum
|
|
188
|
+
},
|
|
189
|
+
isSubmittable: (context, event) => {
|
|
190
|
+
const { selectedAmount, selectedDirect, selectedUserBank } = context
|
|
191
|
+
return selectedAmount && selectedDirect && selectedUserBank
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
services: {
|
|
195
|
+
fetchInitData: async (context, event) => {
|
|
196
|
+
const [paymentDetail = []] = await Promise.all([request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' }))])
|
|
197
|
+
return { paymentDetail }
|
|
198
|
+
},
|
|
199
|
+
fetchBanksList: async (context, event) => {
|
|
200
|
+
const { selectedDirect, bankMap } = context
|
|
201
|
+
const method = selectedDirect?.method
|
|
202
|
+
|
|
203
|
+
if (!selectedDirect) {
|
|
204
|
+
return []
|
|
205
|
+
} else if (bankMap[method]) {
|
|
206
|
+
return bankMap[method]
|
|
207
|
+
} else {
|
|
208
|
+
return await request.send(payment.getBankList(method))
|
|
209
|
+
}
|
|
210
|
+
},
|
|
211
|
+
fetchCalculation: async (context, event) => {
|
|
212
|
+
const { selectedDirect, selectedAmount, promotion } = context
|
|
213
|
+
|
|
214
|
+
return await request.send(
|
|
215
|
+
payment.getDepositExpectedResult({
|
|
216
|
+
method: selectedDirect.method,
|
|
217
|
+
amount: selectedAmount,
|
|
218
|
+
promotionsNo: promotion?.activityNo,
|
|
219
|
+
})
|
|
220
|
+
)
|
|
221
|
+
},
|
|
222
|
+
submitDeposit: async (context, event) => {
|
|
223
|
+
const { selectedDirect, selectedAmount, selectedUserBank, promotion } = context
|
|
224
|
+
return await request.send(
|
|
225
|
+
payment.submitDepositTransactionBank({
|
|
226
|
+
method: selectedDirect.method,
|
|
227
|
+
amount: selectedAmount,
|
|
228
|
+
applyerBankCode: selectedUserBank.bankCode,
|
|
229
|
+
promotionsNo: promotion?.activityNo,
|
|
230
|
+
})
|
|
231
|
+
)
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
}
|
|
235
|
+
)
|
|
236
|
+
}
|
|
@@ -13,6 +13,7 @@ import manual_cash from './manual_cash.js'
|
|
|
13
13
|
import qrcode_cash from './qrcode_cash.js'
|
|
14
14
|
import usdt_cash from './usdt_cash.js'
|
|
15
15
|
import crypto_cash from './crypto_cash.js'
|
|
16
|
+
import direct_cash from './direct_cash.js'
|
|
16
17
|
|
|
17
18
|
export default {
|
|
18
19
|
manual_vn,
|
|
@@ -30,4 +31,5 @@ export default {
|
|
|
30
31
|
qrcode_cash,
|
|
31
32
|
usdt_cash,
|
|
32
33
|
crypto_cash,
|
|
34
|
+
direct_cash,
|
|
33
35
|
}
|
|
@@ -274,7 +274,9 @@ export default function (request, context) {
|
|
|
274
274
|
},
|
|
275
275
|
services: {
|
|
276
276
|
fetchInitData: async (context, event) => {
|
|
277
|
-
const currentPayment = context.paymentDetail.find(
|
|
277
|
+
const currentPayment = context.paymentDetail.find(
|
|
278
|
+
(element) => element.category === context.currentCategory && element.transferType === 'deposit'
|
|
279
|
+
)
|
|
278
280
|
|
|
279
281
|
const [banks, paymentInfo] = await Promise.all([
|
|
280
282
|
request.send(payment.getBankList(currentPayment.method)),
|
|
@@ -118,7 +118,7 @@ export default function (request, context) {
|
|
|
118
118
|
setInitData: assign((context, event) => {
|
|
119
119
|
const { paymentDetail, selectedAmount, promotion } = context
|
|
120
120
|
const qrcodes = paymentDetail
|
|
121
|
-
.filter((element) => element.category === context.currentCategory)
|
|
121
|
+
.filter((element) => element.category === context.currentCategory && element.transferType === 'deposit')
|
|
122
122
|
.map((qrcode) => {
|
|
123
123
|
qrcode.disabled = promotion?.promotionsNo !== 'none' && qrcode.charge > 0
|
|
124
124
|
return qrcode
|