-
Notifications
You must be signed in to change notification settings - Fork 53
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
in app messages support #1290
in app messages support #1290
Conversation
purchases/src/customEntitlementComputation/kotlin/com/revenuecat/purchases/Purchases.kt
Outdated
Show resolved
Hide resolved
* If this setting is disabled, you can show the toast by calling | ||
* [Purchases.showDeclinedPaymentMessageIfNeeded] | ||
*/ | ||
fun showDeclinedPaymentMessagesAutomatically(showDeclinedPaymentMessagesAutomatically: Boolean) = apply { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not married to the naming
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been thinking about it... From the documentation, this seems to be the only use case for inapp messages right now, but the naming in Google Play seems more generic, so I wonder if we should keep it generic as well and have it be showInAppMesssagesAutomatically
... Will keep it like this for now since it's clearer what's going to be doing for now, but we might need to rename it in the future if Google adds more functionality.
@@ -753,6 +756,25 @@ internal class BillingWrapper( | |||
|
|||
override fun isConnected(): Boolean = billingClient?.isReady ?: false | |||
|
|||
override fun showInAppMessagesIfNeeded(activity: Activity) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getting the activity might actually be tricky here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was able to get it by using an ActivityLifecycleCallback
in PurchasesOrchestrator
purchases/src/main/kotlin/com/revenuecat/purchases/google/BillingWrapper.kt
Outdated
Show resolved
Hide resolved
…lient inapp messages + other fixes
@@ -753,6 +756,25 @@ internal class BillingWrapper( | |||
|
|||
override fun isConnected(): Boolean = billingClient?.isReady ?: false | |||
|
|||
override fun showInAppMessagesIfNeeded(activity: Activity) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was able to get it by using an ActivityLifecycleCallback
in PurchasesOrchestrator
import android.os.Bundle | ||
|
||
@Suppress("EmptyFunctionBlock") | ||
internal interface CustomActivityLifecycleHandler : ActivityLifecycleCallbacks { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This interface just adds default empty implementations to all callbacks so we can just use the ones we need in PurchasesOrchestrator
purchases/src/customEntitlementComputation/kotlin/com/revenuecat/purchases/Purchases.kt
Outdated
Show resolved
Hide resolved
val inAppMessageParams = InAppMessageParams.newBuilder() | ||
.addInAppMessageCategoryToShow(InAppMessageParams.InAppMessageCategoryId.TRANSACTIONAL) | ||
.build() | ||
val weakActivity = WeakReference(activity) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using a weak reference here since I want to avoid any chance of leaking the activity if there is a problem connecting to the billing client.
purchases/src/main/kotlin/com/revenuecat/purchases/PurchasesConfiguration.kt
Outdated
Show resolved
Hide resolved
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #1290 +/- ##
==========================================
- Coverage 85.94% 85.82% -0.12%
==========================================
Files 184 185 +1
Lines 6274 6314 +40
Branches 911 916 +5
==========================================
+ Hits 5392 5419 +27
- Misses 536 546 +10
- Partials 346 349 +3
☔ View full report in Codecov by Sentry. |
purchases/src/main/kotlin/com/revenuecat/purchases/PurchasesConfiguration.kt
Outdated
Show resolved
Hide resolved
purchases/src/main/kotlin/com/revenuecat/purchases/strings/BillingStrings.kt
Outdated
Show resolved
Hide resolved
### Description Followup to #1290. This improves the API to future-proof them in case Google adds new in-app message types in the future. This is not a breaking change since the previous APIs haven't been released yet.
### Breaking Changes * Support for Billing Client 6 (#1209) via Mark Villacampa (@MarkVillacampa) * Bump minimum sdk version to Android 4.4 (API level 19) (#1265) via Mark Villacampa (@MarkVillacampa) * in app messages support (#1290) via Andy Boedo (@aboedo) ### Bugfixes * Add `awaitRestore` to customEntitlementComputation library (#1275) via Toni Rico (@tonidero) ### Other Changes * Future-proof in-app message APIs in case new types are added (#1293) via Toni Rico (@tonidero) * `Code style`: enabled `ALLOW_TRAILING_COMMA` (#1280) via NachoSoto (@NachoSoto)
This PR provides support for in app messages for declined payments with BillingClient. They can be shown using
Purchases.showDeclinedPaymentMessageIfNeeded
. It also provides an API inPurchasesConfiguration
to display those messages automatically.