提交 51d52eb2 编写于 作者: D DCloud_LXH

feat(App): requestPayment

上级 fe3d807c
......@@ -80,6 +80,7 @@ export * from './protocols/ui/window'
export * from './protocols/plugin/getProvider'
export * from './protocols/plugin/oauth'
export * from './protocols/plugin/share'
export * from './protocols/plugin/requestPayment'
// helpers
export {
defineOnApi,
......
export const API_REQUEST_PAYMENT = 'requestPayment'
export type API_TYPE_REQUEST_PAYMENT = typeof uni.requestPayment
export const RequestPaymentProtocol: ApiProtocol<API_TYPE_REQUEST_PAYMENT> = {
provider: {
type: String as any,
required: true,
},
orderInfo: {
type: [String, Object],
required: true,
},
timeStamp: String,
nonceStr: String,
package: String,
signType: String,
paySign: String,
}
......@@ -36,3 +36,4 @@ export * from './ui/popup/showToast'
export * from './plugin/getProvider'
export * from './plugin/oauth'
export * from './plugin/share'
export * from './plugin/requestPayment'
import { warpPlusErrorCallback } from '../../../helpers/plus'
import {
defineAsyncApi,
API_REQUEST_PAYMENT,
API_TYPE_REQUEST_PAYMENT,
RequestPaymentProtocol,
} from '@dcloudio/uni-api'
export const requestPayment = defineAsyncApi<API_TYPE_REQUEST_PAYMENT>(
API_REQUEST_PAYMENT,
(params, { resolve, reject }) => {
const provider = params.provider
const errorCallback = warpPlusErrorCallback(reject)
plus.payment.getChannels((services) => {
const service = services.find(({ id }) => id === provider)
if (!service) {
reject('service not found')
} else {
plus.payment.request(
service,
params.orderInfo,
(res) => {
resolve(res)
},
errorCallback
)
}
}, errorCallback)
},
RequestPaymentProtocol
)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册