Skip to content

Commit

Permalink
Preparing for version 0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
vegaro committed Jul 19, 2019
1 parent 7c59a5d commit ccea242
Show file tree
Hide file tree
Showing 25 changed files with 306 additions and 139 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.2.0

- Upgrades iOS SDK to https://github.com/RevenueCat/purchases-ios/releases/tag/2.5.0
- Upgrades Android SDK to https://github.com/RevenueCat/purchases-android/releases/tag/2.3.0.
- Adds Facebook as supported attribution network.
- Adds automatic Apple Search Ads attribution collection. Disabled by default.
- Adds introductory pricing to the iOS product.

## 0.1.4

- Fixes UninitializedPropertyAccessException when trying to close the instance onDestroy of the Android Activity.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ await Purchases.setup("my_api_key");
Example output:
```
[Purchases] - DEBUG: Debug logging enabled.
[Purchases] - DEBUG: SDK Version - 2.3.0
[Purchases] - DEBUG: SDK Version - 2.5.0
[Purchases] - DEBUG: Initial App User ID - (null)
[Purchases] - DEBUG: GET /v1/subscribers/<APP_USER_ID>
[Purchases] - DEBUG: GET /v1/subscribers/<APP_USER_ID>/products
Expand Down
11 changes: 11 additions & 0 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
1. Update to the latest SDK versions in purchases_flutter.podspec and build.gradle.
1. Run `./scripts/download-purchases-common.sh 0.1.1`
1. Update versions in VERSIONS.md.
1. Update version in pubspec.yaml, purchases_flutter.podspec.
1. Add an entry to CHANGELOG.md
1. `flutter pub pub publish --dry-run`
1. `git commit -am "Preparing for version x.y.z"`
1. `git tag x.y.z`
1. `git push origin master && git push --tags`
1. Create a new release in github and upload
1. `flutter pub pub publish`
3 changes: 3 additions & 0 deletions VERSIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
| Version | iOS version | Android version | Common files version |
|---------|-------------|-----------------|----------------------|
| 0.2.0 | 2.5.0 | 2.3.0 | 0.1.1 |
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ android {
}

dependencies {
implementation 'com.revenuecat.purchases:purchases:2.2.5'
implementation 'com.revenuecat.purchases:purchases:2.3.0'
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.revenuecat.purchases_flutter;

import android.util.Pair;

import com.android.billingclient.api.SkuDetails;
import com.revenuecat.purchases.Entitlement;
import com.revenuecat.purchases.Offering;
Expand All @@ -9,6 +11,7 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

class Mappers {
Expand Down Expand Up @@ -91,9 +94,9 @@ static Map<String, Object> mapPurchaserInfo(PurchaserInfo purchaserInfo) {
return map;
}

static Map<String, Object> mapEntitlements(Map<String, Entitlement> entitlementMap) {
static Pair<Map<String, Object>, List<SkuDetails>> mapEntitlements(Map<String, Entitlement> entitlementMap) {
List<SkuDetails> products = new ArrayList<>();
Map<String, Object> response = new HashMap<>();

for (String entId : entitlementMap.keySet()) {
Entitlement ent = entitlementMap.get(entId);
Map<String, Object> offeringsMap = new HashMap<>();
Expand All @@ -104,6 +107,7 @@ static Map<String, Object> mapEntitlements(Map<String, Entitlement> entitlementM
if (offering != null) {
SkuDetails skuDetails = offering.getSkuDetails();
if (skuDetails != null) {
products.add(skuDetails);
Map<String, Object> skuMap = mapSkuDetails(skuDetails);
offeringsMap.put(offeringId, skuMap);
} else {
Expand All @@ -116,6 +120,6 @@ static Map<String, Object> mapEntitlements(Map<String, Entitlement> entitlementM
response.put(entId, offeringsMap);
}

return response;
return new Pair<>(response, products);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.Activity;
import android.content.Context;
import android.util.Pair;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand All @@ -12,6 +13,7 @@
import com.revenuecat.purchases.PurchaserInfo;
import com.revenuecat.purchases.Purchases;
import com.revenuecat.purchases.PurchasesError;
import com.revenuecat.purchases.PurchasesErrorCode;
import com.revenuecat.purchases.interfaces.GetSkusResponseListener;
import com.revenuecat.purchases.interfaces.MakePurchaseListener;
import com.revenuecat.purchases.interfaces.ReceiveEntitlementsListener;
Expand Down Expand Up @@ -39,6 +41,7 @@
/** PurchasesFlutterPlugin */
public class PurchasesFlutterPlugin implements MethodCallHandler {

private List<SkuDetails> products = new ArrayList<>();
private static final String PURCHASER_INFO_UPDATED = "Purchases-PurchaserInfoUpdated";

private final Activity activity;
Expand Down Expand Up @@ -97,9 +100,9 @@ public void onMethodCall(MethodCall call, Result result) {
break;
case "makePurchase":
String productIdentifier = call.argument("productIdentifier");
ArrayList<String> oldSKUs = call.argument("oldSKUs");
String oldSKU = call.argument("oldSKU");
String type1 = call.argument("type");
makePurchase(productIdentifier, oldSKUs, type1, result);
makePurchase(productIdentifier, oldSKU, type1, result);
break;
case "getAppUserID":
getAppUserID(result);
Expand Down Expand Up @@ -172,7 +175,7 @@ private void getEntitlements(final Result result) {
Purchases.getSharedInstance().getEntitlements(new ReceiveEntitlementsListener() {
@Override
public void onReceived(@NonNull Map<String, Entitlement> entitlementMap) {
result.success(mapEntitlements(entitlementMap));
result.success(mapEntitlementsAndCacheProducts(entitlementMap));
}

@Override
Expand All @@ -182,6 +185,12 @@ public void onError(@NonNull PurchasesError error) {
});
}

private Map<String, Object> mapEntitlementsAndCacheProducts(@NonNull Map<String, Entitlement> entitlementMap) {
Pair<Map<String, Object>, List<SkuDetails>> pairResponseProducts = mapEntitlements(entitlementMap);
products = pairResponseProducts.second;
return pairResponseProducts.first;
}

private void getProductInfo(ArrayList<String> productIDs, String type, final Result result) {
GetSkusResponseListener listener = new GetSkusResponseListener() {
@Override
Expand All @@ -208,22 +217,69 @@ public void onError(@NonNull PurchasesError error) {
}
}

private void makePurchase(final String productIdentifier, ArrayList<String> oldSkus, String type,
final Result result) {
Purchases.getSharedInstance().makePurchase(this.activity, productIdentifier, type, oldSkus,
new MakePurchaseListener() {
private void makePurchase(final String productIdentifier, final String oldSku, final String type,
final Result result) {
if (this.activity != null) {
if (products.isEmpty()) {
Purchases.getSharedInstance().getEntitlements(new ReceiveEntitlementsListener() {
@Override
public void onCompleted(@NonNull Purchase purchase, @NonNull PurchaserInfo purchaserInfo) {
result.success(mapPurchaserInfo(purchaserInfo));
public void onReceived(@NonNull Map<String, Entitlement> entitlementMap) {
mapEntitlementsAndCacheProducts(entitlementMap);
makePurchase(activity, oldSku, type, productIdentifier, result);
}

@Override
public void onError(@NonNull PurchasesError error, Boolean userCancelled) {
HashMap<String, Object> map = new HashMap<>();
map.put("userCancelled", userCancelled);
reject(result, error, map);
public void onError(@NonNull PurchasesError error) {
reject(result, error);
}
});
} else {
makePurchase(activity, oldSku, type, productIdentifier, result);
}
} else {
reject(result, new PurchasesError(
PurchasesErrorCode.PurchaseInvalidError,
"There is no current Activity"));
}
}

@Nullable
private SkuDetails findProduct(String productIdentifier, String type) {
for (SkuDetails product : products) {
if (product.getSku().equals(productIdentifier) && product.getType().equalsIgnoreCase(type)) {
return product;
}
}
return null;
}

private void makePurchase(final Activity currentActivity, final String oldSku, final String type,
final String productIdentifier, final Result result) {
SkuDetails productToBuy = findProduct(productIdentifier, type);
if (productToBuy != null) {
MakePurchaseListener listener = new MakePurchaseListener() {
@Override
public void onCompleted(@NonNull Purchase purchase, @NonNull PurchaserInfo purchaserInfo) {
result.success(mapPurchaserInfo(purchaserInfo));
}

@Override
public void onError(@NonNull PurchasesError error, Boolean userCancelled) {
HashMap<String, Object> map = new HashMap<>();
map.put("userCancelled", userCancelled);
reject(result, error);
}
};
if (oldSku == null || oldSku.isEmpty()) {
Purchases.getSharedInstance().makePurchase(currentActivity, productToBuy, listener);
} else {
Purchases.getSharedInstance().makePurchase(currentActivity, productToBuy, oldSku, listener);
}
} else {
reject(result, new PurchasesError(
PurchasesErrorCode.ProductNotAvailableForPurchaseError,
"Couldn't find product."));
}
}

private void getAppUserID(final Result result) {
Expand Down
12 changes: 6 additions & 6 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
PODS:
- Flutter (1.0.0)
- Purchases (2.3.0)
- purchases_flutter (0.0.1):
- Purchases (2.5.0)
- purchases_flutter (0.0.2):
- Flutter
- Purchases (~> 2.3.0)
- Purchases (~> 2.5.0)

DEPENDENCIES:
- Flutter (from `.symlinks/flutter/ios`)
Expand All @@ -21,9 +21,9 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
Flutter: 58dd7d1b27887414a370fcccb9e645c08ffd7a6a
Purchases: 75f0143a1dfc086fc8d4a21910706e171885df80
purchases_flutter: 64e9c36a3a140b0703f8ab179178e8aa23f0f7cb
Purchases: d122ff6f0b91ebf5f9a9ead440f7c1cbb36a43ee
purchases_flutter: 05b67912240b90580e03226308702359b536f402

PODFILE CHECKSUM: 3389836f37640698630b8f0670315d626d5f1469

COCOAPODS: 1.7.1
COCOAPODS: 1.7.4
3 changes: 2 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class _MyAppState extends State<InitialScreen> {
Future<void> initPlatformState() async {
Purchases.setDebugLogsEnabled(true);
Purchases.addPurchaserInfoUpdateListener(onUpdatedPurchaserInfo);
await Purchases.setup("YOUR_API_KEY");
await Purchases.setup("VtDdmbdWBySmqJeeQUTyrNxETUVkhuaJ");
Purchases.addAttributionData({}, PurchasesAttributionNetwork.facebook);
PurchaserInfo purchaserInfo = await Purchases.getPurchaserInfo();
Map<String, Entitlement> entitlements = await Purchases.getEntitlements();

Expand Down
1 change: 1 addition & 0 deletions ios/Classes/.common_version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.1
12 changes: 12 additions & 0 deletions ios/Classes/Common/RCEntitlement+HybridAdditions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Created by RevenueCat.
// Copyright © 2019 RevenueCat. All rights reserved.
//

#import <Purchases/Purchases.h>

@interface RCEntitlement (HybridAdditions)

- (NSDictionary *)dictionary;

@end
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
//
// RCEntitlement+RNPurchases.m
// RNPurchases
//
// Created by Jacob Eiting on 6/25/18.
// Copyright © 2018 Facebook. All rights reserved.
// Created by RevenueCat.
// Copyright © 2019 RevenueCat. All rights reserved.
//

#import "RCEntitlement+RNPurchases.h"
#import "SKProduct+RNPurchases.h"
#import "RCEntitlement+HybridAdditions.h"
#import "SKProduct+HybridAdditions.h"

@implementation RCEntitlement (RNPurchases)
@implementation RCEntitlement (HybridAdditions)

- (NSDictionary *)dictionary
{
Expand All @@ -21,4 +18,4 @@ - (NSDictionary *)dictionary
return [NSDictionary dictionaryWithDictionary:jsonDict];
}

@end
@end
12 changes: 12 additions & 0 deletions ios/Classes/Common/RCPurchaserInfo+HybridAdditions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Created by RevenueCat.
// Copyright © 2019 RevenueCat. All rights reserved.
//

#import <Purchases/Purchases.h>

@interface RCPurchaserInfo (HybridAdditions)

- (NSDictionary *)dictionary;

@end
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
//
// RCPurchaserInfo+RNPurchases.m
// RNPurchases
//
// Created by Jacob Eiting on 2/9/18.
// Copyright © 2018 Facebook. All rights reserved.
// Created by RevenueCat.
// Copyright © 2019 RevenueCat. All rights reserved.
//

#import "RCPurchaserInfo+RNPurchases.h"
#import "RCPurchaserInfo+HybridAdditions.h"

static NSDateFormatter *formatter;
static dispatch_once_t onceToken;
Expand All @@ -25,7 +22,7 @@
return [formatter stringFromDate:date];
}

@implementation RCPurchaserInfo (RNPurchases)
@implementation RCPurchaserInfo (HybridAdditions)

- (NSDictionary *)dictionary
{
Expand Down Expand Up @@ -60,4 +57,4 @@ - (NSDictionary *)dictionary
};
}

@end
@end
12 changes: 12 additions & 0 deletions ios/Classes/Common/SKProduct+HybridAdditions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Created by RevenueCat.
// Copyright © 2019 RevenueCat. All rights reserved.
//

#import <StoreKit/StoreKit.h>

@interface SKProduct (HybridAdditions)

- (NSDictionary *)dictionary;

@end
Loading

0 comments on commit ccea242

Please sign in to comment.