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_purchase_android] GooglePlayPurchaseParam add possibility set selected offerToken #8452

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
@@ -1,3 +1,7 @@
## 0.3.6+14

* GooglePlayPurchaseParam add possibility set selected offerToken

## 0.3.6+13

* Updates androidx.annotation:annotation to 1.9.1.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,15 @@ class InAppPurchaseAndroidPlatform extends InAppPurchasePlatform {
@override
Future<bool> buyNonConsumable({required PurchaseParam purchaseParam}) async {
ChangeSubscriptionParam? changeSubscriptionParam;
String? offerToken;

if (purchaseParam is GooglePlayPurchaseParam) {
changeSubscriptionParam = purchaseParam.changeSubscriptionParam;
offerToken = purchaseParam.offerToken;
}

String? offerToken;
if (purchaseParam.productDetails is GooglePlayProductDetails) {

if (offerToken == null && purchaseParam.productDetails is GooglePlayProductDetails) {
offerToken =
(purchaseParam.productDetails as GooglePlayProductDetails).offerToken;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ class GooglePlayPurchaseParam extends PurchaseParam {
required super.productDetails,
super.applicationUserName,
this.changeSubscriptionParam,
this.offerToken,
});

/// The 'changeSubscriptionParam' containing information for upgrading or
/// downgrading an existing subscription.
final ChangeSubscriptionParam? changeSubscriptionParam;

/// For One-time product, "offerToken" shouldn't be filled.
/// For subscriptions, to get the offer token corresponding to the selected
/// offer call productDetails.subscriptionOfferDetails?.get(selectedOfferIndex)?.offerToken
final String? offerToken;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: in_app_purchase_android
description: An implementation for the Android platform of the Flutter `in_app_purchase` plugin. This uses the Android BillingClient APIs.
repository: https://github.com/flutter/packages/tree/main/packages/in_app_purchase/in_app_purchase_android
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+in_app_purchase%22
version: 0.3.6+13
version: 0.3.6+14

environment:
sdk: ^3.5.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,64 @@ void main() {
});

group('make payment', () {
test('buy non consumable subscribe offer, serializes and deserializes data', () async {
const ProductDetailsWrapper productDetails = dummySubscriptionProductDetails;
const String accountId = 'hashedAccountId';
const String debugMessage = 'dummy message';
const BillingResponse sentCode = BillingResponse.ok;
const BillingResultWrapper expectedBillingResult = BillingResultWrapper(
responseCode: sentCode, debugMessage: debugMessage);

when(mockApi.launchBillingFlow(any)).thenAnswer((_) async {
// Mock java update purchase callback.
iapAndroidPlatform.billingClientManager.client.hostCallbackHandler
.onPurchasesUpdated(PlatformPurchasesResponse(
billingResult: convertToPigeonResult(expectedBillingResult),
purchases: <PlatformPurchase>[
PlatformPurchase(
orderId: 'orderID1',
products: <String>[productDetails.productId],
isAutoRenewing: false,
packageName: 'package',
purchaseTime: 1231231231,
purchaseToken: 'token',
signature: 'sign',
originalJson: 'json',
developerPayload: 'dummy payload',
isAcknowledged: true,
purchaseState: PlatformPurchaseState.purchased,
quantity: 1,
)
],
));

return convertToPigeonResult(expectedBillingResult);
});
final Completer<PurchaseDetails> completer = Completer<PurchaseDetails>();
PurchaseDetails purchaseDetails;
final Stream<List<PurchaseDetails>> purchaseStream =
iapAndroidPlatform.purchaseStream;
late StreamSubscription<List<PurchaseDetails>> subscription;
subscription = purchaseStream.listen((List<PurchaseDetails> details) {
purchaseDetails = details.first;
completer.complete(purchaseDetails);
subscription.cancel();
}, onDone: () {});
final GooglePlayPurchaseParam purchaseParam = GooglePlayPurchaseParam(
offerToken: productDetails.subscriptionOfferDetails?.first.offerIdToken,
productDetails:
GooglePlayProductDetails.fromProductDetails(productDetails).first,
applicationUserName: accountId);
final bool launchResult = await iapAndroidPlatform.buyNonConsumable(
purchaseParam: purchaseParam);

final PurchaseDetails result = await completer.future;
expect(launchResult, isTrue);
expect(result.purchaseID, 'orderID1');
expect(result.status, PurchaseStatus.purchased);
expect(result.productID, productDetails.productId);
});

test('buy non consumable, serializes and deserializes data', () async {
const ProductDetailsWrapper productDetails = dummyOneTimeProductDetails;
const String accountId = 'hashedAccountId';
Expand Down
Loading