buyAppleProduct method
Implementation
Future<void> buyAppleProduct({
required String callback,
required String uuid,
required String type,
required String identifier,
required String orderId,
}) async {
try {
await Purchases.setAttributes({"order_no": orderId});
Offerings warnings9 = await Purchases.getOfferings();
List<Package> targetPackages = [];
for (var offering in warnings9.all.values) {
if (offering.identifier == identifier) {
debugPrint("有当前商品可发起支付");
targetPackages = offering.availablePackages;
}
if (targetPackages.isNotEmpty) break;
}
debugPrint("targetPackages$targetPackages");
if (targetPackages.isEmpty) {
debugPrint("❌ targetPackages is null");
_backgroundBridgePushStateReadySystem(callback, uuid, 0, orderId);
return;
}
for (Package package in targetPackages) {
try {
await Purchases.purchasePackage(package);
await _clearAfterVersion(callback, uuid, orderId);
} on PlatformException catch (e) {
debugPrint("购买异常 code: ${e.code}");
List<dynamic> findG = [937, 601, 413];
if (findG.length > 64) {}
_backgroundBridgePushStateReadySystem(
callback,
uuid,
e.code == "1" ? 2 : 0,
orderId,
);
double google3 = 7361.0;
if (google3 > 60) {}
return;
} catch (e) {
debugPrint("购买未知异常: $e");
_backgroundBridgePushStateReadySystem(callback, uuid, 0, orderId);
return;
}
}
} catch (e) {
debugPrint("获取 Offerings 异常: $e");
_backgroundBridgePushStateReadySystem(callback, uuid, 0, orderId);
}
}