import { RequestPaymentOptions, RequestPaymentSuccess, RequestPaymentComplete } from "../interface.uts"; import { RequestPaymentFailImpl, getErrcode, UniErrors } from '../unierror.uts'; import PayTask from 'com.alipay.sdk.app.PayTask'; const defaultErrorCode : number = 700716 const errorCodeMap : Map = new Map([ [8000, 700710], [4000, 700711], [5000, 700712], [6001, 700713], [6002, 700714], [6004, 700715] ]) export class Alipay { public requestPayment(options : RequestPaymentOptions) { UTSAndroid.getDispatcher("io").async(function (_) { let alipay = new PayTask(UTSAndroid.getTopPageActivity()); let result = alipay.payV2(options.orderInfo, true); UTSAndroid.getDispatcher("main").async(function (_) { let resultStatus : string = result.get("resultStatus") as string if (resultStatus == "9000") { let res : RequestPaymentSuccess = { data: result } options.success?.(res) options.complete?.(res) } else { let code = errorCodeMap[resultStatus.toInt()]; if (code == null) { code = defaultErrorCode } let err = new RequestPaymentFailImpl(getErrcode(code)); options.fail?.(err) options.complete?.(err) } }, null) }, null) } };