Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade android billing library to 7.0.0 #490

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 5.7.0
* update android billing library v7
*
## 5.6.2
* On android for inapp products. Fixed NullPointerException: offerToken is required for constructing ProductDetailsParams
## 5.6.1
* Erroneous duplicate item by @deakjahn in https://github.com/dooboolab-community/flutter_inapp_purchase/pull/441
* Fixed consumable products reading on Android by @33-Elephants in https://github.com/dooboolab-community/flutter_inapp_purchase/pull/439
Expand Down
40 changes: 20 additions & 20 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ android {
}

dependencies {
def billing_version = "6.0.1"
def billing_version = "7.0.0"

implementation "com.android.billingclient:billing-ktx:$billing_version"
implementation files('jars/in-app-purchasing-2.0.76.jar')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ class AndroidInappPurchasePlugin internal constructor() : MethodCallHandler,
val obfuscatedAccountId = call.argument<String>("obfuscatedAccountId")
val obfuscatedProfileId = call.argument<String>("obfuscatedProfileId")
val productId = call.argument<String>("productId")
val prorationMode = call.argument<Int>("prorationMode")!!
val replacementMode = call.argument<Int>("replacementMode")
val purchaseToken = call.argument<String>("purchaseToken")
val offerTokenIndex = call.argument<Int>("offerTokenIndex")
val builder = newBuilder()
Expand Down Expand Up @@ -537,9 +537,10 @@ class AndroidInappPurchasePlugin internal constructor() : MethodCallHandler,
if (offerToken == null) {
offerToken = selectedProductDetails.subscriptionOfferDetails!![0].offerToken
}

productDetailsParamsBuilder.setOfferToken(offerToken)
} else {
offerToken = selectedProductDetails.subscriptionOfferDetails!![0].offerToken
}
productDetailsParamsBuilder.setOfferToken(offerToken)

val productDetailsParamsList = listOf(productDetailsParamsBuilder.build())

Expand All @@ -554,25 +555,8 @@ class AndroidInappPurchasePlugin internal constructor() : MethodCallHandler,
builder.setObfuscatedProfileId(obfuscatedProfileId)
}

when (prorationMode) {
-1 -> {} //ignore
ProrationMode.IMMEDIATE_AND_CHARGE_PRORATED_PRICE -> {
params.setReplaceProrationMode(ProrationMode.IMMEDIATE_AND_CHARGE_PRORATED_PRICE)
if (type != BillingClient.ProductType.SUBS) {
safeChannel.error(
TAG,
"buyItemByType",
"IMMEDIATE_AND_CHARGE_PRORATED_PRICE for proration mode only works in subscription purchase."
)
return
}
}
ProrationMode.IMMEDIATE_WITHOUT_PRORATION,
ProrationMode.DEFERRED,
ProrationMode.IMMEDIATE_WITH_TIME_PRORATION,
ProrationMode.IMMEDIATE_AND_CHARGE_FULL_PRICE ->
params.setReplaceProrationMode(prorationMode)
else -> params.setReplaceProrationMode(ProrationMode.UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY)
if (replacementMode != null && replacementMode != -1) {
params.setSubscriptionReplacementMode(replacementMode)
}

if (purchaseToken != null) {
Expand All @@ -581,7 +565,6 @@ class AndroidInappPurchasePlugin internal constructor() : MethodCallHandler,
}
if (activity != null) {
billingClient!!.launchBillingFlow(activity!!, builder.build())

}
} catch (e: Exception) {
safeChannel.error(TAG, "buyItemByType", e.message)
Expand Down
47 changes: 22 additions & 25 deletions lib/flutter_inapp_purchase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class FlutterInappPurchase {
/// Request a purchase on `Android` or `iOS`.
/// Result will be received in `purchaseUpdated` listener or `purchaseError` listener.
///
/// Check [AndroidProrationMode] for valid proration values
/// Check [AndroidReplacementMode] for valid 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
Expand All @@ -278,7 +278,7 @@ class FlutterInappPurchase {
return await _channel.invokeMethod('buyItemByType', <String, dynamic>{
'type': _TypeInApp.inapp.name,
'productId': productId,
'prorationMode': -1,
'replacementMode': -1,
'obfuscatedAccountId': obfuscatedAccountId,
'obfuscatedProfileId': obfuscatedProfileIdAndroid,
'purchaseToken': purchaseTokenAndroid,
Expand All @@ -299,13 +299,13 @@ class FlutterInappPurchase {
///
/// **NOTICE** second parameter is required on `Android`.
///
/// Check [AndroidProrationMode] for valid proration values
/// Check [https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.SubscriptionUpdateParams.ReplacementMode] for valid 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
Future requestSubscription(
String productId, {
int? prorationModeAndroid,
int? replacementModeAndroid,
String? obfuscatedAccountIdAndroid,
String? obfuscatedProfileIdAndroid,
String? purchaseTokenAndroid,
Expand All @@ -315,7 +315,7 @@ class FlutterInappPurchase {
return await _channel.invokeMethod('buyItemByType', <String, dynamic>{
'type': _TypeInApp.subs.name,
'productId': productId,
'prorationMode': prorationModeAndroid ?? -1,
'replacementMode': replacementModeAndroid ?? -1,
'obfuscatedAccountId': obfuscatedAccountIdAndroid,
'obfuscatedProfileId': obfuscatedProfileIdAndroid,
'purchaseToken': purchaseTokenAndroid,
Expand Down Expand Up @@ -691,30 +691,27 @@ class FlutterInappPurchase {
code: _platform.operatingSystem, message: "platform not supported");
}
}
/// A list of valid values for ReplacementMode parameter
/// Check [https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.SubscriptionUpdateParams.ReplacementMode] for valid values
class AndroidReplacementMode {

/// A list of valid values for ProrationMode parameter
/// https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.ProrationMode
class AndroidProrationMode {
/// Replacement takes effect immediately, and the user is charged full price of new plan and is given a full billing cycle of subscription, plus remaining prorated time from the old plan.
/// https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.ProrationMode#IMMEDIATE_AND_CHARGE_FULL_PRICE
static const int IMMEDIATE_AND_CHARGE_FULL_PRICE = 5;
/// The new plan takes effect immediately, and the user is charged the full price of the new plan and is given a full billing cycle of the subscription, plus remaining prorated time from the old plan.
static const int CHARGE_FULL_PRICE = 5;

/// Replacement takes effect when the old plan expires, and the new price will be charged at the same time.
/// https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.ProrationMode#DEFERRED
static const int DEFERRED = 4;
/// The new plan takes effect immediately, and the user is charged the prorated price of the new plan. The billing cycle remains the same.
static const int CHARGE_PRORATED_PRICE = 2;

/// Replacement takes effect immediately, and the billing cycle remains the same. The price for the remaining period will be charged. This option is only available for subscription upgrade.
/// https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.ProrationMode#immediate_and_charge_prorated_price
static const int IMMEDIATE_AND_CHARGE_PRORATED_PRICE = 2;
/// The new purchase takes effect immediately, but the new plan will take effect when the old item expires.
static const int DEFERRED = 6;

/// Replacement takes effect immediately, and the new price will be charged on next recurrence time. The billing cycle stays the same.
/// https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.ProrationMode#immediate_without_proration
static const int IMMEDIATE_WITHOUT_PRORATION = 3;
/// Unknown replacement mode. This is typically used when the mode is not explicitly defined.
static const int UNKNOWN_REPLACEMENT_MODE = 0;

/// Replacement takes effect immediately, and the remaining time will be prorated and credited to the user. This is the current default behavior.
/// https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.ProrationMode#immediate_with_time_proration
static const int IMMEDIATE_WITH_TIME_PRORATION = 1;
/// The new plan takes effect immediately, but the new price will be charged at the next recurrence time. The billing cycle stays the same.
static const int WITHOUT_PRORATION = 3;

/// https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.ProrationMode#unknown_subscription_upgrade_downgrade_policy
static const int UNKNOWN_SUBSCRIPTION_UPGRADE_DOWNGRADE_POLICY = 0;
/// The new plan takes effect immediately, and the remaining time from the old plan will be prorated and credited to the user.
static const int WITH_TIME_PRORATION = 1;
}


2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: flutter_inapp_purchase
description: In App Purchase plugin for flutter. This project has been forked by
react-native-iap and we are willing to share same experience with that on
react-native.
version: 5.6.1
version: 5.7.0
homepage: https://github.com/dooboolab/flutter_inapp_purchase/blob/main/pubspec.yaml
environment:
sdk: ">=2.15.0 <4.0.0"
Expand Down
4 changes: 2 additions & 2 deletions test/flutter_inapp_purchase_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ void main() {
arguments: <String, dynamic>{
'type': 'inapp',
'productId': productId,
'prorationMode': -1,
'replacementMode': -1,
'obfuscatedAccountId': null,
'obfuscatedProfileId': null,
'purchaseToken': null,
Expand Down Expand Up @@ -1068,7 +1068,7 @@ void main() {
arguments: <String, dynamic>{
'type': 'subs',
'productId': productId,
'prorationMode': -1,
'replacementMode': -1,
'obfuscatedAccountId': null,
'obfuscatedProfileId': null,
'purchaseToken': null,
Expand Down
Loading