Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
953338a
Enable alternitive billing only available check, add test and code to…
reidbaker Feb 2, 2024
8ab32cc
Enable alternative billing only during client creation and tests cove…
reidbaker Feb 2, 2024
4d06253
ShowAlternativeBillingDialog android native method added
reidbaker Feb 2, 2024
8d95e87
Add tests for null activity behavior
reidbaker Feb 2, 2024
3878b4f
Remove not needed lines of code
reidbaker Feb 2, 2024
e516655
Add showAlternativeBillingOnlyInformationDialog and isAlternativeBill…
reidbaker Feb 5, 2024
c8efd99
test showAlternativeBillingOnlyInformationDialog and isAlternativeBil…
reidbaker Feb 5, 2024
3bd6a95
add alternative billing only reporting details implementation and tests
reidbaker Feb 5, 2024
3e77c14
formatting and generated code
reidbaker Feb 5, 2024
b77152b
Changelog and version bump added
reidbaker Feb 5, 2024
8cacaef
Formatting
reidbaker Feb 5, 2024
d4c4454
Merge branch 'main' into i142618-alternitive-billing-api-intro
reidbaker Feb 6, 2024
2f91615
Update to api 34 (required to test end to end, update dependencies, f…
reidbaker Feb 6, 2024
fe7a677
Use 0.3.1 instead of 0+19
reidbaker Feb 6, 2024
95214de
Expose country code as labled button
reidbaker Feb 7, 2024
fd506c2
Expose other alternative apis as buttons in their own section
reidbaker Feb 7, 2024
6415bee
formatting
reidbaker Feb 7, 2024
448dd2c
Add test for BillingClientManager alternative billing only
reidbaker Feb 8, 2024
1524fe0
Add platform addition tests
reidbaker Feb 8, 2024
7507f02
Show the dialog result code
reidbaker Feb 8, 2024
2ae9119
Set alternative billing only to true in example app
reidbaker Feb 8, 2024
99b3baf
Speling mistake fix
reidbaker Feb 9, 2024
b72cd39
Merge branch 'main' into i142618-alternitive-billing-api-intro
reidbaker Feb 9, 2024
240df4a
revert dependencies since they conflict with integration_test
reidbaker Feb 9, 2024
0723af9
changelog copy change
reidbaker Feb 9, 2024
16ce293
Migrate to enum for alternative billing only and play billing
reidbaker Feb 9, 2024
dfbb6b7
java formatting
reidbaker Feb 9, 2024
d073552
Include generated code change
reidbaker Feb 9, 2024
8e041af
Use json conversion for sending object over wire
reidbaker Feb 9, 2024
fe9d77e
Change button text
reidbaker Feb 9, 2024
31788de
Merge branch 'main' into i142618-alternitive-billing-api-intro
reidbaker Feb 9, 2024
31008fa
billingChoiceMode instead of enableAlternatitveBillingOnly
reidbaker Feb 9, 2024
b59c645
billing choice converstion to java
reidbaker Feb 10, 2024
7b6b7a2
Code review feedback, documentation, formatting, spelling
reidbaker Feb 12, 2024
b144067
Add alternative billing only reporting details example code
reidbaker Feb 12, 2024
8450aaa
Changlog formatting
reidbaker Feb 12, 2024
9730db3
Merge branch 'main' into i142618-alternitive-billing-api-intro
reidbaker Feb 12, 2024
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
Prev Previous commit
Next Next commit
Add test for BillingClientManager alternative billing only
  • Loading branch information
reidbaker committed Feb 8, 2024
commit 448dd2ccf8ca12133bde92a2eb24eb8b420b5215
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.json:json:20231013'
testImplementation 'org.mockito:mockito-core:5.4.0'
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test:runner:1.5.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ class BillingClientManager {
///
/// Callers need to check if AlternativeBillingOnly is available by calling
/// [BillingClientWrapper.isAlternativeBillingOnlyAvailable] first.
BillingClientManager({bool enableAlternativeBillingOnly = false})
: _enableAlternativeBillingOnly = enableAlternativeBillingOnly {
BillingClientManager() : _enableAlternativeBillingOnly = false {
_connect();
}

Expand All @@ -58,7 +57,7 @@ class BillingClientManager {
final StreamController<PurchasesResultWrapper> _purchasesUpdatedController =
StreamController<PurchasesResultWrapper>.broadcast();

final bool _enableAlternativeBillingOnly;
bool _enableAlternativeBillingOnly;
bool _isConnecting = false;
bool _isDisposed = false;

Expand Down Expand Up @@ -125,6 +124,14 @@ class BillingClientManager {
_purchasesUpdatedController.close();
}

/// Ends connection to [BillingClient] and reconnects with [alternativeBillingState].
Future<void> reconnectWithAlternativeBillingOnlyState(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Optional: Looking ahead to adding the other mode, would it make more sense to have this be something like reconnectWithBillingMode(SomeNewBillingModeEnum mode) so that we can use the same API for the next change by just adding an enum value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I am now looking at the api https://developer.android.com/reference/com/android/billingclient/api/BillingClient.Builder#enableUserChoiceBilling(com.android.billingclient.api.UserChoiceBillingListener)
They have this in a builder where you can set both user choice and alternative billing only which seems odd.

I will create the enum and redo that section and its tests. Good idea

bool alternativeBillingOnlyState) async {
_enableAlternativeBillingOnly = alternativeBillingOnlyState;
// Ends connection and triggers OnBillingServiceDisconnected, which causes reconnect;
await client.endConnection();
}

// If disposed, does nothing.
// If currently connecting, waits for it to complete.
// Otherwise, starts a new connection.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,17 @@ class InAppPurchaseAndroidPlatformAddition
client.showAlternativeBillingOnlyInformationDialog());
return wrapper;
}

/// Disconnects, Sets AlternativeBillingOnly to true, and recoonects to
/// the [BillingClient].
///
/// [alternativeBillingOnlyState] true will enable alternative billing only.
///
/// Play apis have requirements for when this method can be called.
/// See: https://developer.android.com/google/play/billing/alternative/alternative-billing-without-user-choice-in-app
Future<void> setAlternativeBillingOnlyState(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This would also be a strong candidate for a more generic method with a mode enum. (I would say we should either do both this and BillingClientManager, or neither, for consistency.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep will make an enum and modify it here and and in billing client manager. Then I will probably send down booleans with a documented priority to the java code.

bool alternativeBillingOnlyState) {
return _billingClientManager
.reconnectWithAlternativeBillingOnlyState(alternativeBillingOnlyState);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,35 @@ void main() {
expect(stubPlatform.countPreviousCalls(startConnectionCall), equals(2));
});

test('re-connects when host calls reconnectWithAlternativeBillingOnlyState',
() async {
connectedCompleter.complete();
// Ensures all asynchronous connected code finishes.
await manager.runWithClientNonRetryable((_) async {});

await manager.reconnectWithAlternativeBillingOnlyState(true);
// Verify that connection was ended.
expect(stubPlatform.countPreviousCalls(endConnectionCall), equals(1));

stubPlatform.reset();

late Map<Object?, Object?> arguments;
stubPlatform.addResponse(
name: startConnectionCall,
additionalStepBeforeReturn: (dynamic value) =>
arguments = value as Map<dynamic, dynamic>,
);

/// Fake the disconnect that we would expect from a endConnectionCall.
await manager.client.callHandler(
const MethodCall(onBillingServiceDisconnectedCallback,
<String, dynamic>{'handle': 0}),
);
// Verify that after connection ended reconnect was called.
expect(stubPlatform.countPreviousCalls(startConnectionCall), equals(1));
expect(arguments['enableAlternativeBillingOnly'], isTrue);
});

test(
're-connects when operation returns BillingResponse.serviceDisconnected',
() async {
Expand Down