react-native-iap 14.4.46 → 14.5.0
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 +134 -4
- package/ios/HybridRnIap.swift +73 -2
- package/ios/RnIapHelper.swift +8 -0
- package/lib/module/hooks/useIAP.js +9 -1
- package/lib/module/hooks/useIAP.js.map +1 -1
- package/lib/module/index.js +69 -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/module/utils/type-bridge.js +19 -0
- package/lib/module/utils/type-bridge.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 +86 -26
- package/lib/typescript/src/specs/RnIap.nitro.d.ts.map +1 -1
- package/lib/typescript/src/types.d.ts +145 -55
- package/lib/typescript/src/types.d.ts.map +1 -1
- package/lib/typescript/src/utils/errorMapping.d.ts.map +1 -1
- package/lib/typescript/src/utils/type-bridge.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JFunc_void_NitroPurchase.hpp +2 -0
- package/nitrogen/generated/android/c++/JHybridRnIapSpec.cpp +80 -0
- package/nitrogen/generated/android/c++/JHybridRnIapSpec.hpp +2 -0
- package/nitrogen/generated/android/c++/JIapStore.hpp +65 -0
- package/nitrogen/generated/android/c++/JIapkitPurchaseState.hpp +80 -0
- package/nitrogen/generated/android/c++/JNitroPurchase.hpp +7 -1
- package/nitrogen/generated/android/c++/JNitroPurchaseRequest.hpp +11 -3
- package/nitrogen/generated/android/c++/JNitroReceiptValidationResultIOS.hpp +2 -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++/JNitroVerifyPurchaseWithProviderError.hpp +62 -0
- package/nitrogen/generated/android/c++/JNitroVerifyPurchaseWithProviderProps.hpp +70 -0
- package/nitrogen/generated/android/c++/JNitroVerifyPurchaseWithProviderResult.hpp +94 -0
- package/nitrogen/generated/android/c++/JPurchase.hpp +2 -0
- package/nitrogen/generated/android/c++/JPurchaseAndroid.hpp +7 -1
- package/nitrogen/generated/android/c++/JPurchaseIOS.hpp +7 -1
- package/nitrogen/generated/android/c++/JPurchaseVerificationProvider.hpp +59 -0
- package/nitrogen/generated/android/c++/JRequestPurchaseResult.hpp +2 -0
- package/nitrogen/generated/android/c++/JVariant_NitroReceiptValidationResultIOS_NitroReceiptValidationResultAndroid.hpp +2 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/HybridRnIapSpec.kt +8 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/IapStore.kt +23 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/IapkitPurchaseState.kt +28 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroPurchase.kt +5 -2
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroPurchaseRequest.kt +9 -3
- 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/NitroVerifyPurchaseWithProviderError.kt +39 -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 +42 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/PurchaseAndroid.kt +5 -2
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/PurchaseIOS.kt +5 -2
- 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 +156 -0
- package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Umbrella.hpp +30 -0
- package/nitrogen/generated/ios/c++/HybridRnIapSpecSwift.hpp +46 -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/IapStore.swift +48 -0
- package/nitrogen/generated/ios/swift/IapkitPurchaseState.swift +68 -0
- package/nitrogen/generated/ios/swift/NitroPurchase.swift +13 -2
- package/nitrogen/generated/ios/swift/NitroPurchaseRequest.swift +47 -1
- 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/NitroVerifyPurchaseWithProviderError.swift +65 -0
- package/nitrogen/generated/ios/swift/NitroVerifyPurchaseWithProviderProps.swift +58 -0
- package/nitrogen/generated/ios/swift/NitroVerifyPurchaseWithProviderResult.swift +100 -0
- package/nitrogen/generated/ios/swift/PurchaseAndroid.swift +13 -2
- package/nitrogen/generated/ios/swift/PurchaseIOS.swift +13 -2
- 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++/IapStore.hpp +84 -0
- package/nitrogen/generated/shared/c++/IapkitPurchaseState.hpp +104 -0
- package/nitrogen/generated/shared/c++/NitroPurchase.hpp +8 -1
- package/nitrogen/generated/shared/c++/NitroPurchaseRequest.hpp +10 -2
- 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++/NitroVerifyPurchaseWithProviderError.hpp +80 -0
- package/nitrogen/generated/shared/c++/NitroVerifyPurchaseWithProviderProps.hpp +84 -0
- package/nitrogen/generated/shared/c++/NitroVerifyPurchaseWithProviderResult.hpp +92 -0
- package/nitrogen/generated/shared/c++/PurchaseAndroid.hpp +8 -1
- package/nitrogen/generated/shared/c++/PurchaseIOS.hpp +8 -1
- 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 +77 -5
- package/src/specs/RnIap.nitro.ts +117 -28
- package/src/types.ts +163 -61
- package/src/utils/errorMapping.ts +32 -4
- package/src/utils/type-bridge.ts +22 -0
|
@@ -0,0 +1,92 @@
|
|
|
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 `NitroVerifyPurchaseWithProviderError` to properly resolve imports.
|
|
29
|
+
namespace margelo::nitro::iap { struct NitroVerifyPurchaseWithProviderError; }
|
|
30
|
+
// Forward declaration of `PurchaseVerificationProvider` to properly resolve imports.
|
|
31
|
+
namespace margelo::nitro::iap { enum class PurchaseVerificationProvider; }
|
|
32
|
+
|
|
33
|
+
#include "NitroVerifyPurchaseWithIapkitResult.hpp"
|
|
34
|
+
#include <optional>
|
|
35
|
+
#include "NitroVerifyPurchaseWithProviderError.hpp"
|
|
36
|
+
#include <vector>
|
|
37
|
+
#include "PurchaseVerificationProvider.hpp"
|
|
38
|
+
|
|
39
|
+
namespace margelo::nitro::iap {
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A struct which can be represented as a JavaScript object (NitroVerifyPurchaseWithProviderResult).
|
|
43
|
+
*/
|
|
44
|
+
struct NitroVerifyPurchaseWithProviderResult {
|
|
45
|
+
public:
|
|
46
|
+
std::optional<NitroVerifyPurchaseWithIapkitResult> iapkit SWIFT_PRIVATE;
|
|
47
|
+
std::optional<std::vector<NitroVerifyPurchaseWithProviderError>> errors SWIFT_PRIVATE;
|
|
48
|
+
PurchaseVerificationProvider provider SWIFT_PRIVATE;
|
|
49
|
+
|
|
50
|
+
public:
|
|
51
|
+
NitroVerifyPurchaseWithProviderResult() = default;
|
|
52
|
+
explicit NitroVerifyPurchaseWithProviderResult(std::optional<NitroVerifyPurchaseWithIapkitResult> iapkit, std::optional<std::vector<NitroVerifyPurchaseWithProviderError>> errors, PurchaseVerificationProvider provider): iapkit(iapkit), errors(errors), provider(provider) {}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
} // namespace margelo::nitro::iap
|
|
56
|
+
|
|
57
|
+
namespace margelo::nitro {
|
|
58
|
+
|
|
59
|
+
// C++ NitroVerifyPurchaseWithProviderResult <> JS NitroVerifyPurchaseWithProviderResult (object)
|
|
60
|
+
template <>
|
|
61
|
+
struct JSIConverter<margelo::nitro::iap::NitroVerifyPurchaseWithProviderResult> final {
|
|
62
|
+
static inline margelo::nitro::iap::NitroVerifyPurchaseWithProviderResult fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
63
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
64
|
+
return margelo::nitro::iap::NitroVerifyPurchaseWithProviderResult(
|
|
65
|
+
JSIConverter<std::optional<margelo::nitro::iap::NitroVerifyPurchaseWithIapkitResult>>::fromJSI(runtime, obj.getProperty(runtime, "iapkit")),
|
|
66
|
+
JSIConverter<std::optional<std::vector<margelo::nitro::iap::NitroVerifyPurchaseWithProviderError>>>::fromJSI(runtime, obj.getProperty(runtime, "errors")),
|
|
67
|
+
JSIConverter<margelo::nitro::iap::PurchaseVerificationProvider>::fromJSI(runtime, obj.getProperty(runtime, "provider"))
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::iap::NitroVerifyPurchaseWithProviderResult& arg) {
|
|
71
|
+
jsi::Object obj(runtime);
|
|
72
|
+
obj.setProperty(runtime, "iapkit", JSIConverter<std::optional<margelo::nitro::iap::NitroVerifyPurchaseWithIapkitResult>>::toJSI(runtime, arg.iapkit));
|
|
73
|
+
obj.setProperty(runtime, "errors", JSIConverter<std::optional<std::vector<margelo::nitro::iap::NitroVerifyPurchaseWithProviderError>>>::toJSI(runtime, arg.errors));
|
|
74
|
+
obj.setProperty(runtime, "provider", JSIConverter<margelo::nitro::iap::PurchaseVerificationProvider>::toJSI(runtime, arg.provider));
|
|
75
|
+
return obj;
|
|
76
|
+
}
|
|
77
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
78
|
+
if (!value.isObject()) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
jsi::Object obj = value.getObject(runtime);
|
|
82
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
if (!JSIConverter<std::optional<margelo::nitro::iap::NitroVerifyPurchaseWithIapkitResult>>::canConvert(runtime, obj.getProperty(runtime, "iapkit"))) return false;
|
|
86
|
+
if (!JSIConverter<std::optional<std::vector<margelo::nitro::iap::NitroVerifyPurchaseWithProviderError>>>::canConvert(runtime, obj.getProperty(runtime, "errors"))) return false;
|
|
87
|
+
if (!JSIConverter<margelo::nitro::iap::PurchaseVerificationProvider>::canConvert(runtime, obj.getProperty(runtime, "provider"))) return false;
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
} // namespace margelo::nitro
|
|
@@ -27,12 +27,15 @@
|
|
|
27
27
|
namespace margelo::nitro::iap { enum class IapPlatform; }
|
|
28
28
|
// Forward declaration of `PurchaseState` to properly resolve imports.
|
|
29
29
|
namespace margelo::nitro::iap { enum class PurchaseState; }
|
|
30
|
+
// Forward declaration of `IapStore` to properly resolve imports.
|
|
31
|
+
namespace margelo::nitro::iap { enum class IapStore; }
|
|
30
32
|
|
|
31
33
|
#include <optional>
|
|
32
34
|
#include <string>
|
|
33
35
|
#include <vector>
|
|
34
36
|
#include "IapPlatform.hpp"
|
|
35
37
|
#include "PurchaseState.hpp"
|
|
38
|
+
#include "IapStore.hpp"
|
|
36
39
|
|
|
37
40
|
namespace margelo::nitro::iap {
|
|
38
41
|
|
|
@@ -58,12 +61,13 @@ namespace margelo::nitro::iap {
|
|
|
58
61
|
std::optional<std::string> purchaseToken SWIFT_PRIVATE;
|
|
59
62
|
double quantity SWIFT_PRIVATE;
|
|
60
63
|
std::optional<std::string> signatureAndroid SWIFT_PRIVATE;
|
|
64
|
+
IapStore store SWIFT_PRIVATE;
|
|
61
65
|
double transactionDate SWIFT_PRIVATE;
|
|
62
66
|
std::optional<std::string> transactionId SWIFT_PRIVATE;
|
|
63
67
|
|
|
64
68
|
public:
|
|
65
69
|
PurchaseAndroid() = default;
|
|
66
|
-
explicit PurchaseAndroid(std::optional<bool> autoRenewingAndroid, std::optional<std::string> currentPlanId, 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, std::optional<std::string> transactionId): autoRenewingAndroid(autoRenewingAndroid), currentPlanId(currentPlanId), 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), transactionId(transactionId) {}
|
|
70
|
+
explicit PurchaseAndroid(std::optional<bool> autoRenewingAndroid, std::optional<std::string> currentPlanId, 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, IapStore store, double transactionDate, std::optional<std::string> transactionId): autoRenewingAndroid(autoRenewingAndroid), currentPlanId(currentPlanId), 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), store(store), transactionDate(transactionDate), transactionId(transactionId) {}
|
|
67
71
|
};
|
|
68
72
|
|
|
69
73
|
} // namespace margelo::nitro::iap
|
|
@@ -93,6 +97,7 @@ namespace margelo::nitro {
|
|
|
93
97
|
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "purchaseToken")),
|
|
94
98
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "quantity")),
|
|
95
99
|
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "signatureAndroid")),
|
|
100
|
+
JSIConverter<margelo::nitro::iap::IapStore>::fromJSI(runtime, obj.getProperty(runtime, "store")),
|
|
96
101
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "transactionDate")),
|
|
97
102
|
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "transactionId"))
|
|
98
103
|
);
|
|
@@ -116,6 +121,7 @@ namespace margelo::nitro {
|
|
|
116
121
|
obj.setProperty(runtime, "purchaseToken", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.purchaseToken));
|
|
117
122
|
obj.setProperty(runtime, "quantity", JSIConverter<double>::toJSI(runtime, arg.quantity));
|
|
118
123
|
obj.setProperty(runtime, "signatureAndroid", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.signatureAndroid));
|
|
124
|
+
obj.setProperty(runtime, "store", JSIConverter<margelo::nitro::iap::IapStore>::toJSI(runtime, arg.store));
|
|
119
125
|
obj.setProperty(runtime, "transactionDate", JSIConverter<double>::toJSI(runtime, arg.transactionDate));
|
|
120
126
|
obj.setProperty(runtime, "transactionId", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.transactionId));
|
|
121
127
|
return obj;
|
|
@@ -145,6 +151,7 @@ namespace margelo::nitro {
|
|
|
145
151
|
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "purchaseToken"))) return false;
|
|
146
152
|
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "quantity"))) return false;
|
|
147
153
|
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "signatureAndroid"))) return false;
|
|
154
|
+
if (!JSIConverter<margelo::nitro::iap::IapStore>::canConvert(runtime, obj.getProperty(runtime, "store"))) return false;
|
|
148
155
|
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "transactionDate"))) return false;
|
|
149
156
|
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "transactionId"))) return false;
|
|
150
157
|
return true;
|
|
@@ -31,6 +31,8 @@ namespace margelo::nitro::iap { enum class IapPlatform; }
|
|
|
31
31
|
namespace margelo::nitro::iap { enum class PurchaseState; }
|
|
32
32
|
// Forward declaration of `RenewalInfoIOS` to properly resolve imports.
|
|
33
33
|
namespace margelo::nitro::iap { struct RenewalInfoIOS; }
|
|
34
|
+
// Forward declaration of `IapStore` to properly resolve imports.
|
|
35
|
+
namespace margelo::nitro::iap { enum class IapStore; }
|
|
34
36
|
|
|
35
37
|
#include <string>
|
|
36
38
|
#include <optional>
|
|
@@ -39,6 +41,7 @@ namespace margelo::nitro::iap { struct RenewalInfoIOS; }
|
|
|
39
41
|
#include "IapPlatform.hpp"
|
|
40
42
|
#include "PurchaseState.hpp"
|
|
41
43
|
#include "RenewalInfoIOS.hpp"
|
|
44
|
+
#include "IapStore.hpp"
|
|
42
45
|
|
|
43
46
|
namespace margelo::nitro::iap {
|
|
44
47
|
|
|
@@ -74,6 +77,7 @@ namespace margelo::nitro::iap {
|
|
|
74
77
|
std::optional<RenewalInfoIOS> renewalInfoIOS SWIFT_PRIVATE;
|
|
75
78
|
std::optional<double> revocationDateIOS SWIFT_PRIVATE;
|
|
76
79
|
std::optional<std::string> revocationReasonIOS SWIFT_PRIVATE;
|
|
80
|
+
IapStore store SWIFT_PRIVATE;
|
|
77
81
|
std::optional<std::string> storefrontCountryCodeIOS SWIFT_PRIVATE;
|
|
78
82
|
std::optional<std::string> subscriptionGroupIdIOS SWIFT_PRIVATE;
|
|
79
83
|
double transactionDate SWIFT_PRIVATE;
|
|
@@ -83,7 +87,7 @@ namespace margelo::nitro::iap {
|
|
|
83
87
|
|
|
84
88
|
public:
|
|
85
89
|
PurchaseIOS() = default;
|
|
86
|
-
explicit PurchaseIOS(std::optional<std::string> appAccountToken, std::optional<std::string> appBundleIdIOS, std::optional<std::string> countryCodeIOS, std::optional<std::string> currencyCodeIOS, std::optional<std::string> currencySymbolIOS, std::optional<std::string> currentPlanId, std::optional<std::string> environmentIOS, std::optional<double> expirationDateIOS, std::string id, std::optional<std::vector<std::string>> ids, bool isAutoRenewing, std::optional<bool> isUpgradedIOS, std::optional<PurchaseOfferIOS> offerIOS, std::optional<double> originalTransactionDateIOS, std::optional<std::string> originalTransactionIdentifierIOS, std::optional<std::string> ownershipTypeIOS, IapPlatform platform, std::string productId, PurchaseState purchaseState, std::optional<std::string> purchaseToken, double quantity, std::optional<double> quantityIOS, std::optional<std::string> reasonIOS, std::optional<std::string> reasonStringRepresentationIOS, std::optional<RenewalInfoIOS> renewalInfoIOS, std::optional<double> revocationDateIOS, std::optional<std::string> revocationReasonIOS, std::optional<std::string> storefrontCountryCodeIOS, std::optional<std::string> subscriptionGroupIdIOS, double transactionDate, std::string transactionId, std::optional<std::string> transactionReasonIOS, std::optional<std::string> webOrderLineItemIdIOS): appAccountToken(appAccountToken), appBundleIdIOS(appBundleIdIOS), countryCodeIOS(countryCodeIOS), currencyCodeIOS(currencyCodeIOS), currencySymbolIOS(currencySymbolIOS), currentPlanId(currentPlanId), environmentIOS(environmentIOS), expirationDateIOS(expirationDateIOS), id(id), ids(ids), isAutoRenewing(isAutoRenewing), isUpgradedIOS(isUpgradedIOS), offerIOS(offerIOS), originalTransactionDateIOS(originalTransactionDateIOS), originalTransactionIdentifierIOS(originalTransactionIdentifierIOS), ownershipTypeIOS(ownershipTypeIOS), platform(platform), productId(productId), purchaseState(purchaseState), purchaseToken(purchaseToken), quantity(quantity), quantityIOS(quantityIOS), reasonIOS(reasonIOS), reasonStringRepresentationIOS(reasonStringRepresentationIOS), renewalInfoIOS(renewalInfoIOS), revocationDateIOS(revocationDateIOS), revocationReasonIOS(revocationReasonIOS), storefrontCountryCodeIOS(storefrontCountryCodeIOS), subscriptionGroupIdIOS(subscriptionGroupIdIOS), transactionDate(transactionDate), transactionId(transactionId), transactionReasonIOS(transactionReasonIOS), webOrderLineItemIdIOS(webOrderLineItemIdIOS) {}
|
|
90
|
+
explicit PurchaseIOS(std::optional<std::string> appAccountToken, std::optional<std::string> appBundleIdIOS, std::optional<std::string> countryCodeIOS, std::optional<std::string> currencyCodeIOS, std::optional<std::string> currencySymbolIOS, std::optional<std::string> currentPlanId, std::optional<std::string> environmentIOS, std::optional<double> expirationDateIOS, std::string id, std::optional<std::vector<std::string>> ids, bool isAutoRenewing, std::optional<bool> isUpgradedIOS, std::optional<PurchaseOfferIOS> offerIOS, std::optional<double> originalTransactionDateIOS, std::optional<std::string> originalTransactionIdentifierIOS, std::optional<std::string> ownershipTypeIOS, IapPlatform platform, std::string productId, PurchaseState purchaseState, std::optional<std::string> purchaseToken, double quantity, std::optional<double> quantityIOS, std::optional<std::string> reasonIOS, std::optional<std::string> reasonStringRepresentationIOS, std::optional<RenewalInfoIOS> renewalInfoIOS, std::optional<double> revocationDateIOS, std::optional<std::string> revocationReasonIOS, IapStore store, std::optional<std::string> storefrontCountryCodeIOS, std::optional<std::string> subscriptionGroupIdIOS, double transactionDate, std::string transactionId, std::optional<std::string> transactionReasonIOS, std::optional<std::string> webOrderLineItemIdIOS): appAccountToken(appAccountToken), appBundleIdIOS(appBundleIdIOS), countryCodeIOS(countryCodeIOS), currencyCodeIOS(currencyCodeIOS), currencySymbolIOS(currencySymbolIOS), currentPlanId(currentPlanId), environmentIOS(environmentIOS), expirationDateIOS(expirationDateIOS), id(id), ids(ids), isAutoRenewing(isAutoRenewing), isUpgradedIOS(isUpgradedIOS), offerIOS(offerIOS), originalTransactionDateIOS(originalTransactionDateIOS), originalTransactionIdentifierIOS(originalTransactionIdentifierIOS), ownershipTypeIOS(ownershipTypeIOS), platform(platform), productId(productId), purchaseState(purchaseState), purchaseToken(purchaseToken), quantity(quantity), quantityIOS(quantityIOS), reasonIOS(reasonIOS), reasonStringRepresentationIOS(reasonStringRepresentationIOS), renewalInfoIOS(renewalInfoIOS), revocationDateIOS(revocationDateIOS), revocationReasonIOS(revocationReasonIOS), store(store), storefrontCountryCodeIOS(storefrontCountryCodeIOS), subscriptionGroupIdIOS(subscriptionGroupIdIOS), transactionDate(transactionDate), transactionId(transactionId), transactionReasonIOS(transactionReasonIOS), webOrderLineItemIdIOS(webOrderLineItemIdIOS) {}
|
|
87
91
|
};
|
|
88
92
|
|
|
89
93
|
} // namespace margelo::nitro::iap
|
|
@@ -123,6 +127,7 @@ namespace margelo::nitro {
|
|
|
123
127
|
JSIConverter<std::optional<margelo::nitro::iap::RenewalInfoIOS>>::fromJSI(runtime, obj.getProperty(runtime, "renewalInfoIOS")),
|
|
124
128
|
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "revocationDateIOS")),
|
|
125
129
|
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "revocationReasonIOS")),
|
|
130
|
+
JSIConverter<margelo::nitro::iap::IapStore>::fromJSI(runtime, obj.getProperty(runtime, "store")),
|
|
126
131
|
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "storefrontCountryCodeIOS")),
|
|
127
132
|
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "subscriptionGroupIdIOS")),
|
|
128
133
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "transactionDate")),
|
|
@@ -160,6 +165,7 @@ namespace margelo::nitro {
|
|
|
160
165
|
obj.setProperty(runtime, "renewalInfoIOS", JSIConverter<std::optional<margelo::nitro::iap::RenewalInfoIOS>>::toJSI(runtime, arg.renewalInfoIOS));
|
|
161
166
|
obj.setProperty(runtime, "revocationDateIOS", JSIConverter<std::optional<double>>::toJSI(runtime, arg.revocationDateIOS));
|
|
162
167
|
obj.setProperty(runtime, "revocationReasonIOS", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.revocationReasonIOS));
|
|
168
|
+
obj.setProperty(runtime, "store", JSIConverter<margelo::nitro::iap::IapStore>::toJSI(runtime, arg.store));
|
|
163
169
|
obj.setProperty(runtime, "storefrontCountryCodeIOS", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.storefrontCountryCodeIOS));
|
|
164
170
|
obj.setProperty(runtime, "subscriptionGroupIdIOS", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.subscriptionGroupIdIOS));
|
|
165
171
|
obj.setProperty(runtime, "transactionDate", JSIConverter<double>::toJSI(runtime, arg.transactionDate));
|
|
@@ -203,6 +209,7 @@ namespace margelo::nitro {
|
|
|
203
209
|
if (!JSIConverter<std::optional<margelo::nitro::iap::RenewalInfoIOS>>::canConvert(runtime, obj.getProperty(runtime, "renewalInfoIOS"))) return false;
|
|
204
210
|
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "revocationDateIOS"))) return false;
|
|
205
211
|
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "revocationReasonIOS"))) return false;
|
|
212
|
+
if (!JSIConverter<margelo::nitro::iap::IapStore>::canConvert(runtime, obj.getProperty(runtime, "store"))) return false;
|
|
206
213
|
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "storefrontCountryCodeIOS"))) return false;
|
|
207
214
|
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "subscriptionGroupIdIOS"))) return false;
|
|
208
215
|
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "transactionDate"))) return false;
|
|
@@ -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,77 @@ 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
|
|
1465
|
+
? {
|
|
1466
|
+
isValid: result.iapkit.isValid,
|
|
1467
|
+
state: result.iapkit.state,
|
|
1468
|
+
store: result.iapkit.store,
|
|
1469
|
+
}
|
|
1470
|
+
: null,
|
|
1471
|
+
errors: result.errors ?? null,
|
|
1472
|
+
};
|
|
1473
|
+
} catch (error) {
|
|
1474
|
+
RnIapConsole.error('[verifyPurchaseWithProvider] Failed:', error);
|
|
1475
|
+
const parsedError = parseErrorStringToJsonObj(error);
|
|
1476
|
+
throw createPurchaseError({
|
|
1477
|
+
code: parsedError.code,
|
|
1478
|
+
message: parsedError.message,
|
|
1479
|
+
responseCode: parsedError.responseCode,
|
|
1480
|
+
debugMessage: parsedError.debugMessage,
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1483
|
+
};
|
|
1484
|
+
|
|
1413
1485
|
/**
|
|
1414
1486
|
* Sync iOS purchases with App Store (iOS only)
|
|
1415
1487
|
* @returns Promise<boolean>
|