@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)
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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)
|
|
62
|
+
@objc func restorePurchases(_ call: CAPPluginCall) {
|
|
66
63
|
if #available(iOS 15.0, *) {
|
|
67
64
|
print("restorePurchases")
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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)
|
|
81
|
+
@objc func getProducts(_ call: CAPPluginCall) {
|
|
82
82
|
if #available(iOS 15.0, *) {
|
|
83
83
|
let productIdentifiers = call.getArray("productIdentifiers", String.self) ?? []
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
}
|