Skip to content

Commit 7b8936d

Browse files
committed
Added obfuscatedAccountId and obfuscatedProfileId for android
1 parent 8b52f99 commit 7b8936d

File tree

7 files changed

+42
-11
lines changed

7 files changed

+42
-11
lines changed

android/src/main/java/IapPlugin.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class PurchaseArgs {
3030
var productId: String = ""
3131
var productType: String = "subs" // "subs" or "inapp"
3232
var offerToken: String? = null
33+
var obfuscatedAccountId: String? = null
34+
var obfuscatedProfileId: String? = null
3335
}
3436

3537
@InvokeArg
@@ -232,9 +234,20 @@ class IapPlugin(private val activity: Activity): Plugin(activity), PurchasesUpda
232234
)
233235
}
234236

235-
val billingFlowParams = BillingFlowParams.newBuilder()
237+
val billingFlowParamsBuilder = BillingFlowParams.newBuilder()
236238
.setProductDetailsParamsList(productDetailsParamsList)
237-
.build()
239+
240+
// Add obfuscated account ID if provided
241+
args.obfuscatedAccountId?.let { accountId ->
242+
billingFlowParamsBuilder.setObfuscatedAccountId(accountId)
243+
}
244+
245+
// Add obfuscated profile ID if provided
246+
args.obfuscatedProfileId?.let { profileId ->
247+
billingFlowParamsBuilder.setObfuscatedProfileId(profileId)
248+
}
249+
250+
val billingFlowParams = billingFlowParamsBuilder.build()
238251

239252
val billingResult = billingClient.launchBillingFlow(activity, billingFlowParams)
240253

guest-js/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ export interface ProductStatus {
8787
purchaseToken?: string;
8888
}
8989

90+
export interface PurchaseOptions {
91+
offerToken?: string;
92+
obfuscatedAccountId?: string;
93+
obfuscatedProfileId?: string;
94+
}
95+
9096
export async function initialize(): Promise<InitializeResponse> {
9197
return await invoke<InitializeResponse>("plugin:iap|initialize");
9298
}
@@ -106,13 +112,13 @@ export async function getProducts(
106112
export async function purchase(
107113
productId: string,
108114
productType: "subs" | "inapp" = "subs",
109-
offerToken?: string,
115+
options?: PurchaseOptions,
110116
): Promise<Purchase> {
111117
return await invoke<Purchase>("plugin:iap|purchase", {
112118
payload: {
113119
productId,
114120
productType,
115-
offerToken,
121+
...options,
116122
},
117123
});
118124
}

src/commands.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub(crate) async fn purchase<R: Runtime>(
2525
app.iap().purchase(
2626
payload.product_id,
2727
payload.product_type,
28-
payload.offer_token,
28+
payload.options,
2929
)
3030
}
3131

src/desktop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl<R: Runtime> Iap<R> {
3434
&self,
3535
_product_id: String,
3636
_product_type: String,
37-
_offer_token: Option<String>,
37+
_options: Option<PurchaseOptions>,
3838
) -> crate::Result<Purchase> {
3939
Err(crate::Error::from(std::io::Error::other(
4040
"IAP is not supported on this platform",

src/macos.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,11 @@ impl<R: Runtime> Iap<R> {
107107
&self,
108108
product_id: String,
109109
product_type: String,
110-
offer_token: Option<String>,
110+
options: Option<PurchaseOptions>,
111111
) -> crate::Result<Purchase> {
112112
codesign::is_signature_valid()?;
113113

114+
let offer_token = options.and_then(|opts| opts.offer_token);
114115
Self::to_result(ffi::purchase(product_id, product_type, offer_token))
115116
}
116117

src/mobile.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ impl<R: Runtime> Iap<R> {
5555
&self,
5656
product_id: String,
5757
product_type: String,
58-
offer_token: Option<String>,
58+
options: Option<PurchaseOptions>,
5959
) -> crate::Result<Purchase> {
6060
self.0
6161
.run_mobile_plugin(
6262
"purchase",
6363
PurchaseRequest {
6464
product_id,
6565
product_type,
66-
offer_token,
66+
options,
6767
},
6868
)
6969
.map_err(Into::into)

src/models.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,25 @@ pub struct GetProductsResponse {
6565
pub products: Vec<Product>,
6666
}
6767

68+
#[derive(Debug, Clone, Deserialize, Serialize)]
69+
#[serde(rename_all = "camelCase")]
70+
pub struct PurchaseOptions {
71+
#[serde(skip_serializing_if = "Option::is_none")]
72+
pub offer_token: Option<String>,
73+
#[serde(skip_serializing_if = "Option::is_none")]
74+
pub obfuscated_account_id: Option<String>,
75+
#[serde(skip_serializing_if = "Option::is_none")]
76+
pub obfuscated_profile_id: Option<String>,
77+
}
78+
6879
#[derive(Debug, Deserialize, Serialize)]
6980
#[serde(rename_all = "camelCase")]
7081
pub struct PurchaseRequest {
7182
pub product_id: String,
7283
#[serde(default = "default_product_type")]
7384
pub product_type: String,
74-
#[serde(skip_serializing_if = "Option::is_none")]
75-
pub offer_token: Option<String>,
85+
#[serde(flatten)]
86+
pub options: Option<PurchaseOptions>,
7687
}
7788

7889
#[derive(Debug, Clone, Deserialize, Serialize)]

0 commit comments

Comments
 (0)