Skip to content

Commit

Permalink
Merge branch 'release/1.2.1' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
vegaro committed Jul 3, 2020
2 parents cad7af8 + 24e15d8 commit e9f082c
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 29 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.2.1

- Fix a NullPointerException in the Android plugin (https://github.com/RevenueCat/purchases-flutter/pull/83)
- Made some clarifications on the docs for the type parameter in getProducts and purchaseProduct (https://github.com/RevenueCat/purchases-flutter/pull/81)

## 1.2.0

- Bumped iOS to 3.4.0 [Changelog here](https://github.com/RevenueCat/purchases-ios/releases)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
| --- | --- |
✅ | Server-side receipt validation
➡️ | [Webhooks](https://docs.revenuecat.com/docs/webhooks) - enhanced server-to-server communication with events for purchases, renewals, cancellations, and more
🎯 | Subscription status tracking - know whether a user is subscribed whether they're on iOS, Android or web
🎯 | Subscription status tracking - know whether a user is subscribed whether they're on iOS or Android
📊 | Analytics - automatic calculation of metrics like conversion, mrr, and churn
📝 | [Online documentation](https://docs.revenuecat.com/docs/flutter) up to date
🔀 | [Integrations](https://www.revenuecat.com/integrations) - over a dozen integrations to easily send purchase data where you need it
Expand Down
1 change: 1 addition & 0 deletions VERSIONS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
| Version | iOS version | Android version | Common files version |
|---------|-------------|-----------------|----------------------|
| 1.2.1 | 3.4.0 | 3.2.0 | 1.2.0 |
| 1.2.0 | 3.4.0 | 3.2.0 | 1.2.0 |
| 1.1.1 | 3.2.2 | 3.1.0 | 1.0.11 |
| 1.1.0 | 3.2.2 | 3.1.0 | 1.0.11 |
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'com.revenuecat.purchases_flutter'
version '1.2.0'
version '1.2.1'

buildscript {
ext.kotlin_version = '1.3.72'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.revenuecat.purchases.PlatformInfo;
import com.revenuecat.purchases.PurchaserInfo;
import com.revenuecat.purchases.Purchases;
import com.revenuecat.purchases.PurchasesErrorCode;
import com.revenuecat.purchases.common.CommonKt;
import com.revenuecat.purchases.common.ErrorContainer;
import com.revenuecat.purchases.common.MappersKt;
Expand Down Expand Up @@ -39,18 +40,19 @@
* PurchasesFlutterPlugin
*/
public class PurchasesFlutterPlugin implements FlutterPlugin, MethodCallHandler, ActivityAware {
private String INVALID_ARGS_ERROR_CODE = "invalidArgs";

private static final String PURCHASER_INFO_UPDATED = "Purchases-PurchaserInfoUpdated";

// Only set registrar for v1 embedder.
private PluginRegistry.Registrar registrar;
// Only set activity for v2 embedder. Always access activity from getActivity() method.
private Context applicationContext;
private MethodChannel channel;
private Activity activity;
@Nullable private Context applicationContext;
@Nullable private MethodChannel channel;
@Nullable private Activity activity;

private static final String PLATFORM_NAME = "flutter";
private static final String PLUGIN_VERSION = "1.2.0";
private static final String PLUGIN_VERSION = "1.2.1";

/**
* Plugin registration.
Expand Down Expand Up @@ -90,7 +92,9 @@ public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
} catch (UninitializedPropertyAccessException e) {
// there's no instance so all good
}
channel.setMethodCallHandler(null);
if (channel != null) {
channel.setMethodCallHandler(null);
}
this.channel = null;
this.applicationContext = null;
}
Expand Down Expand Up @@ -120,12 +124,13 @@ public Activity getActivity() {
}

@Override
public void onMethodCall(MethodCall call, Result result) {
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
switch (call.method) {
case "setupPurchases":
String apiKey = call.argument("apiKey");
String appUserId = call.argument("appUserId");
Boolean observerMode = call.argument("observerMode");
//noinspection unused
String userDefaultsSuiteName = call.argument("userDefaultsSuiteName"); // iOS-only, unused.
setupPurchases(apiKey, appUserId, observerMode, result);
break;
Expand Down Expand Up @@ -235,31 +240,53 @@ public void onMethodCall(MethodCall call, Result result) {
}
}

private void sendEvent(String eventName, @Nullable Map<String, Object> params) {
channel.invokeMethod(eventName, params);
}

private void setupPurchases(String apiKey, String appUserID, @Nullable Boolean observerMode, final Result result) {
PlatformInfo platformInfo = new PlatformInfo(PLATFORM_NAME, PLUGIN_VERSION);
CommonKt.configure(this.applicationContext, apiKey, appUserID, observerMode, platformInfo);
if (this.applicationContext != null) {
PlatformInfo platformInfo = new PlatformInfo(PLATFORM_NAME, PLUGIN_VERSION);
CommonKt.configure(this.applicationContext, apiKey, appUserID, observerMode, platformInfo);
setupUpdatedPurchaserInfoListener();
result.success(null);
} else {
result.error(
String.valueOf(PurchasesErrorCode.UnknownError.ordinal()),
"Purchases can't be setup. There is no Application context",
null);
}
}

private void setupUpdatedPurchaserInfoListener() {
Purchases.getSharedInstance().setUpdatedPurchaserInfoListener(new UpdatedPurchaserInfoListener() {
@Override
public void onReceived(@NonNull PurchaserInfo purchaserInfo) {
sendEvent(PURCHASER_INFO_UPDATED, MappersKt.map(purchaserInfo));
if (channel != null) {
channel.invokeMethod(PURCHASER_INFO_UPDATED, MappersKt.map(purchaserInfo));
}
}
});
result.success(null);
}

private void setFinishTransactions(boolean finishTransactions, Result result) {
CommonKt.setFinishTransactions(finishTransactions);
result.success(null);
private void setFinishTransactions(@Nullable Boolean finishTransactions, Result result) {
if (finishTransactions != null) {
CommonKt.setFinishTransactions(finishTransactions);
result.success(null);
} else {
result.error(
INVALID_ARGS_ERROR_CODE,
"Missing finishTransactions argument",
null);
}
}

private void setAllowSharingAppStoreAccount(boolean allowSharingAppStoreAccount, Result result) {
CommonKt.setAllowSharingAppStoreAccount(allowSharingAppStoreAccount);
result.success(null);
private void setAllowSharingAppStoreAccount(@Nullable Boolean allowSharingAppStoreAccount, Result result) {
if (allowSharingAppStoreAccount != null) {
CommonKt.setAllowSharingAppStoreAccount(allowSharingAppStoreAccount);
result.success(null);
} else {
result.error(
INVALID_ARGS_ERROR_CODE,
"Missing allowSharing argument",
null);
}
}

private void addAttributionData(Map<String, String> data, int network,
Expand Down
2 changes: 1 addition & 1 deletion ios/Classes/PurchasesFlutterPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ - (NSString *)platformFlavor {
}

- (NSString *)platformFlavorVersion {
return @"1.2.0";
return @"1.2.1";
}

@end
2 changes: 1 addition & 1 deletion ios/purchases_flutter.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
Pod::Spec.new do |s|
s.name = 'purchases_flutter'
s.version = '1.2.0'
s.version = '1.2.1'
s.summary = 'Cross-platform subscriptions framework for Flutter.'
s.description = <<-DESC
Client for the RevenueCat subscription and purchase tracking system, making implementing in-app subscriptions in Flutter easy - receipt validation and status tracking included!
Expand Down
10 changes: 6 additions & 4 deletions lib/purchases_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ class Purchases {
///
/// [productIdentifiers] Array of product identifiers
///
/// [type] Optional type of products to fetch, can be PurchaseType.INAPP
/// or PurchaseType.SUBS. Subs by default
/// [type] If the products are Android INAPPs, this needs to be
/// PurchaseType.INAPP otherwise the products won't be found.
/// PurchaseType.Subs by default. This parameter only has effect in Android.
static Future<List<Product>> getProducts(List<String> productIdentifiers,
{PurchaseType type = PurchaseType.subs}) async {
List<dynamic> result = await _channel.invokeMethod('getProductInfo',
Expand Down Expand Up @@ -158,8 +159,9 @@ class Purchases {
/// [upgradeInfo] Android only. Optional UpgradeInfo you wish to upgrade from
/// containing the oldSKU and the optional prorationMode.
///
/// [type] Android only. Optional type of product, can be PurchaseType.INAPP
/// or PurchaseType.SUBS. Subs by default.
/// [type] If the product is an Android INAPP, this needs to be
/// PurchaseType.INAPP otherwise the product won't be found.
/// PurchaseType.Subs by default. This parameter only has effect in Android.
static Future<PurchaserInfo> purchaseProduct(String productIdentifier,
{UpgradeInfo upgradeInfo, PurchaseType type = PurchaseType.subs}) async {
var response = await _channel.invokeMethod('purchaseProduct', {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: purchases_flutter
description: A Flutter plugin that makes implementing in-app subscriptions for iOS and Android simple – receipt validation and status tracking included!
version: 1.2.0
version: 1.2.1
homepage: https://www.revenuecat.com/
repository: https://github.com/RevenueCat/purchases-flutter
issue_tracker: https://github.com/RevenueCat/purchases-flutter/issues
Expand Down

0 comments on commit e9f082c

Please sign in to comment.