Copy class PLYPresentation(
id: String?
placementId: String?
audienceId: String?
abTestId: String?
abTestVariantId: String?
language: String?
type: PLYPresentationType
plans: [String] // get PLYPlan instance with Purchasely.plan("planId")
// Android SDK only (Kotlin or Java)
view: PLYTemplateView?
// iOS SDK only (Swift or Objective-C)
controller: UIViewController?
}
Swift Objective-C Kotlin Java React Native Flutter Cordova Unity
Copy // fetch presentation with id
Purchasely.fetchPresentation(with: "presentationId", fetchCompletion: { presentation, error in
})
// fetch presentation for placement
Purchasely.fetchPresentation(for: "onboarding", fetchCompletion: { presentation, error in
guard let presentation = presentation, error == nil else {
print("Error while fetching presentation: \(error?.localizedDescription ?? "unknown")")
return
}
if presentation.type == .normal || presentation.type == .fallback {
let paywallController = presentation.controller
// display paywall controller.
} else if presentation.type == .deactivated {
// nothing to display
} else if presentation.type == .client {
let presentationId = presentation.id
let planIds = presentation.plans
// display your own paywall
}
})
Copy [Purchasely fetchPresentationFor:@"onboarding" fetchCompletion:^(PLYPresentation * _Nullable presentation, NSError * _Nullable error) {
if (error != nil) {
NSLog(@"Error while fetching presentation: %@", error.localizedDescription);
return;
}
if (presentation.type == PLYPresentationTypeNormal || presentation.type == PLYPresentationTypeFallback) {
PLYPresentationViewController *paywallController = presentation.controller;
// display paywall controller.
} else if (presentation.type == PLYPresentationTypeDeactivated) {
// nothing to display
} else if (presentation.type == PLYPresentationTypeClient) {
NSString *presentationId = presentation.id;
NSArray<NSString *> *plans = presentation.plans;
//display your own paywall
}
} completion:nil];
Copy Purchasely.fetchPresentationForPlacement("onboarding") { presentation, error ->
if(error != null) {
Log.d("Purchasely", "Error fetching paywall", error)
return@fetchPresentationForPlacement
}
when(presentation?.type) {
PLYPresentationType.NORMAL,
PLYPresentationType.FALLBACK -> {
val paywallView = presentation.buildView(
context = this@MainActivity,
viewProperties = PLYPresentationViewProperties(
onClose = {
// TODO remove view
}
)
)
// Display Purchasely paywall
}
PLYPresentationType.DEACTIVATED -> {
// Nothing to display
}
PLYPresentationType.CLIENT -> {
val paywallId = presentation.id
val planIds = presentation.plans
// Display your own paywall
}
else -> {
//No presentation, it means an error was triggered
}
}
}
Copy Purchasely.fetchPresentationForPlacement(
this,
"onboarding",
null,
(presentation, error) -> {
if(error != null) {
Log.d("Purchasely", "Error fetching paywall", error);
return null;
}
if(presentation.getType() == PLYPresentationType.NORMAL
|| presentation.getType() == PLYPresentationType.FALLBACK) {
// display Purchasely paywall
PLYTemplateView paywallView = presentation.view
}
if(presentation.getType() == PLYPresentationType.DEACTIVATED) {
// nothing to display
}
if(presentation.getType() == PLYPresentationType.CLIENT) {
String paywallId = presentation.getId();
List<String> planIds = presentation.getPlans();
// Display your own paywall
}
return null;
}
);
Copy try {
// Fetch presentation to display
const presentation = await Purchasely.fetchPresentation({
placementId: 'onboarding'
})
if(presentation.type == PLYPresentationType.DEACTIVATED) {
// No paywall to display
return
}
if(presentation.type == PLYPresentationType.CLIENT) {
// Display my own paywall
return
}
//Display Purchasely paywall
const result = await Purchasely.presentPresentation({
presentation: presentation
})
switch (result.result) {
case ProductResult.PRODUCT_RESULT_PURCHASED:
case ProductResult.PRODUCT_RESULT_RESTORED:
if (result.plan != null) {
console.log('User purchased ' + result.plan.name);
}
break;
case ProductResult.PRODUCT_RESULT_CANCELLED:
console.log('User cancelled');
break;
}
} catch (e) {
console.error(e);
}
Copy try {
var presentation = await Purchasely.fetchPresentation("ONBOARDING");
if (presentation == null) {
print("No presentation found");
return;
}
if (presentation.type == PLYPresentationType.deactivated) {
// No paywall to display
return;
}
if (presentation.type == PLYPresentationType.client) {
// Display my own paywall
return;
}
//Display Purchasely paywall
var presentResult = await Purchasely.presentPresentation(presentation,
isFullscreen: false);
switch (presentResult.result) {
case PLYPurchaseResult.cancelled:
{
print("User cancelled purchased");
}
break;
case PLYPurchaseResult.purchased:
{
print("User purchased ${presentResult.plan?.name}");
}
break;
case PLYPurchaseResult.restored:
{
print("User restored ${presentResult.plan?.name}");
}
break;
}
} catch (e) {
print(e);
}
Copy private PurchaselyRuntime.Purchasely _purchasely;
...
_purchasely.FetchPresentation("presentationId",
OnFetchPresentationSuccess,
Log,
"contentId");
...
private void OnFetchPresentationSuccess(Presentation presentation)
{
Log("Fetch Presentation Success.");
LogPresentation(presentation);
switch (presentation.presentationType)
{
case PresentationType.Normal:
case PresentationType.Fallback:
_purchasely.PresentPresentationWithId(presentation.id,
OnPresentationResult,
OnPresentationContentLoaded,
OnPresentationContentClosed);
break;
case PresentationType.Unknown:
case PresentationType.Deactivated:
Log($"Fetched presentation with type: {presentation.presentationType}. Will not show content.");
break;
case PresentationType.Client:
paywall.Show(presentation);
break;
}
}