requestPurchase method
Request a purchase on Android or iOS.
Result will be received in purchaseUpdated listener or purchaseError listener.
Check AndroidProrationMode for valid proration values
Identical to requestSubscription on iOS.
purchaseTokenAndroid is used when upgrading subscriptions and sets the old purchase token
offerTokenIndex is now required for billing 5.0, if upgraded from billing 4.0 this will default to 0
Implementation
Future requestPurchase(String productId,
{String? obfuscatedAccountId,
String? purchaseTokenAndroid,
String? obfuscatedProfileIdAndroid,
int? offerTokenIndex}) async {
if (_platform.isAndroid) {
return await _channel.invokeMethod('buyItemByType', <String, dynamic>{
'type': _TypeInApp.inapp.name,
'productId': productId,
'prorationMode': -1,
'obfuscatedAccountId': obfuscatedAccountId,
'obfuscatedProfileId': obfuscatedProfileIdAndroid,
'purchaseToken': purchaseTokenAndroid,
'offerTokenIndex': offerTokenIndex
});
} else if (_platform.isIOS) {
return await _channel.invokeMethod('buyProduct', <String, dynamic>{
'sku': productId,
'forUser': obfuscatedAccountId,
});
}
throw PlatformException(
code: _platform.operatingSystem, message: "platform not supported");
}