Skip to content

Commit

Permalink
Version 2.1.0 (#56)
Browse files Browse the repository at this point in the history
* update RN

* Wraps up update

* fix windows

* Updates changelog and removes todo

* Fixes JS tests

* Removes iOS Tests target

* Revert "Removes iOS Tests target"

This reverts commit 5ab26dc.

* Fixes scheme

* Updates Xcode and more ram for android
  • Loading branch information
vegaro authored Apr 10, 2019
1 parent 2f8e81b commit 75d8232
Show file tree
Hide file tree
Showing 35 changed files with 3,570 additions and 2,645 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ executors:
default: "28"
environment:
FL_OUTPUT_DIR: output
_JAVA_OPTIONS: "-Xmx1500m"
_JAVA_OPTIONS: "-XX:MaxRAM=3072m -Xmx2048m"
docker:
- image: circleci/android:api-<<parameters.version>>-node8-alpha
working_directory: ~/react-native-purchases
Expand All @@ -29,7 +29,7 @@ executors:
parameters:
xcode_version:
type: string
default: "9.4.1"
default: "10.1.0"
macos:
xcode: <<parameters.xcode_version>>
working_directory: ~/react-native-purchases
Expand Down Expand Up @@ -57,7 +57,7 @@ jobs:
command: yarn run setup.example
- run:
name: Android compiles
command: ./gradlew build
command: ./gradlew build --stacktrace
working_directory: example/android
ios:
executor: ios
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 2.1.0
- Updates SDK versions to 2.1.0 to include new error handling
- **BREAKING CHANGE** errors now contain a `userInfo` object with the message, an underlying error and a readable error code. The error codes have completely changed too and updated to the SDK 2.1.0.
- Updates RN and React versions.
- Fixes Windows installation

## 2.0.0
- Updates native SDKs to versions iOS 2.0.0 and Android 2.0.1
- Checks that the user ID sent to setup, identify or create alias is actually a string #28
Expand Down
2 changes: 1 addition & 1 deletion RNPurchases.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ Pod::Spec.new do |spec|
spec.exclude_files = "ios/Purchases.framework"

spec.dependency "React"
spec.dependency "Purchases", "~> 2.0.0"
spec.dependency "Purchases", "~> 2.1.0"
end
78 changes: 19 additions & 59 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ describe("Purchases", () => {
it("makePurchase works", () => {
const Purchases = require("../index").default;

NativeModules.RNPurchases.makePurchase.mockResolvedValue({
purchasedProductIdentifier: "123",
purchaserInfo: purchaserInfoStub
});

Purchases.makePurchase("onemonth_freetrial")

expect(NativeModules.RNPurchases.makePurchase).toBeCalledWith("onemonth_freetrial", [], "subs");
Expand Down Expand Up @@ -246,83 +251,38 @@ describe("Purchases", () => {
expect(NativeModules.RNPurchases.setupPurchases).toBeCalledTimes(1);
})

it("ios cancelled purchase sets userCancelled in the error", () => {
it("cancelled purchase sets userCancelled in the error", () => {
const Purchases = require("../index").default;

const promise = Purchases.makePurchase("onemonth_freetrial")

promise.then(function(result) {
expect(result).toEqual(undefined);
}, function(err) {
expect(err).toEqual({
code: 2,
domain: "SKErrorDomain",
message: "message",
userCancelled: true
});
NativeModules.RNPurchases.makePurchase.mockRejectedValueOnce({
code: "1"
});

const nativeEmitter = new NativeEventEmitter();
const error = {
code: 2,
domain: "SKErrorDomain",
message: "message"
}
nativeEmitter.emit("Purchases-PurchaseCompleted", { error });
})

it("android cancelled purchase sets userCancelled in the error", () => {
const Purchases = require("../index").default;

const promise = Purchases.makePurchase("onemonth_freetrial")

promise.then(function(result) {
expect(result).toBeEqual(undefined);
}, function(err) {
expect(err).toEqual({
code: 1,
domain: "Play Billing",
message: "message",
userCancelled: true
});
return expect(Purchases.makePurchase("onemonth_freetrial")).rejects.toEqual({
code: "1",
userCancelled: true
});

const nativeEmitter = new NativeEventEmitter();
const error = {
code: 1,
domain: "Play Billing",
message: "message"
}
nativeEmitter.emit("Purchases-PurchaseCompleted", { error });
})

it("successful purchase works", () => {
const Purchases = require("../index").default;

const promise = Purchases.makePurchase("onemonth_freetrial")

promise.then(function(result) {
expect(result).toBeEqual({
purchasedProductIdentifier: "123",
purchaserInfo: purchaserInfoStub
});
}, function(err) {
expect(err).toBeEqual(undefined);
NativeModules.RNPurchases.makePurchase.mockResolvedValueOnce({
purchasedProductIdentifier: "123",
purchaserInfo: purchaserInfoStub
});

const nativeEmitter = new NativeEventEmitter();
nativeEmitter.emit("Purchases-PurchaseCompleted", {
return expect(Purchases.makePurchase("onemonth_freetrial")).resolves.toEqual({
purchasedProductIdentifier: "123",
purchaserInfo: purchaserInfoStub
});
});
})

it("reset works", async () => {
it("reset works", () => {
const Purchases = require("../index").default;

NativeModules.RNPurchases.reset.mockResolvedValueOnce(purchaserInfoStub);
const info = await Purchases.reset();
expect(info).toEqual(purchaserInfoStub);
expect(NativeModules.RNPurchases.reset).toBeCalledTimes(1);

return expect(Purchases.reset()).resolves.toEqual(purchaserInfoStub);
})
});
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ repositories {
dependencies {
//noinspection GradleDynamicVersion
api 'com.facebook.react:react-native:+'
api 'com.revenuecat.purchases:purchases:2.0.1'
api 'com.revenuecat.purchases:purchases:2.1.0'
}
60 changes: 24 additions & 36 deletions android/src/main/java/com/reactlibrary/RNPurchasesModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.util.Log;

import androidx.annotation.NonNull;
import com.android.billingclient.api.Purchase;
import com.android.billingclient.api.SkuDetails;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Promise;
Expand All @@ -22,7 +23,6 @@
import com.revenuecat.purchases.util.Iso8601Utils;

import kotlin.UninitializedPropertyAccessException;
import org.jetbrains.annotations.NotNull;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand All @@ -34,7 +34,6 @@

public class RNPurchasesModule extends ReactContextBaseJavaModule implements UpdatedPurchaserInfoListener {

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

private final ReactApplicationContext reactContext;
Expand Down Expand Up @@ -140,7 +139,7 @@ public void onReceived(@NonNull Map<String, Entitlement> entitlementMap) {

@Override
public void onError(@NonNull PurchasesError error) {
promise.reject("ERROR_GETTING_ENTITLEMENTS", error.toString());
reject(promise, error);
}
});
}
Expand All @@ -165,7 +164,7 @@ public void onReceived(@NonNull List<SkuDetails> skus) {

@Override
public void onError(@NonNull PurchasesError error) {
promise.reject("ERROR_GETTING_PURCHASER_INFO", error.toString());
reject(promise, error);
}

};
Expand All @@ -188,20 +187,18 @@ public void makePurchase(final String productIdentifier, ReadableArray oldSkus,
Activity currentActivity = getCurrentActivity();
if (currentActivity != null) {
Purchases.getSharedInstance().makePurchase(currentActivity, productIdentifier, type, oldSkusList,
new PurchaseCompletedListener() {
new MakePurchaseListener() {
@Override
public void onCompleted(@NonNull String sku, @NonNull PurchaserInfo purchaserInfo) {
public void onCompleted(@NonNull Purchase purchase, @NonNull PurchaserInfo purchaserInfo) {
WritableMap map = Arguments.createMap();
map.putString("productIdentifier", sku);
map.putString("productIdentifier", purchase.getSku());
map.putMap("purchaserInfo", mapPurchaserInfo(purchaserInfo));
sendEvent(PURCHASE_COMPLETED_EVENT, map);
promise.resolve(map);
}

@Override
public void onError(@NonNull PurchasesError error) {
WritableMap map = Arguments.createMap();
map.putMap("error", errorMap(error));
sendEvent(PURCHASE_COMPLETED_EVENT, map);
public void onError(@NonNull PurchasesError error, Boolean userCancelled) {
reject(promise, error);
}
});
} else {
Expand All @@ -224,7 +221,7 @@ public void onReceived(@NonNull PurchaserInfo purchaserInfo) {

@Override
public void onError(@NonNull PurchasesError error) {
promise.reject("ERROR_RESTORING_TRANSACTIONS", error.toString());
reject(promise, error);
}
});
}
Expand All @@ -239,7 +236,7 @@ public void onReceived(@NonNull PurchaserInfo purchaserInfo) {

@Override
public void onError(@NonNull PurchasesError error) {
promise.reject("ERROR_RESETTING", error.toString());
reject(promise, error);
}
});
}
Expand All @@ -254,7 +251,7 @@ public void onReceived(@NonNull PurchaserInfo purchaserInfo) {

@Override
public void onError(@NonNull PurchasesError error) {
promise.reject("ERROR_IDENTIFYING", error.toString());
reject(promise, error);
}
});
}
Expand All @@ -269,7 +266,7 @@ public void onReceived(@NonNull PurchaserInfo purchaserInfo) {

@Override
public void onError(@NonNull PurchasesError error) {
promise.reject("ERROR_ALIASING", error.toString());
reject(promise, error);
}
});
}
Expand All @@ -289,7 +286,7 @@ public void onReceived(@NonNull PurchaserInfo purchaserInfo) {

@Override
public void onError(@NonNull PurchasesError error) {
promise.reject("ERROR_GETTING_PURCHASER_INFO", error.toString());
reject(promise, error);
}
});
}
Expand Down Expand Up @@ -365,25 +362,6 @@ private WritableMap mapPurchaserInfo(PurchaserInfo purchaserInfo) {
return map;
}

private WritableMap errorMap(PurchasesError error) {
WritableMap errorMap = Arguments.createMap();
String domainString;

if (error.getDomain() == Purchases.ErrorDomains.REVENUECAT_BACKEND) {
domainString = "RevenueCat Backend";
} else if (error.getDomain() == Purchases.ErrorDomains.PLAY_BILLING) {
domainString = "Play Billing";
} else {
domainString = "Unknown";
}

errorMap.putString("message", error.getMessage());
errorMap.putInt("code", error.getCode());
errorMap.putString("domain", domainString);

return errorMap;
}

@Override
public void onReceived(PurchaserInfo purchaserInfo) {
sendEvent(PURCHASER_INFO_UPDATED, mapPurchaserInfo(purchaserInfo));
Expand Down Expand Up @@ -443,4 +421,14 @@ private static JSONArray convertArrayToJson(ReadableArray readableArray) throws
}
return array;
}

private static void reject(Promise promise, PurchasesError error) {
WritableMap userInfoMap = Arguments.createMap();
userInfoMap.putString("message", error.getMessage());
userInfoMap.putString("readable_error_code", error.getCode().name());
if (error.getUnderlyingErrorMessage() != null && !error.getUnderlyingErrorMessage().isEmpty()) {
userInfoMap.putString("underlyingErrorMessage", error.getUnderlyingErrorMessage());
}
promise.reject(error.getCode().ordinal() + "", error.getMessage(), userInfoMap);
}
}
14 changes: 14 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var sys = require('sys')
var exec = require('child_process').exec;
function puts(error, stdout, stderr) { sys.puts(stdout) }

var os = require('os');

if (os.type() === 'Linux')
exec("Skipping iOS Dependencies", puts);
else if (os.type() === 'Darwin')
exec("./scripts/download-purchases-framework.sh 2.1.0", puts);
else if (os.type() === 'Windows_NT')
exec("Skipping iOS Dependencies", puts);
else
throw new Error("Unsupported OS found: " + os.type());
3 changes: 1 addition & 2 deletions example/.flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
[libs]
node_modules/react-native/Libraries/react-native/react-native-interface.js
node_modules/react-native/flow/
node_modules/react-native/flow-github/

[options]
emoji=true
Expand Down Expand Up @@ -67,4 +66,4 @@ suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError

[version]
^0.86.0
^0.92.0
1 change: 0 additions & 1 deletion example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,3 @@ buck-out/

# Bundle artifact
*.jsbundle
ios/Pods
Loading

0 comments on commit 75d8232

Please sign in to comment.