Skip to content

Commit

Permalink
Merge pull request #32 from RevenueCat/subscriber_attributes
Browse files Browse the repository at this point in the history
[final] Subscriber attributes
  • Loading branch information
aboedo authored Apr 2, 2020
2 parents 3685b0c + 81ad76f commit c9feead
Show file tree
Hide file tree
Showing 51 changed files with 1,242 additions and 135 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 1.1.0

- Adds an example project that shows how to set up an app with RevenueCat
https://github.com/RevenueCat/cordova-plugin-purchases/pull/29
- Adds Subscriber Attributes, which allow developers to store additional, structured information
for a user in RevenueCat. More info: https://docs.revenuecat.com/docs/user-attributes.
- Adds new method to invalidate the purchaser info cache, useful when promotional purchases are granted from outside the app.
https://github.com/RevenueCat/cordova-plugin-purchases/pull/32

## 1.0.5

- Adds `shouldPurchasePromoProduct`, which allows the app to decide how and when to handle promotional purchases made by users directly through the App Store (https://github.com/RevenueCat/cordova-plugin-purchases/pull/25).
Expand Down
5 changes: 3 additions & 2 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
1. Update version in `package.json` and `plugin.xml`.
1. Run `npm run fetch:ios:sdk`
1. Run `npm run fetch:ios:common`
1. Compile common files aar
1. Grab the `purchases-hybrid-common` .aar [from its release page](https://github.com/RevenueCat/purchases-hybrid-common/releases/) and replace it in `src/android/common-release.aar`
1. Run `npm run build`
1. Add an entry to CHANGELOG.md
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. `npm publish`
1. `npm publish`
1. Update the version in `package.json` and `plugin.xml` to x.y.z-SNAPSHOT, with x.y.z being the next version
2 changes: 2 additions & 0 deletions VERSIONS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
| Version | iOS version | Android version | Common files version |
| ------- | ----------- | --------------- | -------------------- |
| 1.1.0 | 3.2.2 | 3.1.0 | 1.0.11 |
| 1.0.5 | 3.0.2 | 3.0.4 | 1.0.5 |
| 1.0.4 | 3.0.1 | 3.0.4 | 1.0.5 |
| 1.0.3 | 3.0.1 | 3.0.4 | 1.0.5 |
| 1.0.2 | 3.0.1 | 3.0.4 | 1.0.4 |
Expand Down
12 changes: 12 additions & 0 deletions examples/cordova-sample/MyApp/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions examples/cordova-sample/MyApp/www/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ const app = {
onDeviceReady: function() {
this.receivedEvent("deviceready");
this.setupShouldPurchasePromoProductListener();
Purchases.setPhoneNumber("12345678");
Purchases.setDisplayName("Garfield");
Purchases.setAttributes({ "favorite_cat": "garfield" });
Purchases.setEmail("[email protected]");
},

setupShouldPurchasePromoProductListener: function() {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-purchases",
"version": "1.0.6-SNAPSHOT",
"version": "1.1.0",
"description": "Purchases Cordova Plugin",
"cordova": {
"id": "cordova-plugin-purchases",
Expand All @@ -21,8 +21,8 @@
"cordova-android"
],
"scripts": {
"fetch:ios:sdk": "./scripts/download-purchases-framework.sh 3.0.2",
"fetch:ios:common": "./scripts/download-purchases-common.sh 1.0.5",
"fetch:ios:sdk": "./scripts/download-purchases-framework.sh 3.2.2",
"fetch:ios:common": "./scripts/download-purchases-common.sh 1.0.11",
"build": "tsc",
"build-watch": "tsc --watch",
"tslint": "tslint -c tslint.json 'src/plugin/*.ts'",
Expand Down
29 changes: 17 additions & 12 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="cordova-plugin-purchases" version="1.0.6-SNAPSHOT">
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="cordova-plugin-purchases" version="1.1.0">

<dependency id="cordova-annotated-plugin-android" />

Expand All @@ -16,7 +16,7 @@
<param name="android-package" value="com.revenuecat.purchases.PurchasesPlugin" />
</feature>
</config-file>
<framework src="com.revenuecat.purchases:purchases:3.0.5" />
<framework src="com.revenuecat.purchases:purchases:3.1.0" />
<lib-file src="src/android/common-release.aar"/>
<framework src="src/android/common.gradle" custom="true" type="gradleReference"/>
<source-file src="src/android/PurchasesPlugin.java" target-dir="src/com/revenuecat/purchases"/>
Expand All @@ -29,24 +29,29 @@
</config-file>
<header-file src="src/ios/CDVPurchasesPlugin.h" />
<source-file src="src/ios/CDVPurchasesPlugin.m" />
<header-file src="src/ios/Common/RCCommonFunctionality.h" />
<header-file src="src/ios/Common/RCEntitlementInfo+HybridAdditions.h" />
<header-file src="src/ios/Common/RCEntitlementInfos+HybridAdditions.h" />
<header-file src="src/ios/Common/RCErrorContainer.h" />
<header-file src="src/ios/Common/RCOffering+HybridAdditions.h" />
<header-file src="src/ios/Common/RCOfferings+HybridAdditions.h" />
<header-file src="src/ios/Common/RCPackage+HybridAdditions.h" />
<header-file src="src/ios/Common/RCPurchaserInfo+HybridAdditions.h" />
<source-file src="src/ios/Common/RCPurchaserInfo+HybridAdditions.m" />
<header-file src="src/ios/Common/RCPurchases+HybridAdditions.h" />
<header-file src="src/ios/Common/SKPaymentDiscount+HybridAdditions.h" />
<header-file src="src/ios/Common/SKProduct+HybridAdditions.h" />
<source-file src="src/ios/Common/SKProduct+HybridAdditions.m" />
<source-file src="src/ios/Common/RCEntitlementInfo+HybridAdditions.h" />
<header-file src="src/ios/Common/SKProductDiscount+HybridAdditions.h" />
<source-file src="src/ios/Common/RCCommonFunctionality.m" />
<source-file src="src/ios/Common/RCEntitlementInfo+HybridAdditions.m" />
<source-file src="src/ios/Common/RCEntitlementInfos+HybridAdditions.h" />
<source-file src="src/ios/Common/RCEntitlementInfos+HybridAdditions.m" />
<source-file src="src/ios/Common/RCCommonFunctionality.h" />
<source-file src="src/ios/Common/RCCommonFunctionality.m" />
<source-file src="src/ios/Common/RCErrorContainer.h" />
<source-file src="src/ios/Common/RCErrorContainer.m" />
<source-file src="src/ios/Common/RCOffering+HybridAdditions.h" />
<source-file src="src/ios/Common/RCOffering+HybridAdditions.m" />
<source-file src="src/ios/Common/RCOfferings+HybridAdditions.h" />
<source-file src="src/ios/Common/RCOfferings+HybridAdditions.m" />
<source-file src="src/ios/Common/RCPackage+HybridAdditions.h" />
<source-file src="src/ios/Common/RCPackage+HybridAdditions.m" />
<source-file src="src/ios/Common/RCPurchaserInfo+HybridAdditions.m" />
<source-file src="src/ios/Common/SKPaymentDiscount+HybridAdditions.m" />
<source-file src="src/ios/Common/SKProduct+HybridAdditions.m" />
<source-file src="src/ios/Common/SKProductDiscount+HybridAdditions.m" />
<framework src="src/ios/Purchases.framework" embed="true" custom="true" />
</platform>
</plugin>
2 changes: 1 addition & 1 deletion scripts/download-purchases-framework.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ curl -sSL $URL > temp.zip
# In some cases the temp folder can not be created by unzip, https://github.com/RevenueCat/react-native-purchases/issues/26
mkdir -p temp
unzip -o temp.zip -d temp
mv temp/Purchases.framework ./Purchases.framework
mv temp/Carthage/Build/iOS/Purchases.framework ./Purchases.framework
rm -r temp
rm temp.zip

Expand Down
64 changes: 64 additions & 0 deletions src/android/PurchasesPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

Expand All @@ -42,12 +44,14 @@ private void setupPurchases(String apiKey, String appUserID, boolean observerMod
@PluginAction(thread = ExecutionThread.MAIN, actionName = "setAllowSharingStoreAccount")
public void setAllowSharingStoreAccount(boolean allowSharingStoreAccount, CallbackContext callbackContext) {
CommonKt.setAllowSharingAppStoreAccount(allowSharingStoreAccount);
callbackContext.success();
}

@PluginAction(thread = ExecutionThread.MAIN, actionName = "addAttributionData")
public void addAttributionData(JSONObject data, Integer network, @Nullable String networkUserId,
CallbackContext callbackContext) {
CommonKt.addAttributionData(data, network, networkUserId);
callbackContext.success();
}

@PluginAction(thread = ExecutionThread.MAIN, actionName = "getOfferings", isAutofinish = false)
Expand Down Expand Up @@ -114,6 +118,7 @@ private void purchasePackage(final String packageIdentifier,
@PluginAction(thread = ExecutionThread.MAIN, actionName = "syncPurchases")
public void syncPurchases(CallbackContext callbackContext) {
CommonKt.syncPurchases();
callbackContext.success();
}

@PluginAction(thread = ExecutionThread.MAIN, actionName = "getAppUserID", isAutofinish = false)
Expand Down Expand Up @@ -149,6 +154,7 @@ private void getPurchaserInfo(CallbackContext callbackContext) {
@PluginAction(thread = ExecutionThread.WORKER, actionName = "setDebugLogsEnabled")
private void setDebugLogsEnabled(boolean enabled, CallbackContext callbackContext) {
CommonKt.setDebugLogsEnabled(enabled);
callbackContext.success();
}

@PluginAction(thread = ExecutionThread.WORKER, actionName = "setAutomaticAppleSearchAdsAttributionCollection")
Expand Down Expand Up @@ -179,6 +185,50 @@ private void isAnonymous(JSONArray productIDs, CallbackContext callbackContext)
Map<String, Map<String, Object>> map = CommonKt.checkTrialOrIntroductoryPriceEligibility(productIDList);
callbackContext.success(convertMapToJson(map));
}

@PluginAction(thread = ExecutionThread.WORKER, actionName = "invalidatePurchaserInfoCache")
private void invalidatePurchaserInfoCache(CallbackContext callbackContext) {
CommonKt.invalidatePurchaserInfoCache();
callbackContext.success();
}

//================================================================================
// Subscriber Attributes
//================================================================================

@PluginAction(thread = ExecutionThread.WORKER, actionName = "setAttributes")
private void setAttributes(JSONObject attributes, CallbackContext callbackContext) throws JSONException {
CommonKt.setAttributes(convertJsonToMap(attributes));
callbackContext.success();
}

@PluginAction(thread = ExecutionThread.WORKER, actionName = "setEmail")
private void setEmail(String email, CallbackContext callbackContext) {
CommonKt.setEmail(email);
callbackContext.success();
}

@PluginAction(thread = ExecutionThread.WORKER, actionName = "setPhoneNumber")
private void setPhoneNumber(String phoneNumber, CallbackContext callbackContext) {
CommonKt.setPhoneNumber(phoneNumber);
callbackContext.success();
}

@PluginAction(thread = ExecutionThread.WORKER, actionName = "setDisplayName")
private void setDisplayName(String displayName, CallbackContext callbackContext) {
CommonKt.setDisplayName(displayName);
callbackContext.success();
}

@PluginAction(thread = ExecutionThread.WORKER, actionName = "setPushToken")
private void setPushToken(String pushToken, CallbackContext callbackContext) {
CommonKt.setPushToken(pushToken);
callbackContext.success();
}

//================================================================================
// Private methods
//================================================================================

private OnResult getOnResult(CallbackContext callbackContext) {
return new OnResult() {
Expand All @@ -194,6 +244,20 @@ public void onError(ErrorContainer errorContainer) {
};
}

private static Map<String, String> convertJsonToMap(JSONObject jsonObject) {
HashMap map = new HashMap();
Iterator keys = jsonObject.keys();
while (keys.hasNext()) {
String key = (String) keys.next();
try {
map.put(key, jsonObject.get(key));
} catch (JSONException e) {
e.printStackTrace();
}
}
return map;
}

private static JSONObject convertMapToJson(Map<String, ?> readableMap) {
JSONObject object = new JSONObject();

Expand Down
Binary file modified src/android/common-release.aar
Binary file not shown.
2 changes: 1 addition & 1 deletion src/ios/.common_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.5
1.0.11
2 changes: 1 addition & 1 deletion src/ios/.framework_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.2
3.2.2
6 changes: 6 additions & 0 deletions src/ios/CDVPurchasesPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,11 @@
- (void)setAutomaticAppleSearchAdsAttributionCollection:(CDVInvokedUrlCommand *)command;
- (void)isAnonymous:(CDVInvokedUrlCommand *)command;
- (void)checkTrialOrIntroductoryPriceEligibility:(CDVInvokedUrlCommand *)command;
- (void)invalidatePurchaserInfoCache:(CDVInvokedUrlCommand *)command;
- (void)setAttributes:(NSDictionary<NSString *, NSString *> *)attributes;
- (void)setEmail:(nullable NSString *)email;
- (void)setPhoneNumber:(nullable NSString *)phoneNumber;
- (void)setDisplayName:(nullable NSString *)displayName;
- (void)setPushToken:(nullable NSData *)pushToken;

@end
51 changes: 49 additions & 2 deletions src/ios/CDVPurchasesPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,20 @@ - (void)purchaseProduct:(CDVInvokedUrlCommand *)command
{
NSString *productIdentifier = [command argumentAtIndex:0];

[RCCommonFunctionality purchaseProduct:productIdentifier completionBlock:[self getResponseCompletionBlock:command]];
[RCCommonFunctionality purchaseProduct:productIdentifier
signedDiscountTimestamp:nil
completionBlock:[self getResponseCompletionBlock:command]];
}

- (void)purchasePackage:(CDVInvokedUrlCommand *)command
{
NSString *packageIdentifier = [command argumentAtIndex:0];
NSString *offeringIdentifier = [command argumentAtIndex:1];

[RCCommonFunctionality purchasePackage:packageIdentifier offering:offeringIdentifier completionBlock:[self getResponseCompletionBlock:command]];
[RCCommonFunctionality purchasePackage:packageIdentifier
offering:offeringIdentifier
signedDiscountTimestamp:nil
completionBlock:[self getResponseCompletionBlock:command]];
}

- (void)restoreTransactions:(CDVInvokedUrlCommand *)command
Expand Down Expand Up @@ -164,6 +169,48 @@ - (void)setupShouldPurchasePromoProductCallback:(CDVInvokedUrlCommand *)command
self.shouldPurchasePromoProductCallbackID = command.callbackId;
}

- (void)invalidatePurchaserInfoCache:(CDVInvokedUrlCommand *)command {
[RCCommonFunctionality invalidatePurchaserInfoCache];
[self sendOKForCommand:command messageAsArray:nil];
}

#pragma mark Subscriber Attributes

- (void)setAttributes:(CDVInvokedUrlCommand *)command {
NSDictionary <NSString *, NSString *> *attributes = [command argumentAtIndex:0];

[RCCommonFunctionality setAttributes:attributes];
[self sendOKForCommand:command messageAsArray:nil];
}

- (void)setEmail:(CDVInvokedUrlCommand *)command {
NSString *email = [command argumentAtIndex:0];

[RCCommonFunctionality setEmail:email];
[self sendOKForCommand:command messageAsArray:nil];
}

- (void)setPhoneNumber:(CDVInvokedUrlCommand *)command {
NSString *phoneNumber = [command argumentAtIndex:0];

[RCCommonFunctionality setPhoneNumber:phoneNumber];
[self sendOKForCommand:command messageAsArray:nil];
}

- (void)setDisplayName:(CDVInvokedUrlCommand *)command {
NSString *displayName = [command argumentAtIndex:0];

[RCCommonFunctionality setDisplayName:displayName];
[self sendOKForCommand:command messageAsArray:nil];
}

- (void)setPushToken:(CDVInvokedUrlCommand *)command {
NSString *pushToken = [command argumentAtIndex:0];

[RCCommonFunctionality setPushToken:pushToken];
[self sendOKForCommand:command messageAsArray:nil];
}

#pragma mark Delegate Methods

- (void)purchases:(RCPurchases *)purchases didReceiveUpdatedPurchaserInfo:(RCPurchaserInfo *)purchaserInfo
Expand Down
Loading

0 comments on commit c9feead

Please sign in to comment.