Skip to content

Commit

Permalink
Merge pull request #279 from qonversion/feature/googleBilling6
Browse files Browse the repository at this point in the history
Google Play Billing Library 6 support
  • Loading branch information
SpertsyanKM committed Jan 22, 2024
2 parents d63dd47 + 1ed1b97 commit ce27ebf
Show file tree
Hide file tree
Showing 21 changed files with 1,124 additions and 269 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:3.3.3"
implementation "io.qonversion.sandwich:sandwich:4.0.0"
}

afterEvaluate { project ->
Expand Down
47 changes: 12 additions & 35 deletions android/src/main/java/com/reactlibrary/QonversionModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,52 +84,29 @@ public void syncHistoricalData() {
}

@ReactMethod
public void purchaseProduct(String productId, String offeringId, final Promise promise) {
qonversionSandwich.purchaseProduct(productId, offeringId, getPurchaseResultListener(promise));
public void purchase(String productId, @Nullable String offerId, @Nullable Boolean applyOffer, final Promise promise) {
qonversionSandwich.purchase(productId, offerId, applyOffer, getPurchaseResultListener(promise));
}

@ReactMethod
public void purchase(String productId, final Promise promise) {
qonversionSandwich.purchase(productId, getPurchaseResultListener(promise));
}

@ReactMethod
public void updateProductWithId(
final String productId,
@Nullable final String offeringId,
final String oldProductId,
final Promise promise
) {
updateProductWithIdAndProrationMode(productId, offeringId, oldProductId, null, promise);
}

@ReactMethod
public void updateProductWithIdAndProrationMode(
final String productId,
@Nullable final String offeringId,
final String oldProductId,
@Nullable final Integer prorationMode,
public void updatePurchase(
String productId,
@Nullable String offerId,
@Nullable Boolean applyOffer,
String oldProductId,
@Nullable String updatePolicyKey,
final Promise promise
) {
qonversionSandwich.updatePurchaseWithProduct(
qonversionSandwich.updatePurchase(
productId,
offeringId,
offerId,
applyOffer,
oldProductId,
prorationMode,
updatePolicyKey,
getPurchaseResultListener(promise)
);
}

@ReactMethod
public void updatePurchase(String productId, String oldProductId, final Promise promise) {
updatePurchaseWithProrationMode(productId, oldProductId, null, promise);
}

@ReactMethod
public void updatePurchaseWithProrationMode(String productId, String oldProductId, Integer prorationMode, final Promise promise) {
qonversionSandwich.updatePurchase(productId, oldProductId, prorationMode, getPurchaseResultListener(promise));
}

@ReactMethod
public void setDefinedProperty(String key, String value) {
qonversionSandwich.setDefinedProperty(key, value);
Expand Down
30 changes: 16 additions & 14 deletions example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Qonversion, {
Environment,
Entitlement,
EntitlementsCacheLifetime,
PurchaseModel,
} from 'react-native-qonversion';
import NotificationsManager from './notificationsManager';

Expand All @@ -28,14 +29,8 @@ type StateType = {
checkEntitlementsHidden: boolean;
};

const prettyDuration = {
'WEEKLY': 'weekly',
'MONTHLY': 'monthly',
'3_MONTHS': '3 months',
'6_MONTHS': '6 months',
'ANNUAL': 'annual',
'LIFETIME': 'lifetime',
};
const InAppProductId = 'in_app';
const SubscriptionProductId = 'weekly';

export class QonversionSample extends React.PureComponent<{}, StateType> {
constructor(props) {
Expand Down Expand Up @@ -90,18 +85,25 @@ export class QonversionSample extends React.PureComponent<{}, StateType> {
let inAppTitle = this.state.inAppButtonTitle;
let subscriptionButtonTitle = this.state.subscriptionButtonTitle;

const inApp: Product = products.get('in_app');
const inApp: Product = products.get(InAppProductId);
if (inApp) {
inAppTitle = 'Buy for ' + inApp.prettyPrice;

const entitlement = entitlements.get('Test Entitlement');
if (entitlement) {
inAppTitle = entitlement.isActive ? 'Purchased' : inAppTitle;
}
}

const main: Product = products.get('weekly');
if (main) {
subscriptionButtonTitle = 'Subscribe for ' + main.prettyPrice + ' / ' + prettyDuration[main.duration];
const subscription: Product = products.get(SubscriptionProductId);
if (subscription) {
subscriptionButtonTitle = 'Subscribe for '
+ subscription.prettyPrice
+ ' / '
+ subscription.subscriptionPeriod.unitCount
+ ' '
+ subscription.subscriptionPeriod.unit;

const entitlement = entitlements.get('plus');
if (entitlement) {
subscriptionButtonTitle = entitlement.isActive ? 'Purchased' : subscriptionButtonTitle;
Expand Down Expand Up @@ -146,7 +148,7 @@ export class QonversionSample extends React.PureComponent<{}, StateType> {
style={styles.subscriptionButton}
onPress={() => {
this.setState({loading: true});
Qonversion.getSharedInstance().purchase('weekly').then(() => {
Qonversion.getSharedInstance().purchase(new PurchaseModel(SubscriptionProductId)).then(() => {
this.setState({loading: false, subscriptionButtonTitle: 'Purchased'});
}).catch(error => {
this.setState({loading: false});
Expand All @@ -170,7 +172,7 @@ export class QonversionSample extends React.PureComponent<{}, StateType> {
style={styles.inAppButton}
onPress={() => {
this.setState({loading: true});
Qonversion.getSharedInstance().purchase('in_app').then(() => {
Qonversion.getSharedInstance().purchase(new PurchaseModel(InAppProductId)).then(() => {
this.setState({loading: false, inAppButtonTitle: 'Purchased'});
}).catch(error => {
this.setState({loading: false});
Expand Down
12 changes: 6 additions & 6 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ PODS:
- Qonversion (5.5.2):
- Qonversion/Main (= 5.5.2)
- Qonversion/Main (5.5.2)
- QonversionSandwich (3.3.1):
- QonversionSandwich (4.0.0):
- Qonversion (= 5.5.2)
- RCT-Folly (2021.07.22.00):
- boost
Expand Down Expand Up @@ -289,8 +289,8 @@ PODS:
- React-jsinspector (0.70.5)
- React-logger (0.70.5):
- glog
- react-native-qonversion (6.2.0):
- QonversionSandwich (= 3.3.1)
- react-native-qonversion (6.3.1):
- QonversionSandwich (= 4.0.0)
- React
- React-perflogger (0.70.5)
- React-RCTActionSheet (0.70.5):
Expand Down Expand Up @@ -535,7 +535,7 @@ SPEC CHECKSUMS:
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c
Qonversion: 290d69d209f83a1defa914912a83fc8897a4af34
QonversionSandwich: a8339feabb3302d6b2dfe9a21372906cfccd507a
QonversionSandwich: 6c377e9f302673eeb22813c5bcc3be70ead9a491
RCT-Folly: 0080d0a6ebf2577475bda044aa59e2ca1f909cda
RCTRequired: 21229f84411088e5d8538f21212de49e46cc83e2
RCTTypeSafety: 62eed57a32924b09edaaf170a548d1fc96223086
Expand All @@ -550,7 +550,7 @@ SPEC CHECKSUMS:
React-jsiexecutor: 31564fa6912459921568e8b0e49024285a4d584b
React-jsinspector: badd81696361249893a80477983e697aab3c1a34
React-logger: fdda34dd285bdb0232e059b19d9606fa0ec3bb9c
react-native-qonversion: 83b17ba32811c66dc8bf1182b3fe782f4ab22fa6
react-native-qonversion: a070dfd191b0c52b459970e1c7b6e14d4fe7e03c
React-perflogger: e68d3795cf5d247a0379735cbac7309adf2fb931
React-RCTActionSheet: 05452c3b281edb27850253db13ecd4c5a65bc247
React-RCTAnimation: 578eebac706428e68466118e84aeacf3a282b4da
Expand All @@ -570,4 +570,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 0dce4b7944944a0de16fd6cacc29aa20d6858b4f

COCOAPODS: 1.11.3
COCOAPODS: 1.13.0
6 changes: 0 additions & 6 deletions ios/RNQonversion.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ + (BOOL)requiresMainQueueSetup
}];
}

RCT_EXPORT_METHOD(purchaseProduct:(NSString *)productId offeringId:(NSString *)offeringId completion:(RCTResponseSenderBlock)completion rejecter:(RCTPromiseRejectBlock)reject) {
[_qonversionSandwich purchaseProduct:productId offeringId:offeringId completion:^(NSDictionary<NSString *,id> * _Nullable result, SandwichError * _Nullable error) {
[self handlePurchaseResult:result error:error completion:completion rejecter:reject];
}];
}

RCT_EXPORT_METHOD(setDefinedProperty:(NSString *)property value:(NSString *)value) {
[_qonversionSandwich setDefinedProperty:property value:value];
}
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", "3.3.3"
s.dependency "QonversionSandwich", "4.0.0"
end
57 changes: 10 additions & 47 deletions src/QonversionApi.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import Entitlement from './dto/Entitlement';
import Product from './dto/Product';
import {UserPropertyKey, ProrationMode, AttributionProvider} from './dto/enums';
import {UserPropertyKey, AttributionProvider} from './dto/enums';
import Offerings from './dto/Offerings';
import IntroEligibility from './dto/IntroEligibility';
import User from './dto/User';
import {EntitlementsUpdateListener} from './dto/EntitlementsUpdateListener';
import {PromoPurchasesListener} from './dto/PromoPurchasesListener';
import RemoteConfig from "./dto/RemoteConfig";
import UserProperties from './dto/UserProperties';
import PurchaseModel from './dto/PurchaseModel';
import PurchaseUpdateModel from './dto/PurchaseUpdateModel';

interface QonversionApi {

Expand All @@ -25,68 +27,30 @@ interface QonversionApi {

/**
* Make a purchase and validate it through server-to-server using Qonversion's Backend
*
* @param productId Qonversion product identifier for purchase
* @param purchaseModel necessary information for purchase
* @returns the promise with the user entitlements including the ones obtained by the purchase
*/
purchase(productId: string): Promise<Map<string, Entitlement>>;

/**
* Make a purchase and validate it through server-to-server using Qonversion's Backend
*
* @param product - Qonversion's {@link Product} object
* @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): Promise<Map<string, Entitlement>>;
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
*
* @param productId Qonversion product identifier for purchase
* @param oldProductId Qonversion product identifier from which the upgrade/downgrade will be initialized
* @param prorationMode proration mode
* @param purchaseUpdateModel necessary information for purchase update
* @returns the promise with the user entitlements including updated ones.
*
* @see [Google Play Documentation](https://developer.android.com/google/play/billing/subscriptions#upgrade-downgrade)
* for more details.
* @see [Proration mode](https://developer.android.com/google/play/billing/subscriptions#proration)
* @see [Product Center](https://qonversion.io/docs/product-center)
* @see [Update policy](https://developer.android.com/google/play/billing/subscriptions#replacement-modes)
* @see [Making Purchases](https://documentation.qonversion.io/docs/making-purchases)
*/
updatePurchase(
productId: string,
oldProductId: string,
prorationMode: ProrationMode | undefined
): Promise<Map<string, Entitlement> | null>;

/**
* 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
*
* @param product Qonversion product for purchase
* @param oldProductId Qonversion product identifier from which the upgrade/downgrade will be initialized
* @param prorationMode proration mode
* @returns the promise with the user entitlements including updated ones
*
* @see [Google Play Documentation](https://developer.android.com/google/play/billing/subscriptions#upgrade-downgrade)
* for more details.
* @see [Proration mode](https://developer.android.com/google/play/billing/subscriptions#proration)
* @see [Product Center](https://qonversion.io/docs/product-center)
*/
updatePurchaseWithProduct(
product: Product,
oldProductId: String,
prorationMode: ProrationMode | undefined
): Promise<Map<string, Entitlement> | null>;
updatePurchase(purchaseUpdateModel: PurchaseUpdateModel): Promise<Map<string, Entitlement> | null>;

/**
* Returns Qonversion products in association with Apple and Google Play Store Products.
*
* @returns the promise with Qonversion products
*
* @see [Product Center](https://qonversion.io/docs/product-center)
*/
products(): Promise<Map<string, Product>>;

Expand All @@ -101,7 +65,6 @@ interface QonversionApi {
* @returns the promise with Qonversion offerings
*
* @see [Offerings](https://qonversion.io/docs/offerings) for more details
* @see [Product Center](https://qonversion.io/docs/product-center) for more details
*/
offerings(): Promise<Offerings | null>;

Expand Down
Loading

0 comments on commit ce27ebf

Please sign in to comment.