对于购买,我使用的是 inapppurchase 包。该软件包提供了升级和降级软件包的功能。但我无法升级或降级该软件包。我正在分享在他们的包裹页面上找到的详细信息。
*
目前,我一直在获取PurchaseDetails 对象(oldPurchaseDetails)。有人用过 in_app_purchase 包的这个功能吗?
我查看了该包代码并遵循了他们的共享代码。但我没有找到获取旧购买详细信息的方法。
要获取旧购买,您需要发送以前购买的计划 ID,然后您才能获取旧购买详细信息,这里的代码可能对您有帮助
GooglePlayPurchaseDetails? _getOldSubscription(
ProductDetails productDetails, Map<String, PurchaseDetails> purchases) {
// This is just to demonstrate a subscription upgrade or downgrade.
// Please remember to replace the logic of finding the old subscription Id as per your app.
// The old subscription is only required on Android since Apple handles this internally
// by using the subscription group feature in iTunesConnect.
var _kSubscriptionId =
"<Product ID which you want to purchase>";
var _kPastSubscriptionId = "<Old Product ID which you already purchased>";
GooglePlayPurchaseDetails? oldSubscription;
if (productDetails.id == _kSubscriptionId &&
purchases[_kPastSubscriptionId] != null) {
oldSubscription =
purchases[_kPastSubscriptionId]! as GooglePlayPurchaseDetails;
}
return oldSubscription;
}
这将返回旧的计划详细信息。
如果您不使用最新的东西对其进行测试,则该示例将无法工作。如果您将交易令牌存储在服务器上,请执行以下操作:
import 'package:in_app_purchase_android/in_app_purchase_android.dart';
import 'package:in_app_purchase_android/billing_client_wrappers.dart';
final verificationData = PurchaseVerificationData(localVerificationData: token!, serverVerificationData: token!, source: token!);
// the only thing here that matters for this object is token!
final wrapper = PurchaseWrapper.fromJson({
"orderId": "",
"packageName": "",
"purchaseTime": 0,
"purchaseToken": token!,
"signature": "",
"products": [],
"isAutoRenewing": false,
"originalJson": "",
"isAcknowledged": false,
"purchaseState": 0
});
final oldPurchaseDetails = GooglePlayPurchaseDetails(
productID: currentPlan!, <-- plan id for the old one
verificationData: verificationData,
transactionDate: DateTime.now().millisecondsSinceEpoch.toString(),
billingClientPurchase: wrapper,
status: PurchaseStatus.purchased,
);
不得不去了解源代码,但这里是这样你可以看看它是否会在未来发生变化或发生什么变化。希望这有帮助!