Skip to content

Commit ed03359

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

4 files changed

Lines changed: 42 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: 7 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,10 @@ 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+
///
32+
/// Setting this field requires [applicationUserName], which maps to the
33+
/// obfuscated account ID, to be specified as well.
34+
final String? obfuscatedProfileId;
2835
}

packages/in_app_purchase/in_app_purchase_android/test/in_app_purchase_android_platform_test.dart

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

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

0 commit comments

Comments
 (0)