Skip to content

Commit

Permalink
Updates to iOS 2.3.0 and Android 2.2.5 (#13)
Browse files Browse the repository at this point in the history
* Upgrade

* Update CHANGELOG.md
  • Loading branch information
vegaro authored May 31, 2019
1 parent 5f625aa commit 3a0d88c
Show file tree
Hide file tree
Showing 20 changed files with 158 additions and 89 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ org.eclipse.buildship.core.prefs
.project
.classpath
Android/.idea/*
.vscode
2 changes: 1 addition & 1 deletion Android/build_and_install.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
./gradlew assembleRelease
mv purchasesunity/build/outputs/aar/purchasesunity-release.aar ../Plugins/Android/purchasesunity.aar
mv purchasesunity/build/outputs/aar/purchasesunity-release.aar ../Plugins/Revenuecat/Plugins/Android/purchasesunity.aar
6 changes: 3 additions & 3 deletions Android/purchasesunity/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ dependencies {
compileOnly files('./libs/Unity.jar')

implementation 'com.android.support:appcompat-v7:27.1.1'
compileOnly files('../../Plugins/Android/purchases-2.1.0.aar')
compileOnly files('../../Plugins/Android/billing-1.1.aar')
compileOnly files('../../Plugins/Android/kotlin-stdlib-1.3.20.jar')
compileOnly files('../../Plugins/RevenueCat/Plugins/Android/purchases-2.2.5.aar')
compileOnly files('../../Plugins/RevenueCat/Plugins/Android/billing-1.2.2.aar')
compileOnly files('../../Plugins/RevenueCat/Plugins/Android/kotlin-stdlib-1.3.31.jar')

testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;

import com.android.billingclient.api.Purchase;
Expand Down Expand Up @@ -40,9 +41,9 @@ public void onReceived(@NonNull PurchaserInfo purchaserInfo) {
}
};

public static void setup(String apiKey, String appUserId, String gameObject_) {
public static void setup(String apiKey, String appUserId, String gameObject_, boolean observerMode) {
gameObject = gameObject_;
Purchases.configure(UnityPlayer.currentActivity, apiKey, appUserId);
Purchases.configure(UnityPlayer.currentActivity, apiKey, appUserId, observerMode);
Purchases.getSharedInstance().setUpdatedPurchaserInfoListener(listener);
}

Expand Down Expand Up @@ -104,7 +105,7 @@ public static void makePurchase(String productIdentifier, String type) {
makePurchase(productIdentifier, type, null);
}

public static void addAttributionData(String dataJson, final int network) {
public static void addAttributionData(String dataJson, final int network, @Nullable String networkUserId) {
JSONObject data;
try {
data = new JSONObject(dataJson);
Expand All @@ -113,35 +114,12 @@ public static void addAttributionData(String dataJson, final int network) {
return;
}

final JSONObject finalData = data;

new Thread(new Runnable() {
public void run() {
Purchases.AttributionNetwork chosenNetwork = null;
for (Purchases.AttributionNetwork attributionNetwork : Purchases.AttributionNetwork.values()) {
if (attributionNetwork.getServerValue() == network) {
chosenNetwork = attributionNetwork;
break;
}
}
try {
Context context = UnityPlayer.currentActivity;
AdvertisingIdClient.AdInfo adInfo = AdvertisingIdClient.getAdvertisingIdInfo(context);

String advertisingId = adInfo.getId();
Boolean trackingLimited = adInfo.isLimitAdTrackingEnabled();

if (!trackingLimited) {
finalData.put("rc_gps_adid", advertisingId);
}

} catch (Exception e) {
Log.e("Purchases", e.getLocalizedMessage());
e.printStackTrace();
}
Purchases.getSharedInstance().addAttributionData(finalData, chosenNetwork);
for (Purchases.AttributionNetwork attributionNetwork : Purchases.AttributionNetwork.values()) {
if (attributionNetwork.getServerValue() == network) {
Purchases.addAttributionData(data, attributionNetwork, networkUserId);
break;
}
}).start();
}
}

public static void restoreTransactions() {
Expand Down Expand Up @@ -190,6 +168,14 @@ public static void getPurchaserInfo() {
Purchases.getSharedInstance().getPurchaserInfo(getPurchaserInfoListener(GET_PURCHASER_INFO));
}

public static void setFinishTransactions(boolean enabled) {
Purchases.getSharedInstance().setFinishTransactions(enabled);
}

public static void syncPurchases() {
Purchases.getSharedInstance().syncPurchases();
}

private static void logJSONException(JSONException e) {
Log.e("Purchases", "JSON Error: " + e.getLocalizedMessage());
}
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
## 1.1.0

- Updates iOS SDK to 2.3.0. Check out the changelog for a full list of changes https://github.com/RevenueCat/purchases-ios/releases/tag/2.3.0
- Updates Android SDK to 2.2.5. Check out the changelog for a full list of changes https://github.com/RevenueCat/purchases-android/releases/tag/2.2.5
- ** BREAKING CHANGE ** makePurchase parameter oldSKUs is not an array anymore, it only accepts a string now. This is due to changes in the BillingClient.
- AddAttributionData can be called before the SDK has been setup. A network user identifier can be send to the addAttribution function, replacing the previous rc_appsflyer_id parameter.
- Adds an optional configuration boolean observerMode. This will set the value of finishTransactions at configuration time.

### Android only:
- addAttribution will automatically add the rc_gps_adid parameter.
- ** ANDROID BREAKING CHANGE ** Call syncPurchases to send purchases information to RevenueCat after any restore or purchase if you are using the SDK in observerMode. See our guide on Migrating Subscriptions for more information on syncPurchases: https://docs.revenuecat.com/docs/migrating-existing-subscriptions

### iOS only
- addAttribution will automatically add the rc_idfa and rc_idfv parameters if the AdSupport and UIKit frameworks are included, respectively.
- Apple Search Ad attribution can be automatically collected by setting the automaticAttributionCollection boolean to true before the SDK is configured.

## 1.0.2

- Updates iOS SDK to 2.1.1
Expand Down
Binary file removed Plugins/RevenueCat/Plugins/Android/billing-1.1.aar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Plugins/RevenueCat/Plugins/Android/purchasesunity.aar
Binary file not shown.
37 changes: 21 additions & 16 deletions Plugins/RevenueCat/Plugins/iOS/PurchasesUnityHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ @interface RCUnityHelperDelegate : NSObject <RCPurchasesDelegate>

@implementation RCUnityHelperDelegate

- (void)setupPurchases:(NSString *)apiKey appUserID:(NSString *)appUserID gameObject:(NSString *)gameObject {
- (void)setupPurchases:(NSString *)apiKey appUserID:(NSString *)appUserID gameObject:(NSString *)gameObject observerMode:(BOOL)observerMode {
[[RCPurchases sharedPurchases] setDelegate:nil];
self.products = nil;
self.gameObject = nil;

[RCPurchases configureWithAPIKey:apiKey appUserID:appUserID];
[RCPurchases configureWithAPIKey:apiKey appUserID:appUserID observerMode:observerMode];
self.gameObject = gameObject;
[[RCPurchases sharedPurchases] setDelegate:self];
}
Expand Down Expand Up @@ -193,7 +193,7 @@ - (void)restoreTransactions {
[[RCPurchases sharedPurchases] restoreTransactionsWithCompletionBlock:[self getPurchaserInfoCompletionBlockFor:RESTORE_TRANSACTIONS]];
}

- (void)addAttributionData:(NSString *)dataJSON network:(int)network
- (void)addAttributionData:(NSString *)dataJSON network:(int)network networkUserId:(NSString * _Nullable)networkUserId
{
NSError *error = nil;
NSDictionary *data = [NSJSONSerialization JSONObjectWithData:[dataJSON dataUsingEncoding:NSUTF8StringEncoding]
Expand All @@ -205,15 +205,7 @@ - (void)addAttributionData:(NSString *)dataJSON network:(int)network
return;
}

// If idfa is available, add it
NSString *idfa = ASIdentifierManager.sharedManager.advertisingIdentifier.UUIDString;
if (idfa) {
NSMutableDictionary *newData = [NSMutableDictionary dictionaryWithDictionary:data];
newData[@"rc_idfa"] = idfa;
data = [NSDictionary dictionaryWithDictionary:newData];
}

[[RCPurchases sharedPurchases] addAttributionData:data fromNetwork:network];
[RCPurchases addAttributionData:data fromNetwork:network forNetworkUserId:networkUserId];
}

- (void)createAlias:(NSString *)newAppUserID {
Expand Down Expand Up @@ -258,6 +250,11 @@ - (void)setFinishTransactions:(BOOL)finishTransactions
[RCPurchases sharedPurchases].finishTransactions = finishTransactions;
}

- (void)setAutomaticAttributionCollection:(BOOL)enabled
{
[RCPurchases setAutomaticAttributionCollection:enabled];
}

- (void)purchases:(RCPurchases *)purchases didReceiveUpdatedPurchaserInfo:(RCPurchaserInfo *)purchaserInfo {
[self sendJSONObject:[self purchaserInfoJSON:purchaserInfo] toMethod:RECEIVE_PURCHASER_INFO];
}
Expand Down Expand Up @@ -311,8 +308,8 @@ - (char *)getAppUserID
return _RCUnityHelper;
}

void _RCSetupPurchases(const char *gameObject, const char *apiKey, const char *appUserID) {
[_RCUnityHelperShared() setupPurchases:convertCString(apiKey) appUserID:convertCString(appUserID) gameObject:convertCString(gameObject)];
void _RCSetupPurchases(const char *gameObject, const char *apiKey, const char *appUserID, const BOOL observerMode) {
[_RCUnityHelperShared() setupPurchases:convertCString(apiKey) appUserID:convertCString(appUserID) gameObject:convertCString(gameObject) observerMode:observerMode];
}

void _RCGetProducts(const char *productIdentifiersJSON, const char *type) {
Expand All @@ -335,9 +332,9 @@ void _RCRestoreTransactions() {
[_RCUnityHelperShared() restoreTransactions];
}

void _RCAddAttributionData(const int network, const char *data)
void _RCAddAttributionData(const int network, const char *data, const char *networkUserId)
{
[_RCUnityHelperShared() addAttributionData:convertCString(data) network:network];
[_RCUnityHelperShared() addAttributionData:convertCString(data) network:network networkUserId:convertCString(networkUserId)];
}

void _RCCreateAlias(const char *newAppUserID) {
Expand Down Expand Up @@ -374,3 +371,11 @@ void _RCGetPurchaserInfo() {
char * _RCGetAppUserID() {
return [_RCUnityHelperShared() getAppUserID];
}

void _RCSyncPurchases() {
// NOOP
}

void _RCSetAutomaticAttributionCollection(const BOOL enabled) {
[_RCUnityHelperShared() setAutomaticAttributionCollection:enabled];
}
49 changes: 36 additions & 13 deletions Plugins/RevenueCat/Scripts/Purchases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ public abstract class UpdatedPurchaserInfoListener : MonoBehaviour

private class PurchasesWrapperNoop : IPurchasesWrapper
{
public void Setup(string gameObject, string apiKey, string appUserId)
public void Setup(string gameObject, string apiKey, string appUserId, bool observerMode)
{

}

public void AddAttributionData(int network, string data)
public void AddAttributionData(int network, string data, string networkUserId)
{

}
Expand Down Expand Up @@ -93,6 +93,15 @@ public void GetEntitlements()

}

public void SyncPurchases()
{

}

public void SetAutomaticAttributionCollection(bool enabled)
{

}
}

/*
Expand All @@ -117,7 +126,7 @@ public List<string> ActiveSubscriptions
{
get { return _response.activeSubscriptions; }
}

public List<string> AllPurchasedProductIdentifiers
{
get { return _response.allPurchasedProductIdentifiers; }
Expand Down Expand Up @@ -187,6 +196,9 @@ public Entitlement(EntitlementResponse response)
[Tooltip("A subclass of Purchases.UpdatedPurchaserInfoListener component. Use your custom subclass to define how to handle updated purchaser information.")]
public UpdatedPurchaserInfoListener listener;

[Tooltip("An optional boolean. Set this to TRUE if you have your own IAP implementation and want to use only RevenueCat's backend. Default is FALSE.")]
public bool observerMode;

private IPurchasesWrapper _wrapper;

private void Start()
Expand All @@ -206,7 +218,7 @@ private void Start()
// Call this if you want to reset with a new user id
private void Setup(string newUserId)
{
_wrapper.Setup(gameObject.name, revenueCatAPIKey, newUserId);
_wrapper.Setup(gameObject.name, revenueCatAPIKey, newUserId, observerMode);
}

private GetProductsFunc ProductsCallback { get; set; }
Expand Down Expand Up @@ -249,9 +261,9 @@ public enum AttributionNetwork
TENJIN = 4
}

public void AddAttributionData(string dataJson, AttributionNetwork network)
public void AddAttributionData(string dataJson, AttributionNetwork network, string networkUserId = null)
{
_wrapper.AddAttributionData((int)network, dataJson);
_wrapper.AddAttributionData((int)network, dataJson, networkUserId);
}

private PurchaserInfoFunc CreateAliasCallback { get; set; }
Expand Down Expand Up @@ -280,25 +292,25 @@ public void Reset(PurchaserInfoFunc callback)
ResetCallback = callback;
_wrapper.Reset();
}

// ReSharper disable once UnusedMember.Global
public void SetFinishTransactions(bool finishTransactions)
{
_wrapper.SetFinishTransactions(finishTransactions);
}

// ReSharper disable once UnusedMember.Global
public void SetAllowSharingStoreAccount(bool allow)
{
_wrapper.SetAllowSharingStoreAccount(allow);
}

// ReSharper disable once UnusedMember.Global
public string GetAppUserId()
{
return _wrapper.GetAppUserId();
}

// ReSharper disable once UnusedMember.Global
public void SetDebugLogsEnabled(bool logsEnabled)
{
Expand All @@ -322,6 +334,17 @@ public void GetEntitlements(GetEntitlementsFunc callback)
_wrapper.GetEntitlements();
}

public void SyncPurchases()
{
_wrapper.SyncPurchases();
}

// ReSharper disable once UnusedMember.Global
public void SetAutomaticAttributionCollection(bool enabled)
{
_wrapper.SetAutomaticAttributionCollection(enabled);
}

// ReSharper disable once UnusedMember.Local
private void _receiveProducts(string productsJson)
{
Expand All @@ -331,7 +354,7 @@ private void _receiveProducts(string productsJson)

var response = JsonUtility.FromJson<ProductResponse>(productsJson);
var error = response.error.message != null ? response.error : null;

if (error != null)
{
ProductsCallback(null, error);
Expand Down Expand Up @@ -364,7 +387,7 @@ private void _makePurchase(string makePurchaseResponseJson)
var info = response.purchaserInfo.activeSubscriptions != null
? new PurchaserInfo(response.purchaserInfo)
: null;

if (error != null)
{
MakePurchaseCallback(null, null, response.userCancelled, error);
Expand Down Expand Up @@ -500,7 +523,7 @@ private class ReceivePurchaserInfoResponse
{
public PurchaserInfoResponse purchaserInfo;
public Error error;
}
}

[Serializable]
private class MakePurchaseResponse
Expand Down
6 changes: 4 additions & 2 deletions Plugins/RevenueCat/Scripts/PurchasesWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

public interface IPurchasesWrapper
{
void Setup(string gameObject, string apiKey, string appUserId);
void AddAttributionData(int network, string data);
void Setup(string gameObject, string apiKey, string appUserId, bool observerMode);
void AddAttributionData(int network, string data, string networkUserId);
void GetProducts(string[] productIdentifiers, string type = "subs");
void MakePurchase(string productIdentifier, string type = "subs", string oldSku = null);
void RestoreTransactions();
Expand All @@ -16,4 +16,6 @@ public interface IPurchasesWrapper
string GetAppUserId();
void GetPurchaserInfo();
void GetEntitlements();
void SyncPurchases();
void SetAutomaticAttributionCollection(bool enabled);
}
Loading

0 comments on commit 3a0d88c

Please sign in to comment.