Using No-Codes with custom purchases handling
By default, Qonversion No-Codes utilize the Qonversion SDK for managing purchases. This implies that you should operate Qonversion in subscription management mode. However, if you have your own purchasing infrastructure, you can manage purchases and restores from No-Code screens on your end. It’s as straightforward as supplying a single delegate to Qonversion No-Codes prior to showing the screen.
Integrating Qonversion No-Codes with your own purchasing infrastructure necessitates:
- creating a product within the Qonversion dashboard and associating it with a purchase action on your screen,
- implementing and providing a
PurchaseDelegateto Qonversion No-Codes that is responsible for managing purchase and restore requests from No-Code screens.
Implementing PurchaseDelegate
PurchaseDelegateTo handle purchase and restore requests from No-Code screens on your end, you should implement PurchaseDelegate. It has two simple methods - purchase, accepting the requested product, and restore.
extension MyPurchaseHandler: NoCodesPurchaseDelegate {
func purchase(product: Qonversion.Product) async throws {
// Execute the purchase as you wish here
// You can throw exceptions in case of errors
}
func restore() async throws {
// Execute the restore as you wish here
// You can throw exceptions in case of errors
}
}// You can use either coroutine interface as follows:
class MyPurchasesHandler : PurchaseDelegate {
override suspend fun purchase(product: QProduct) {
// Execute the purchase as you wish here
// You can throw exceptions in case of errors
}
override suspend fun restore() {
// Execute the restore as you wish here
// You can throw exceptions in case of errors
}
}
// Or you can use callbacks interface:
class MyPurchaseHandler : PurchaseDelegateWithCallbacks {
override fun purchase(
product: QProduct,
onSuccess: PurchaseDelegateWithCallbacks.OnSuccess,
onError: PurchaseDelegateWithCallbacks.OnError
) {
// Execute the purchase as you wish here
// And call onSuccess once everything is done to close the No-Code screen
onSuccess()
// Call onError with exception in case of error.
}
override fun restore(
onSuccess: PurchaseDelegateWithCallbacks.OnSuccess,
onError: PurchaseDelegateWithCallbacks.OnError
) {
// Execute the restore as you wish here
// And call onSuccess once everything is done to close the No-Code screen
onSuccess()
// Call onError with exception in case of error.
}
}class MyPurchasesHandler implements PurchaseDelegateWithCallbacks {
@Override
public void purchase(@NonNull QProduct product, @NonNull OnSuccess onSuccess, @NonNull OnError onError) {
// Execute the purchase as you wish here
// And call onSuccess once everything is done to close the No-Code screen
onSuccess.invoke();
// Call onError with exception in case of error.
}
@Override
public void restore(@NonNull OnSuccess onSuccess, @NonNull OnError onError) {
// Execute the restore as you wish here
// And call onSuccess once everything is done to close the No-Code screen
onSuccess.invoke()
// Call onError with exception in case of error.
}
}Providing PurchaseDelegate
PurchaseDelegateOnce you've implemented the PurchaseDelegate, you need to provide it to Qonversion No-Codes. There are two equal ways to do it - during the initialization via configuration or after - via the No-Codes method.
// Providing during the initialization
let purchaseDelegate = MyPurchaseHandler()
let configuration = NoCodesConfiguration(projectKey: "projectKey", purchaseDelegate: purchaseDelegate)
NoCodes.initialize(with: configuration)
// Or after initialization
let purchaseDelegate = MyPurchaseHandler()
NoCodes.shared.set(purchaseDelegate: purchaseDelegate)// Providing during the initialization
val purchaseDelegate = MyPurchaseHandler()
val noCodesConfig = NoCodesConfig.Builder(this, "projectKey")
.setPurchaseDelegate(purchaseDelegate)
.build()
NoCodes.initialize(noCodesConfig)
// Or after initialization
val purchaseDelegate = MyPurchaseHandler()
NoCodes.shared.setPurchaseDelegate(purchaseDelegate)// Providing during the initialization
final PurchaseDelegateWithCallbacks purchaseDelegate = new MyPurchaseHandler();
final NoCodesConfig noCodesConfig = new NoCodesConfig.Builder(this, "projectKey")
.setPurchaseDelegate(purchaseDelegate)
.build();
NoCodes.initialize(noCodesConfig);
// Or after initialization
final PurchaseDelegateWithCallbacks purchaseDelegate = new MyPurchaseHandler();
NoCodes.getSharedInstance().setPurchaseDelegate(purchaseDelegate);Availability
The described feature is available in the following SDK versions
| Platform | SDK version |
|---|---|
| iOS | 6.1.0 |
| Android | No-Codes 1.2.1 |
Updated about 10 hours ago
