-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
36 lines (31 loc) · 902 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { Platform, NativeModules } from 'react-native'
const iOS = Platform.OS === 'ios'
const Pay = {
onAliPay,
onWxPay,
}
function onAliPay(url) {
const orderString = url
let res = null
if (!url) return Promise.resolve({ code: 400, msg: 'illegal string' })
return new Promise((resolve) => {
NativeModules.RNWxAliPay.onAliPay(iOS ? { orderString } : url).then(() => {
resolve({ code: 200, data: res })
}).catch((err) => {
resolve({ code: 400, msg: err })
})
})
}
function onWxPay(wxObj) {
let res = null
if (!wxObj) return Promise.resolve({ code: 400, data: 'illegal object' })
iOS ? null : (typeof wxObj.timestamp != 'string' ? wxObj.timestamp.toString() : null)
return new Promise((resolve) => {
NativeModules.RNWxAliPay.onWxPay(wxObj).then(d => {
resolve({ code: 200, data: d })
}).catch(err => {
resolve({ code: 400, msg: err })
})
})
}
export default Pay