Skip to content

Commit

Permalink
Merge pull request #318 from qonversion/release/8.1.0
Browse files Browse the repository at this point in the history
Release 8.1.0
  • Loading branch information
suriksarkisyan committed Aug 25, 2024
2 parents c84ecef + 27d169b commit 182bbbb
Show file tree
Hide file tree
Showing 13 changed files with 220 additions and 32 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ repositories {
dependencies {
//noinspection GradleDynamicVersion
implementation 'com.facebook.react:react-native:+' // From node_modules
implementation "io.qonversion.sandwich:sandwich:5.0.4"
implementation "io.qonversion.sandwich:sandwich:5.1.2"
}

afterEvaluate { project ->
Expand Down
25 changes: 15 additions & 10 deletions android/src/main/java/com/reactlibrary/QonversionModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,19 @@ public void syncHistoricalData() {
}

@ReactMethod
public void purchase(String productId, @Nullable String offerId, @Nullable Boolean applyOffer, final Promise promise) {
qonversionSandwich.purchase(productId, offerId, applyOffer, Utils.getResultListener(promise));
public void purchase(
String productId,
@Nullable String offerId,
@Nullable Boolean applyOffer,
@Nullable String oldProductId,
@Nullable String updatePolicyKey,
@Nullable ReadableArray contextKeys,
final Promise promise) {
List<String> contextKeysList = null;
if (contextKeys != null) {
contextKeysList = EntitiesConverter.convertArrayToStringList(contextKeys);
}
qonversionSandwich.purchase(productId, offerId, applyOffer, oldProductId, updatePolicyKey, contextKeysList, Utils.getResultListener(promise));
}

@ReactMethod
Expand All @@ -92,16 +103,10 @@ public void updatePurchase(
@Nullable Boolean applyOffer,
String oldProductId,
@Nullable String updatePolicyKey,
@Nullable ReadableArray contextKeys,
final Promise promise
) {
qonversionSandwich.updatePurchase(
productId,
offerId,
applyOffer,
oldProductId,
updatePolicyKey,
Utils.getResultListener(promise)
);
purchase(productId, offerId, applyOffer, oldProductId, updatePolicyKey, contextKeys, promise);
}

@ReactMethod
Expand Down
20 changes: 10 additions & 10 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ PODS:
- glog (0.3.5)
- libevent (2.1.12)
- OpenSSL-Universal (1.1.1100)
- Qonversion (5.11.0):
- Qonversion/Main (= 5.11.0)
- Qonversion/Main (5.11.0)
- QonversionSandwich (5.0.2):
- Qonversion (= 5.11.0)
- Qonversion (5.12.0):
- Qonversion/Main (= 5.12.0)
- Qonversion/Main (5.12.0)
- QonversionSandwich (5.1.1):
- Qonversion (= 5.12.0)
- RCT-Folly (2021.07.22.00):
- boost
- DoubleConversion
Expand Down Expand Up @@ -289,8 +289,8 @@ PODS:
- React-jsinspector (0.70.7)
- React-logger (0.70.7):
- glog
- react-native-qonversion (8.0.0):
- QonversionSandwich (= 5.0.2)
- react-native-qonversion (8.0.1):
- QonversionSandwich (= 5.1.1)
- React
- React-perflogger (0.70.7)
- React-RCTActionSheet (0.70.7):
Expand Down Expand Up @@ -535,8 +535,8 @@ SPEC CHECKSUMS:
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c
Qonversion: b39cb723b933c6e18bd9e03c763b366385906d83
QonversionSandwich: dbaec81051fe172857e008c5fc6e8d2f9bc1642f
Qonversion: ac2da69e497cb1f01cea13d82513fde14f338ca3
QonversionSandwich: 0fc30a920cfed34238bdb6830b6ca6388294107c
RCT-Folly: 0080d0a6ebf2577475bda044aa59e2ca1f909cda
RCTRequired: 837880d26ec119e105317dc28a456f3016bf16d1
RCTTypeSafety: 5c854c04c3383cab04f404e25d408ed52124b300
Expand All @@ -551,7 +551,7 @@ SPEC CHECKSUMS:
React-jsiexecutor: e95cdd036e7947ddf87f3049319ac3064deb76b5
React-jsinspector: 1c34fea1868136ecde647bc11fae9266d4143693
React-logger: e9f407f9fdf3f3ce7749ae6f88affe63e8446019
react-native-qonversion: f274a7b0c9af02bb9f77b6d1a2e6a1f9fce22b24
react-native-qonversion: 0fa511df2132c06ba0cbe0f5764124c97074cd99
React-perflogger: 52a94f38c19a518d05726624b49bfc192639374d
React-RCTActionSheet: 7b89fe64a852bc3ae39b91dbd142ef09931ef3f7
React-RCTAnimation: ad84bfbf8c5f6f77e65092d0c2b0506b80b5cf99
Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"start": "react-native start",
"test": "jest",
"lint": "eslint .",
"clean": "rm -rf node_modules/ && cd .. && rm -rf node_modules/ && yarn install && cd example && yarn install",
"clean": "rm -rf node_modules/ && cd .. && rm -rf node_modules/ && yarn install && yarn prepare && cd example && yarn install",
"cleanIos": "yarn clean && cd ios && pod install && cd .."
},
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions ios/RNQonversion.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ + (BOOL)requiresMainQueueSetup
[_qonversionSandwich syncStoreKit2Purchases];
}

RCT_EXPORT_METHOD(purchase:(NSString *)productId completion:(RCTResponseSenderBlock)completion rejecter:(RCTPromiseRejectBlock)reject) {
[_qonversionSandwich purchase:productId completion:^(NSDictionary<NSString *,id> * _Nullable result, SandwichError * _Nullable error) {
RCT_EXPORT_METHOD(purchase:(NSString *)productId quantity:(NSInteger)quantity contextKeys:(NSArray *)contextKeys completion:(RCTResponseSenderBlock)completion rejecter:(RCTPromiseRejectBlock)reject) {
[_qonversionSandwich purchase:productId quantity:quantity contextKeys:contextKeys completion:^(NSDictionary<NSString *,id> * _Nullable result, SandwichError * _Nullable error) {
[self handleResult:result error:error completion:completion rejecter:reject];
}];
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-native-qonversion",
"title": "React Native Qonversion",
"version": "8.0.1",
"version": "8.1.0",
"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.",
"main": "build/index.js",
"types": "build/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion react-native-qonversion.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ Pod::Spec.new do |s|
s.requires_arc = true

s.dependency "React"
s.dependency "QonversionSandwich", "5.0.4"
s.dependency "QonversionSandwich", "5.1.2"
end
18 changes: 15 additions & 3 deletions src/QonversionApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import RemoteConfigList from "./dto/RemoteConfigList";
import UserProperties from './dto/UserProperties';
import PurchaseModel from './dto/PurchaseModel';
import PurchaseUpdateModel from './dto/PurchaseUpdateModel';
import PurchaseOptions from "./dto/PurchaseOptions";

interface QonversionApi {

Expand All @@ -34,21 +35,32 @@ interface QonversionApi {

/**
* Make a purchase and validate it through server-to-server using Qonversion's Backend
* @param purchaseModel necessary information for purchase
* @param product product to purchase
* @param options additional options for the purchase process.
* @returns the promise with the user entitlements including the ones obtained by the purchase
*
* @see [Making Purchases](https://documentation.qonversion.io/docs/making-purchases)
*/
purchaseProduct(product: Product, options: PurchaseOptions): Promise<Map<string, Entitlement>>

/**
* Make a purchase and validate it through server-to-server using Qonversion's Backend.
*
* @deprecated Use {@link purchaseProduct} function instead.
* @param purchaseModel necessary information for purchase
* @returns the promise with the user entitlements including the ones obtained by the purchase
* @see [Making Purchases](https://documentation.qonversion.io/docs/making-purchases)
*/
purchase(purchaseModel: PurchaseModel): Promise<Map<string, Entitlement>>;

/**
* Android only. Returns `null` if called on iOS.
*
* Update (upgrade/downgrade) subscription on Google Play Store and validate it through server-to-server using Qonversion's Backend
* Update (upgrade/downgrade) subscription on Google Play Store and validate it through server-to-server using Qonversion's Backend.
*
* @deprecated Use {@link purchaseProduct} function instead.
* @param purchaseUpdateModel necessary information for purchase update
* @returns the promise with the user entitlements including updated ones.
*
* @see [Update policy](https://developer.android.com/google/play/billing/subscriptions#replacement-modes)
* @see [Making Purchases](https://documentation.qonversion.io/docs/making-purchases)
*/
Expand Down
29 changes: 29 additions & 0 deletions src/dto/PurchaseOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import Product from "./Product";
import {PurchaseUpdatePolicy} from "./enums";

class PurchaseOptions {
public readonly offerId: string | null;
public readonly applyOffer: boolean;
public readonly oldProduct: Product | null;
public readonly updatePolicy: PurchaseUpdatePolicy | null;
public readonly contextKeys: string[] | null;
public readonly quantity: number;

constructor (
offerId: string | null,
applyOffer: boolean,
oldProduct: Product | null,
updatePolicy: PurchaseUpdatePolicy | null,
contextKeys: string[] | null,
quantity: number
) {
this.offerId = offerId;
this.applyOffer = applyOffer;
this.oldProduct = oldProduct;
this.updatePolicy = updatePolicy;
this.contextKeys = contextKeys;
this.quantity = quantity;
}
}

export default PurchaseOptions;
107 changes: 107 additions & 0 deletions src/dto/PurchaseOptionsBuilder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import Product from "./Product";
import {PurchaseUpdatePolicy} from "./enums";
import ProductOfferDetails from "./storeProducts/ProductOfferDetails";
import PurchaseOptions from "./PurchaseOptions";

class PurchaseOptionsBuilder {
private offerId: string | null = null;
private applyOffer: boolean = true;
private oldProduct: Product | null = null;
private updatePolicy: PurchaseUpdatePolicy | null = null;
private contextKeys: string[] | null = null;
private quantity: number = 1;

/**
* iOS only.
* Set quantity of product purchasing. Use for consumable in-app products.
* @param quantity of product purchasing.
* @return builder instance for chain calls.
*/
setQuantity(quantity: number): PurchaseOptionsBuilder {
this.quantity = quantity;
return this;
}

/**
* Android only.
* Set offer for the purchase.
* If offer is not specified, then the default offer will be applied. To know how we choose
* the default offer, see {@link ProductStoreDetails.defaultSubscriptionOfferDetails}.
* @param offer concrete offer which you'd like to purchase.
* @return builder instance for chain calls.
*/
setOffer(offer: ProductOfferDetails) {
this.offerId = offer.offerId;
return this;
}

/**
* Android only.
* Set the offer Id to the purchase.
* If {@link offerId} is not specified, then the default offer will be applied. To know how we choose
* the default offer, see {@link ProductStoreDetails.defaultSubscriptionOfferDetails}.
* @param offerId concrete offer Id which you'd like to purchase.
* @return builder instance for chain calls.
*/
setOfferId(offerId: string): PurchaseOptionsBuilder {
this.offerId = offerId;
return this;
}

/**
* Android only.
* Call this function to remove any intro/trial offer from the purchase (use only a bare base plan).
* @return builder instance for chain calls.
*/
removeOffer(): PurchaseOptionsBuilder {
this.applyOffer = false;
return this;
}

/**
* Android only.
* Set Qonversion product from which the upgrade/downgrade will be initialized.
*
* @param oldProduct Qonversion product from which the upgrade/downgrade
* will be initialized.
* @return builder instance for chain calls.
*/
setOldProduct(oldProduct: Product): PurchaseOptionsBuilder {
this.oldProduct = oldProduct;
return this;
}

/**
* Android only.
* Set the update policy for the purchase.
* If the {@link updatePolicy} is not provided, then default one
* will be selected - {@link PurchaseUpdatePolicy.WITH_TIME_PRORATION}.
* @param updatePolicy update policy for the purchase.
* @return builder instance for chain calls.
*/
setUpdatePolicy(updatePolicy: PurchaseUpdatePolicy): PurchaseOptionsBuilder {
this.updatePolicy = updatePolicy;
return this;
}

/**
* Set the context keys associated with a purchase.
*
* @param contextKeys context keys for the purchase.
* @return builder instance for chain calls.
*/
setContextKeys(contextKeys: string[]): PurchaseOptionsBuilder {
this.contextKeys = contextKeys;
return this;
}

/**
* Generate {@link PurchaseOptions} instance with all the provided options.
* @return the complete {@link PurchaseOptions} instance.
*/
build(): PurchaseOptions {
return new PurchaseOptions(this.offerId, this.applyOffer, this.oldProduct, this.updatePolicy, this.contextKeys, this.quantity)
}
}

export default PurchaseOptionsBuilder;
2 changes: 1 addition & 1 deletion src/dto/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export enum AttributionProvider {
* A policy used for purchase updates on Android, which describes
* how to migrate from purchased plan to a new one.
*
* Used in {@link PurchaseUpdateModel} class for purchase updates.
* Used in {@link PurchaseOptions} class for purchase updates.
*/
export enum PurchaseUpdatePolicy {
/**
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ export { default as SKProduct } from './dto/storeProducts/SKProduct';
export { default as SKProductDiscount } from './dto/storeProducts/SKProductDiscount';
export { default as SKSubscriptionPeriod } from './dto/storeProducts/SKSubscriptionPeriod';
export { default as SkuDetails } from './dto/storeProducts/SkuDetails';
export { default as PurchaseOptionsBuilder } from './dto/PurchaseOptionsBuilder';
export { default as PurchaseOptions } from './dto/PurchaseOptionsBuilder';
Loading

0 comments on commit 182bbbb

Please sign in to comment.