Skip to content

Commit fb6cfd2

Browse files
committed
[in_app_purchase_android] Add obfuscated profile ID purchase param
1 parent e742106 commit fb6cfd2

4 files changed

Lines changed: 36 additions & 0 deletions

File tree

packages/in_app_purchase/in_app_purchase_android/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## NEXT
2+
3+
* Adds support for passing an obfuscated profile ID in GooglePlayPurchaseParam.
4+
15
## 0.5.1
26

37
* Adds support to overlay billing related messages. See `InAppPurchaseAndroidPlatformAddition.showInAppMessages`.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,12 @@ class InAppPurchaseAndroidPlatform extends InAppPurchasePlatform {
152152
Future<bool> buyNonConsumable({required PurchaseParam purchaseParam}) async {
153153
ChangeSubscriptionParam? changeSubscriptionParam;
154154
String? offerToken;
155+
String? obfuscatedProfileId;
155156

156157
if (purchaseParam is GooglePlayPurchaseParam) {
157158
changeSubscriptionParam = purchaseParam.changeSubscriptionParam;
158159
offerToken = purchaseParam.offerToken;
160+
obfuscatedProfileId = purchaseParam.obfuscatedProfileId;
159161
}
160162

161163
if (offerToken == null && purchaseParam.productDetails is GooglePlayProductDetails) {
@@ -167,6 +169,7 @@ class InAppPurchaseAndroidPlatform extends InAppPurchasePlatform {
167169
product: purchaseParam.productDetails.id,
168170
offerToken: offerToken,
169171
accountId: purchaseParam.applicationUserName,
172+
obfuscatedProfileId: obfuscatedProfileId,
170173
oldProduct: changeSubscriptionParam?.oldPurchaseDetails.productID,
171174
purchaseToken:
172175
changeSubscriptionParam?.oldPurchaseDetails.verificationData.serverVerificationData,

packages/in_app_purchase/in_app_purchase_android/lib/src/types/google_play_purchase_param.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class GooglePlayPurchaseParam extends PurchaseParam {
1414
super.applicationUserName,
1515
this.changeSubscriptionParam,
1616
this.offerToken,
17+
this.obfuscatedProfileId,
1718
});
1819

1920
/// The 'changeSubscriptionParam' containing information for upgrading or
@@ -25,4 +26,7 @@ class GooglePlayPurchaseParam extends PurchaseParam {
2526
/// For subscriptions, to get the offer token corresponding to the selected
2627
/// offer call productDetails.subscriptionOfferDetails?.get(selectedOfferIndex)?.offerToken
2728
final String? offerToken;
29+
30+
/// An optional obfuscated profile ID associated with the user's profile.
31+
final String? obfuscatedProfileId;
2832
}

packages/in_app_purchase/in_app_purchase_android/test/in_app_purchase_android_platform_test.dart

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,31 @@ void main() {
415415
expect(result.productID, productDetails.productId);
416416
});
417417

418+
test('buyNonConsumable passes obfuscatedProfileId', () async {
419+
const profileId = 'hashedProfileId';
420+
const expectedBillingResult = BillingResultWrapper(
421+
responseCode: BillingResponse.ok,
422+
debugMessage: 'dummy message',
423+
);
424+
when(
425+
mockApi.launchBillingFlow(any),
426+
).thenAnswer((_) async => convertToPigeonResult(expectedBillingResult));
427+
428+
final bool launchResult = await iapAndroidPlatform.buyNonConsumable(
429+
purchaseParam: GooglePlayPurchaseParam(
430+
productDetails: GooglePlayProductDetails.fromProductDetails(
431+
dummyOneTimeProductDetails,
432+
).first,
433+
obfuscatedProfileId: profileId,
434+
),
435+
);
436+
437+
final VerificationResult result = verify(mockApi.launchBillingFlow(captureAny));
438+
final params = result.captured.single as PlatformBillingFlowParams;
439+
expect(launchResult, isTrue);
440+
expect(params.obfuscatedProfileId, profileId);
441+
});
442+
418443
test('handles an error with an empty purchases list', () async {
419444
const ProductDetailsWrapper productDetails = dummyOneTimeProductDetails;
420445
const accountId = 'hashedAccountId';

0 commit comments

Comments
 (0)