Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated purchase logic #212

Merged
merged 1 commit into from
Aug 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,39 +90,6 @@ class QonversionSandwich(
// region Entitlements and Products

fun purchase(
productId: String,
offerId: String?,
applyOffer: Boolean?,
contextKeys: List<String>?,
resultListener: ResultListener
) {
val currentActivity = activityProvider.currentActivity
?: run {
resultListener.onError(noActivityForPurchaseError.toSandwichError())
return
}

val purchaseCallback = getEntitlementsCallback(resultListener)

Qonversion.shared.products(object: QonversionProductsCallback {
override fun onSuccess(products: Map<String, QProduct>) {
val product = products[productId]
if (product != null) {
val purchaseOptions = configurePurchaseOptions(offerId, applyOffer, contextKeys = contextKeys)

Qonversion.shared.purchase(currentActivity, product, purchaseOptions, purchaseCallback)
} else {
purchaseCallback.onError(QonversionError(QonversionErrorCode.ProductNotFound))
}
}

override fun onError(error: QonversionError) {
purchaseCallback.onError(error)
}
})
}

fun updatePurchase(
productId: String,
offerId: String?,
applyOffer: Boolean?,
Expand All @@ -143,10 +110,12 @@ class QonversionSandwich(
override fun onSuccess(products: Map<String, QProduct>) {
val product = products[productId]
val oldProduct = products[oldProductId]
if (product != null && oldProduct != null) {
val purchaseOptions = configurePurchaseOptions(offerId, applyOffer, oldProduct, updatePolicyKey, contextKeys)
val purchaseOptions = configurePurchaseOptions(offerId, applyOffer, oldProduct, updatePolicyKey, contextKeys)
Copy link
Collaborator

Choose a reason for hiding this comment

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

no more need in this method?


if (product != null && oldProduct != null) {
Qonversion.shared.updatePurchase(currentActivity, product, purchaseOptions, purchaseCallback)
} else if (product != null) {
Qonversion.shared.purchase(currentActivity, product, purchaseOptions, purchaseCallback)
} else {
purchaseCallback.onError(QonversionError(QonversionErrorCode.ProductNotFound))
}
Comment on lines +115 to 121
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if (product != null && oldProduct != null) {
Qonversion.shared.updatePurchase(currentActivity, product, purchaseOptions, purchaseCallback)
} else if (product != null) {
Qonversion.shared.purchase(currentActivity, product, purchaseOptions, purchaseCallback)
} else {
purchaseCallback.onError(QonversionError(QonversionErrorCode.ProductNotFound))
}
if (product == null) {
purchaseCallback.onError(QonversionError(QonversionErrorCode.ProductNotFound))
return
}
if (oldProduct == null) {
Qonversion.shared.purchase(currentActivity, product, purchaseOptions, purchaseCallback)
} else {
Qonversion.shared.updatePurchase(currentActivity, product, purchaseOptions, purchaseCallback)
}

i think that's more clear way

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We decided to leave it as it is.

Expand Down
Loading