-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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_purchase_android] Add UserChoiceBilling mode. #6162
Changes from all commits
3427813
b8dc1ed
8440a75
bfd7786
939545d
613f5f0
4f2ab49
8106192
6f583d0
4ca1aeb
b2e00ce
d88603e
818e800
e2d30da
02e7638
024bbf5
818adf2
10ad143
3c0067a
dda2a57
2e20b70
0e8bc5b
7efca0f
6b282f8
43e00d7
3df9dd5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -6,7 +6,10 @@ | |||
|
||||
import android.content.Context; | ||||
import androidx.annotation.NonNull; | ||||
import androidx.annotation.Nullable; | ||||
import com.android.billingclient.api.BillingClient; | ||||
import com.android.billingclient.api.UserChoiceBillingListener; | ||||
import io.flutter.Log; | ||||
import io.flutter.plugin.common.MethodChannel; | ||||
import io.flutter.plugins.inapppurchase.MethodCallHandlerImpl.BillingChoiceMode; | ||||
|
||||
|
@@ -15,11 +18,34 @@ final class BillingClientFactoryImpl implements BillingClientFactory { | |||
|
||||
@Override | ||||
public BillingClient createBillingClient( | ||||
@NonNull Context context, @NonNull MethodChannel channel, int billingChoiceMode) { | ||||
@NonNull Context context, | ||||
@NonNull MethodChannel channel, | ||||
int billingChoiceMode, | ||||
@Nullable UserChoiceBillingListener userChoiceBillingListener) { | ||||
BillingClient.Builder builder = BillingClient.newBuilder(context).enablePendingPurchases(); | ||||
if (billingChoiceMode == BillingChoiceMode.ALTERNATIVE_BILLING_ONLY) { | ||||
// https://developer.android.com/google/play/billing/alternative/alternative-billing-without-user-choice-in-app | ||||
builder.enableAlternativeBillingOnly(); | ||||
switch (billingChoiceMode) { | ||||
case BillingChoiceMode.ALTERNATIVE_BILLING_ONLY: | ||||
// https://developer.android.com/google/play/billing/alternative/alternative-billing-without-user-choice-in-app | ||||
builder.enableAlternativeBillingOnly(); | ||||
break; | ||||
case BillingChoiceMode.USER_CHOICE_BILLING: | ||||
if (userChoiceBillingListener != null) { | ||||
// https://developer.android.com/google/play/billing/alternative/alternative-billing-with-user-choice-in-app | ||||
builder.enableUserChoiceBilling(userChoiceBillingListener); | ||||
} else { | ||||
Log.e( | ||||
"BillingClientFactoryImpl", | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about enforcing this being an error case, instead of defaulting? I think I might be confusing for developers to default to Not a strong preference, though, as long as the messaging is clear There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After reading further, we should never reach this case right? We define the listener, and we basically do it as a pass through where we pass the And the only time that listener is null is when the Can't we instead move that logic where we construct the listener (lines 547-557 in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that we should not every hit this case as the code is currently written but I added the additional fallaback logic to protect against future bugs and give us a way to know that we were in a bad state. I didnt want to create the listener in this class because it needed to invoke methodChannel and I thought the methodchannelimpl class would be where you would look for that logic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Part of why I suggested this is that we have existing code where we do something similar to construct a listener in this plugin, see Line 39 in a10b360
I still lean towards moving the listener construction, so we can eliminate the bad case here, but if you have a strong preference to keep the structure as is I'm fine that way too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about a compromise. I am worried about the march 13th deadline for apps to |
||||
"userChoiceBillingListener null when USER_CHOICE_BILLING set. Defaulting to PLAY_BILLING_ONLY"); | ||||
} | ||||
break; | ||||
case BillingChoiceMode.PLAY_BILLING_ONLY: | ||||
// Do nothing. | ||||
break; | ||||
default: | ||||
Log.e( | ||||
"BillingClientFactoryImpl", | ||||
"Unknown BillingChoiceMode " + billingChoiceMode + ", Defaulting to PLAY_BILLING_ONLY"); | ||||
break; | ||||
} | ||||
return builder.setListener(new PluginPurchaseListener(channel)).build(); | ||||
} | ||||
|
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.
Should this have a docs link too, like the above?
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.
Done