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

in app messages support #1290

Merged
merged 7 commits into from
Sep 26, 2023

Conversation

aboedo
Copy link
Member

@aboedo aboedo commented Sep 25, 2023

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 in PurchasesConfiguration to display those messages automatically.

image

@aboedo aboedo self-assigned this Sep 25, 2023
* If this setting is disabled, you can show the toast by calling
* [Purchases.showDeclinedPaymentMessageIfNeeded]
*/
fun showDeclinedPaymentMessagesAutomatically(showDeclinedPaymentMessagesAutomatically: Boolean) = apply {
Copy link
Member Author

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

Copy link
Contributor

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) {
Copy link
Member Author

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

Copy link
Contributor

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

@aboedo aboedo added the pr:feat A new feature label Sep 25, 2023
@@ -753,6 +756,25 @@ internal class BillingWrapper(

override fun isConnected(): Boolean = billingClient?.isReady ?: false

override fun showInAppMessagesIfNeeded(activity: Activity) {
Copy link
Contributor

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 {
Copy link
Contributor

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

val inAppMessageParams = InAppMessageParams.newBuilder()
.addInAppMessageCategoryToShow(InAppMessageParams.InAppMessageCategoryId.TRANSACTIONAL)
.build()
val weakActivity = WeakReference(activity)
Copy link
Contributor

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.

@tonidero tonidero marked this pull request as ready for review September 26, 2023 09:03
@tonidero tonidero requested a review from a team September 26, 2023 09:03
@tonidero tonidero marked this pull request as draft September 26, 2023 10:44
@tonidero tonidero marked this pull request as ready for review September 26, 2023 11:20
@codecov
Copy link

codecov bot commented Sep 26, 2023

Codecov Report

Attention: 14 lines in your changes are missing coverage. Please review.

Comparison is base (be660b2) 85.94% compared to head (a8eb16f) 85.82%.

❗ Current head a8eb16f differs from pull request most recent head ed89ca6. Consider uploading reports for the commit ed89ca6 to get more accurate results

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     
Files Coverage Δ
...com/revenuecat/purchases/PurchasesConfiguration.kt 89.39% <100.00%> (+1.06%) ⬆️
...otlin/com/revenuecat/purchases/PurchasesFactory.kt 85.79% <100.00%> (+0.08%) ⬆️
.../com/revenuecat/purchases/PurchasesOrchestrator.kt 83.47% <100.00%> (+0.32%) ⬆️
...com/revenuecat/purchases/common/BillingAbstract.kt 100.00% <ø> (ø)
...com/revenuecat/purchases/strings/BillingStrings.kt 0.00% <ø> (ø)
...n/com/revenuecat/purchases/amazon/AmazonBilling.kt 62.96% <0.00%> (-0.30%) ⬇️
...otlin/com/revenuecat/purchases/common/AppConfig.kt 81.96% <75.00%> (-0.49%) ⬇️
.../com/revenuecat/purchases/google/BillingWrapper.kt 83.60% <68.75%> (-0.52%) ⬇️
.../purchases/utils/CustomActivityLifecycleHandler.kt 0.00% <0.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tonidero tonidero enabled auto-merge (squash) September 26, 2023 14:44
@tonidero tonidero disabled auto-merge September 26, 2023 14:49
@tonidero tonidero merged commit e7bbdcd into main Sep 26, 2023
@tonidero tonidero deleted the andy/sdk-3266-android-support-showing-inapp-messages branch September 26, 2023 15:03
@tonidero tonidero added the pr:breaking Changes that are breaking label Sep 26, 2023
tonidero added a commit that referenced this pull request Sep 27, 2023
### 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.
@MarkVillacampa MarkVillacampa mentioned this pull request Sep 27, 2023
MarkVillacampa added a commit that referenced this pull request Sep 28, 2023
### 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:breaking Changes that are breaking pr:feat A new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants