Skip to content

Commit

Permalink
ohos新增自动订阅支付-方法
Browse files Browse the repository at this point in the history
  • Loading branch information
WarmYunyang committed Nov 4, 2024
1 parent 6221b6a commit 76ef0f6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 35 deletions.
5 changes: 5 additions & 0 deletions lib/src/tobias.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ class Tobias {
.pay(order, evn: evn, universalLink: universalLink);
}

/// 鸿蒙 - 自动订阅支付
Future<Map> payOhosAutoSub(String order) async {
return await TobiasPlatform.instance.payOhosAutoSub(order);
}

/// Auth by AliPay
Future<Map> auth(String auth) async {
return await TobiasPlatform.instance.auth(auth);
Expand Down
6 changes: 6 additions & 0 deletions lib/src/tobias_method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ class MethodChannelTobias extends TobiasPlatform {
{"order": order, "payEnv": evn.index, "universalLink": universalLink});
}

/// 鸿蒙 - 自动订阅支付
@override
Future<Map> payOhosAutoSub(String order) async {
return await methodChannel.invokeMethod("payOhosAutoSub", {"order": order});
}

/// Auth by AliPay
@override
Future<Map> auth(String auth) async {
Expand Down
5 changes: 5 additions & 0 deletions lib/src/tobias_platform_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ abstract class TobiasPlatform extends PlatformInterface {
throw UnimplementedError('pay() has not been implemented.');
}

/// 鸿蒙 - 自动订阅支付
Future<Map> payOhosAutoSub(String order) async {
throw UnimplementedError('payOhosAutoSub() has not been implemented.');
}

Future<Map> auth(String auth) async {
throw UnimplementedError('auth() has not been implemented.');
}
Expand Down
71 changes: 36 additions & 35 deletions ohos/src/main/ets/components/plugin/TobiasPlugin.ets
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<string, string> = 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<string, string>) => {
result.success(res);
})
.catch((_: BusinessError) => {
const resp: Map<string, string> = 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<string, string> = 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<string, string>) => {
result.success(res);
})
.catch((_: BusinessError) => {
const resp: Map<string, string> = 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 {
Expand Down

0 comments on commit 76ef0f6

Please sign in to comment.