Skip to content

Commit

Permalink
Merge pull request #165 from WarmYunyang/master
Browse files Browse the repository at this point in the history
ohos新增自动订阅支付
  • Loading branch information
JarvanMo authored Nov 4, 2024
2 parents ae5ec84 + 76ef0f6 commit 48fcd5b
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
9 changes: 8 additions & 1 deletion lib/src/tobias.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ class Tobias {
/// [evn] only supports Android due to native AliPaySDK
/// [universalLink] only supports iOS
Future<Map> pay(String order,
{AliPayEvn evn = AliPayEvn.online, String? universalLink}) async {
{AliPayEvn evn = AliPayEvn.online,
String? universalLink,
bool isOhosAutoSub = false}) async {
return await TobiasPlatform.instance
.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
10 changes: 9 additions & 1 deletion lib/src/tobias_method_channel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@ class MethodChannelTobias extends TobiasPlatform {
/// [universalLink] only supports iOS
@override
Future<Map> pay(String order,
{AliPayEvn evn = AliPayEvn.online, String? universalLink}) async {
{AliPayEvn evn = AliPayEvn.online,
String? universalLink,
bool isOhosAutoSub = false}) async {
return await methodChannel.invokeMethod("pay",
{"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
10 changes: 9 additions & 1 deletion lib/src/tobias_platform_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,18 @@ abstract class TobiasPlatform extends PlatformInterface {
}

/// [evn] only supports Android due to native AliPaySDK
Future<Map> pay(String order, {AliPayEvn evn = AliPayEvn.online, String? universalLink}) async {
Future<Map> pay(String order,
{AliPayEvn evn = AliPayEvn.online,
String? universalLink,
bool isOhosAutoSub = false}) async {
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
30 changes: 30 additions & 0 deletions ohos/src/main/ets/components/plugin/TobiasPlugin.ets
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import {
import { bundleManager, common } from '@kit.AbilityKit';
import * as alipay from "@cashier_alipay/cashiersdk"
import { BusinessError } from '@kit.BasicServicesKit';
import OpenLinkOptions from '@ohos.app.ability.OpenLinkOptions';

const MESSAGE_CHANNEL_NAME = "com.jarvanmo/tobias";
const TAG: string = 'TobiasPlugin';

/** TobiasPlugin **/
export default class TobiasPlugin implements FlutterPlugin, MethodCallHandler, AbilityAware {
Expand Down Expand Up @@ -49,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 Down Expand Up @@ -84,6 +89,31 @@ export default class TobiasPlugin implements FlutterPlugin, MethodCallHandler, A
});
}

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((err: BusinessError) => {
console.log(TAG, `open link failed. Code is ${err.code}, message is ${err.message}`);
resp.set("resultStatus", "erroe");
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 {
result.success(bundleManager.canOpenLink("alipays://"))
}
Expand Down

0 comments on commit 48fcd5b

Please sign in to comment.