react-native-iap 14.3.4 → 14.3.5
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.
- package/NitroIap.podspec +1 -1
- package/README.md +1 -1
- package/android/CMakeLists.txt +4 -0
- package/android/build.gradle +2 -2
- package/android/src/main/cpp/cpp-adapter.cpp +8 -0
- package/android/src/main/java/com/margelo/nitro/iap/HybridRnIap.kt +93 -51
- package/ios/HybridRnIap.swift +38 -30
- package/lib/module/hooks/useIAP.js +4 -4
- package/lib/module/hooks/useIAP.js.map +1 -1
- package/lib/module/index.js +54 -53
- package/lib/module/index.js.map +1 -1
- package/lib/module/types.js +1 -59
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils/type-bridge.js +44 -33
- package/lib/module/utils/type-bridge.js.map +1 -1
- package/lib/typescript/src/hooks/useIAP.d.ts +4 -4
- package/lib/typescript/src/hooks/useIAP.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +8 -7
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/RnIap.nitro.d.ts +2 -1
- package/lib/typescript/src/specs/RnIap.nitro.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +159 -204
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/utils/type-bridge.d.ts.map +1 -1
- package/nitrogen/generated/android/NitroIap+autolinking.cmake +9 -4
- package/nitrogen/generated/android/c++/JHybridRnIapSpec.cpp +32 -5
- package/nitrogen/generated/android/c++/JHybridRnIapSpec.hpp +1 -1
- package/nitrogen/generated/android/c++/JIapPlatform.hpp +59 -0
- package/nitrogen/generated/android/c++/JPurchase.cpp +26 -0
- package/nitrogen/generated/android/c++/JPurchase.hpp +80 -0
- package/nitrogen/generated/android/c++/JPurchaseAndroid.hpp +140 -0
- package/nitrogen/generated/android/c++/JPurchaseIOS.hpp +194 -0
- package/nitrogen/generated/android/c++/JPurchaseOfferIOS.hpp +61 -0
- package/nitrogen/generated/android/c++/JPurchaseState.hpp +71 -0
- package/nitrogen/generated/android/c++/JRequestPurchaseResult.hpp +89 -0
- package/nitrogen/generated/android/c++/JVariant_PurchaseAndroid_PurchaseIOS.cpp +26 -0
- package/nitrogen/generated/android/c++/JVariant_PurchaseAndroid_PurchaseIOS.hpp +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/HybridRnIapSpec.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/IapPlatform.kt +21 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/Purchase.kt +42 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/PurchaseAndroid.kt +77 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/PurchaseIOS.kt +116 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/PurchaseOfferIOS.kt +35 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/PurchaseState.kt +25 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/RequestPurchaseResult.kt +32 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/Variant_PurchaseAndroid_PurchaseIOS.kt +42 -0
- package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Bridge.cpp +13 -5
- package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Bridge.hpp +186 -25
- package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Umbrella.hpp +18 -0
- package/nitrogen/generated/ios/c++/HybridRnIapSpecSwift.hpp +20 -2
- package/nitrogen/generated/ios/swift/Func_void_RequestPurchaseResult.swift +47 -0
- package/nitrogen/generated/ios/swift/HybridRnIapSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridRnIapSpec_cxx.swift +7 -7
- package/nitrogen/generated/ios/swift/IapPlatform.swift +40 -0
- package/nitrogen/generated/ios/swift/Purchase.swift +18 -0
- package/nitrogen/generated/ios/swift/PurchaseAndroid.swift +399 -0
- package/nitrogen/generated/ios/swift/PurchaseIOS.swift +768 -0
- package/nitrogen/generated/ios/swift/PurchaseOfferIOS.swift +57 -0
- package/nitrogen/generated/ios/swift/PurchaseState.swift +56 -0
- package/nitrogen/generated/ios/swift/RequestPurchaseResult.swift +148 -0
- package/nitrogen/generated/ios/swift/Variant_PurchaseAndroid_PurchaseIOS.swift +18 -0
- package/nitrogen/generated/shared/c++/HybridRnIapSpec.hpp +4 -1
- package/nitrogen/generated/shared/c++/IapPlatform.hpp +76 -0
- package/nitrogen/generated/shared/c++/PurchaseAndroid.hpp +138 -0
- package/nitrogen/generated/shared/c++/PurchaseIOS.hpp +193 -0
- package/nitrogen/generated/shared/c++/PurchaseOfferIOS.hpp +75 -0
- package/nitrogen/generated/shared/c++/PurchaseState.hpp +92 -0
- package/nitrogen/generated/shared/c++/RequestPurchaseResult.hpp +78 -0
- package/package.json +5 -4
- package/plugin/build/withIAP.js +1 -1
- package/plugin/src/withIAP.ts +1 -1
- package/src/hooks/useIAP.ts +14 -8
- package/src/index.ts +73 -74
- package/src/specs/RnIap.nitro.ts +4 -1
- package/src/types.ts +183 -216
- package/src/utils/type-bridge.ts +55 -43
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// PurchaseOfferIOS.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
import NitroModules
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Represents an instance of `PurchaseOfferIOS`, backed by a C++ struct.
|
|
12
|
+
*/
|
|
13
|
+
public typealias PurchaseOfferIOS = margelo.nitro.iap.PurchaseOfferIOS
|
|
14
|
+
|
|
15
|
+
public extension PurchaseOfferIOS {
|
|
16
|
+
private typealias bridge = margelo.nitro.iap.bridge.swift
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Create a new instance of `PurchaseOfferIOS`.
|
|
20
|
+
*/
|
|
21
|
+
init(id: String, paymentMode: String, type: String) {
|
|
22
|
+
self.init(std.string(id), std.string(paymentMode), std.string(type))
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var id: String {
|
|
26
|
+
@inline(__always)
|
|
27
|
+
get {
|
|
28
|
+
return String(self.__id)
|
|
29
|
+
}
|
|
30
|
+
@inline(__always)
|
|
31
|
+
set {
|
|
32
|
+
self.__id = std.string(newValue)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
var paymentMode: String {
|
|
37
|
+
@inline(__always)
|
|
38
|
+
get {
|
|
39
|
+
return String(self.__paymentMode)
|
|
40
|
+
}
|
|
41
|
+
@inline(__always)
|
|
42
|
+
set {
|
|
43
|
+
self.__paymentMode = std.string(newValue)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
var type: String {
|
|
48
|
+
@inline(__always)
|
|
49
|
+
get {
|
|
50
|
+
return String(self.__type)
|
|
51
|
+
}
|
|
52
|
+
@inline(__always)
|
|
53
|
+
set {
|
|
54
|
+
self.__type = std.string(newValue)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// PurchaseState.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Represents the JS union `PurchaseState`, backed by a C++ enum.
|
|
10
|
+
*/
|
|
11
|
+
public typealias PurchaseState = margelo.nitro.iap.PurchaseState
|
|
12
|
+
|
|
13
|
+
public extension PurchaseState {
|
|
14
|
+
/**
|
|
15
|
+
* Get a PurchaseState for the given String value, or
|
|
16
|
+
* return `nil` if the given value was invalid/unknown.
|
|
17
|
+
*/
|
|
18
|
+
init?(fromString string: String) {
|
|
19
|
+
switch string {
|
|
20
|
+
case "deferred":
|
|
21
|
+
self = .deferred
|
|
22
|
+
case "failed":
|
|
23
|
+
self = .failed
|
|
24
|
+
case "pending":
|
|
25
|
+
self = .pending
|
|
26
|
+
case "purchased":
|
|
27
|
+
self = .purchased
|
|
28
|
+
case "restored":
|
|
29
|
+
self = .restored
|
|
30
|
+
case "unknown":
|
|
31
|
+
self = .unknown
|
|
32
|
+
default:
|
|
33
|
+
return nil
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Get the String value this PurchaseState represents.
|
|
39
|
+
*/
|
|
40
|
+
var stringValue: String {
|
|
41
|
+
switch self {
|
|
42
|
+
case .deferred:
|
|
43
|
+
return "deferred"
|
|
44
|
+
case .failed:
|
|
45
|
+
return "failed"
|
|
46
|
+
case .pending:
|
|
47
|
+
return "pending"
|
|
48
|
+
case .purchased:
|
|
49
|
+
return "purchased"
|
|
50
|
+
case .restored:
|
|
51
|
+
return "restored"
|
|
52
|
+
case .unknown:
|
|
53
|
+
return "unknown"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// RequestPurchaseResult.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
import NitroModules
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Represents an instance of `RequestPurchaseResult`, backed by a C++ struct.
|
|
12
|
+
*/
|
|
13
|
+
public typealias RequestPurchaseResult = margelo.nitro.iap.RequestPurchaseResult
|
|
14
|
+
|
|
15
|
+
public extension RequestPurchaseResult {
|
|
16
|
+
private typealias bridge = margelo.nitro.iap.bridge.swift
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Create a new instance of `RequestPurchaseResult`.
|
|
20
|
+
*/
|
|
21
|
+
init(purchase: Variant_PurchaseAndroid_PurchaseIOS?, purchases: [Purchase]?) {
|
|
22
|
+
self.init({ () -> bridge.std__optional_std__variant_PurchaseAndroid__PurchaseIOS__ in
|
|
23
|
+
if let __unwrappedValue = purchase {
|
|
24
|
+
return bridge.create_std__optional_std__variant_PurchaseAndroid__PurchaseIOS__({ () -> bridge.std__variant_PurchaseAndroid__PurchaseIOS_ in
|
|
25
|
+
switch __unwrappedValue {
|
|
26
|
+
case .first(let __value):
|
|
27
|
+
return bridge.create_std__variant_PurchaseAndroid__PurchaseIOS_(__value)
|
|
28
|
+
case .second(let __value):
|
|
29
|
+
return bridge.create_std__variant_PurchaseAndroid__PurchaseIOS_(__value)
|
|
30
|
+
}
|
|
31
|
+
}().variant)
|
|
32
|
+
} else {
|
|
33
|
+
return .init()
|
|
34
|
+
}
|
|
35
|
+
}(), { () -> bridge.std__optional_std__vector_std__variant_PurchaseAndroid__PurchaseIOS___ in
|
|
36
|
+
if let __unwrappedValue = purchases {
|
|
37
|
+
return bridge.create_std__optional_std__vector_std__variant_PurchaseAndroid__PurchaseIOS___({ () -> bridge.std__vector_std__variant_PurchaseAndroid__PurchaseIOS__ in
|
|
38
|
+
var __vector = bridge.create_std__vector_std__variant_PurchaseAndroid__PurchaseIOS__(__unwrappedValue.count)
|
|
39
|
+
for __item in __unwrappedValue {
|
|
40
|
+
__vector.push_back({ () -> bridge.std__variant_PurchaseAndroid__PurchaseIOS_ in
|
|
41
|
+
switch __item {
|
|
42
|
+
case .first(let __value):
|
|
43
|
+
return bridge.create_std__variant_PurchaseAndroid__PurchaseIOS_(__value)
|
|
44
|
+
case .second(let __value):
|
|
45
|
+
return bridge.create_std__variant_PurchaseAndroid__PurchaseIOS_(__value)
|
|
46
|
+
}
|
|
47
|
+
}().variant)
|
|
48
|
+
}
|
|
49
|
+
return __vector
|
|
50
|
+
}())
|
|
51
|
+
} else {
|
|
52
|
+
return .init()
|
|
53
|
+
}
|
|
54
|
+
}())
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
var purchase: Variant_PurchaseAndroid_PurchaseIOS? {
|
|
58
|
+
@inline(__always)
|
|
59
|
+
get {
|
|
60
|
+
return { () -> Variant_PurchaseAndroid_PurchaseIOS? in
|
|
61
|
+
if bridge.has_value_std__optional_std__variant_PurchaseAndroid__PurchaseIOS__(self.__purchase) {
|
|
62
|
+
let __unwrapped = bridge.get_std__optional_std__variant_PurchaseAndroid__PurchaseIOS__(self.__purchase)
|
|
63
|
+
return { () -> Variant_PurchaseAndroid_PurchaseIOS in
|
|
64
|
+
let __variant = bridge.std__variant_PurchaseAndroid__PurchaseIOS_(__unwrapped)
|
|
65
|
+
switch __variant.index() {
|
|
66
|
+
case 0:
|
|
67
|
+
let __actual = __variant.get_0()
|
|
68
|
+
return .first(__actual)
|
|
69
|
+
case 1:
|
|
70
|
+
let __actual = __variant.get_1()
|
|
71
|
+
return .second(__actual)
|
|
72
|
+
default:
|
|
73
|
+
fatalError("Variant can never have index \(__variant.index())!")
|
|
74
|
+
}
|
|
75
|
+
}()
|
|
76
|
+
} else {
|
|
77
|
+
return nil
|
|
78
|
+
}
|
|
79
|
+
}()
|
|
80
|
+
}
|
|
81
|
+
@inline(__always)
|
|
82
|
+
set {
|
|
83
|
+
self.__purchase = { () -> bridge.std__optional_std__variant_PurchaseAndroid__PurchaseIOS__ in
|
|
84
|
+
if let __unwrappedValue = newValue {
|
|
85
|
+
return bridge.create_std__optional_std__variant_PurchaseAndroid__PurchaseIOS__({ () -> bridge.std__variant_PurchaseAndroid__PurchaseIOS_ in
|
|
86
|
+
switch __unwrappedValue {
|
|
87
|
+
case .first(let __value):
|
|
88
|
+
return bridge.create_std__variant_PurchaseAndroid__PurchaseIOS_(__value)
|
|
89
|
+
case .second(let __value):
|
|
90
|
+
return bridge.create_std__variant_PurchaseAndroid__PurchaseIOS_(__value)
|
|
91
|
+
}
|
|
92
|
+
}().variant)
|
|
93
|
+
} else {
|
|
94
|
+
return .init()
|
|
95
|
+
}
|
|
96
|
+
}()
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
var purchases: [Purchase]? {
|
|
101
|
+
@inline(__always)
|
|
102
|
+
get {
|
|
103
|
+
return { () -> [Purchase]? in
|
|
104
|
+
if bridge.has_value_std__optional_std__vector_std__variant_PurchaseAndroid__PurchaseIOS___(self.__purchases) {
|
|
105
|
+
let __unwrapped = bridge.get_std__optional_std__vector_std__variant_PurchaseAndroid__PurchaseIOS___(self.__purchases)
|
|
106
|
+
return __unwrapped.map({ __item in { () -> Purchase in
|
|
107
|
+
let __variant = bridge.std__variant_PurchaseAndroid__PurchaseIOS_(__item)
|
|
108
|
+
switch __variant.index() {
|
|
109
|
+
case 0:
|
|
110
|
+
let __actual = __variant.get_0()
|
|
111
|
+
return .first(__actual)
|
|
112
|
+
case 1:
|
|
113
|
+
let __actual = __variant.get_1()
|
|
114
|
+
return .second(__actual)
|
|
115
|
+
default:
|
|
116
|
+
fatalError("Variant can never have index \(__variant.index())!")
|
|
117
|
+
}
|
|
118
|
+
}() })
|
|
119
|
+
} else {
|
|
120
|
+
return nil
|
|
121
|
+
}
|
|
122
|
+
}()
|
|
123
|
+
}
|
|
124
|
+
@inline(__always)
|
|
125
|
+
set {
|
|
126
|
+
self.__purchases = { () -> bridge.std__optional_std__vector_std__variant_PurchaseAndroid__PurchaseIOS___ in
|
|
127
|
+
if let __unwrappedValue = newValue {
|
|
128
|
+
return bridge.create_std__optional_std__vector_std__variant_PurchaseAndroid__PurchaseIOS___({ () -> bridge.std__vector_std__variant_PurchaseAndroid__PurchaseIOS__ in
|
|
129
|
+
var __vector = bridge.create_std__vector_std__variant_PurchaseAndroid__PurchaseIOS__(__unwrappedValue.count)
|
|
130
|
+
for __item in __unwrappedValue {
|
|
131
|
+
__vector.push_back({ () -> bridge.std__variant_PurchaseAndroid__PurchaseIOS_ in
|
|
132
|
+
switch __item {
|
|
133
|
+
case .first(let __value):
|
|
134
|
+
return bridge.create_std__variant_PurchaseAndroid__PurchaseIOS_(__value)
|
|
135
|
+
case .second(let __value):
|
|
136
|
+
return bridge.create_std__variant_PurchaseAndroid__PurchaseIOS_(__value)
|
|
137
|
+
}
|
|
138
|
+
}().variant)
|
|
139
|
+
}
|
|
140
|
+
return __vector
|
|
141
|
+
}())
|
|
142
|
+
} else {
|
|
143
|
+
return .init()
|
|
144
|
+
}
|
|
145
|
+
}()
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Variant_PurchaseAndroid_PurchaseIOS.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* An Swift enum with associated values representing a Variant/Union type.
|
|
12
|
+
* JS type: `struct | struct`
|
|
13
|
+
*/
|
|
14
|
+
@frozen
|
|
15
|
+
public indirect enum Variant_PurchaseAndroid_PurchaseIOS {
|
|
16
|
+
case first(PurchaseAndroid)
|
|
17
|
+
case second(PurchaseIOS)
|
|
18
|
+
}
|
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
|
|
16
16
|
// Forward declaration of `NitroProduct` to properly resolve imports.
|
|
17
17
|
namespace margelo::nitro::iap { struct NitroProduct; }
|
|
18
|
+
// Forward declaration of `RequestPurchaseResult` to properly resolve imports.
|
|
19
|
+
namespace margelo::nitro::iap { struct RequestPurchaseResult; }
|
|
18
20
|
// Forward declaration of `NitroPurchaseRequest` to properly resolve imports.
|
|
19
21
|
namespace margelo::nitro::iap { struct NitroPurchaseRequest; }
|
|
20
22
|
// Forward declaration of `NitroPurchase` to properly resolve imports.
|
|
@@ -40,6 +42,7 @@ namespace margelo::nitro::iap { struct NitroDeepLinkOptionsAndroid; }
|
|
|
40
42
|
#include "NitroProduct.hpp"
|
|
41
43
|
#include <vector>
|
|
42
44
|
#include <string>
|
|
45
|
+
#include "RequestPurchaseResult.hpp"
|
|
43
46
|
#include "NitroPurchaseRequest.hpp"
|
|
44
47
|
#include "NitroPurchase.hpp"
|
|
45
48
|
#include "NitroAvailablePurchasesOptions.hpp"
|
|
@@ -88,7 +91,7 @@ namespace margelo::nitro::iap {
|
|
|
88
91
|
virtual std::shared_ptr<Promise<bool>> initConnection() = 0;
|
|
89
92
|
virtual std::shared_ptr<Promise<bool>> endConnection() = 0;
|
|
90
93
|
virtual std::shared_ptr<Promise<std::vector<NitroProduct>>> fetchProducts(const std::vector<std::string>& skus, const std::string& type) = 0;
|
|
91
|
-
virtual std::shared_ptr<Promise<
|
|
94
|
+
virtual std::shared_ptr<Promise<RequestPurchaseResult>> requestPurchase(const NitroPurchaseRequest& request) = 0;
|
|
92
95
|
virtual std::shared_ptr<Promise<std::vector<NitroPurchase>>> getAvailablePurchases(const std::optional<NitroAvailablePurchasesOptions>& options) = 0;
|
|
93
96
|
virtual std::shared_ptr<Promise<std::variant<bool, NitroPurchaseResult>>> finishTransaction(const NitroFinishTransactionParams& params) = 0;
|
|
94
97
|
virtual void addPurchaseUpdatedListener(const std::function<void(const NitroPurchase& /* purchase */)>& listener) = 0;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// IapPlatform.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/NitroHash.hpp>)
|
|
11
|
+
#include <NitroModules/NitroHash.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
16
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
21
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
namespace margelo::nitro::iap {
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* An enum which can be represented as a JavaScript union (IapPlatform).
|
|
30
|
+
*/
|
|
31
|
+
enum class IapPlatform {
|
|
32
|
+
ANDROID SWIFT_NAME(android) = 0,
|
|
33
|
+
IOS SWIFT_NAME(ios) = 1,
|
|
34
|
+
} CLOSED_ENUM;
|
|
35
|
+
|
|
36
|
+
} // namespace margelo::nitro::iap
|
|
37
|
+
|
|
38
|
+
namespace margelo::nitro {
|
|
39
|
+
|
|
40
|
+
// C++ IapPlatform <> JS IapPlatform (union)
|
|
41
|
+
template <>
|
|
42
|
+
struct JSIConverter<margelo::nitro::iap::IapPlatform> final {
|
|
43
|
+
static inline margelo::nitro::iap::IapPlatform fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
44
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
|
|
45
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
46
|
+
case hashString("android"): return margelo::nitro::iap::IapPlatform::ANDROID;
|
|
47
|
+
case hashString("ios"): return margelo::nitro::iap::IapPlatform::IOS;
|
|
48
|
+
default: [[unlikely]]
|
|
49
|
+
throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum IapPlatform - invalid value!");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::iap::IapPlatform arg) {
|
|
53
|
+
switch (arg) {
|
|
54
|
+
case margelo::nitro::iap::IapPlatform::ANDROID: return JSIConverter<std::string>::toJSI(runtime, "android");
|
|
55
|
+
case margelo::nitro::iap::IapPlatform::IOS: return JSIConverter<std::string>::toJSI(runtime, "ios");
|
|
56
|
+
default: [[unlikely]]
|
|
57
|
+
throw std::invalid_argument("Cannot convert IapPlatform to JS - invalid value: "
|
|
58
|
+
+ std::to_string(static_cast<int>(arg)) + "!");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
62
|
+
if (!value.isString()) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
|
|
66
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
67
|
+
case hashString("android"):
|
|
68
|
+
case hashString("ios"):
|
|
69
|
+
return true;
|
|
70
|
+
default:
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// PurchaseAndroid.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
11
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
16
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
|
|
21
|
+
// Forward declaration of `IapPlatform` to properly resolve imports.
|
|
22
|
+
namespace margelo::nitro::iap { enum class IapPlatform; }
|
|
23
|
+
// Forward declaration of `PurchaseState` to properly resolve imports.
|
|
24
|
+
namespace margelo::nitro::iap { enum class PurchaseState; }
|
|
25
|
+
|
|
26
|
+
#include <optional>
|
|
27
|
+
#include <string>
|
|
28
|
+
#include <vector>
|
|
29
|
+
#include "IapPlatform.hpp"
|
|
30
|
+
#include "PurchaseState.hpp"
|
|
31
|
+
|
|
32
|
+
namespace margelo::nitro::iap {
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A struct which can be represented as a JavaScript object (PurchaseAndroid).
|
|
36
|
+
*/
|
|
37
|
+
struct PurchaseAndroid {
|
|
38
|
+
public:
|
|
39
|
+
std::optional<bool> autoRenewingAndroid SWIFT_PRIVATE;
|
|
40
|
+
std::optional<std::string> dataAndroid SWIFT_PRIVATE;
|
|
41
|
+
std::optional<std::string> developerPayloadAndroid SWIFT_PRIVATE;
|
|
42
|
+
std::string id SWIFT_PRIVATE;
|
|
43
|
+
std::optional<std::vector<std::string>> ids SWIFT_PRIVATE;
|
|
44
|
+
std::optional<bool> isAcknowledgedAndroid SWIFT_PRIVATE;
|
|
45
|
+
bool isAutoRenewing SWIFT_PRIVATE;
|
|
46
|
+
std::optional<std::string> obfuscatedAccountIdAndroid SWIFT_PRIVATE;
|
|
47
|
+
std::optional<std::string> obfuscatedProfileIdAndroid SWIFT_PRIVATE;
|
|
48
|
+
std::optional<std::string> packageNameAndroid SWIFT_PRIVATE;
|
|
49
|
+
IapPlatform platform SWIFT_PRIVATE;
|
|
50
|
+
std::string productId SWIFT_PRIVATE;
|
|
51
|
+
PurchaseState purchaseState SWIFT_PRIVATE;
|
|
52
|
+
std::optional<std::string> purchaseToken SWIFT_PRIVATE;
|
|
53
|
+
double quantity SWIFT_PRIVATE;
|
|
54
|
+
std::optional<std::string> signatureAndroid SWIFT_PRIVATE;
|
|
55
|
+
double transactionDate SWIFT_PRIVATE;
|
|
56
|
+
|
|
57
|
+
public:
|
|
58
|
+
PurchaseAndroid() = default;
|
|
59
|
+
explicit PurchaseAndroid(std::optional<bool> autoRenewingAndroid, std::optional<std::string> dataAndroid, std::optional<std::string> developerPayloadAndroid, std::string id, std::optional<std::vector<std::string>> ids, std::optional<bool> isAcknowledgedAndroid, bool isAutoRenewing, std::optional<std::string> obfuscatedAccountIdAndroid, std::optional<std::string> obfuscatedProfileIdAndroid, std::optional<std::string> packageNameAndroid, IapPlatform platform, std::string productId, PurchaseState purchaseState, std::optional<std::string> purchaseToken, double quantity, std::optional<std::string> signatureAndroid, double transactionDate): autoRenewingAndroid(autoRenewingAndroid), dataAndroid(dataAndroid), developerPayloadAndroid(developerPayloadAndroid), id(id), ids(ids), isAcknowledgedAndroid(isAcknowledgedAndroid), isAutoRenewing(isAutoRenewing), obfuscatedAccountIdAndroid(obfuscatedAccountIdAndroid), obfuscatedProfileIdAndroid(obfuscatedProfileIdAndroid), packageNameAndroid(packageNameAndroid), platform(platform), productId(productId), purchaseState(purchaseState), purchaseToken(purchaseToken), quantity(quantity), signatureAndroid(signatureAndroid), transactionDate(transactionDate) {}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
} // namespace margelo::nitro::iap
|
|
63
|
+
|
|
64
|
+
namespace margelo::nitro {
|
|
65
|
+
|
|
66
|
+
// C++ PurchaseAndroid <> JS PurchaseAndroid (object)
|
|
67
|
+
template <>
|
|
68
|
+
struct JSIConverter<margelo::nitro::iap::PurchaseAndroid> final {
|
|
69
|
+
static inline margelo::nitro::iap::PurchaseAndroid fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
70
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
71
|
+
return margelo::nitro::iap::PurchaseAndroid(
|
|
72
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, "autoRenewingAndroid")),
|
|
73
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "dataAndroid")),
|
|
74
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "developerPayloadAndroid")),
|
|
75
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "id")),
|
|
76
|
+
JSIConverter<std::optional<std::vector<std::string>>>::fromJSI(runtime, obj.getProperty(runtime, "ids")),
|
|
77
|
+
JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, "isAcknowledgedAndroid")),
|
|
78
|
+
JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, "isAutoRenewing")),
|
|
79
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "obfuscatedAccountIdAndroid")),
|
|
80
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "obfuscatedProfileIdAndroid")),
|
|
81
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "packageNameAndroid")),
|
|
82
|
+
JSIConverter<margelo::nitro::iap::IapPlatform>::fromJSI(runtime, obj.getProperty(runtime, "platform")),
|
|
83
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "productId")),
|
|
84
|
+
JSIConverter<margelo::nitro::iap::PurchaseState>::fromJSI(runtime, obj.getProperty(runtime, "purchaseState")),
|
|
85
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "purchaseToken")),
|
|
86
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "quantity")),
|
|
87
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "signatureAndroid")),
|
|
88
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "transactionDate"))
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::iap::PurchaseAndroid& arg) {
|
|
92
|
+
jsi::Object obj(runtime);
|
|
93
|
+
obj.setProperty(runtime, "autoRenewingAndroid", JSIConverter<std::optional<bool>>::toJSI(runtime, arg.autoRenewingAndroid));
|
|
94
|
+
obj.setProperty(runtime, "dataAndroid", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.dataAndroid));
|
|
95
|
+
obj.setProperty(runtime, "developerPayloadAndroid", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.developerPayloadAndroid));
|
|
96
|
+
obj.setProperty(runtime, "id", JSIConverter<std::string>::toJSI(runtime, arg.id));
|
|
97
|
+
obj.setProperty(runtime, "ids", JSIConverter<std::optional<std::vector<std::string>>>::toJSI(runtime, arg.ids));
|
|
98
|
+
obj.setProperty(runtime, "isAcknowledgedAndroid", JSIConverter<std::optional<bool>>::toJSI(runtime, arg.isAcknowledgedAndroid));
|
|
99
|
+
obj.setProperty(runtime, "isAutoRenewing", JSIConverter<bool>::toJSI(runtime, arg.isAutoRenewing));
|
|
100
|
+
obj.setProperty(runtime, "obfuscatedAccountIdAndroid", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.obfuscatedAccountIdAndroid));
|
|
101
|
+
obj.setProperty(runtime, "obfuscatedProfileIdAndroid", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.obfuscatedProfileIdAndroid));
|
|
102
|
+
obj.setProperty(runtime, "packageNameAndroid", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.packageNameAndroid));
|
|
103
|
+
obj.setProperty(runtime, "platform", JSIConverter<margelo::nitro::iap::IapPlatform>::toJSI(runtime, arg.platform));
|
|
104
|
+
obj.setProperty(runtime, "productId", JSIConverter<std::string>::toJSI(runtime, arg.productId));
|
|
105
|
+
obj.setProperty(runtime, "purchaseState", JSIConverter<margelo::nitro::iap::PurchaseState>::toJSI(runtime, arg.purchaseState));
|
|
106
|
+
obj.setProperty(runtime, "purchaseToken", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.purchaseToken));
|
|
107
|
+
obj.setProperty(runtime, "quantity", JSIConverter<double>::toJSI(runtime, arg.quantity));
|
|
108
|
+
obj.setProperty(runtime, "signatureAndroid", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.signatureAndroid));
|
|
109
|
+
obj.setProperty(runtime, "transactionDate", JSIConverter<double>::toJSI(runtime, arg.transactionDate));
|
|
110
|
+
return obj;
|
|
111
|
+
}
|
|
112
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
113
|
+
if (!value.isObject()) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
jsi::Object obj = value.getObject(runtime);
|
|
117
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, "autoRenewingAndroid"))) return false;
|
|
118
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "dataAndroid"))) return false;
|
|
119
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "developerPayloadAndroid"))) return false;
|
|
120
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "id"))) return false;
|
|
121
|
+
if (!JSIConverter<std::optional<std::vector<std::string>>>::canConvert(runtime, obj.getProperty(runtime, "ids"))) return false;
|
|
122
|
+
if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, "isAcknowledgedAndroid"))) return false;
|
|
123
|
+
if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, "isAutoRenewing"))) return false;
|
|
124
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "obfuscatedAccountIdAndroid"))) return false;
|
|
125
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "obfuscatedProfileIdAndroid"))) return false;
|
|
126
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "packageNameAndroid"))) return false;
|
|
127
|
+
if (!JSIConverter<margelo::nitro::iap::IapPlatform>::canConvert(runtime, obj.getProperty(runtime, "platform"))) return false;
|
|
128
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "productId"))) return false;
|
|
129
|
+
if (!JSIConverter<margelo::nitro::iap::PurchaseState>::canConvert(runtime, obj.getProperty(runtime, "purchaseState"))) return false;
|
|
130
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "purchaseToken"))) return false;
|
|
131
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "quantity"))) return false;
|
|
132
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "signatureAndroid"))) return false;
|
|
133
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "transactionDate"))) return false;
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
} // namespace margelo::nitro
|