Setup
There aren't really any setup step. As long as you already integrated and setup the Payment module of this package, you can just use the code in the Usage section to display the paywall.
Usage
At any point of your app, use the following snippet to load the paywall:
Payment.shared.isUserSubscribed { subscribed in
let monthlyPrice: NSDecimalNumber = Payment.shared.getPriceForProduct(productId: Payment.MONTHLY)
let yearlyPrice: NSDecimalNumber = Payment.shared.getPriceForProduct(productId: Payment.YEARLY)
let lifetimePrice: NSDecimalNumber = Payment.shared.getPriceForProduct(productId: Payment.LIFETIME)
let monthlyLocalizedPrice: String = Payment.shared.getLocalizedPriceForProduct(productId: Payment.MONTHLY)
let yearlyLocalizedPrice: String = Payment.shared.getLocalizedPriceForProduct(productId: Payment.YEARLY)
let lifetimeLocalizedPrice: String = Payment.shared.getLocalizedPriceForProduct(productId: Payment.LIFETIME)
let paywall = PaywallViewControllerFactory.init(source: "onboarding", monthlyPrice: monthlyPrice, yearlyPrice: yearlyPrice, lifetimePrice: lifetimePrice, isUserSubscribed: subscribed, monthlyLocalizedPrice: monthlyLocalizedPrice, yearlyLocalizedPrice: yearlyLocalizedPrice, lifetimeLocalizedPrice: lifetimeLocalizedPrice).build()
paywall.modalPresentationStyle = .fullScreen
self.present(paywall, animated: true)
}
Important notes
You should only use the above code after your AppDelegate starts the Payment service AND all products have been loaded.
The payment service dispatches a notification IAP_PRODUCTS_DID_LOAD_NOTIFICATION
you can listen to in order to know when products are ready.
For instance:
if Payment.shared.products.isEmpty {
NotificationCenter.default.addObserver(self, selector: #selector(productsReady(notification:)), name: IAP_PRODUCTS_DID_LOAD_NOTIFICATION, object: nil)
Payment.shared.start()
} else {
productsReady(notification: nil)
}
And then:
@objc private func productsReady(notification: Notification?) {
Payment.shared.isUserSubscribed { subscribed in
let monthlyPrice: NSDecimalNumber = Payment.shared.getPriceForProduct(productId: Payment.MONTHLY)
let yearlyPrice: NSDecimalNumber = Payment.shared.getPriceForProduct(productId: Payment.YEARLY)
let lifetimePrice: NSDecimalNumber = Payment.shared.getPriceForProduct(productId: Payment.LIFETIME)
let monthlyLocalizedPrice: String = Payment.shared.getLocalizedPriceForProduct(productId: Payment.MONTHLY)
let yearlyLocalizedPrice: String = Payment.shared.getLocalizedPriceForProduct(productId: Payment.YEARLY)
let lifetimeLocalizedPrice: String = Payment.shared.getLocalizedPriceForProduct(productId: Payment.LIFETIME)
DispatchQueue.main.async { [self] in
let paywall = PaywallViewControllerFactory.init(source: "onboarding", monthlyPrice: monthlyPrice, yearlyPrice: yearlyPrice, lifetimePrice: lifetimePrice, isUserSubscribed: subscribed, monthlyLocalizedPrice: monthlyLocalizedPrice, yearlyLocalizedPrice: yearlyLocalizedPrice, lifetimeLocalizedPrice: lifetimeLocalizedPrice).build()
paywall.modalPresentationStyle = .fullScreen
self.present(paywall, animated: true)
}
}
}