Purchasely
Rechercher…
Paywall action interceptor
This feature replaces both Login and Purchase interceptor with a more generic approach.
Starting with v3.0, Purchasely allow you to intercept and override every paywall action.
This can be used to:
  • In paywallOnly and paywallObserver modes, intercept purchase and restore actions to perform them using your own code or another SDK
  • Intercept the login button tapped to display your login form
  • Force the explicit acceptance of terms and conditions before a purchase
  • Intercept the call to a webview to inject credentials and be directly logged in
  • Block promo codes in Kids category apps to add a parental permission gate
  • Block direct access to external content (webview or link to Safari) in Kids category apps to add a parental permission gate
Example of an interceptor use on The Explorers app
With the action interceptor, you get everything you need to:
  • Get the action (and context)
  • Display views, errors, messages, … above our paywalls
  • Choose if Purchasely should continue the action or not
You can intercept the following buttons being tapped:
  • Close
  • Login
  • Navigate (web or deeplink)
  • Purchase
  • Restore
  • Open another paywall
  • Promo code

Implementation

The interceptor passes 4 parameters:
  1. 1.
    action, the PLYPresentationAction enum that gives the type of action
  2. 2.
    parameters, a dictionary that contains the objects needed to perform the action (like a PLYPlan for a purchase)
  3. 3.
    info, the PLYPresentationInfo object containing the controller of the paywall to dismiss it or display content / error messages above it, and the presentation id and content id associated to this paywall
  4. 4.
    proceed a completion handler parameter with a boolean telling Purchasely if it should continue the action itself.
    i.e. : Returning true on a purchase action will lead Purchasely to trigger the purchase
On a login action, call proceed(true) to refresh the paywall if the user has logged in
If you don't handle every action, you HAVE TO call proceed(true) otherwise the bouton will keep spinning and nothing will happen.
Swift
Objective-C
Kotlin
Java
React Native
Cordova
Flutter
1
Purchasely.setPaywallActionsInterceptor { [weak self] (action, parameters, info, proceed) in
2
3
switch action {
4
5
// Intercept the tap on login
6
case .login:
7
// When the user has completed the process
8
// Pass true to reload the paywall if user is logged in
9
self?.presentLogin(above: info?.controller) { (loggedIn) in
10
Purchasely.userLogin(with: "MY_USER_ID")
11
proceed(loggedIn)
12
}
13
14
// Intercept the tap on purchase to display the terms and condition
15
case .purchase:
16
self?.presentTermsAndConditions(above: info?.controller) { (userAcceptedTerms) in
17
proceed(userAcceptedTerms)
18
}
19
default:
20
proceed(true)
21
break
22
}
23
}
24
Copied!
1
[Purchasely setPaywallActionsInterceptor:^(enum PLYPresentationAction action, PLYPresentationActionParameters *parameters, PLYPresentationInfo *info, void (^ proceed)(BOOL)) {
2
switch (action) {
3
4
// Intercept the tap on login
5
case PLYPresentationActionLogin:{
6
// When the user has completed the process
7
//Pass true to reload the paywall if user is logged in
8
9
[self presentLoginAbove:info.controller completion:^(BOOL loggedIn) {
10
[Purchasely userLoginWith:@"MY_USER_ID"];
11
proceed(loggedIn);
12
}];
13
break;
14
}
15
16
// Intercept the tap on purchase to display the terms and condition
17
case PLYPresentationActionPurchase:{
18
[self presentTermsAndConditionsAbove:info.controller completion:^(BOOL userAcceptedTerms) {
19
proceed(userAcceptedTerms);
20
}];
21
break;
22
}
23
default:
24
proceed(YES);
25
break;
26
}
27
}];
Copied!
1
Purchasely.setPaywallActionsInterceptor { info, action, parameters, processAction ->
2
if (info?.activity == null) return@setPaywallActionsInterceptor
3
4
when(action) {
5
PLYPresentationAction.PURCHASE -> {
6
presentTermsAndConditions(info.activity) { userAcceptedTerms ->
7
// Don't forget to notify the SDK by calling `processAction`
8
processAction(userAcceptedTerms)
9
}
10
PLYPresentationAction.LOGIN -> {
11
// Call your method to display your view
12
// and return boolean result to userLoggedIn
13
presentLogin(info.activity) { userLoggedIn ->
14
Purchasely.userLogin("MY_USER_ID")
15
// Pass true to reload the paywall if user is logged in
16
processAction(userLoggedIn)
17
}
18
}
19
else -> {
20
Log.d("PLYActionInterceptor", action.value + " " + parameters)
21
processAction(true)
22
}
23
}
24
}
Copied!
1
Purchasely.setPaywallActionsInterceptor((info, action, parameters, listener) -> {
2
//if there is no activity then there is nothing to display
3
if (info == null || info.getActivity() == null) return;
4
5
switch (action) {
6
case PURCHASE:
7
//present your terms and call
8
//listener.processAction(true) if accepted
9
//or listener.processAction(false) if not to cancel purchase
10
presentTermsAndConditions(info.getActivity(), listener);
11
break;
12
case LOGIN:
13
// call your method to display your view
14
// and return boolean result to listener
15
// Pass true to reload the paywall if user is logged in
16
// listener.processAction(true);
17
presentLogin(info.getActivity(), listener);
18
break;
19
default:
20
listener.processAction(true);
21
}
22
});
Copied!
1
Purchasely.setPaywallActionInterceptorCallback((result) => {
2
console.log('Received action from paywall ' + result.info.presentationId);
3
4
if (result.action === PLYPaywallAction.NAVIGATE) {
5
console.log(
6
'User wants to navigate to website ' +
7
result.parameters.title +
8
' ' +
9
result.parameters.url
10
);
11
Purchasely.onProcessAction(true);
12
} else if (result.action === PLYPaywallAction.CLOSE) {
13
console.log('User wants to close paywall');
14
Purchasely.onProcessAction(true);
15
} else if (result.action === PLYPaywallAction.LOGIN) {
16
console.log('User wants to login');
17
//Present your own screen for user to log in
18
Purchasely.closePaywall();
19
Purchasely.userLogin('MY_USER_ID');
20
//Call this method to update Purchasely Paywall
21
Purchasely.onProcessAction(true);
22
} else if (result.action === PLYPaywallAction.OPEN_PRESENTATION) {
23
console.log('User wants to open a new paywall');
24
Purchasely.onProcessAction(true);
25
} else if (result.action === PLYPaywallAction.PURCHASE) {
26
console.log('User wants to purchase');
27
//If you want to intercept it, close paywall and display your screen
28
Purchasely.closePaywall();
29
} else if (result.action === PLYPaywallAction.RESTORE) {
30
console.log('User wants to restore his purchases');
31
Purchasely.onProcessAction(true);
32
} else {
33
console.log('Action unknown ' + result.action);
34
Purchasely.onProcessAction(true);
35
}
36
});
Copied!
1
Purchasely.setPaywallActionInterceptor((result) => {
2
console.log('Received action from paywall' + result.info.presentationId);
3
4
if (result.action === Purchasely.PaywallAction.navigate) {
5
console.log(
6
'User wants to navigate to website ' +
7
result.parameters.title +
8
' ' +
9
result.parameters.url
10
);
11
Purchasely.onProcessAction(true);
12
} else if (result.action === Purchasely.PaywallAction.close) {
13
console.log('User wants to close paywall');
14
Purchasely.onProcessAction(true);
15
} else if (result.action === Purchasely.PaywallAction.login) {
16
console.log('User wants to login');
17
//Present your own screen for user to log in
18
Purchasely.closePaywall();
19
Purchasely.userLogin('MY_USER_ID');
20
//Call this method to update Purchasely Paywall
21
Purchasely.onProcessAction(true);
22
} else if (result.action === Purchasely.PaywallAction.open_presentation) {
23
console.log('User wants to open a new paywall');
24
Purchasely.onProcessAction(true);
25
} else if (result.action === Purchasely.PaywallAction.purchase) {
26
console.log('User wants to purchase');
27
//If you want to intercept it, close paywall and display your screen
28
Purchasely.closePaywall();
29
} else if (result.action === Purchasely.PaywallAction.restore) {
30
console.log('User wants to restore his purchases');
31
Purchasely.onProcessAction(true);
32
} else {
33
console.log('Action unknown ' + result.action);
34
Purchasely.onProcessAction(true);
35
}
36
});
Copied!
1
Purchasely.setPaywallActionInterceptorCallback(
2
(PaywallActionInterceptorResult result) {
3
if (result.action == PLYPaywallAction.navigate) {
4
print('User wants to navigate');
5
Purchasely.onProcessAction(true);
6
} else if (result.action == PLYPaywallAction.close) {
7
print('User wants to close paywall');
8
Purchasely.onProcessAction(false);
9
} else if (result.action == PLYPaywallAction.login) {
10
print('User wants to login');
11
//Present your own screen for user to log in
12
Purchasely.closePaywall();
13
Purchasely.userLogin('MY_USER_ID');
14
//Call this method to update Purchasely Paywall
15
Purchasely.onProcessAction(true);
16
} else if (result.action == PLYPaywallAction.open_presentation) {
17
print('User wants to open a new paywall');
18
Purchasely.onProcessAction(true);
19
} else if (result.action == PLYPaywallAction.purchase) {
20
print('User wants to purchase');
21
//If you want to intercept it, close paywall and display your screen
22
Purchasely.closePaywall();
23
Purchasely.onProcessAction(false);
24
} else if (result.action == PLYPaywallAction.restore) {
25
print('User wants to restore his purchases');
26
Purchasely.onProcessAction(true);
27
} else {
28
print('Action unknown ' + result.action.toString());
29
Purchasely.onProcessAction(true);
30
}
31
});
Copied!
Copier le lien
Éditer sur GitHub