Purchasely will provide the controllers (iOS) and fragments (Android) for your paywalls and will inform you about subscription events through our Webhook and integrations.
In this mode Purchasely won't consume your purchases or acknowledge purchases made.
On iOS we won't finish the transaction of your consumables that will remain in the queue if you don't do that in your code.
On Android the transactions will be cancelled and refunded after 3 days.
General overview
Implementation
1- Start the SDK
The start method must be called as soon as possible to catch every purchase / renewal.
In this mode, Purchasely will be able to display paywalls and observe transactions but will not process them and validate them with Apple and Google
The most important argument to set, besides apiKey , of course, is the runningMode in paywallObserver
The userID parameter is optional and allows you to associate the purchase to a user instead of a device. You can also set it up later if you wish to.
import io.purchasely.ext.PurchaselyPurchasely.Builder(applicationContext) .apiKey("API_KEY") .logLevel(LogLevel.DEBUG) // set to warning or error for release .userId("USER_ID") .eventListener(eventListener) .runningMode(PLYRunningMode.PaywallObserver) .stores(listOf(GoogleStore(), HuaweiStore())) .build()// When you are ready for Purchasely to initialize,// you must call start() method that will grab configuration and products// from the selected stores.Purchasely.start { isConfigured ->}
List<Store> stores =newArrayList();stores.add(newGoogleStore(),newHuaweiStore());new Purchasely.Builder(getApplicationContext()).apiKey("API_KEY").logLevel(LogLevel.DEBUG) // set to warning or error for release.userId("USER_ID").eventListener(this).runningMode(PLYRunningMode.Full.PaywallObserver).stores(stores).build();// When you are ready for Purchasely to initialize,// you must call start() method that will grab configuration and products// from the selected stores.Purchasely.start(isConfigured -> {null;});
import Purchasely from'react-native-purchasely';/*** @params String apiKey* @params StringArray stores : may be Google, Amazon and Huawei* @params String userId* @params Purchasley.LogLevel logLevel* @params RunningMode runningMode**/Purchasely.startWithAPIKey('API_KEY', ['Google'],'USER_ID',Purchasely.logLevelDebug,RunningMode.PaywallObserver);
/*** @params String apiKey* @params StringArray stores : may be Google, Amazon and Huawei* @params String userId* @params Purchasley.LogLevel logLevel* @params Purchasely.RunningMode runningMode**/Purchasely.startWithAPIKey('API_KEY', ['Google'],null,Purchasely.LogLevel.DEBUG,Purchasely.RunningMode.paywallObserver);
/*** @params String apiKey* @params StringArray stores : may be Google, Amazon and Huawei* @params String userId* @params PLYLogLevel logLevel* @params PLYRunningMode runningMode**/bool configured =awaitPurchasely.startWithApiKey('API_KEY', ['Google'],null,PLYLogLevel.debug,PLYRunningMode.paywallObserver );if (!configured) {print('Purchasely SDK not configured');return;}
Then you must use the Paywall Actions Interceptor to perform the purchase triggered from Purchasely's paywalls with your purchase system.
Here is an example where MyPurchaseSystem is your internal subscription management system.
Purchasely.setPaywallActionsInterceptor { [weak self](action, parameters, presentationInfos, proceed)inswitch action {// Intercept the tap on purchase to display the terms and conditioncase .purchase:// Grab the plan to purchaseguardlet plan = parameters?.plan, let appleProductId = plan.appleProductId else {proceed(false)return } MyPurchaseSystem.purchase(appleProductId) { (success, error) {// We handle the purchase so we tell Purchasley not to handle itproceed(false)if success { presentationInfos?.controller?.dismiss(animated:true, completion:nil) } }default:proceed(true) }}
[Purchasely setPaywallActionsInterceptor:^(enum PLYPresentationAction action, PLYPresentationActionParameters *parameters, PLYPresentationInfo *presentationInfos, void (^ proceed)(BOOL)) {
switch (action) {
// Intercept the tap on purchase to display the terms and condition
case PLYPresentationActionPurchase:{
// Grab the plan to purchase
NSString *appleProductId = parameters.plan.appleProductId;
if (appleProductId == nil) {
proceed(NO);
return;
}
[MyPurchaseSystem purchase:appleProductId completion:^(BOOL success, NSError *Error) {
// We handle the purchase so we tell Purchasely not to handle it
proceed(false);
if (success) {
[presentationInfos.controller dismissViewControllerAnimated:YES completion:nil];
}
}];
break;
}
default:
proceed(YES);
break;
}
}];
Purchasely.setPaywallActionInterceptorCallback((result) => {if (result.action ===PLYPaywallAction.PURCHASE) {try {constplan=awaitPurchasely.planWithIdentifier('PLAN_VENDOR_ID');//If you want to intercept it, close paywall and display your screenPurchasely.closePaywall();MyPurchaseSystem.purchase(plan.productId)Purchasely.onProcessAction(false); } catch (e) {console.log(e);Purchasely.onProcessAction(false); } } else {Purchasely.onProcessAction(true); } });
Purchasely.setPaywallActionInterceptorCallback((result) => {if (result.action===Purchasely.PaywallAction.purchase) {Purchasely.planWithIdentifier('PLAN_VENDOR_ID', (plan) => {//If you want to intercept it, close paywall and display your screenPurchasely.closePaywall();MyPurchaseSystem.purchase(plan.productId)Purchasely.onProcessAction(false); }, (error) => {Purchasely.onProcessAction(false); }); } else {Purchasely.onProcessAction(true); } });
Purchasely.setPaywallActionInterceptorCallback( (PaywallActionInterceptorResult result) {if (result.action ==PLYPaywallAction.purchase) {try {var plan =awaitPurchasely.planWithIdentifier('PLAN_VENDOR_ID');//If you want to intercept it, close paywall and display your screenPurchasely.closePaywall();MyPurchaseSystem.purchase(plan.productId)Purchasely.onProcessAction(false); } catch (e) {print(e);Purchasely.onProcessAction(false); } } else {Purchasely.onProcessAction(true); } });
4- Sync your purchases (Android only)
In oberver and paywallObserver modes, when a purchase or a restoration is made with your current flow, call the synchronize() method of our SDK to send the receipt to our backend. This allow us to save the receipts on our server to prepare for your migration.
Purchasely.synchronize()
Purchasely.synchronize();
Purchasely.synchronize();
Purchasely.synchronize();
5- Configure deeplinks (optional)
Paywalls can be used in many othe ways that can be: