Purchasely
Rechercher…
SDK Implementation
The only required steps to get started with Purchasely
This is a simplified overview of our SDK implementation, you can find a more detailed one in SDK configurations section

Configuration

The start method must be called as soon as possible to catch every purchase / renewal.
Swift
Objective-C
Kotlin
Java
React Native
Cordova
Flutter
1
import Purchasely
2
3
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
4
Purchasely.start(withAPIKey: "API_KEY,
5
appUserId: nil,
6
runningMode: .full,
7
eventDelegate: nil,
8
logLevel: .debug) { (success, error) in
9
print(success)
10
}
11
return true
12
}
Copied!
1
#import <Purchasely/Purchasely-Swift.h>
2
3
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
4
// Override point for customization after application launch.
5
6
[Purchasely startWithAPIKey:@"API_KEY"
7
appUserId:@"USER_ID"
8
runningMode: PLYRunningModeFull
9
eventDelegate:nil
10
uiDelegate:nil
11
paywallActionsInterceptor:nil
12
logLevel: LogLevelInfo
13
initialized: nil];
14
return YES;
15
}
Copied!
1
import io.purchasely.ext.Purchasely
2
3
Purchasely.Builder(applicationContext)
4
.apiKey("API_KEY")
5
.logLevel(LogLevel.DEBUG) // set to warning or error for release
6
.userId("USER_ID")
7
.eventListener(eventListener)
8
.runningMode(PLYRunningMode.Full)
9
.stores(listOf(GoogleStore(), HuaweiStore()))
10
.build()
11
12
// When you are ready for Purchasely to initialize,
13
// you must call start() method that will grab configuration and products
14
// from the selected stores.
15
Purchasely.start { isConfigured ->
16
}
Copied!
1
List<Store> stores = new ArrayList();
2
stores.add(new GoogleStore(), new HuaweiStore());
3
4
new Purchasely.Builder(getApplicationContext())
5
.apiKey("API_KEY")
6
.logLevel(LogLevel.DEBUG) // set to warning or error for release
7
.userId("USER_ID")
8
.eventListener(this)
9
.runningMode(PLYRunningMode.Full.INSTANCE)
10
.stores(stores)
11
.build();
12
13
// When you are ready for Purchasely to initialize,
14
// you must call start() method that will grab configuration and products
15
// from the selected stores.
16
Purchasely.start(isConfigured -> {
17
null;
18
});
Copied!
1
import Purchasely from 'react-native-purchasely';
2
3
/**
4
* @params String apiKey
5
* @params StringArray stores : may be Google, Amazon and Huawei
6
* @params String userId
7
* @params Purchasley.LogLevel logLevel
8
* @params RunningMode runningMode
9
**/
10
Purchasely.startWithAPIKey(
11
'API_KEY',
12
['Google'],
13
'USER_ID',
14
Purchasely.logLevelDebug,
15
RunningMode.FULL
16
);
17
Copied!
1
/**
2
* @params String apiKey
3
* @params StringArray stores : may be Google, Amazon and Huawei
4
* @params String userId
5
* @params Purchasley.LogLevel logLevel
6
* @params Purchasely.RunningMode runningMode
7
**/
8
Purchasely.startWithAPIKey(
9
'API_KEY',
10
['Google'],
11
null,
12
Purchasely.LogLevel.DEBUG,
13
Purchasely.RunningMode.full
14
);
Copied!
1
/**
2
* @params String apiKey
3
* @params StringArray stores : may be Google, Amazon and Huawei
4
* @params String userId
5
* @params PLYLogLevel logLevel
6
* @params PLYRunningMode runningMode
7
**/
8
bool configured = await Purchasely.startWithApiKey(
9
'API_KEY',
10
['Google'],
11
null,
12
PLYLogLevel.debug,
13
PLYRunningMode.full
14
);
15
16
if (!configured) {
17
print('Purchasely SDK not configured');
18
return;
19
}
Copied!
The userID parameter is optional and allows you to associate the purchase to a user instead of a device.

Display a placement

Paywalls are displayed by calling a Placement.
A Placement represents a specific location in your user journey inside your app (e.g. Onboarding, Settings, Home page, Article). A placement is linked to a paywall and a single paywall can be used for different Placements. You can create as many Placements as you want, and this is the only thing that ties the app developer to the marketer.
Once the placements are defined and called from the app, you can change the displayed paywall remotely without any developer action.
Swift
Objective-C
Kotlin
Java
React Native
Cordova
Flutter
1
let placementId = "ONBOARDING"
2
paywallCtrl = Purchasely.presentationController(for: placementId, contentId: contentId, loaded: { _, _, _ in
3
}, completion: completion)
Copied!
1
UIViewController *paywallCtrl = [Purchasely presentationControllerFor:@"my_placement_id"
2
contentId:@"my_content_id"
3
completion:^(enum PLYProductViewControllerResult result, PLYPlan * _Nullable plan) {
4
}];
5
Copied!
1
val placementId = "onboarding"
2
val contentId = "my_content_id" //or null
3
Purchasely.presentationFragmentForPlacement(placementId, contentId) { result, plan ->
4
Log.d("Purchasely", "Result is $result with plan $plan")
5
}
Copied!
1
String placementId = "onboarding"
2
String contentId = "my_content_id" //or null
3
Purchasely.presentationFragmentForPlacement(placementId, contentId);
Copied!
1
await Purchasely.presentPresentationForPlacement({
2
placementVendorId: 'onboarding',
3
contentId: 'my_content_id',
4
isFullscreen: true,
5
});
Copied!
1
Purchasely.presentPresentationForPlacement('onboarding');
Copied!
1
await Purchasely.presentPresentationForPlacement('onboarding');
Copied!

Unlock content

With the method to display a placement, you get the result of the user action on the paywall.
  • Cancelled: User did not purchase a plan
  • Restored: User restored a previous purchased plan
  • Purchased: User purchased a plan which was validated by the store and your webhook
You also have as a second argument the plan bought or restored by the user, it is set to nil if no purchase was made.
Swift
Objective-C
Kotlin
Java
React Native
Cordova
Flutter
1
let paywallCtrl = Purchasely.presentationController(
2
for: "my_placement_id",
3
contentId: "my_content_id",
4
completion: { (result, plan) in
5
switch result {
6
case .purchased:
7
print("User purchased: \(plan?.name)")
8
break
9
case .restored:
10
print("User restored: \(plan?.name)")
11
break
12
case .cancelled:
13
break
14
@unknown default:
15
break
16
}
17
})
Copied!
1
UIViewController *paywallCtrl = [Purchasely presentationControllerWith:@"my_presentation_id"
2
contentId:@"my_content_id"
3
completion:^(enum PLYProductViewControllerResult result, PLYPlan * _Nullable plan) {
4
5
}];
6
[self presentViewController:paywallCtrl animated:YES completion:nil];
Copied!
1
Purchasely.presentationFragmentForPlacement(
2
placementId = "my_placement_id",
3
contentId = "my_content_id",
4
callbackLoaded = { isLoaded -> }
5
) { result, plan ->
6
when(result) {
7
PLYProductViewResult.PURCHASED -> Log.d("Purchasely", "User purchased ${plan?.name}")
8
PLYProductViewResult.CANCELLED -> Log.d("Purchasely", "User cancelled purchased")
9
PLYProductViewResult.RESTORED -> Log.d("Purchasely", "User restored ${plan?.name}")
10
}
11
12
}
Copied!
1
Purchasely.presentationFragmentForPlacement(
2
"my_placement_id",
3
"my_content_id",
4
isLoaded -> null,
5
(result, plan) -> {
6
switch (result) {
7
case PURCHASED:
8
Log.d("Purchasely", "User purchased" + plan.getName());
9
break;
10
case RESTORED:
11
Log.d("Purchasely", "User restored" + plan.getName());
12
break;
13
case CANCELLED:
14
Log.d("Purchasely", "User cancelled purchase");
15
break;
16
}
17
}
18
);
Copied!
1
try {
2
const result = await Purchasely.presentPresentationForPlacement({
3
placementVendorId: 'onboarding',
4
isFullscreen: true,
5
});
6
7
switch (result.result) {
8
case ProductResult.PRODUCT_RESULT_PURCHASED:
9
case ProductResult.PRODUCT_RESULT_RESTORED:
10
if (result.plan != null) {
11
console.log('User purchased ' + result.plan.name);
12
}
13
break;
14
case ProductResult.PRODUCT_RESULT_CANCELLED:
15
break;
16
}
17
} catch (e) {
18
console.error(e);
19
}
Copied!
1
Purchasely.presentPresentationForPlacement(
2
'onboarding', //placementId
3
null, //contentId
4
true, //fullscreen
5
(callback) => {
6
if(callback.result == Purchasely.PurchaseResult.PURCHASED) {
7
console.log("User purchased " + callback.plan.name);
8
} else if(callback.result == Purchasely.PurchaseResult.RESTORED) {
9
console.log("User restored " + callback.plan.name);
10
} else if(callback.result == Purchasely.PurchaseResult.CANCELLED) {
11
console.log("User cancelled purchased");
12
}
13
},
14
(error) => {
15
console.log("Error with purchase : " + error);
16
}
17
);
Copied!
1
try {
2
var result = await Purchasely.presentPresentationForPlacement(
3
"onboarding",
4
isFullscreen: true);
5
6
switch (result.result) {
7
case PLYPurchaseResult.purchased:
8
print('User purchased: ${result.plan?.name}');
9
break;
10
case PLYPurchaseResult.restored:
11
print('User restored: ${result.plan?.name}');
12
break;
13
case PLYPurchaseResult.cancelled:
14
print("User cancelled purchased");
15
break;
16
}
17
} catch (e) {
18
print(e);
19
}
Copied!
Copier le lien
Éditer sur GitHub