@capgo/native-purchases 7.7.13 → 7.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,7 +27,7 @@ public class NativePurchasesPlugin: CAPPlugin, CAPBridgedPlugin {
27
27
  call.resolve(["version": self.PLUGIN_VERSION])
28
28
  }
29
29
 
30
- public override func load() {
30
+ override public func load() {
31
31
  super.load()
32
32
  // Start listening to StoreKit transaction updates as early as possible
33
33
  if #available(iOS 15.0, *) {
@@ -51,7 +51,7 @@ public class NativePurchasesPlugin: CAPPlugin, CAPBridgedPlugin {
51
51
  let task = Task.detached { [weak self] in
52
52
  // Create a single ISO8601DateFormatter once per Task to avoid repeated allocations
53
53
  let dateFormatter = ISO8601DateFormatter()
54
-
54
+
55
55
  for await result in Transaction.updates {
56
56
  guard !Task.isCancelled else { break }
57
57
  do {
@@ -62,7 +62,7 @@ public class NativePurchasesPlugin: CAPPlugin, CAPBridgedPlugin {
62
62
 
63
63
  // Build payload similar to purchase response
64
64
  var payload: [String: Any] = ["transactionId": String(transaction.id)]
65
-
65
+
66
66
  // Always include willCancel key with NSNull() default
67
67
  payload["willCancel"] = NSNull()
68
68
 
@@ -91,7 +91,7 @@ public class NativePurchasesPlugin: CAPPlugin, CAPBridgedPlugin {
91
91
  switch renewalInfo {
92
92
  case .verified(let value):
93
93
  payload["willCancel"] = !value.willAutoRenew
94
- case .unverified(_, _):
94
+ case .unverified:
95
95
  // willCancel remains NSNull() for unverified renewalInfo
96
96
  break
97
97
  }
@@ -130,7 +130,6 @@ public class NativePurchasesPlugin: CAPPlugin, CAPBridgedPlugin {
130
130
  let productIdentifier = call.getString("productIdentifier", "")
131
131
  let quantity = call.getInt("quantity", 1)
132
132
  let appAccountToken = call.getString("appAccountToken")
133
-
134
133
  if productIdentifier.isEmpty {
135
134
  call.reject("productIdentifier is Empty, give an id")
136
135
  return
@@ -172,7 +171,11 @@ public class NativePurchasesPlugin: CAPPlugin, CAPBridgedPlugin {
172
171
  response["productIdentifier"] = transaction.productID
173
172
  response["purchaseDate"] = ISO8601DateFormatter().string(from: transaction.purchaseDate)
174
173
  response["productType"] = transaction.productType == .autoRenewable ? "subs" : "inapp"
175
-
174
+ if let token = transaction.appAccountToken {
175
+ let tokenString = token.uuidString
176
+ response["appAccountToken"] = tokenString
177
+ }
178
+
176
179
  // Add subscription-specific information
177
180
  if transaction.productType == .autoRenewable {
178
181
  response["originalPurchaseDate"] = ISO8601DateFormatter().string(from: transaction.originalPurchaseDate)
@@ -182,7 +185,7 @@ public class NativePurchasesPlugin: CAPPlugin, CAPBridgedPlugin {
182
185
  response["isActive"] = isActive
183
186
  }
184
187
  }
185
-
188
+
186
189
  let subscriptionStatus = await transaction.subscriptionStatus
187
190
  if let subscriptionStatus = subscriptionStatus {
188
191
  // You can use 'state' here if needed
@@ -190,21 +193,19 @@ public class NativePurchasesPlugin: CAPPlugin, CAPBridgedPlugin {
190
193
  if state == .subscribed {
191
194
  // Use Objective-C reflection to access advancedCommerceInfo
192
195
  let renewalInfo = subscriptionStatus.renewalInfo
193
-
194
- switch (renewalInfo) {
196
+
197
+ switch renewalInfo {
195
198
  case .verified(let value):
196
- // if #available(iOS 18.4, *) {
197
- // // This should work but may need runtime access
198
- // let advancedInfo = value.advancedCommerceInfo
199
- // print("Advanced commerce info: \(advancedInfo)")
200
- // }
201
- // print("[InAppPurchase] Subscription renewalInfo verified.")
199
+ // if #available(iOS 18.4, *) {
200
+ // // This should work but may need runtime access
201
+ // let advancedInfo = value.advancedCommerceInfo
202
+ // print("Advanced commerce info: \(advancedInfo)")
203
+ // }
204
+ // print("[InAppPurchase] Subscription renewalInfo verified.")
202
205
  response["willCancel"] = !value.willAutoRenew
203
- break;
204
- case .unverified(_, _):
206
+ case .unverified:
205
207
  print("[InAppPurchase] Subscription renewalInfo not verified.")
206
208
  response["willCancel"] = NSNull()
207
- break;
208
209
  }
209
210
  }
210
211
  }
@@ -317,6 +318,7 @@ public class NativePurchasesPlugin: CAPPlugin, CAPBridgedPlugin {
317
318
  }
318
319
 
319
320
  @objc func getPurchases(_ call: CAPPluginCall) {
321
+ let appAccountTokenFilter = call.getString("appAccountToken")
320
322
  if #available(iOS 15.0, *) {
321
323
  print("getPurchases")
322
324
  DispatchQueue.global().async {
@@ -327,6 +329,12 @@ public class NativePurchasesPlugin: CAPPlugin, CAPBridgedPlugin {
327
329
  // Get all current entitlements (active subscriptions)
328
330
  for await result in Transaction.currentEntitlements {
329
331
  if case .verified(let transaction) = result {
332
+ let transactionAccountToken = transaction.appAccountToken?.uuidString
333
+ if let filter = appAccountTokenFilter {
334
+ guard let token = transactionAccountToken, token == filter else {
335
+ continue
336
+ }
337
+ }
330
338
  var purchaseData: [String: Any] = ["transactionId": String(transaction.id)]
331
339
 
332
340
  // Get receipt data
@@ -341,7 +349,10 @@ public class NativePurchasesPlugin: CAPPlugin, CAPBridgedPlugin {
341
349
  purchaseData["productIdentifier"] = transaction.productID
342
350
  purchaseData["purchaseDate"] = ISO8601DateFormatter().string(from: transaction.purchaseDate)
343
351
  purchaseData["productType"] = transaction.productType == .autoRenewable ? "subs" : "inapp"
344
-
352
+ if let token = transactionAccountToken {
353
+ purchaseData["appAccountToken"] = token
354
+ }
355
+
345
356
  // Add subscription-specific information
346
357
  if transaction.productType == .autoRenewable {
347
358
  purchaseData["originalPurchaseDate"] = ISO8601DateFormatter().string(from: transaction.originalPurchaseDate)
@@ -351,7 +362,7 @@ public class NativePurchasesPlugin: CAPPlugin, CAPBridgedPlugin {
351
362
  purchaseData["isActive"] = isActive
352
363
  }
353
364
  }
354
-
365
+
355
366
  let subscriptionStatus = await transaction.subscriptionStatus
356
367
  if let subscriptionStatus = subscriptionStatus {
357
368
  // You can use 'state' here if needed
@@ -359,21 +370,19 @@ public class NativePurchasesPlugin: CAPPlugin, CAPBridgedPlugin {
359
370
  if state == .subscribed {
360
371
  // Use Objective-C reflection to access advancedCommerceInfo
361
372
  let renewalInfo = subscriptionStatus.renewalInfo
362
-
363
- switch (renewalInfo) {
373
+
374
+ switch renewalInfo {
364
375
  case .verified(let value):
365
- // if #available(iOS 18.4, *) {
366
- // // This should work but may need runtime access
367
- // let advancedInfo = value.advancedCommerceInfo
368
- // print("Advanced commerce info: \(advancedInfo)")
369
- // }
370
- // print("[InAppPurchase] Subscription renewalInfo verified.")
376
+ // if #available(iOS 18.4, *) {
377
+ // // This should work but may need runtime access
378
+ // let advancedInfo = value.advancedCommerceInfo
379
+ // print("Advanced commerce info: \(advancedInfo)")
380
+ // }
381
+ // print("[InAppPurchase] Subscription renewalInfo verified.")
371
382
  purchaseData["willCancel"] = !value.willAutoRenew
372
- break;
373
- case .unverified(_, _):
383
+ case .unverified:
374
384
  print("[InAppPurchase] Subscription renewalInfo not verified.")
375
385
  purchaseData["willCancel"] = NSNull()
376
- break;
377
386
  }
378
387
  }
379
388
  }
@@ -386,6 +395,13 @@ public class NativePurchasesPlugin: CAPPlugin, CAPBridgedPlugin {
386
395
  for await result in Transaction.all {
387
396
  if case .verified(let transaction) = result {
388
397
  let transactionIdString = String(transaction.id)
398
+ let transactionAccountToken = transaction.appAccountToken?.uuidString
399
+
400
+ if let filter = appAccountTokenFilter {
401
+ guard let token = transactionAccountToken, token == filter else {
402
+ continue
403
+ }
404
+ }
389
405
 
390
406
  // Check if we already have this transaction
391
407
  let alreadyExists = allPurchases.contains { purchase in
@@ -410,7 +426,10 @@ public class NativePurchasesPlugin: CAPPlugin, CAPBridgedPlugin {
410
426
  purchaseData["productIdentifier"] = transaction.productID
411
427
  purchaseData["purchaseDate"] = ISO8601DateFormatter().string(from: transaction.purchaseDate)
412
428
  purchaseData["productType"] = transaction.productType == .autoRenewable ? "subs" : "inapp"
413
-
429
+ if let token = transactionAccountToken {
430
+ purchaseData["appAccountToken"] = token
431
+ }
432
+
414
433
  // Add subscription-specific information
415
434
  if transaction.productType == .autoRenewable {
416
435
  purchaseData["originalPurchaseDate"] = ISO8601DateFormatter().string(from: transaction.originalPurchaseDate)
@@ -420,7 +439,7 @@ public class NativePurchasesPlugin: CAPPlugin, CAPBridgedPlugin {
420
439
  purchaseData["isActive"] = isActive
421
440
  }
422
441
  }
423
-
442
+
424
443
  let subscriptionStatus = await transaction.subscriptionStatus
425
444
  if let subscriptionStatus = subscriptionStatus {
426
445
  // You can use 'state' here if needed
@@ -428,21 +447,19 @@ public class NativePurchasesPlugin: CAPPlugin, CAPBridgedPlugin {
428
447
  if state == .subscribed {
429
448
  // Use Objective-C reflection to access advancedCommerceInfo
430
449
  let renewalInfo = subscriptionStatus.renewalInfo
431
-
432
- switch (renewalInfo) {
450
+
451
+ switch renewalInfo {
433
452
  case .verified(let value):
434
- // if #available(iOS 18.4, *) {
435
- // // This should work but may need runtime access
436
- // let advancedInfo = value.advancedCommerceInfo
437
- // print("Advanced commerce info: \(advancedInfo)")
438
- // }
439
- // print("[InAppPurchase] Subscription renewalInfo verified.")
453
+ // if #available(iOS 18.4, *) {
454
+ // // This should work but may need runtime access
455
+ // let advancedInfo = value.advancedCommerceInfo
456
+ // print("Advanced commerce info: \(advancedInfo)")
457
+ // }
458
+ // print("[InAppPurchase] Subscription renewalInfo verified.")
440
459
  purchaseData["willCancel"] = !value.willAutoRenew
441
- break;
442
- case .unverified(_, _):
460
+ case .unverified:
443
461
  print("[InAppPurchase] Subscription renewalInfo not verified.")
444
462
  purchaseData["willCancel"] = NSNull()
445
- break;
446
463
  }
447
464
  }
448
465
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/native-purchases",
3
- "version": "7.7.13",
3
+ "version": "7.8.2",
4
4
  "description": "In-app Subscriptions Made Easy",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -38,11 +38,11 @@
38
38
  "verify:ios": "xcodebuild -scheme CapgoNativePurchases -destination generic/platform=iOS",
39
39
  "verify:android": "cd android && ./gradlew clean build test && cd ..",
40
40
  "verify:web": "npm run build",
41
- "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
42
41
  "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
43
- "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --autocorrect --format",
42
+ "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
43
+ "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
44
44
  "eslint": "eslint . --ext ts",
45
- "prettier": "prettier --config .prettierrc.js \"**/*.{css,html,ts,js,java}\"",
45
+ "prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
46
46
  "swiftlint": "node-swiftlint",
47
47
  "docgen": "docgen --api NativePurchasesPlugin --output-readme README.md --output-json dist/docs.json",
48
48
  "clean": "rimraf ./dist",