Files
frontend-app/uni_modules/tb-douyin-pay/utssdk/app-ios/index.uts
T

51 lines
2.0 KiB
Plaintext

import { UIApplication } from 'UIKit'
import { URL, NSUserActivity } from 'Foundation'
import { InitOptions, PayOptions, PayCallback } from '../interface.uts'
import { configure, invoke, resetPending } from '../common.uts'
export function resetDypay(): void {
resetPending()
TbDouyinPayNative.resetPending()
}
export function initDypay(options: InitOptions): boolean {
let callbackURL = options.callbackScheme.trim()
if (callbackURL.length == 0) return false
// CFBundleURLSchemes contains a bare scheme, but Dypay's callbackScheme API
// requires a complete URL. Official registration example: <scheme>://dypay.
// https://pay.douyinpay.com/wiki/639fd757f4a57b0226bb2066/639fd78317c2f3021d238378
if (callbackURL.indexOf('://') < 0) {
callbackURL = callbackURL + '://dypay'
} else if (callbackURL.endsWith('://')) {
callbackURL = callbackURL + 'dypay'
}
if (!new RegExp('^[A-Za-z][A-Za-z0-9+.-]*://dypay$').test(callbackURL)) return false
if (!configure(options.appId)) return false
TbDouyinPayNative.initialize(options.appId, callbackURL, options.universalLink ?? '')
return true
}
export function canOpenDypay(): boolean {
return TbDouyinPayNative.available()
}
export function openDypay(options: PayOptions, callback: PayCallback): void {
invoke(options, callback, (payload: string, loading: boolean, done: (raw: string) => void) => {
TbDouyinPayNative.pay(payload, done)
})
}
export class TbDouyinPayHook implements UTSiOSHookProxy {
applicationOpenURLOptions(app: UIApplication | null, url: URL,
options: Map<UIApplication.OpenURLOptionsKey, any> | null = null): boolean {
return TbDouyinPayNative.processURL(url)
}
applicationContinueUserActivityRestorationHandler(application: UIApplication | null,
userActivity: NSUserActivity | null,
restorationHandler: ((res: [any] | null) => void) | null = null): boolean {
if (userActivity == null) return false
return TbDouyinPayNative.processActivity(userActivity!)
}
}