Skip to content

Commit 182bbbb

Browse files
Merge pull request #318 from qonversion/release/8.1.0
Release 8.1.0
2 parents c84ecef + 27d169b commit 182bbbb

13 files changed

Lines changed: 220 additions & 32 deletions

File tree

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ repositories {
6565
dependencies {
6666
//noinspection GradleDynamicVersion
6767
implementation 'com.facebook.react:react-native:+' // From node_modules
68-
implementation "io.qonversion.sandwich:sandwich:5.0.4"
68+
implementation "io.qonversion.sandwich:sandwich:5.1.2"
6969
}
7070

7171
afterEvaluate { project ->

android/src/main/java/com/reactlibrary/QonversionModule.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,19 @@ public void syncHistoricalData() {
8181
}
8282

8383
@ReactMethod
84-
public void purchase(String productId, @Nullable String offerId, @Nullable Boolean applyOffer, final Promise promise) {
85-
qonversionSandwich.purchase(productId, offerId, applyOffer, Utils.getResultListener(promise));
84+
public void purchase(
85+
String productId,
86+
@Nullable String offerId,
87+
@Nullable Boolean applyOffer,
88+
@Nullable String oldProductId,
89+
@Nullable String updatePolicyKey,
90+
@Nullable ReadableArray contextKeys,
91+
final Promise promise) {
92+
List<String> contextKeysList = null;
93+
if (contextKeys != null) {
94+
contextKeysList = EntitiesConverter.convertArrayToStringList(contextKeys);
95+
}
96+
qonversionSandwich.purchase(productId, offerId, applyOffer, oldProductId, updatePolicyKey, contextKeysList, Utils.getResultListener(promise));
8697
}
8798

8899
@ReactMethod
@@ -92,16 +103,10 @@ public void updatePurchase(
92103
@Nullable Boolean applyOffer,
93104
String oldProductId,
94105
@Nullable String updatePolicyKey,
106+
@Nullable ReadableArray contextKeys,
95107
final Promise promise
96108
) {
97-
qonversionSandwich.updatePurchase(
98-
productId,
99-
offerId,
100-
applyOffer,
101-
oldProductId,
102-
updatePolicyKey,
103-
Utils.getResultListener(promise)
104-
);
109+
purchase(productId, offerId, applyOffer, oldProductId, updatePolicyKey, contextKeys, promise);
105110
}
106111

107112
@ReactMethod

example/ios/Podfile.lock

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ PODS:
7575
- glog (0.3.5)
7676
- libevent (2.1.12)
7777
- OpenSSL-Universal (1.1.1100)
78-
- Qonversion (5.11.0):
79-
- Qonversion/Main (= 5.11.0)
80-
- Qonversion/Main (5.11.0)
81-
- QonversionSandwich (5.0.2):
82-
- Qonversion (= 5.11.0)
78+
- Qonversion (5.12.0):
79+
- Qonversion/Main (= 5.12.0)
80+
- Qonversion/Main (5.12.0)
81+
- QonversionSandwich (5.1.1):
82+
- Qonversion (= 5.12.0)
8383
- RCT-Folly (2021.07.22.00):
8484
- boost
8585
- DoubleConversion
@@ -289,8 +289,8 @@ PODS:
289289
- React-jsinspector (0.70.7)
290290
- React-logger (0.70.7):
291291
- glog
292-
- react-native-qonversion (8.0.0):
293-
- QonversionSandwich (= 5.0.2)
292+
- react-native-qonversion (8.0.1):
293+
- QonversionSandwich (= 5.1.1)
294294
- React
295295
- React-perflogger (0.70.7)
296296
- React-RCTActionSheet (0.70.7):
@@ -535,8 +535,8 @@ SPEC CHECKSUMS:
535535
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
536536
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
537537
OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c
538-
Qonversion: b39cb723b933c6e18bd9e03c763b366385906d83
539-
QonversionSandwich: dbaec81051fe172857e008c5fc6e8d2f9bc1642f
538+
Qonversion: ac2da69e497cb1f01cea13d82513fde14f338ca3
539+
QonversionSandwich: 0fc30a920cfed34238bdb6830b6ca6388294107c
540540
RCT-Folly: 0080d0a6ebf2577475bda044aa59e2ca1f909cda
541541
RCTRequired: 837880d26ec119e105317dc28a456f3016bf16d1
542542
RCTTypeSafety: 5c854c04c3383cab04f404e25d408ed52124b300
@@ -551,7 +551,7 @@ SPEC CHECKSUMS:
551551
React-jsiexecutor: e95cdd036e7947ddf87f3049319ac3064deb76b5
552552
React-jsinspector: 1c34fea1868136ecde647bc11fae9266d4143693
553553
React-logger: e9f407f9fdf3f3ce7749ae6f88affe63e8446019
554-
react-native-qonversion: f274a7b0c9af02bb9f77b6d1a2e6a1f9fce22b24
554+
react-native-qonversion: 0fa511df2132c06ba0cbe0f5764124c97074cd99
555555
React-perflogger: 52a94f38c19a518d05726624b49bfc192639374d
556556
React-RCTActionSheet: 7b89fe64a852bc3ae39b91dbd142ef09931ef3f7
557557
React-RCTAnimation: ad84bfbf8c5f6f77e65092d0c2b0506b80b5cf99

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"start": "react-native start",
1111
"test": "jest",
1212
"lint": "eslint .",
13-
"clean": "rm -rf node_modules/ && cd .. && rm -rf node_modules/ && yarn install && cd example && yarn install",
13+
"clean": "rm -rf node_modules/ && cd .. && rm -rf node_modules/ && yarn install && yarn prepare && cd example && yarn install",
1414
"cleanIos": "yarn clean && cd ios && pod install && cd .."
1515
},
1616
"dependencies": {

ios/RNQonversion.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ + (BOOL)requiresMainQueueSetup
4646
[_qonversionSandwich syncStoreKit2Purchases];
4747
}
4848

49-
RCT_EXPORT_METHOD(purchase:(NSString *)productId completion:(RCTResponseSenderBlock)completion rejecter:(RCTPromiseRejectBlock)reject) {
50-
[_qonversionSandwich purchase:productId completion:^(NSDictionary<NSString *,id> * _Nullable result, SandwichError * _Nullable error) {
49+
RCT_EXPORT_METHOD(purchase:(NSString *)productId quantity:(NSInteger)quantity contextKeys:(NSArray *)contextKeys completion:(RCTResponseSenderBlock)completion rejecter:(RCTPromiseRejectBlock)reject) {
50+
[_qonversionSandwich purchase:productId quantity:quantity contextKeys:contextKeys completion:^(NSDictionary<NSString *,id> * _Nullable result, SandwichError * _Nullable error) {
5151
[self handleResult:result error:error completion:completion rejecter:reject];
5252
}];
5353
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-native-qonversion",
33
"title": "React Native Qonversion",
4-
"version": "8.0.1",
4+
"version": "8.1.0",
55
"description": "Qonversion provides full in-app purchases infrastructure, so you do not need to build your own server for receipt validation. Implement in-app subscriptions, validate user receipts, check subscription status, and provide access to your app features and content using our StoreKit wrapper and Google Play Billing wrapper.",
66
"main": "build/index.js",
77
"types": "build/index.d.ts",

react-native-qonversion.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ Pod::Spec.new do |s|
2222
s.requires_arc = true
2323

2424
s.dependency "React"
25-
s.dependency "QonversionSandwich", "5.0.4"
25+
s.dependency "QonversionSandwich", "5.1.2"
2626
end

src/QonversionApi.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import RemoteConfigList from "./dto/RemoteConfigList";
1111
import UserProperties from './dto/UserProperties';
1212
import PurchaseModel from './dto/PurchaseModel';
1313
import PurchaseUpdateModel from './dto/PurchaseUpdateModel';
14+
import PurchaseOptions from "./dto/PurchaseOptions";
1415

1516
interface QonversionApi {
1617

@@ -34,21 +35,32 @@ interface QonversionApi {
3435

3536
/**
3637
* Make a purchase and validate it through server-to-server using Qonversion's Backend
37-
* @param purchaseModel necessary information for purchase
38+
* @param product product to purchase
39+
* @param options additional options for the purchase process.
3840
* @returns the promise with the user entitlements including the ones obtained by the purchase
3941
*
4042
* @see [Making Purchases](https://documentation.qonversion.io/docs/making-purchases)
4143
*/
44+
purchaseProduct(product: Product, options: PurchaseOptions): Promise<Map<string, Entitlement>>
45+
46+
/**
47+
* Make a purchase and validate it through server-to-server using Qonversion's Backend.
48+
*
49+
* @deprecated Use {@link purchaseProduct} function instead.
50+
* @param purchaseModel necessary information for purchase
51+
* @returns the promise with the user entitlements including the ones obtained by the purchase
52+
* @see [Making Purchases](https://documentation.qonversion.io/docs/making-purchases)
53+
*/
4254
purchase(purchaseModel: PurchaseModel): Promise<Map<string, Entitlement>>;
4355

4456
/**
4557
* Android only. Returns `null` if called on iOS.
4658
*
47-
* Update (upgrade/downgrade) subscription on Google Play Store and validate it through server-to-server using Qonversion's Backend
59+
* Update (upgrade/downgrade) subscription on Google Play Store and validate it through server-to-server using Qonversion's Backend.
4860
*
61+
* @deprecated Use {@link purchaseProduct} function instead.
4962
* @param purchaseUpdateModel necessary information for purchase update
5063
* @returns the promise with the user entitlements including updated ones.
51-
*
5264
* @see [Update policy](https://developer.android.com/google/play/billing/subscriptions#replacement-modes)
5365
* @see [Making Purchases](https://documentation.qonversion.io/docs/making-purchases)
5466
*/

src/dto/PurchaseOptions.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Product from "./Product";
2+
import {PurchaseUpdatePolicy} from "./enums";
3+
4+
class PurchaseOptions {
5+
public readonly offerId: string | null;
6+
public readonly applyOffer: boolean;
7+
public readonly oldProduct: Product | null;
8+
public readonly updatePolicy: PurchaseUpdatePolicy | null;
9+
public readonly contextKeys: string[] | null;
10+
public readonly quantity: number;
11+
12+
constructor (
13+
offerId: string | null,
14+
applyOffer: boolean,
15+
oldProduct: Product | null,
16+
updatePolicy: PurchaseUpdatePolicy | null,
17+
contextKeys: string[] | null,
18+
quantity: number
19+
) {
20+
this.offerId = offerId;
21+
this.applyOffer = applyOffer;
22+
this.oldProduct = oldProduct;
23+
this.updatePolicy = updatePolicy;
24+
this.contextKeys = contextKeys;
25+
this.quantity = quantity;
26+
}
27+
}
28+
29+
export default PurchaseOptions;

src/dto/PurchaseOptionsBuilder.ts

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import Product from "./Product";
2+
import {PurchaseUpdatePolicy} from "./enums";
3+
import ProductOfferDetails from "./storeProducts/ProductOfferDetails";
4+
import PurchaseOptions from "./PurchaseOptions";
5+
6+
class PurchaseOptionsBuilder {
7+
private offerId: string | null = null;
8+
private applyOffer: boolean = true;
9+
private oldProduct: Product | null = null;
10+
private updatePolicy: PurchaseUpdatePolicy | null = null;
11+
private contextKeys: string[] | null = null;
12+
private quantity: number = 1;
13+
14+
/**
15+
* iOS only.
16+
* Set quantity of product purchasing. Use for consumable in-app products.
17+
* @param quantity of product purchasing.
18+
* @return builder instance for chain calls.
19+
*/
20+
setQuantity(quantity: number): PurchaseOptionsBuilder {
21+
this.quantity = quantity;
22+
return this;
23+
}
24+
25+
/**
26+
* Android only.
27+
* Set offer for the purchase.
28+
* If offer is not specified, then the default offer will be applied. To know how we choose
29+
* the default offer, see {@link ProductStoreDetails.defaultSubscriptionOfferDetails}.
30+
* @param offer concrete offer which you'd like to purchase.
31+
* @return builder instance for chain calls.
32+
*/
33+
setOffer(offer: ProductOfferDetails) {
34+
this.offerId = offer.offerId;
35+
return this;
36+
}
37+
38+
/**
39+
* Android only.
40+
* Set the offer Id to the purchase.
41+
* If {@link offerId} is not specified, then the default offer will be applied. To know how we choose
42+
* the default offer, see {@link ProductStoreDetails.defaultSubscriptionOfferDetails}.
43+
* @param offerId concrete offer Id which you'd like to purchase.
44+
* @return builder instance for chain calls.
45+
*/
46+
setOfferId(offerId: string): PurchaseOptionsBuilder {
47+
this.offerId = offerId;
48+
return this;
49+
}
50+
51+
/**
52+
* Android only.
53+
* Call this function to remove any intro/trial offer from the purchase (use only a bare base plan).
54+
* @return builder instance for chain calls.
55+
*/
56+
removeOffer(): PurchaseOptionsBuilder {
57+
this.applyOffer = false;
58+
return this;
59+
}
60+
61+
/**
62+
* Android only.
63+
* Set Qonversion product from which the upgrade/downgrade will be initialized.
64+
*
65+
* @param oldProduct Qonversion product from which the upgrade/downgrade
66+
* will be initialized.
67+
* @return builder instance for chain calls.
68+
*/
69+
setOldProduct(oldProduct: Product): PurchaseOptionsBuilder {
70+
this.oldProduct = oldProduct;
71+
return this;
72+
}
73+
74+
/**
75+
* Android only.
76+
* Set the update policy for the purchase.
77+
* If the {@link updatePolicy} is not provided, then default one
78+
* will be selected - {@link PurchaseUpdatePolicy.WITH_TIME_PRORATION}.
79+
* @param updatePolicy update policy for the purchase.
80+
* @return builder instance for chain calls.
81+
*/
82+
setUpdatePolicy(updatePolicy: PurchaseUpdatePolicy): PurchaseOptionsBuilder {
83+
this.updatePolicy = updatePolicy;
84+
return this;
85+
}
86+
87+
/**
88+
* Set the context keys associated with a purchase.
89+
*
90+
* @param contextKeys context keys for the purchase.
91+
* @return builder instance for chain calls.
92+
*/
93+
setContextKeys(contextKeys: string[]): PurchaseOptionsBuilder {
94+
this.contextKeys = contextKeys;
95+
return this;
96+
}
97+
98+
/**
99+
* Generate {@link PurchaseOptions} instance with all the provided options.
100+
* @return the complete {@link PurchaseOptions} instance.
101+
*/
102+
build(): PurchaseOptions {
103+
return new PurchaseOptions(this.offerId, this.applyOffer, this.oldProduct, this.updatePolicy, this.contextKeys, this.quantity)
104+
}
105+
}
106+
107+
export default PurchaseOptionsBuilder;

0 commit comments

Comments
 (0)