Alipay.uts 1.2 KB
Newer Older
DCloud-yyl's avatar
DCloud-yyl 已提交
1 2
import PayTask from 'com.alipay.sdk.app.PayTask';
import string from 'android.R.string';
DCloud-yyl's avatar
DCloud-yyl 已提交
3
const defaultErrorCode : number = 700000
DCloud-yyl's avatar
DCloud-yyl 已提交
4
const errorCodeMap : Map<number, number> = new Map([
DCloud-yyl's avatar
DCloud-yyl 已提交
5 6 7 8 9 10
	[8000, 700600],
	[4000, 701100],
	[5000, 701110],
	[6001, 700601],
	[6002, 700602],
	[6004, 700603]
DCloud-yyl's avatar
DCloud-yyl 已提交
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 37 38 39 40 41 42
])
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 (_) {
				console.log(result)
				let resultStatus : string | null = result.get("resultStatus")
				if (resultStatus == null) {
					resultStatus = '' + defaultErrorCode
				}
				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(code.toInt());
					options.fail?.(err)
					options.complete?.(err)
				}
			}, null)
		}, null)

	}
};