@capgo/native-purchases 0.0.5 → 0.0.6

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.
@@ -11,7 +11,7 @@ public class NativePurchasesPlugin: CAPPlugin {
11
11
 
12
12
  private let PLUGIN_VERSION = "2.0.13"
13
13
 
14
- @objc func purchaseProduct(_ call: CAPPluginCall) async {
14
+ @objc func purchaseProduct(_ call: CAPPluginCall) {
15
15
  if #available(iOS 15, *) {
16
16
  print("purchaseProduct")
17
17
  let productIdentifier = call.getString("productIdentifier", "")
@@ -20,57 +20,57 @@ public class NativePurchasesPlugin: CAPPlugin {
20
20
  call.reject("productIdentifier is Empty, give an id")
21
21
  return
22
22
  }
23
- do {
24
- let products = try await Product.products(for: [productIdentifier])
25
- let product = products[0]
26
- var purchaseOptions = Set<Product.PurchaseOption>()
27
- purchaseOptions.insert(Product.PurchaseOption.quantity(quantity))
28
- let result = try await product.purchase(options: purchaseOptions)
29
- print("purchaseProduct result \(result)")
30
- switch result {
31
- case let .success(.verified(transaction)):
32
- // Successful purhcase
33
- await transaction.finish()
34
- call.resolve(["transactionId": transaction.id])
35
- break
36
- case let .success(.unverified(_, error)):
37
- // Successful purchase but transaction/receipt can't be verified
38
- // Could be a jailbroken phone
39
- call.reject(error.localizedDescription)
40
- break
41
- case .pending:
42
- // Transaction waiting on SCA (Strong Customer Authentication) or
43
- // approval from Ask to Buy
44
- call.reject("Transaction pending")
45
- break
46
- case .userCancelled:
47
- // ^^^
48
- call.reject("User cancelled")
49
- break
50
- @unknown default:
51
- call.reject("Unknown error")
52
- break
23
+
24
+ Task {
25
+ do {
26
+ let products = try await Product.products(for: [productIdentifier])
27
+ let product = products[0]
28
+ var purchaseOptions = Set<Product.PurchaseOption>()
29
+ purchaseOptions.insert(Product.PurchaseOption.quantity(quantity))
30
+ let result = try await product.purchase(options: purchaseOptions)
31
+ print("purchaseProduct result \(result)")
32
+ switch result {
33
+ case let .success(.verified(transaction)):
34
+ // Successful purhcase
35
+ await transaction.finish()
36
+ call.resolve(["transactionId": transaction.id])
37
+ case let .success(.unverified(_, error)):
38
+ // Successful purchase but transaction/receipt can't be verified
39
+ // Could be a jailbroken phone
40
+ call.reject(error.localizedDescription)
41
+ case .pending:
42
+ // Transaction waiting on SCA (Strong Customer Authentication) or
43
+ // approval from Ask to Buy
44
+ call.reject("Transaction pending")
45
+ case .userCancelled:
46
+ // ^^^
47
+ call.reject("User cancelled")
48
+ @unknown default:
49
+ call.reject("Unknown error")
50
+ }
51
+ } catch {
52
+ print(error)
53
+ call.reject(error.localizedDescription)
53
54
  }
54
- } catch {
55
- print(error)
56
- call.reject(error.localizedDescription)
57
55
  }
58
56
  } else {
59
57
  print("Not implemented under ios 15")
60
58
  call.reject("Not implemented under ios 15")
61
- return
62
59
  }
63
60
  }
64
61
 
65
- @objc func restorePurchases(_ call: CAPPluginCall) async {
62
+ @objc func restorePurchases(_ call: CAPPluginCall) {
66
63
  if #available(iOS 15.0, *) {
67
64
  print("restorePurchases")
68
- do {
69
- try await AppStore.sync()
70
- call.resolve()
71
- } catch {
72
- print(error)
73
- call.reject(error.localizedDescription)
65
+ DispatchQueue.global().async {
66
+ Task {
67
+ do {
68
+ try await AppStore.sync()
69
+ call.resolve()
70
+ } catch {
71
+ call.reject(error.localizedDescription)
72
+ }
73
+ }
74
74
  }
75
75
  } else {
76
76
  print("Not implemented under ios 15")
@@ -78,20 +78,22 @@ public class NativePurchasesPlugin: CAPPlugin {
78
78
  }
79
79
  }
80
80
 
81
- @objc func getProducts(_ call: CAPPluginCall) async {
81
+ @objc func getProducts(_ call: CAPPluginCall) {
82
82
  if #available(iOS 15.0, *) {
83
83
  let productIdentifiers = call.getArray("productIdentifiers", String.self) ?? []
84
- do {
85
- let products = try await Product.products(for: productIdentifiers)
86
- let productsJson = products.map { (product) -> [String: Any] in
87
- return product.dictionary
84
+ DispatchQueue.global().async {
85
+ Task {
86
+ do {
87
+ let products = try await Product.products(for: productIdentifiers)
88
+ var productsJson: [[String: Any]] = products.map { $0.dictionary }
89
+ call.resolve([
90
+ "products": productsJson
91
+ ])
92
+ } catch {
93
+ print(error)
94
+ call.reject(error.localizedDescription)
95
+ }
88
96
  }
89
- call.resolve([
90
- "products": productsJson
91
- ])
92
- } catch {
93
- print(error)
94
- call.reject(error.localizedDescription)
95
97
  }
96
98
  } else {
97
99
  print("Not implemented under ios 15")
@@ -99,4 +101,6 @@ public class NativePurchasesPlugin: CAPPlugin {
99
101
  }
100
102
  }
101
103
 
104
+
105
+
102
106
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/native-purchases",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "In-app Subscriptions Made Easy",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",