react-native-iap 14.4.45 → 14.4.47
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 +2 -2
- package/android/src/main/java/com/margelo/nitro/iap/HybridRnIap.kt +113 -3
- package/ios/HybridRnIap.swift +61 -2
- package/lib/module/hooks/useIAP.js +9 -1
- package/lib/module/hooks/useIAP.js.map +1 -1
- package/lib/module/index.js +68 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/types.js +5 -0
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils/errorMapping.js +32 -6
- package/lib/module/utils/errorMapping.js.map +1 -1
- package/lib/typescript/src/hooks/useIAP.d.ts +5 -1
- package/lib/typescript/src/hooks/useIAP.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +34 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/RnIap.nitro.d.ts +72 -26
- package/lib/typescript/src/specs/RnIap.nitro.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +109 -51
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/utils/errorMapping.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JHybridRnIapSpec.cpp +76 -0
- package/nitrogen/generated/android/c++/JHybridRnIapSpec.hpp +2 -0
- package/nitrogen/generated/android/c++/JIapkitPurchaseState.hpp +80 -0
- package/nitrogen/generated/android/c++/JIapkitStore.hpp +59 -0
- package/nitrogen/generated/android/c++/JNitroVerifyPurchaseWithIapkitAppleProps.hpp +57 -0
- package/nitrogen/generated/android/c++/JNitroVerifyPurchaseWithIapkitGoogleProps.hpp +57 -0
- package/nitrogen/generated/android/c++/JNitroVerifyPurchaseWithIapkitProps.hpp +70 -0
- package/nitrogen/generated/android/c++/JNitroVerifyPurchaseWithIapkitResult.hpp +68 -0
- package/nitrogen/generated/android/c++/JNitroVerifyPurchaseWithProviderProps.hpp +70 -0
- package/nitrogen/generated/android/c++/JNitroVerifyPurchaseWithProviderResult.hpp +86 -0
- package/nitrogen/generated/android/c++/JPurchaseVerificationProvider.hpp +59 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/HybridRnIapSpec.kt +8 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/IapkitPurchaseState.kt +28 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/IapkitStore.kt +21 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroVerifyPurchaseWithIapkitAppleProps.kt +36 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroVerifyPurchaseWithIapkitGoogleProps.kt +36 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroVerifyPurchaseWithIapkitProps.kt +42 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroVerifyPurchaseWithIapkitResult.kt +42 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroVerifyPurchaseWithProviderProps.kt +39 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroVerifyPurchaseWithProviderResult.kt +39 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/PurchaseVerificationProvider.kt +21 -0
- package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Bridge.cpp +8 -0
- package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Bridge.hpp +123 -0
- package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Umbrella.hpp +27 -0
- package/nitrogen/generated/ios/c++/HybridRnIapSpecSwift.hpp +43 -0
- package/nitrogen/generated/ios/swift/Func_void_NitroVerifyPurchaseWithProviderResult.swift +47 -0
- package/nitrogen/generated/ios/swift/HybridRnIapSpec.swift +2 -0
- package/nitrogen/generated/ios/swift/HybridRnIapSpec_cxx.swift +45 -0
- package/nitrogen/generated/ios/swift/IapkitPurchaseState.swift +68 -0
- package/nitrogen/generated/ios/swift/IapkitStore.swift +40 -0
- package/nitrogen/generated/ios/swift/NitroVerifyPurchaseWithIapkitAppleProps.swift +35 -0
- package/nitrogen/generated/ios/swift/NitroVerifyPurchaseWithIapkitGoogleProps.swift +35 -0
- package/nitrogen/generated/ios/swift/NitroVerifyPurchaseWithIapkitProps.swift +100 -0
- package/nitrogen/generated/ios/swift/NitroVerifyPurchaseWithIapkitResult.swift +57 -0
- package/nitrogen/generated/ios/swift/NitroVerifyPurchaseWithProviderProps.swift +58 -0
- package/nitrogen/generated/ios/swift/NitroVerifyPurchaseWithProviderResult.swift +58 -0
- package/nitrogen/generated/ios/swift/PurchaseVerificationProvider.swift +40 -0
- package/nitrogen/generated/shared/c++/HybridRnIapSpec.cpp +2 -0
- package/nitrogen/generated/shared/c++/HybridRnIapSpec.hpp +8 -0
- package/nitrogen/generated/shared/c++/IapkitPurchaseState.hpp +104 -0
- package/nitrogen/generated/shared/c++/IapkitStore.hpp +76 -0
- package/nitrogen/generated/shared/c++/NitroVerifyPurchaseWithIapkitAppleProps.hpp +75 -0
- package/nitrogen/generated/shared/c++/NitroVerifyPurchaseWithIapkitGoogleProps.hpp +75 -0
- package/nitrogen/generated/shared/c++/NitroVerifyPurchaseWithIapkitProps.hpp +89 -0
- package/nitrogen/generated/shared/c++/NitroVerifyPurchaseWithIapkitResult.hpp +87 -0
- package/nitrogen/generated/shared/c++/NitroVerifyPurchaseWithProviderProps.hpp +84 -0
- package/nitrogen/generated/shared/c++/NitroVerifyPurchaseWithProviderResult.hpp +84 -0
- package/nitrogen/generated/shared/c++/PurchaseVerificationProvider.hpp +76 -0
- package/openiap-versions.json +3 -3
- package/package.json +1 -1
- package/src/hooks/useIAP.ts +32 -0
- package/src/index.ts +74 -5
- package/src/specs/RnIap.nitro.ts +101 -28
- package/src/types.ts +126 -57
- package/src/utils/errorMapping.ts +32 -4
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroVerifyPurchaseWithProviderProps.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
|
+
#if __has_include(<NitroModules/JSIHelpers.hpp>)
|
|
21
|
+
#include <NitroModules/JSIHelpers.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
// Forward declaration of `NitroVerifyPurchaseWithIapkitProps` to properly resolve imports.
|
|
27
|
+
namespace margelo::nitro::iap { struct NitroVerifyPurchaseWithIapkitProps; }
|
|
28
|
+
// Forward declaration of `PurchaseVerificationProvider` to properly resolve imports.
|
|
29
|
+
namespace margelo::nitro::iap { enum class PurchaseVerificationProvider; }
|
|
30
|
+
|
|
31
|
+
#include "NitroVerifyPurchaseWithIapkitProps.hpp"
|
|
32
|
+
#include <optional>
|
|
33
|
+
#include "PurchaseVerificationProvider.hpp"
|
|
34
|
+
|
|
35
|
+
namespace margelo::nitro::iap {
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A struct which can be represented as a JavaScript object (NitroVerifyPurchaseWithProviderProps).
|
|
39
|
+
*/
|
|
40
|
+
struct NitroVerifyPurchaseWithProviderProps {
|
|
41
|
+
public:
|
|
42
|
+
std::optional<NitroVerifyPurchaseWithIapkitProps> iapkit SWIFT_PRIVATE;
|
|
43
|
+
PurchaseVerificationProvider provider SWIFT_PRIVATE;
|
|
44
|
+
|
|
45
|
+
public:
|
|
46
|
+
NitroVerifyPurchaseWithProviderProps() = default;
|
|
47
|
+
explicit NitroVerifyPurchaseWithProviderProps(std::optional<NitroVerifyPurchaseWithIapkitProps> iapkit, PurchaseVerificationProvider provider): iapkit(iapkit), provider(provider) {}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
} // namespace margelo::nitro::iap
|
|
51
|
+
|
|
52
|
+
namespace margelo::nitro {
|
|
53
|
+
|
|
54
|
+
// C++ NitroVerifyPurchaseWithProviderProps <> JS NitroVerifyPurchaseWithProviderProps (object)
|
|
55
|
+
template <>
|
|
56
|
+
struct JSIConverter<margelo::nitro::iap::NitroVerifyPurchaseWithProviderProps> final {
|
|
57
|
+
static inline margelo::nitro::iap::NitroVerifyPurchaseWithProviderProps fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
58
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
59
|
+
return margelo::nitro::iap::NitroVerifyPurchaseWithProviderProps(
|
|
60
|
+
JSIConverter<std::optional<margelo::nitro::iap::NitroVerifyPurchaseWithIapkitProps>>::fromJSI(runtime, obj.getProperty(runtime, "iapkit")),
|
|
61
|
+
JSIConverter<margelo::nitro::iap::PurchaseVerificationProvider>::fromJSI(runtime, obj.getProperty(runtime, "provider"))
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::iap::NitroVerifyPurchaseWithProviderProps& arg) {
|
|
65
|
+
jsi::Object obj(runtime);
|
|
66
|
+
obj.setProperty(runtime, "iapkit", JSIConverter<std::optional<margelo::nitro::iap::NitroVerifyPurchaseWithIapkitProps>>::toJSI(runtime, arg.iapkit));
|
|
67
|
+
obj.setProperty(runtime, "provider", JSIConverter<margelo::nitro::iap::PurchaseVerificationProvider>::toJSI(runtime, arg.provider));
|
|
68
|
+
return obj;
|
|
69
|
+
}
|
|
70
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
71
|
+
if (!value.isObject()) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
jsi::Object obj = value.getObject(runtime);
|
|
75
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
if (!JSIConverter<std::optional<margelo::nitro::iap::NitroVerifyPurchaseWithIapkitProps>>::canConvert(runtime, obj.getProperty(runtime, "iapkit"))) return false;
|
|
79
|
+
if (!JSIConverter<margelo::nitro::iap::PurchaseVerificationProvider>::canConvert(runtime, obj.getProperty(runtime, "provider"))) return false;
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// NitroVerifyPurchaseWithProviderResult.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
|
+
#if __has_include(<NitroModules/JSIHelpers.hpp>)
|
|
21
|
+
#include <NitroModules/JSIHelpers.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
// Forward declaration of `NitroVerifyPurchaseWithIapkitResult` to properly resolve imports.
|
|
27
|
+
namespace margelo::nitro::iap { struct NitroVerifyPurchaseWithIapkitResult; }
|
|
28
|
+
// Forward declaration of `PurchaseVerificationProvider` to properly resolve imports.
|
|
29
|
+
namespace margelo::nitro::iap { enum class PurchaseVerificationProvider; }
|
|
30
|
+
|
|
31
|
+
#include "NitroVerifyPurchaseWithIapkitResult.hpp"
|
|
32
|
+
#include <vector>
|
|
33
|
+
#include "PurchaseVerificationProvider.hpp"
|
|
34
|
+
|
|
35
|
+
namespace margelo::nitro::iap {
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A struct which can be represented as a JavaScript object (NitroVerifyPurchaseWithProviderResult).
|
|
39
|
+
*/
|
|
40
|
+
struct NitroVerifyPurchaseWithProviderResult {
|
|
41
|
+
public:
|
|
42
|
+
std::vector<NitroVerifyPurchaseWithIapkitResult> iapkit SWIFT_PRIVATE;
|
|
43
|
+
PurchaseVerificationProvider provider SWIFT_PRIVATE;
|
|
44
|
+
|
|
45
|
+
public:
|
|
46
|
+
NitroVerifyPurchaseWithProviderResult() = default;
|
|
47
|
+
explicit NitroVerifyPurchaseWithProviderResult(std::vector<NitroVerifyPurchaseWithIapkitResult> iapkit, PurchaseVerificationProvider provider): iapkit(iapkit), provider(provider) {}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
} // namespace margelo::nitro::iap
|
|
51
|
+
|
|
52
|
+
namespace margelo::nitro {
|
|
53
|
+
|
|
54
|
+
// C++ NitroVerifyPurchaseWithProviderResult <> JS NitroVerifyPurchaseWithProviderResult (object)
|
|
55
|
+
template <>
|
|
56
|
+
struct JSIConverter<margelo::nitro::iap::NitroVerifyPurchaseWithProviderResult> final {
|
|
57
|
+
static inline margelo::nitro::iap::NitroVerifyPurchaseWithProviderResult fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
58
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
59
|
+
return margelo::nitro::iap::NitroVerifyPurchaseWithProviderResult(
|
|
60
|
+
JSIConverter<std::vector<margelo::nitro::iap::NitroVerifyPurchaseWithIapkitResult>>::fromJSI(runtime, obj.getProperty(runtime, "iapkit")),
|
|
61
|
+
JSIConverter<margelo::nitro::iap::PurchaseVerificationProvider>::fromJSI(runtime, obj.getProperty(runtime, "provider"))
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::iap::NitroVerifyPurchaseWithProviderResult& arg) {
|
|
65
|
+
jsi::Object obj(runtime);
|
|
66
|
+
obj.setProperty(runtime, "iapkit", JSIConverter<std::vector<margelo::nitro::iap::NitroVerifyPurchaseWithIapkitResult>>::toJSI(runtime, arg.iapkit));
|
|
67
|
+
obj.setProperty(runtime, "provider", JSIConverter<margelo::nitro::iap::PurchaseVerificationProvider>::toJSI(runtime, arg.provider));
|
|
68
|
+
return obj;
|
|
69
|
+
}
|
|
70
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
71
|
+
if (!value.isObject()) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
jsi::Object obj = value.getObject(runtime);
|
|
75
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
if (!JSIConverter<std::vector<margelo::nitro::iap::NitroVerifyPurchaseWithIapkitResult>>::canConvert(runtime, obj.getProperty(runtime, "iapkit"))) return false;
|
|
79
|
+
if (!JSIConverter<margelo::nitro::iap::PurchaseVerificationProvider>::canConvert(runtime, obj.getProperty(runtime, "provider"))) return false;
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// PurchaseVerificationProvider.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 (PurchaseVerificationProvider).
|
|
30
|
+
*/
|
|
31
|
+
enum class PurchaseVerificationProvider {
|
|
32
|
+
NONE SWIFT_NAME(none) = 0,
|
|
33
|
+
IAPKIT SWIFT_NAME(iapkit) = 1,
|
|
34
|
+
} CLOSED_ENUM;
|
|
35
|
+
|
|
36
|
+
} // namespace margelo::nitro::iap
|
|
37
|
+
|
|
38
|
+
namespace margelo::nitro {
|
|
39
|
+
|
|
40
|
+
// C++ PurchaseVerificationProvider <> JS PurchaseVerificationProvider (union)
|
|
41
|
+
template <>
|
|
42
|
+
struct JSIConverter<margelo::nitro::iap::PurchaseVerificationProvider> final {
|
|
43
|
+
static inline margelo::nitro::iap::PurchaseVerificationProvider 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("none"): return margelo::nitro::iap::PurchaseVerificationProvider::NONE;
|
|
47
|
+
case hashString("iapkit"): return margelo::nitro::iap::PurchaseVerificationProvider::IAPKIT;
|
|
48
|
+
default: [[unlikely]]
|
|
49
|
+
throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum PurchaseVerificationProvider - invalid value!");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::iap::PurchaseVerificationProvider arg) {
|
|
53
|
+
switch (arg) {
|
|
54
|
+
case margelo::nitro::iap::PurchaseVerificationProvider::NONE: return JSIConverter<std::string>::toJSI(runtime, "none");
|
|
55
|
+
case margelo::nitro::iap::PurchaseVerificationProvider::IAPKIT: return JSIConverter<std::string>::toJSI(runtime, "iapkit");
|
|
56
|
+
default: [[unlikely]]
|
|
57
|
+
throw std::invalid_argument("Cannot convert PurchaseVerificationProvider 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("none"):
|
|
68
|
+
case hashString("iapkit"):
|
|
69
|
+
return true;
|
|
70
|
+
default:
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
} // namespace margelo::nitro
|
package/openiap-versions.json
CHANGED
package/package.json
CHANGED
package/src/hooks/useIAP.ts
CHANGED
|
@@ -14,6 +14,8 @@ import {
|
|
|
14
14
|
requestPurchase as requestPurchaseInternal,
|
|
15
15
|
fetchProducts,
|
|
16
16
|
validateReceipt as validateReceiptInternal,
|
|
17
|
+
verifyPurchase as verifyPurchaseTopLevel,
|
|
18
|
+
verifyPurchaseWithProvider as verifyPurchaseWithProviderTopLevel,
|
|
17
19
|
getActiveSubscriptions,
|
|
18
20
|
hasActiveSubscriptions,
|
|
19
21
|
restorePurchases as restorePurchasesTopLevel,
|
|
@@ -33,6 +35,10 @@ import type {
|
|
|
33
35
|
RequestPurchaseResult,
|
|
34
36
|
AlternativeBillingModeAndroid,
|
|
35
37
|
UserChoiceBillingDetails,
|
|
38
|
+
VerifyPurchaseProps,
|
|
39
|
+
VerifyPurchaseResult,
|
|
40
|
+
VerifyPurchaseWithProviderProps,
|
|
41
|
+
VerifyPurchaseWithProviderResult,
|
|
36
42
|
} from '../types';
|
|
37
43
|
import type {
|
|
38
44
|
ActiveSubscription,
|
|
@@ -74,6 +80,14 @@ type UseIap = {
|
|
|
74
80
|
isSub?: boolean;
|
|
75
81
|
},
|
|
76
82
|
) => Promise<any>;
|
|
83
|
+
/** Verify purchase with the configured providers (alias for validateReceipt) */
|
|
84
|
+
verifyPurchase: (
|
|
85
|
+
options: VerifyPurchaseProps,
|
|
86
|
+
) => Promise<VerifyPurchaseResult>;
|
|
87
|
+
/** Verify purchase with a specific provider (e.g., IAPKit) */
|
|
88
|
+
verifyPurchaseWithProvider: (
|
|
89
|
+
options: VerifyPurchaseWithProviderProps,
|
|
90
|
+
) => Promise<VerifyPurchaseWithProviderResult>;
|
|
77
91
|
restorePurchases: () => Promise<void>;
|
|
78
92
|
getPromotedProductIOS: () => Promise<Product | null>;
|
|
79
93
|
requestPurchaseOnPromotedProductIOS: () => Promise<boolean>;
|
|
@@ -314,6 +328,22 @@ export function useIAP(options?: UseIapOptions): UseIap {
|
|
|
314
328
|
[],
|
|
315
329
|
);
|
|
316
330
|
|
|
331
|
+
const verifyPurchase = useCallback(
|
|
332
|
+
async (options: VerifyPurchaseProps): Promise<VerifyPurchaseResult> => {
|
|
333
|
+
return verifyPurchaseTopLevel(options);
|
|
334
|
+
},
|
|
335
|
+
[],
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
const verifyPurchaseWithProvider = useCallback(
|
|
339
|
+
async (
|
|
340
|
+
options: VerifyPurchaseWithProviderProps,
|
|
341
|
+
): Promise<VerifyPurchaseWithProviderResult> => {
|
|
342
|
+
return verifyPurchaseWithProviderTopLevel(options);
|
|
343
|
+
},
|
|
344
|
+
[],
|
|
345
|
+
);
|
|
346
|
+
|
|
317
347
|
const initIapWithSubscriptions = useCallback(async (): Promise<void> => {
|
|
318
348
|
// Register listeners BEFORE initConnection to avoid race condition
|
|
319
349
|
subscriptionsRef.current.purchaseUpdate = purchaseUpdatedListener(
|
|
@@ -420,6 +450,8 @@ export function useIAP(options?: UseIapOptions): UseIap {
|
|
|
420
450
|
fetchProducts: fetchProductsInternal,
|
|
421
451
|
requestPurchase,
|
|
422
452
|
validateReceipt,
|
|
453
|
+
verifyPurchase,
|
|
454
|
+
verifyPurchaseWithProvider,
|
|
423
455
|
restorePurchases: async () => {
|
|
424
456
|
try {
|
|
425
457
|
await restorePurchasesTopLevel();
|
package/src/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ import type {
|
|
|
13
13
|
NitroSubscriptionStatus,
|
|
14
14
|
RnIap,
|
|
15
15
|
} from './specs/RnIap.nitro';
|
|
16
|
+
import {ErrorCode} from './types';
|
|
16
17
|
import type {
|
|
17
18
|
AndroidSubscriptionOfferInput,
|
|
18
19
|
DiscountOfferInputIOS,
|
|
@@ -27,8 +28,8 @@ import type {
|
|
|
27
28
|
PurchaseIOS,
|
|
28
29
|
QueryField,
|
|
29
30
|
AppTransaction,
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
VerifyPurchaseResultAndroid,
|
|
32
|
+
VerifyPurchaseResultIOS,
|
|
32
33
|
RequestPurchaseAndroidProps,
|
|
33
34
|
RequestPurchaseIosProps,
|
|
34
35
|
RequestPurchasePropsByPlatforms,
|
|
@@ -1336,7 +1337,7 @@ export const consumePurchaseAndroid: MutationField<
|
|
|
1336
1337
|
* Validate receipt on both iOS and Android platforms
|
|
1337
1338
|
* @param sku - Product SKU
|
|
1338
1339
|
* @param androidOptions - Android-specific validation options (required for Android)
|
|
1339
|
-
* @returns Promise<
|
|
1340
|
+
* @returns Promise<VerifyPurchaseResultIOS | VerifyPurchaseResultAndroid> - Platform-specific receipt validation result
|
|
1340
1341
|
*/
|
|
1341
1342
|
export const validateReceipt: MutationField<'validateReceipt'> = async (
|
|
1342
1343
|
options,
|
|
@@ -1364,7 +1365,7 @@ export const validateReceipt: MutationField<'validateReceipt'> = async (
|
|
|
1364
1365
|
// Convert Nitro result to public API result
|
|
1365
1366
|
if (Platform.OS === 'ios') {
|
|
1366
1367
|
const iosResult = nitroResult as NitroReceiptValidationResultIOS;
|
|
1367
|
-
const result:
|
|
1368
|
+
const result: VerifyPurchaseResultIOS = {
|
|
1368
1369
|
isValid: iosResult.isValid,
|
|
1369
1370
|
receiptData: iosResult.receiptData,
|
|
1370
1371
|
jwsRepresentation: iosResult.jwsRepresentation,
|
|
@@ -1376,7 +1377,7 @@ export const validateReceipt: MutationField<'validateReceipt'> = async (
|
|
|
1376
1377
|
} else {
|
|
1377
1378
|
// Android
|
|
1378
1379
|
const androidResult = nitroResult as NitroReceiptValidationResultAndroid;
|
|
1379
|
-
const result:
|
|
1380
|
+
const result: VerifyPurchaseResultAndroid = {
|
|
1380
1381
|
autoRenewing: androidResult.autoRenewing,
|
|
1381
1382
|
betaProduct: androidResult.betaProduct,
|
|
1382
1383
|
cancelDate: androidResult.cancelDate,
|
|
@@ -1410,6 +1411,74 @@ export const validateReceipt: MutationField<'validateReceipt'> = async (
|
|
|
1410
1411
|
}
|
|
1411
1412
|
};
|
|
1412
1413
|
|
|
1414
|
+
/**
|
|
1415
|
+
* Verify purchase with the configured providers
|
|
1416
|
+
*
|
|
1417
|
+
* This function uses the native OpenIAP verifyPurchase implementation
|
|
1418
|
+
* which validates purchases using platform-specific methods.
|
|
1419
|
+
* This is an alias for validateReceipt for API consistency with OpenIAP.
|
|
1420
|
+
*
|
|
1421
|
+
* @param options - Receipt validation options containing the SKU
|
|
1422
|
+
* @returns Promise resolving to receipt validation result
|
|
1423
|
+
*/
|
|
1424
|
+
export const verifyPurchase: MutationField<'verifyPurchase'> = validateReceipt;
|
|
1425
|
+
|
|
1426
|
+
/**
|
|
1427
|
+
* Verify purchase with a specific provider (e.g., IAPKit)
|
|
1428
|
+
*
|
|
1429
|
+
* This function allows you to verify purchases using external verification
|
|
1430
|
+
* services like IAPKit, which provide additional validation and security.
|
|
1431
|
+
*
|
|
1432
|
+
* @param options - Verification options including provider and credentials
|
|
1433
|
+
* @returns Promise resolving to provider-specific verification result
|
|
1434
|
+
*
|
|
1435
|
+
* @example
|
|
1436
|
+
* ```typescript
|
|
1437
|
+
* const result = await verifyPurchaseWithProvider({
|
|
1438
|
+
* provider: 'iapkit',
|
|
1439
|
+
* iapkit: {
|
|
1440
|
+
* apiKey: 'your-api-key',
|
|
1441
|
+
* apple: { jws: purchase.purchaseToken },
|
|
1442
|
+
* google: { purchaseToken: purchase.purchaseToken },
|
|
1443
|
+
* },
|
|
1444
|
+
* });
|
|
1445
|
+
* ```
|
|
1446
|
+
*/
|
|
1447
|
+
export const verifyPurchaseWithProvider: MutationField<
|
|
1448
|
+
'verifyPurchaseWithProvider'
|
|
1449
|
+
> = async (options) => {
|
|
1450
|
+
try {
|
|
1451
|
+
const result = await IAP.instance.verifyPurchaseWithProvider({
|
|
1452
|
+
provider: options.provider,
|
|
1453
|
+
iapkit: options.iapkit ?? null,
|
|
1454
|
+
});
|
|
1455
|
+
// Validate provider - Nitro spec allows 'none' for compatibility, but this function only supports 'iapkit'
|
|
1456
|
+
if (result.provider !== 'iapkit') {
|
|
1457
|
+
throw createPurchaseError({
|
|
1458
|
+
code: ErrorCode.DeveloperError,
|
|
1459
|
+
message: `Unsupported provider: ${result.provider}. Only 'iapkit' is supported.`,
|
|
1460
|
+
});
|
|
1461
|
+
}
|
|
1462
|
+
return {
|
|
1463
|
+
provider: result.provider,
|
|
1464
|
+
iapkit: result.iapkit.map((item) => ({
|
|
1465
|
+
isValid: item.isValid,
|
|
1466
|
+
state: item.state,
|
|
1467
|
+
store: item.store,
|
|
1468
|
+
})),
|
|
1469
|
+
};
|
|
1470
|
+
} catch (error) {
|
|
1471
|
+
RnIapConsole.error('[verifyPurchaseWithProvider] Failed:', error);
|
|
1472
|
+
const parsedError = parseErrorStringToJsonObj(error);
|
|
1473
|
+
throw createPurchaseError({
|
|
1474
|
+
code: parsedError.code,
|
|
1475
|
+
message: parsedError.message,
|
|
1476
|
+
responseCode: parsedError.responseCode,
|
|
1477
|
+
debugMessage: parsedError.debugMessage,
|
|
1478
|
+
});
|
|
1479
|
+
}
|
|
1480
|
+
};
|
|
1481
|
+
|
|
1413
1482
|
/**
|
|
1414
1483
|
* Sync iOS purchases with App Store (iOS only)
|
|
1415
1484
|
* @returns Promise<boolean>
|
package/src/specs/RnIap.nitro.ts
CHANGED
|
@@ -14,9 +14,9 @@ import type {
|
|
|
14
14
|
ProductCommon,
|
|
15
15
|
PurchaseCommon,
|
|
16
16
|
PurchaseOptions,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
VerifyPurchaseAndroidOptions,
|
|
18
|
+
VerifyPurchaseProps,
|
|
19
|
+
VerifyPurchaseResultAndroid,
|
|
20
20
|
RequestPurchaseIosProps,
|
|
21
21
|
RequestPurchaseResult,
|
|
22
22
|
RequestSubscriptionAndroidProps,
|
|
@@ -24,6 +24,25 @@ import type {
|
|
|
24
24
|
PaymentModeIOS,
|
|
25
25
|
} from '../types';
|
|
26
26
|
|
|
27
|
+
// Nitro-compatible enum types (Nitro doesn't support inline string unions from types.ts)
|
|
28
|
+
export type IapPlatform = 'ios' | 'android';
|
|
29
|
+
|
|
30
|
+
export type IapkitPurchaseState =
|
|
31
|
+
| 'entitled'
|
|
32
|
+
| 'pending-acknowledgment'
|
|
33
|
+
| 'pending'
|
|
34
|
+
| 'canceled'
|
|
35
|
+
| 'expired'
|
|
36
|
+
| 'ready-to-consume'
|
|
37
|
+
| 'consumed'
|
|
38
|
+
| 'unknown'
|
|
39
|
+
| 'inauthentic';
|
|
40
|
+
|
|
41
|
+
export type IapkitStore = 'apple' | 'google';
|
|
42
|
+
|
|
43
|
+
// Note: Nitro requires at least 2 values for union types
|
|
44
|
+
export type PurchaseVerificationProvider = 'iapkit' | 'none';
|
|
45
|
+
|
|
27
46
|
// ╔══════════════════════════════════════════════════════════════════════════╗
|
|
28
47
|
// ║ PARAMS ║
|
|
29
48
|
// ╚══════════════════════════════════════════════════════════════════════════╝
|
|
@@ -31,14 +50,14 @@ import type {
|
|
|
31
50
|
// Receipt validation parameters
|
|
32
51
|
|
|
33
52
|
export interface NitroReceiptValidationAndroidOptions {
|
|
34
|
-
accessToken:
|
|
35
|
-
isSub?:
|
|
36
|
-
packageName:
|
|
37
|
-
productToken:
|
|
53
|
+
accessToken: VerifyPurchaseAndroidOptions['accessToken'];
|
|
54
|
+
isSub?: VerifyPurchaseAndroidOptions['isSub'];
|
|
55
|
+
packageName: VerifyPurchaseAndroidOptions['packageName'];
|
|
56
|
+
productToken: VerifyPurchaseAndroidOptions['productToken'];
|
|
38
57
|
}
|
|
39
58
|
|
|
40
59
|
export interface NitroReceiptValidationParams {
|
|
41
|
-
sku:
|
|
60
|
+
sku: VerifyPurchaseProps['sku'];
|
|
42
61
|
androidOptions?: NitroReceiptValidationAndroidOptions | null;
|
|
43
62
|
}
|
|
44
63
|
|
|
@@ -165,24 +184,58 @@ export interface NitroReceiptValidationResultIOS {
|
|
|
165
184
|
}
|
|
166
185
|
|
|
167
186
|
export interface NitroReceiptValidationResultAndroid {
|
|
168
|
-
autoRenewing:
|
|
169
|
-
betaProduct:
|
|
170
|
-
cancelDate:
|
|
171
|
-
cancelReason:
|
|
172
|
-
deferredDate:
|
|
173
|
-
deferredSku:
|
|
174
|
-
freeTrialEndDate:
|
|
175
|
-
gracePeriodEndDate:
|
|
176
|
-
parentProductId:
|
|
177
|
-
productId:
|
|
178
|
-
productType:
|
|
179
|
-
purchaseDate:
|
|
180
|
-
quantity:
|
|
181
|
-
receiptId:
|
|
182
|
-
renewalDate:
|
|
183
|
-
term:
|
|
184
|
-
termSku:
|
|
185
|
-
testTransaction:
|
|
187
|
+
autoRenewing: VerifyPurchaseResultAndroid['autoRenewing'];
|
|
188
|
+
betaProduct: VerifyPurchaseResultAndroid['betaProduct'];
|
|
189
|
+
cancelDate: VerifyPurchaseResultAndroid['cancelDate'];
|
|
190
|
+
cancelReason: VerifyPurchaseResultAndroid['cancelReason'];
|
|
191
|
+
deferredDate: VerifyPurchaseResultAndroid['deferredDate'];
|
|
192
|
+
deferredSku: VerifyPurchaseResultAndroid['deferredSku'];
|
|
193
|
+
freeTrialEndDate: VerifyPurchaseResultAndroid['freeTrialEndDate'];
|
|
194
|
+
gracePeriodEndDate: VerifyPurchaseResultAndroid['gracePeriodEndDate'];
|
|
195
|
+
parentProductId: VerifyPurchaseResultAndroid['parentProductId'];
|
|
196
|
+
productId: VerifyPurchaseResultAndroid['productId'];
|
|
197
|
+
productType: VerifyPurchaseResultAndroid['productType'];
|
|
198
|
+
purchaseDate: VerifyPurchaseResultAndroid['purchaseDate'];
|
|
199
|
+
quantity: VerifyPurchaseResultAndroid['quantity'];
|
|
200
|
+
receiptId: VerifyPurchaseResultAndroid['receiptId'];
|
|
201
|
+
renewalDate: VerifyPurchaseResultAndroid['renewalDate'];
|
|
202
|
+
term: VerifyPurchaseResultAndroid['term'];
|
|
203
|
+
termSku: VerifyPurchaseResultAndroid['termSku'];
|
|
204
|
+
testTransaction: VerifyPurchaseResultAndroid['testTransaction'];
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// VerifyPurchaseWithProvider types
|
|
208
|
+
|
|
209
|
+
export interface NitroVerifyPurchaseWithIapkitAppleProps {
|
|
210
|
+
/** The JWS token returned with the purchase response. */
|
|
211
|
+
jws: string;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export interface NitroVerifyPurchaseWithIapkitGoogleProps {
|
|
215
|
+
/** The token provided to the user's device when the product or subscription was purchased. */
|
|
216
|
+
purchaseToken: string;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export interface NitroVerifyPurchaseWithIapkitProps {
|
|
220
|
+
apiKey?: string | null;
|
|
221
|
+
apple?: NitroVerifyPurchaseWithIapkitAppleProps | null;
|
|
222
|
+
google?: NitroVerifyPurchaseWithIapkitGoogleProps | null;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export interface NitroVerifyPurchaseWithProviderProps {
|
|
226
|
+
iapkit?: NitroVerifyPurchaseWithIapkitProps | null;
|
|
227
|
+
provider: PurchaseVerificationProvider;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
export interface NitroVerifyPurchaseWithIapkitResult {
|
|
231
|
+
isValid: boolean;
|
|
232
|
+
state: IapkitPurchaseState;
|
|
233
|
+
store: IapkitStore;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export interface NitroVerifyPurchaseWithProviderResult {
|
|
237
|
+
iapkit: NitroVerifyPurchaseWithIapkitResult[];
|
|
238
|
+
provider: PurchaseVerificationProvider;
|
|
186
239
|
}
|
|
187
240
|
|
|
188
241
|
/**
|
|
@@ -199,7 +252,7 @@ export interface NitroPurchase {
|
|
|
199
252
|
productId: PurchaseCommon['productId'];
|
|
200
253
|
transactionDate: PurchaseCommon['transactionDate'];
|
|
201
254
|
purchaseToken?: PurchaseCommon['purchaseToken'];
|
|
202
|
-
platform:
|
|
255
|
+
platform: IapPlatform;
|
|
203
256
|
quantity: PurchaseCommon['quantity'];
|
|
204
257
|
purchaseState: PurchaseCommon['purchaseState'];
|
|
205
258
|
isAutoRenewing: PurchaseCommon['isAutoRenewing'];
|
|
@@ -288,7 +341,7 @@ export interface NitroProduct {
|
|
|
288
341
|
displayPrice?: ProductCommon['displayPrice'];
|
|
289
342
|
currency?: ProductCommon['currency'];
|
|
290
343
|
price?: ProductCommon['price'];
|
|
291
|
-
platform:
|
|
344
|
+
platform: IapPlatform;
|
|
292
345
|
// iOS specific fields
|
|
293
346
|
typeIOS?: string | null;
|
|
294
347
|
isFamilyShareableIOS?: boolean | null;
|
|
@@ -378,6 +431,13 @@ export interface RnIap extends HybridObject<{ios: 'swift'; android: 'kotlin'}> {
|
|
|
378
431
|
subscriptionIds?: string[],
|
|
379
432
|
): Promise<NitroActiveSubscription[]>;
|
|
380
433
|
|
|
434
|
+
/**
|
|
435
|
+
* Check if there are any active subscriptions
|
|
436
|
+
* @param subscriptionIds - Optional array of subscription IDs to filter
|
|
437
|
+
* @returns Promise<boolean> - True if there are active subscriptions
|
|
438
|
+
*/
|
|
439
|
+
hasActiveSubscriptions(subscriptionIds?: string[]): Promise<boolean>;
|
|
440
|
+
|
|
381
441
|
/**
|
|
382
442
|
* Finish a transaction (unified method for both platforms)
|
|
383
443
|
* @param params - Platform-specific transaction finish parameters
|
|
@@ -646,6 +706,19 @@ export interface RnIap extends HybridObject<{ios: 'swift'; android: 'kotlin'}> {
|
|
|
646
706
|
NitroReceiptValidationResultIOS | NitroReceiptValidationResultAndroid
|
|
647
707
|
>;
|
|
648
708
|
|
|
709
|
+
/**
|
|
710
|
+
* Verify purchase with a specific provider (e.g., IAPKit)
|
|
711
|
+
*
|
|
712
|
+
* This function allows you to verify purchases using external verification
|
|
713
|
+
* services like IAPKit, which provide additional validation and security.
|
|
714
|
+
*
|
|
715
|
+
* @param params - Verification options including provider and credentials
|
|
716
|
+
* @returns Promise<NitroVerifyPurchaseWithProviderResult> - Provider-specific verification result
|
|
717
|
+
*/
|
|
718
|
+
verifyPurchaseWithProvider(
|
|
719
|
+
params: NitroVerifyPurchaseWithProviderProps,
|
|
720
|
+
): Promise<NitroVerifyPurchaseWithProviderResult>;
|
|
721
|
+
|
|
649
722
|
/**
|
|
650
723
|
* Get the storefront country/region code for the current user.
|
|
651
724
|
* @returns Promise<string> - The storefront country code (e.g., "USA")
|