diff --git a/lib/src/tobias.dart b/lib/src/tobias.dart index beae573..f2928ef 100644 --- a/lib/src/tobias.dart +++ b/lib/src/tobias.dart @@ -12,6 +12,11 @@ class Tobias { .pay(order, evn: evn, universalLink: universalLink); } + /// 鸿蒙 - 自动订阅支付 + Future payOhosAutoSub(String order) async { + return await TobiasPlatform.instance.payOhosAutoSub(order); + } + /// Auth by AliPay Future auth(String auth) async { return await TobiasPlatform.instance.auth(auth); diff --git a/lib/src/tobias_method_channel.dart b/lib/src/tobias_method_channel.dart index 975acb9..1bbfdc5 100644 --- a/lib/src/tobias_method_channel.dart +++ b/lib/src/tobias_method_channel.dart @@ -21,6 +21,12 @@ class MethodChannelTobias extends TobiasPlatform { {"order": order, "payEnv": evn.index, "universalLink": universalLink}); } + /// 鸿蒙 - 自动订阅支付 + @override + Future payOhosAutoSub(String order) async { + return await methodChannel.invokeMethod("payOhosAutoSub", {"order": order}); + } + /// Auth by AliPay @override Future auth(String auth) async { diff --git a/lib/src/tobias_platform_interface.dart b/lib/src/tobias_platform_interface.dart index 6723ae8..318c239 100644 --- a/lib/src/tobias_platform_interface.dart +++ b/lib/src/tobias_platform_interface.dart @@ -36,6 +36,11 @@ abstract class TobiasPlatform extends PlatformInterface { throw UnimplementedError('pay() has not been implemented.'); } + /// 鸿蒙 - 自动订阅支付 + Future payOhosAutoSub(String order) async { + throw UnimplementedError('payOhosAutoSub() has not been implemented.'); + } + Future auth(String auth) async { throw UnimplementedError('auth() has not been implemented.'); } diff --git a/ohos/src/main/ets/components/plugin/TobiasPlugin.ets b/ohos/src/main/ets/components/plugin/TobiasPlugin.ets index 6ee1f82..f9121e5 100644 --- a/ohos/src/main/ets/components/plugin/TobiasPlugin.ets +++ b/ohos/src/main/ets/components/plugin/TobiasPlugin.ets @@ -51,6 +51,9 @@ export default class TobiasPlugin implements FlutterPlugin, MethodCallHandler, A case "pay": this.pay(call, result); break; + case "payOhosAutoSub": + this.payOhosAutoSub(call, result); + break; case "auth": result.notImplemented(); break; @@ -73,44 +76,42 @@ export default class TobiasPlugin implements FlutterPlugin, MethodCallHandler, A pay(call: MethodCall, result: MethodResult): void { const order: string = call.argument("order"); - const isOhosAutoSub: boolean = call.argument("isOhosAutoSub"); - if(isOhosAutoSub){ - console.log(TAG, '当前为自动订阅'); - let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; - let openLinkOptions: OpenLinkOptions = { - appLinkingOnly: false - }; - const resp: Map = new Map(); - try { - context.openLink(order, openLinkOptions) - .then(() => { - console.log(TAG, 'open link success.'); - resp.set("resultStatus", "success"); - result.success(resp) - }).catch((err: BusinessError) => { - console.log(TAG, `open link failed. Code is ${err.code}, message is ${err.message}`); - resp.set("resultStatus", "erroe"); + const isShowLoading: boolean = true; + const payment = new alipay.Pay(); + payment.pay(order, isShowLoading) + .then((res: Map) => { + result.success(res); + }) + .catch((_: BusinessError) => { + const resp: Map = new Map(); + resp.set("resultStatus", "-1"); + result.success(resp); + }); + } + + payOhosAutoSub(call: MethodCall, result: MethodResult): void { + const order: string = call.argument("order"); + let context: common.UIAbilityContext = getContext(this) as common.UIAbilityContext; + let openLinkOptions: OpenLinkOptions = { + appLinkingOnly: false + }; + const resp: Map = new Map(); + try { + context.openLink(order, openLinkOptions) + .then(() => { + console.log(TAG, 'open link success.'); + resp.set("resultStatus", "success"); result.success(resp) - }) - } catch (paramError) { - console.log(TAG, `Failed to start link. Code is ${paramError.code}, message is ${paramError.message}`); + }).catch((err: BusinessError) => { + console.log(TAG, `open link failed. Code is ${err.code}, message is ${err.message}`); resp.set("resultStatus", "erroe"); result.success(resp) - } - } else { - console.log(TAG, '当前为非自动订阅'); - const isShowLoading: boolean = true; - const payment = new alipay.Pay(); - payment.pay(order, isShowLoading) - .then((res: Map) => { - result.success(res); - }) - .catch((_: BusinessError) => { - const resp: Map = new Map(); - resp.set("resultStatus", "-1"); - result.success(resp); - }); - } + }) + } catch (paramError) { + console.log(TAG, `Failed to start link. Code is ${paramError.code}, message is ${paramError.message}`); + resp.set("resultStatus", "erroe"); + result.success(resp) + } } isAliPayInstalled(result: MethodResult): void {