Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit b9f9778

Browse files
committed
Don't force GooglePlayPurchaseParam
1 parent 81f7e6b commit b9f9778

File tree

2 files changed

+9
-28
lines changed

2 files changed

+9
-28
lines changed

packages/in_app_purchase/in_app_purchase_android/lib/src/in_app_purchase_android_platform.dart

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,22 +130,20 @@ class InAppPurchaseAndroidPlatform extends InAppPurchasePlatform {
130130

131131
@override
132132
Future<bool> buyNonConsumable({required PurchaseParam purchaseParam}) async {
133-
if (!(purchaseParam is GooglePlayPurchaseParam)) {
134-
throw ArgumentError(
135-
'On Android, the `purchaseParam` should always be of type `GooglePlayPurchaseParam`.',
136-
);
133+
ChangeSubscriptionParam? changeSubscriptionParam;
134+
135+
if (purchaseParam is GooglePlayPurchaseParam) {
136+
changeSubscriptionParam = purchaseParam.changeSubscriptionParam;
137137
}
138138

139139
BillingResultWrapper billingResultWrapper =
140140
await billingClient.launchBillingFlow(
141141
sku: purchaseParam.productDetails.id,
142142
accountId: purchaseParam.applicationUserName,
143-
oldSku: purchaseParam
144-
.changeSubscriptionParam?.oldPurchaseDetails.productID,
145-
purchaseToken: purchaseParam.changeSubscriptionParam
143+
oldSku: changeSubscriptionParam?.oldPurchaseDetails.productID,
144+
purchaseToken: changeSubscriptionParam
146145
?.oldPurchaseDetails.verificationData.serverVerificationData,
147-
prorationMode:
148-
purchaseParam.changeSubscriptionParam?.prorationMode);
146+
prorationMode: changeSubscriptionParam?.prorationMode);
149147
return billingResultWrapper.responseCode == BillingResponse.ok;
150148
}
151149

packages/in_app_purchase/in_app_purchase_android/test/in_app_purchase_android_platform_test.dart

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ void main() {
221221

222222
late StreamSubscription subscription;
223223
subscription = stream.listen((purchaseDetailsList) {
224-
if (purchaseDetailsList.first.status == PurchaseStatus.purchased) {
224+
if (purchaseDetailsList.first.status == PurchaseStatus.restored) {
225225
completer.complete(purchaseDetailsList);
226226
subscription.cancel();
227227
}
@@ -260,7 +260,7 @@ void main() {
260260
expect(purchase.verificationData.source, kIAPSource);
261261
expect(purchase.transactionDate, dummyPurchase.purchaseTime.toString());
262262
expect(purchase.billingClientPurchase, dummyPurchase);
263-
expect(purchase.status, PurchaseStatus.purchased);
263+
expect(purchase.status, PurchaseStatus.restored);
264264
});
265265
});
266266
});
@@ -271,23 +271,6 @@ void main() {
271271
const String consumeMethodName =
272272
'BillingClient#consumeAsync(String, ConsumeResponseListener)';
273273

274-
test('buy non consumable, throw argument exception', () {
275-
final PurchaseParam purchaseParam = PurchaseParam(
276-
productDetails:
277-
GooglePlayProductDetails.fromSkuDetails(dummySkuDetails),
278-
applicationUserName: "hashedAccountId");
279-
expect(
280-
() => iapAndroidPlatform.buyNonConsumable(purchaseParam: purchaseParam),
281-
throwsA(
282-
isA<ArgumentError>().having(
283-
(e) => e.message,
284-
'message',
285-
'On Android, the `purchaseParam` should always be of type `GooglePlayPurchaseParam`.',
286-
),
287-
),
288-
);
289-
});
290-
291274
test('buy non consumable, serializes and deserializes data', () async {
292275
final SkuDetailsWrapper skuDetails = dummySkuDetails;
293276
final String accountId = "hashedAccountId";

0 commit comments

Comments
 (0)