
import { NativeModules, Platform } from 'react-native';
const payModule = NativeModules.PayManager


/**
 *   微信注册 appKey
 * @param appKey 微信的AppId
 * @param appKey App的链接
 */
const wechatRegister = (appKey: String, universalLink?: string) => {
    payModule.wechatRegister(appKey, universalLink)
}

/**
 *  微信支付
 * @param data 支付信息
 */
const wechatPay = (data: { partnerid: string, prepayid: string, noncestr: string, timestamp: number, package: string, sign: string }) => {
    return payModule.wechatPay(data) as Promise<any>
}

/**
 *  支付宝支付
 * @param data 支付信息  payInfo:签名成功字符串格式化为订单字符串
 */
const aliPay = (data: { payInfo: string }) => {
    return payModule.aliPay(data) as Promise<any>
}

/**
 *  苹果支付
 * @param data 支付信息  productId:商品id
 */
const applePay = (data: { productId: string }) => {
    if (Platform.OS == 'ios') {
        return payModule.applePay(data) as Promise<any>
    } else {
        return Promise.reject("安卓不支持苹果支付");
    }
}


export default { wechatRegister, wechatPay, aliPay, applePay }