Skip to content

Commit

Permalink
Updated to support PHC 10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkVillacampa committed Feb 24, 2024
1 parent 300328e commit b93b5eb
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 22 deletions.
2 changes: 1 addition & 1 deletion RNPurchases.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Pod::Spec.new do |spec|
spec.authors = package['author']
spec.homepage = "https://github.com/RevenueCat/react-native-purchases"
spec.license = package['license']
spec.platform = :ios, "11.0"
spec.platform = :ios, "13.0"

spec.source = { :git => "https://github.com/RevenueCat/react-native-purchases.git" }
spec.source_files = "ios/**/*.{h,m,swift}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void removeListeners(Integer count) {
@ReactMethod
public void setupPurchases(String apiKey, @Nullable String appUserID,
boolean observerMode, @Nullable String userDefaultsSuiteName,
@Nullable Boolean usesStoreKit2IfAvailable, boolean useAmazon,
@Nullable String storeKitVersion, boolean useAmazon,
boolean shouldShowInAppMessagesAutomatically,
@Nullable String entitlementVerificationMode) {
PlatformInfo platformInfo = new PlatformInfo(PLATFORM_NAME, PLUGIN_VERSION);
Expand Down
21 changes: 15 additions & 6 deletions apitesters/purchases.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ENTITLEMENT_VERIFICATION_MODE, IN_APP_MESSAGE_TYPE} from '@revenuecat/purchases-typescript-internal';
import {ENTITLEMENT_VERIFICATION_MODE, IN_APP_MESSAGE_TYPE, STOREKIT_VERSION} from '@revenuecat/purchases-typescript-internal';
import {
CustomerInfo,
PurchasesEntitlementInfo,
Expand Down Expand Up @@ -124,13 +124,14 @@ async function checkPurchasing(purchases: Purchases,

await Purchases.showInAppMessages();
await Purchases.showInAppMessages(messageTypes);
await Purchases.handleObserverModeTransaction("product_id");
}

async function checkConfigure() {
const apiKey: string = "";
const appUserID: string | null = "";
const observerMode: boolean = false;
const usesStoreKit2IfAvailable: boolean = true;
const storeKitVersion: STOREKIT_VERSION = Purchases.STOREKIT_VERSION.DEFAULT;
const useAmazon: boolean = true;
const entitlementVerificationMode: ENTITLEMENT_VERIFICATION_MODE = Purchases.ENTITLEMENT_VERIFICATION_MODE.INFORMATIONAL;
const userDefaultsSuiteName: string = "";
Expand All @@ -152,22 +153,22 @@ async function checkConfigure() {
appUserID,
observerMode,
userDefaultsSuiteName,
usesStoreKit2IfAvailable
storeKitVersion
});
Purchases.configure({
apiKey,
appUserID,
observerMode,
userDefaultsSuiteName,
usesStoreKit2IfAvailable,
storeKitVersion,
entitlementVerificationMode
});
Purchases.configure({
apiKey,
appUserID,
observerMode,
userDefaultsSuiteName,
usesStoreKit2IfAvailable,
storeKitVersion,
entitlementVerificationMode,
useAmazon
});
Expand All @@ -176,7 +177,7 @@ async function checkConfigure() {
appUserID,
observerMode,
userDefaultsSuiteName,
usesStoreKit2IfAvailable,
storeKitVersion,
useAmazon,
shouldShowInAppMessagesAutomatically
});
Expand Down Expand Up @@ -213,6 +214,14 @@ async function checkEntitlementVerificationModeEnum(mode: ENTITLEMENT_VERIFICATI
}
}

function checkStoreKitVersion(status: STOREKIT_VERSION) {
switch (status) {
case STOREKIT_VERSION.DEFAULT:
case STOREKIT_VERSION.STOREKIT_1:
case STOREKIT_VERSION.STOREKIT_2:
}
}

function checkListeners() {
const customerInfoUpdateListener: CustomerInfoUpdateListener = customerInfo => {
};
Expand Down
2 changes: 1 addition & 1 deletion examples/MagicWeather/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, '11.0'
platform :ios, '13.0'

target 'MagicWeatherReactNative' do
config = use_native_modules!
Expand Down
2 changes: 1 addition & 1 deletion examples/purchaseTesterTypescript/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

platform :ios, min_ios_version_supported
platform :ios, "13.0"
prepare_react_native_project!

# If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@
"$(inherited)",
);
INFOPLIST_FILE = PurchaseTesterTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.4;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -495,7 +495,7 @@
COPY_PHASE_STRIP = NO;
DEVELOPMENT_TEAM = 8SXR2327BM;
INFOPLIST_FILE = PurchaseTesterTests/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 12.4;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -616,7 +616,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.4;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = (
/usr/lib/swift,
"$(inherited)",
Expand Down Expand Up @@ -690,7 +690,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 12.4;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = (
/usr/lib/swift,
"$(inherited)",
Expand Down
19 changes: 16 additions & 3 deletions ios/RNPurchases.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ - (dispatch_queue_t)methodQueue {
appUserID:(nullable NSString *)appUserID
observerMode:(BOOL)observerMode
userDefaultsSuiteName:(nullable NSString *)userDefaultsSuiteName
usesStoreKit2IfAvailable:(BOOL)usesStoreKit2IfAvailable
storeKitVersion:(nullable NSString *)storeKitVersion
useAmazon:(BOOL)useAmazon
shouldShowInAppMessagesAutomatically:(BOOL)shouldShowInAppMessagesAutomatically
entitlementVerificationMode:(nullable NSString *)entitlementVerificationMode) {
Expand All @@ -51,8 +51,8 @@ - (dispatch_queue_t)methodQueue {
userDefaultsSuiteName:userDefaultsSuiteName
platformFlavor:self.platformFlavor
platformFlavorVersion:self.platformFlavorVersion
usesStoreKit2IfAvailable:usesStoreKit2IfAvailable
dangerousSettings:nil
storeKitVersion:storeKitVersion
dangerousSettings:nil
shouldShowInAppMessagesAutomatically:shouldShowInAppMessagesAutomatically
verificationMode:entitlementVerificationMode];
purchases.delegate = self;
Expand Down Expand Up @@ -232,6 +232,19 @@ static void logUnavailablePresentCodeRedemptionSheet() {
NSLog(@"[Purchases] Warning: tried to present codeRedemptionSheet, but it's only available on iOS 14.0 or greater.");
}

RCT_EXPORT_METHOD(handleObserverModeTransactionForProductID:(nonnull NSString *)productID
resolve:(RCTPromiseResolveBlock)resolve
reject:(RCTPromiseRejectBlock)reject) {
if (@available(iOS 15.0, *)) {
[RCCommonFunctionality handleObserverModeTransactionForProductID:@""
completion: [self getResponseCompletionBlockWithResolve:resolve
reject:reject]];
} else {
NSLog(@"[Purchases] Warning: tried to handle Observer Mode transaction, but it's only available on iOS 15.0 or greater.");
resolve(nil);
}
}

#pragma mark - Subscriber Attributes

RCT_EXPORT_METHOD(setProxyURLString:(nullable NSString *)proxyURLString) {
Expand Down
2 changes: 1 addition & 1 deletion react-native-purchases-ui/RNPaywalls.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Pod::Spec.new do |spec|
spec.authors = package['author']
spec.homepage = "https://github.com/RevenueCat/react-native-purchases"
spec.license = package['license']
spec.platform = :ios, "11.0"
spec.platform = :ios, "13.0"

spec.source = { :git => "https://github.com/RevenueCat/react-native-purchases.git" }
spec.source_files = "ios/**/*.{h,m,swift}"
Expand Down
36 changes: 32 additions & 4 deletions src/purchases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ import {
LogInResult,
IN_APP_MESSAGE_TYPE,
ENTITLEMENT_VERIFICATION_MODE,
VERIFICATION_RESULT
VERIFICATION_RESULT,
STOREKIT_VERSION,
PurchasesStoreTransaction
} from '@revenuecat/purchases-typescript-internal';

// This export is kept to keep backwards compatibility to any possible users using this file directly
Expand Down Expand Up @@ -169,6 +171,13 @@ export default class Purchases {
*/
public static VERIFICATION_RESULT = VERIFICATION_RESULT;

/**
* Enum of StoreKit version.
* @readonly
* @enum {string}
*/
public static STOREKIT_VERSION = STOREKIT_VERSION;

/**
* @internal
*/
Expand All @@ -184,7 +193,7 @@ export default class Purchases {
* @param {String} apiKey RevenueCat API Key. Needs to be a String
* @param {String?} appUserID An optional unique id for identifying the user. Needs to be a string.
* @param {boolean} [observerMode=false] An optional boolean. Set this to TRUE if you have your own IAP implementation and want to use only RevenueCat's backend. Default is FALSE.
* @param {boolean} [usesStoreKit2IfAvailable=false] DEPRECATED. An optional boolean. iOS-only. Defaults to FALSE. Setting this to TRUE will enable StoreKit2 on compatible devices.
* @param {STOREKIT_VERSION} [storeKitVersion=STOREKIT_2] iOS-only. Defaults to STOREKIT_2. StoreKit 2 is only available on iOS 15+. StoreKit 1 will be used for previous iOS versions regardless of this setting.
* We recommend not using this parameter, letting RevenueCat decide for you which StoreKit implementation to use.
* @param {ENTITLEMENT_VERIFICATION_MODE} [entitlementVerificationMode=ENTITLEMENT_VERIFICATION_MODE.DISABLED] Sets the entitlement verifciation mode to use. For more details, check https://rev.cat/trusted-entitlements
* @param {boolean} [useAmazon=false] An optional boolean. Android-only. Set this to TRUE to enable Amazon on compatible devices.
Expand All @@ -197,7 +206,7 @@ export default class Purchases {
appUserID = null,
observerMode = false,
userDefaultsSuiteName,
usesStoreKit2IfAvailable = false,
storeKitVersion = STOREKIT_VERSION.DEFAULT,
useAmazon = false,
shouldShowInAppMessagesAutomatically = true,
entitlementVerificationMode = ENTITLEMENT_VERIFICATION_MODE.DISABLED
Expand All @@ -215,7 +224,7 @@ export default class Purchases {
appUserID,
observerMode,
userDefaultsSuiteName,
usesStoreKit2IfAvailable,
storeKitVersion,
useAmazon,
shouldShowInAppMessagesAutomatically,
entitlementVerificationMode
Expand Down Expand Up @@ -666,6 +675,25 @@ export default class Purchases {
RNPurchases.syncObserverModeAmazonPurchase(productID, receiptID, amazonUserID, isoCurrencyCode, price);
}

/**
* Use this method only if you already have your own IAP implementation using StoreKit 2 and want to use
* RevenueCat's backend. If you are using StoreKit 1 for your implementation, you do not need this method.
*
* You only need to use this method with *new* purchases. Subscription updates are observed automatically.
*
* Important: This should only be used if you have enabled observer mode during SDK configuration.
*
* @warning You need to finish the transaction yourself after calling this method.
*
* @param {string} productID Product ID that was just purchased
* @returns {Promise<PurchasesStoreTransaction>} If there was a transacton found and handled for the provided product ID.
*/
public static async handleObserverModeTransaction(productID: string): Promise<PurchasesStoreTransaction> {
await Purchases.throwIfAndroidPlatform();
await Purchases.throwIfNotConfigured();
return RNPurchases.handleObserverModeTransactionForProductID(productID);
}

/**
* @deprecated, use enableAdServicesAttributionTokenCollection instead.
* Enable automatic collection of Apple Search Ad attribution. Disabled by default
Expand Down

0 comments on commit b93b5eb

Please sign in to comment.