Skip to content

Conversation

@suriksarkisyan
Copy link
Contributor

No description provided.

@suriksarkisyan suriksarkisyan changed the base branch from develop to ssarkisyan/dev-69-sdk-skeleton-loading-on-android October 27, 2025 13:32
Base automatically changed from ssarkisyan/dev-69-sdk-skeleton-loading-on-android to feature/screensPreloading October 28, 2025 10:05
Base automatically changed from feature/screensPreloading to develop October 28, 2025 10:32
})
}

private fun handlePurchaseResult(result: QPurchaseResult) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename to "handlePurchaseError"


/**
* Purchase a product and validate it through server-to-server using Qonversion's Backend.
* This is the new recommended method that returns a single PurchaseResult object containing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and below let's use linking syntax for class name

* all relevant information about the purchase outcome.
* @param context current activity context
* @param product product for purchase
* @param options optional purchase options (can be null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is no need to add (can be null) after optional

Comment on lines 1 to 17
package com.qonversion.android.sdk.dto

/**
* Enum representing the type of purchase completion callback.
* Used to distinguish between legacy callback methods and new result-based methods.
*/
enum class QPurchaseCompletionType {
/**
* Legacy callback type with separate parameters for entitlements, error, and cancellation status
*/
LEGACY,

/**
* New result-based callback type with a single PurchaseResult object
*/
RESULT
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really like this approach with having multiple callback types. I think the best option is to wrap each type of callbacks into internal callback that will be used in the internal logic and will prepare results depending on which callback it was initialized with. This way we will avoid the necessity of this class and all the corresponding spaghetti with lots of ifs, arrays and method duplications

Comment on lines 93 to 103
/**
* Called when the purchase operation completes successfully
* @param result PurchaseResult containing entitlements and purchase details
*/
fun onSuccess(result: QPurchaseResult)

/**
* Called when the purchase operation fails
* @param result PurchaseResult containing error information
*/
fun onError(result: QPurchaseResult)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need two methods here. Single onResult is enough as the provided object contains all the necessary information about both success and error states. What is crucial is can there be both error and entitlements? If so, then we need sort of description about the source of entitlements. I think, it would be useful to specify if we've received the entitlements from the API, created them manually locally, or didn't get because of error. Sort of enum with these three values that will be included in result. Or two boolean fields: isSuccessful, isFallbackGenerated. Or even both approaches together - enum with two utility properties.

Because we can't just refer to the error field to decide if it was successful purchase or not. As in fallback scenario there can be both error and entitlements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants