Migrate to SDK v4.0.0

Introducing Promotional offers

At Purchasely, we believe that every app deserves to be profitable. That's why we're excited to announce the release of our new SDK version 4.0.0, which allows you to set promotional offers. This new version makes it easier than ever to create and manage effective promotional campaigns, helping you to increase your app's revenue.

Take note that : On Android, we have adopted Google Billing v5.2.1 and the minimum required Kotlin version is 1.6.0 On iOS, setting a StoreKit version is mandatory

Initialization update

The start method no longer includes the uiListener/uiDelegate and eventListener/eventDelegate configuration options as part of its initial configuration, but they can still be set after calling the start() method.

import Purchasely

Purchasely.start(withAPIKey: "API_KEY",
                         appUserId: "USER_ID",
                         runningMode: .full,
                         paywallActionsInterceptor: PLYPaywallActionsInterceptor,
                         storekitSettings: .storeKit2, // Set your StoreKit version
                         logLevel: .debug, // set to warning or error for release
                         initialized: PLYSuccessErrorClosure))
                         
// Paywall interceptor can be setted afterwards by calling
Purchasely.setPaywallActionsInterceptor { [weak self] (action, parameters, presentationInfo, proceed) in
}

// Set your ui listener
Purchasely.Purchasely.setUIDelegate(PLYUIDelegate?)

The attribute isReadyToPurchase , to indicate that your app is ready to open deeplinks, has been renamed to readyToOpenDeeplink

We have additionally changed the name of the method handle to isDeeplinkHandled

Purchasely.readyToOpenDeeplink(true)

Purchasely.isDeeplinkHandled(deeplink: "URL")

Methods for presentation display

Only with our bridges SDKs: ReactNative, Flutter and Unity Before you could call the method Purchasely.closePresentation() to hide the presentation or Purchasely.closePresentation(true) to close it We have changed those methods and added new ones to make it easier to manage and understand, see below

// Hide the presentation being display
// for example when you are in paywall action interceptor
// to display your own screen like a login screen
Purchasely.hidePresentation();

// Display the presentation previously hidden
Purchasely.showPresentation();

// Close the presentation
// cannot be displayed again until you call Purchasely.presentPresentation()
Purchasely.closePresentation();

Fetch presentation with context (Android only)

The methods FetchPresentation and FetchPresentationForPresentation have been updated as well. The previously required parameters Context and PLYPresentationResultHandler have been removed and are no longer necessary.

Purchasely.fetchPresentationForPlacement(placementId = "placementId") { presentation, error ->
    if(presentation?.type == PLYPresentationType.NORMAL || presentation?.type == PLYPresentationType.FALLBACK) {
        val paywallView = presentation?.buildView(context, viewProperties = PLYPresentationViewProperties(onClose = {
            //TODO remove paywallView from layout
        })) { result, plan ->
            // Paywall is closed, check result to know if a purchase happened
            when(result) {
                PLYProductViewResult.PURCHASED -> Log.d("Purchasely", "User purchased ${plan?.name}")
                PLYProductViewResult.CANCELLED -> Log.d("Purchasely", "User cancelled purchased")
                PLYProductViewResult.RESTORED -> Log.d("Purchasely", "User restored ${plan?.name}")
            }
        }
        
        // TODO Add paywallView to your layout to display it
    }
}

// You should always use a placement to display paywalls 
// but if you really need to display a specific paywall
// you can use properties to set the your paywall id
Purchasely.fetchPresentation(properties = PLYPresentationViewProperties(presentationId = "paywall_id")) { presentation, error ->
    if(presentation?.type == PLYPresentationType.NORMAL || presentation?.type == PLYPresentationType.FALLBACK) {
        val paywallView = presentation?.buildView(context, viewProperties = PLYPresentationViewProperties(onClose = {
            //TODO remove paywallView from layout
        })) { result, plan ->
            // Paywall is closed, check result to know if a purchase happened
            when(result) {
                PLYProductViewResult.PURCHASED -> Log.d("Purchasely", "User purchased ${plan?.name}")
                PLYProductViewResult.CANCELLED -> Log.d("Purchasely", "User cancelled purchased")
                PLYProductViewResult.RESTORED -> Log.d("Purchasely", "User restored ${plan?.name}")
            }
        }
        
        // TODO Add paywallView to your layout to display it
    }
}

Use Views instead of Fragments (Android only)

In this version, we have taken the step to entirely eliminate fragment-related methods that had been deprecated in our prior releases. Instead, opt for one of the view-related methods to display your presentations:

Purchasely.presentationView(...)

//or 

presentationViewForPlacement(...)

And to ensure coherence and consistency, we've gone ahead and renamed all classes, enums, and interfaces related to fragments.

Update Purchase method

By introducing offer to the purchase method as an optional parameter, we now support the ability to purchase a specific offer of a plan.

// Purchase with promotional offer    
Purchasely.purchaseWithPromotionalOffer(plan: <PLYPlan>,
                                        contentId: "contentId",
                                        storeOfferId: "storeOfferId") {
// Success completion block
} failure: { error in
// Failure completion block                    
}

Last updated

© Purchasely 2020-2023