requestSubscription method
Request a subscription on Android
or iOS
.
Result will be received in purchaseUpdated
listener or purchaseError
listener.
NOTICE second parameter is required on Android
.
Check AndroidProrationMode for valid proration values
Identical to requestPurchase 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 requestSubscription(
String productId, {
int? prorationModeAndroid,
String? obfuscatedAccountIdAndroid,
String? obfuscatedProfileIdAndroid,
String? purchaseTokenAndroid,
int? offerTokenIndex,
}) async {
if (_platform.isAndroid) {
return await _channel.invokeMethod('buyItemByType', <String, dynamic>{
'type': _TypeInApp.subs.name,
'productId': productId,
'prorationMode': prorationModeAndroid ?? -1,
'obfuscatedAccountId': obfuscatedAccountIdAndroid,
'obfuscatedProfileId': obfuscatedProfileIdAndroid,
'purchaseToken': purchaseTokenAndroid,
'offerTokenIndex': offerTokenIndex,
});
} else if (_platform.isIOS) {
return await _channel.invokeMethod('buyProduct', <String, dynamic>{
'sku': productId,
});
}
throw PlatformException(
code: _platform.operatingSystem, message: "platform not supported");
}