react-native-iap 14.3.6 → 14.3.8

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.
Files changed (98) hide show
  1. package/README.md +1 -1
  2. package/android/build.gradle +1 -3
  3. package/android/src/main/java/com/margelo/nitro/iap/HybridRnIap.kt +61 -11
  4. package/ios/HybridRnIap.swift +47 -12
  5. package/lib/module/hooks/useIAP.js +31 -21
  6. package/lib/module/hooks/useIAP.js.map +1 -1
  7. package/lib/module/index.js +629 -700
  8. package/lib/module/index.js.map +1 -1
  9. package/lib/module/types.js +12 -0
  10. package/lib/module/types.js.map +1 -1
  11. package/lib/module/utils/purchase.js +22 -0
  12. package/lib/module/utils/purchase.js.map +1 -0
  13. package/lib/module/utils.js +43 -0
  14. package/lib/module/utils.js.map +1 -0
  15. package/lib/typescript/plugin/src/withIAP.d.ts +1 -0
  16. package/lib/typescript/plugin/src/withIAP.d.ts.map +1 -1
  17. package/lib/typescript/src/hooks/useIAP.d.ts +4 -5
  18. package/lib/typescript/src/hooks/useIAP.d.ts.map +1 -1
  19. package/lib/typescript/src/index.d.ts +57 -176
  20. package/lib/typescript/src/index.d.ts.map +1 -1
  21. package/lib/typescript/src/specs/RnIap.nitro.d.ts +113 -154
  22. package/lib/typescript/src/specs/RnIap.nitro.d.ts.map +1 -1
  23. package/lib/typescript/src/types.d.ts +99 -76
  24. package/lib/typescript/src/types.d.ts.map +1 -1
  25. package/lib/typescript/src/utils/purchase.d.ts +4 -0
  26. package/lib/typescript/src/utils/purchase.d.ts.map +1 -0
  27. package/lib/typescript/src/utils.d.ts +8 -0
  28. package/lib/typescript/src/utils.d.ts.map +1 -0
  29. package/nitrogen/generated/android/NitroIap+autolinking.cmake +1 -1
  30. package/nitrogen/generated/android/c++/{JNitroSubscriptionOffer.hpp → JAndroidSubscriptionOfferInput.hpp} +15 -15
  31. package/nitrogen/generated/android/c++/JFunc_void_NitroProduct.hpp +2 -0
  32. package/nitrogen/generated/android/c++/JFunc_void_NitroPurchase.hpp +4 -0
  33. package/nitrogen/generated/android/c++/JHybridRnIapSpec.cpp +16 -16
  34. package/nitrogen/generated/android/c++/JHybridRnIapSpec.hpp +1 -1
  35. package/nitrogen/generated/android/c++/JNitroAvailablePurchasesAndroidOptions.hpp +6 -5
  36. package/nitrogen/generated/android/c++/JNitroAvailablePurchasesAndroidType.hpp +59 -0
  37. package/nitrogen/generated/android/c++/JNitroAvailablePurchasesOptions.hpp +2 -1
  38. package/nitrogen/generated/android/c++/JNitroProduct.hpp +22 -20
  39. package/nitrogen/generated/android/c++/JNitroPurchase.hpp +12 -8
  40. package/nitrogen/generated/android/c++/JNitroPurchaseRequest.hpp +2 -2
  41. package/nitrogen/generated/android/c++/JNitroReceiptValidationAndroidOptions.hpp +10 -10
  42. package/nitrogen/generated/android/c++/JNitroReceiptValidationResultAndroid.hpp +6 -6
  43. package/nitrogen/generated/android/c++/JNitroReceiptValidationResultIOS.hpp +4 -0
  44. package/nitrogen/generated/android/c++/JNitroRequestPurchaseAndroid.hpp +7 -7
  45. package/nitrogen/generated/android/c++/JRequestPurchaseResult.cpp +39 -0
  46. package/nitrogen/generated/android/c++/JRequestPurchaseResult.hpp +68 -53
  47. package/nitrogen/generated/android/c++/JVariant_NitroReceiptValidationResultIOS_NitroReceiptValidationResultAndroid.hpp +4 -0
  48. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/{NitroSubscriptionOffer.kt → AndroidSubscriptionOfferInput.kt} +5 -5
  49. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/HybridRnIapSpec.kt +1 -1
  50. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroAvailablePurchasesAndroidOptions.kt +1 -1
  51. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroAvailablePurchasesAndroidType.kt +21 -0
  52. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroProduct.kt +11 -11
  53. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroPurchase.kt +2 -2
  54. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroReceiptValidationAndroidOptions.kt +4 -4
  55. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroReceiptValidationResultAndroid.kt +2 -2
  56. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/NitroRequestPurchaseAndroid.kt +1 -1
  57. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/RequestPurchaseResult.kt +31 -13
  58. package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Bridge.cpp +4 -4
  59. package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Bridge.hpp +99 -64
  60. package/nitrogen/generated/ios/NitroIap-Swift-Cxx-Umbrella.hpp +6 -6
  61. package/nitrogen/generated/ios/c++/HybridRnIapSpecSwift.hpp +10 -10
  62. package/nitrogen/generated/ios/swift/{NitroSubscriptionOffer.swift → AndroidSubscriptionOfferInput.swift} +13 -13
  63. package/nitrogen/generated/ios/swift/Func_void_std__optional_std__variant_PurchaseAndroid__PurchaseIOS__std__vector_std__variant_PurchaseAndroid__PurchaseIOS____.swift +81 -0
  64. package/nitrogen/generated/ios/swift/HybridRnIapSpec.swift +1 -1
  65. package/nitrogen/generated/ios/swift/HybridRnIapSpec_cxx.swift +35 -7
  66. package/nitrogen/generated/ios/swift/NitroAvailablePurchasesAndroidOptions.swift +7 -14
  67. package/nitrogen/generated/ios/swift/NitroAvailablePurchasesAndroidType.swift +40 -0
  68. package/nitrogen/generated/ios/swift/NitroProduct.swift +72 -72
  69. package/nitrogen/generated/ios/swift/NitroPurchase.swift +8 -8
  70. package/nitrogen/generated/ios/swift/NitroReceiptValidationAndroidOptions.swift +21 -21
  71. package/nitrogen/generated/ios/swift/NitroReceiptValidationResultAndroid.swift +37 -11
  72. package/nitrogen/generated/ios/swift/NitroRequestPurchaseAndroid.swift +11 -11
  73. package/nitrogen/generated/ios/swift/RequestPurchaseResult.swift +8 -137
  74. package/nitrogen/generated/shared/c++/{NitroSubscriptionOffer.hpp → AndroidSubscriptionOfferInput.hpp} +15 -15
  75. package/nitrogen/generated/shared/c++/HybridRnIapSpec.hpp +9 -6
  76. package/nitrogen/generated/shared/c++/NitroAvailablePurchasesAndroidOptions.hpp +8 -7
  77. package/nitrogen/generated/shared/c++/NitroAvailablePurchasesAndroidType.hpp +76 -0
  78. package/nitrogen/generated/shared/c++/NitroProduct.hpp +24 -22
  79. package/nitrogen/generated/shared/c++/NitroPurchase.hpp +15 -10
  80. package/nitrogen/generated/shared/c++/NitroReceiptValidationAndroidOptions.hpp +10 -10
  81. package/nitrogen/generated/shared/c++/NitroReceiptValidationResultAndroid.hpp +9 -9
  82. package/nitrogen/generated/shared/c++/NitroRequestPurchaseAndroid.hpp +8 -8
  83. package/package.json +2 -2
  84. package/plugin/build/withIAP.d.ts +1 -0
  85. package/plugin/build/withIAP.js +8 -2
  86. package/plugin/src/withIAP.ts +13 -3
  87. package/src/hooks/useIAP.ts +63 -32
  88. package/src/index.ts +832 -796
  89. package/src/specs/RnIap.nitro.ts +131 -163
  90. package/src/types.ts +131 -85
  91. package/src/utils/purchase.ts +32 -0
  92. package/src/utils.ts +68 -0
  93. package/nitrogen/generated/android/c++/JVariant_PurchaseAndroid_PurchaseIOS.cpp +0 -26
  94. package/nitrogen/generated/android/c++/JVariant_PurchaseAndroid_PurchaseIOS.hpp +0 -80
  95. package/nitrogen/generated/android/kotlin/com/margelo/nitro/iap/Variant_PurchaseAndroid_PurchaseIOS.kt +0 -42
  96. package/nitrogen/generated/ios/swift/Func_void_RequestPurchaseResult.swift +0 -47
  97. package/nitrogen/generated/ios/swift/Variant_PurchaseAndroid_PurchaseIOS.swift +0 -18
  98. package/nitrogen/generated/shared/c++/RequestPurchaseResult.hpp +0 -78
@@ -32,19 +32,19 @@ namespace margelo::nitro::iap {
32
32
  [[nodiscard]]
33
33
  NitroReceiptValidationAndroidOptions toCpp() const {
34
34
  static const auto clazz = javaClassStatic();
35
- static const auto fieldPackageName = clazz->getField<jni::JString>("packageName");
36
- jni::local_ref<jni::JString> packageName = this->getFieldValue(fieldPackageName);
37
- static const auto fieldProductToken = clazz->getField<jni::JString>("productToken");
38
- jni::local_ref<jni::JString> productToken = this->getFieldValue(fieldProductToken);
39
35
  static const auto fieldAccessToken = clazz->getField<jni::JString>("accessToken");
40
36
  jni::local_ref<jni::JString> accessToken = this->getFieldValue(fieldAccessToken);
41
37
  static const auto fieldIsSub = clazz->getField<jni::JBoolean>("isSub");
42
38
  jni::local_ref<jni::JBoolean> isSub = this->getFieldValue(fieldIsSub);
39
+ static const auto fieldPackageName = clazz->getField<jni::JString>("packageName");
40
+ jni::local_ref<jni::JString> packageName = this->getFieldValue(fieldPackageName);
41
+ static const auto fieldProductToken = clazz->getField<jni::JString>("productToken");
42
+ jni::local_ref<jni::JString> productToken = this->getFieldValue(fieldProductToken);
43
43
  return NitroReceiptValidationAndroidOptions(
44
- packageName->toStdString(),
45
- productToken->toStdString(),
46
44
  accessToken->toStdString(),
47
- isSub != nullptr ? std::make_optional(static_cast<bool>(isSub->value())) : std::nullopt
45
+ isSub != nullptr ? std::make_optional(static_cast<bool>(isSub->value())) : std::nullopt,
46
+ packageName->toStdString(),
47
+ productToken->toStdString()
48
48
  );
49
49
  }
50
50
 
@@ -55,10 +55,10 @@ namespace margelo::nitro::iap {
55
55
  [[maybe_unused]]
56
56
  static jni::local_ref<JNitroReceiptValidationAndroidOptions::javaobject> fromCpp(const NitroReceiptValidationAndroidOptions& value) {
57
57
  return newInstance(
58
- jni::make_jstring(value.packageName),
59
- jni::make_jstring(value.productToken),
60
58
  jni::make_jstring(value.accessToken),
61
- value.isSub.has_value() ? jni::JBoolean::valueOf(value.isSub.value()) : nullptr
59
+ value.isSub.has_value() ? jni::JBoolean::valueOf(value.isSub.value()) : nullptr,
60
+ jni::make_jstring(value.packageName),
61
+ jni::make_jstring(value.productToken)
62
62
  );
63
63
  }
64
64
  };
@@ -42,8 +42,8 @@ namespace margelo::nitro::iap {
42
42
  jni::local_ref<jni::JString> cancelReason = this->getFieldValue(fieldCancelReason);
43
43
  static const auto fieldDeferredDate = clazz->getField<jni::JDouble>("deferredDate");
44
44
  jni::local_ref<jni::JDouble> deferredDate = this->getFieldValue(fieldDeferredDate);
45
- static const auto fieldDeferredSku = clazz->getField<jni::JDouble>("deferredSku");
46
- jni::local_ref<jni::JDouble> deferredSku = this->getFieldValue(fieldDeferredSku);
45
+ static const auto fieldDeferredSku = clazz->getField<jni::JString>("deferredSku");
46
+ jni::local_ref<jni::JString> deferredSku = this->getFieldValue(fieldDeferredSku);
47
47
  static const auto fieldFreeTrialEndDate = clazz->getField<double>("freeTrialEndDate");
48
48
  double freeTrialEndDate = this->getFieldValue(fieldFreeTrialEndDate);
49
49
  static const auto fieldGracePeriodEndDate = clazz->getField<double>("gracePeriodEndDate");
@@ -72,9 +72,9 @@ namespace margelo::nitro::iap {
72
72
  static_cast<bool>(autoRenewing),
73
73
  static_cast<bool>(betaProduct),
74
74
  cancelDate != nullptr ? std::make_optional(cancelDate->value()) : std::nullopt,
75
- cancelReason->toStdString(),
75
+ cancelReason != nullptr ? std::make_optional(cancelReason->toStdString()) : std::nullopt,
76
76
  deferredDate != nullptr ? std::make_optional(deferredDate->value()) : std::nullopt,
77
- deferredSku != nullptr ? std::make_optional(deferredSku->value()) : std::nullopt,
77
+ deferredSku != nullptr ? std::make_optional(deferredSku->toStdString()) : std::nullopt,
78
78
  freeTrialEndDate,
79
79
  gracePeriodEndDate,
80
80
  parentProductId->toStdString(),
@@ -100,9 +100,9 @@ namespace margelo::nitro::iap {
100
100
  value.autoRenewing,
101
101
  value.betaProduct,
102
102
  value.cancelDate.has_value() ? jni::JDouble::valueOf(value.cancelDate.value()) : nullptr,
103
- jni::make_jstring(value.cancelReason),
103
+ value.cancelReason.has_value() ? jni::make_jstring(value.cancelReason.value()) : nullptr,
104
104
  value.deferredDate.has_value() ? jni::JDouble::valueOf(value.deferredDate.value()) : nullptr,
105
- value.deferredSku.has_value() ? jni::JDouble::valueOf(value.deferredSku.value()) : nullptr,
105
+ value.deferredSku.has_value() ? jni::make_jstring(value.deferredSku.value()) : nullptr,
106
106
  value.freeTrialEndDate,
107
107
  value.gracePeriodEndDate,
108
108
  jni::make_jstring(value.parentProductId),
@@ -10,8 +10,12 @@
10
10
  #include <fbjni/fbjni.h>
11
11
  #include "NitroReceiptValidationResultIOS.hpp"
12
12
 
13
+ #include "IapPlatform.hpp"
14
+ #include "JIapPlatform.hpp"
13
15
  #include "JNitroPurchase.hpp"
16
+ #include "JPurchaseState.hpp"
14
17
  #include "NitroPurchase.hpp"
18
+ #include "PurchaseState.hpp"
15
19
  #include <optional>
16
20
  #include <string>
17
21
 
@@ -10,8 +10,8 @@
10
10
  #include <fbjni/fbjni.h>
11
11
  #include "NitroRequestPurchaseAndroid.hpp"
12
12
 
13
- #include "JNitroSubscriptionOffer.hpp"
14
- #include "NitroSubscriptionOffer.hpp"
13
+ #include "AndroidSubscriptionOfferInput.hpp"
14
+ #include "JAndroidSubscriptionOfferInput.hpp"
15
15
  #include <optional>
16
16
  #include <string>
17
17
  #include <vector>
@@ -43,8 +43,8 @@ namespace margelo::nitro::iap {
43
43
  jni::local_ref<jni::JString> obfuscatedProfileIdAndroid = this->getFieldValue(fieldObfuscatedProfileIdAndroid);
44
44
  static const auto fieldIsOfferPersonalized = clazz->getField<jni::JBoolean>("isOfferPersonalized");
45
45
  jni::local_ref<jni::JBoolean> isOfferPersonalized = this->getFieldValue(fieldIsOfferPersonalized);
46
- static const auto fieldSubscriptionOffers = clazz->getField<jni::JArrayClass<JNitroSubscriptionOffer>>("subscriptionOffers");
47
- jni::local_ref<jni::JArrayClass<JNitroSubscriptionOffer>> subscriptionOffers = this->getFieldValue(fieldSubscriptionOffers);
46
+ static const auto fieldSubscriptionOffers = clazz->getField<jni::JArrayClass<JAndroidSubscriptionOfferInput>>("subscriptionOffers");
47
+ jni::local_ref<jni::JArrayClass<JAndroidSubscriptionOfferInput>> subscriptionOffers = this->getFieldValue(fieldSubscriptionOffers);
48
48
  static const auto fieldReplacementModeAndroid = clazz->getField<jni::JDouble>("replacementModeAndroid");
49
49
  jni::local_ref<jni::JDouble> replacementModeAndroid = this->getFieldValue(fieldReplacementModeAndroid);
50
50
  static const auto fieldPurchaseTokenAndroid = clazz->getField<jni::JString>("purchaseTokenAndroid");
@@ -65,7 +65,7 @@ namespace margelo::nitro::iap {
65
65
  isOfferPersonalized != nullptr ? std::make_optional(static_cast<bool>(isOfferPersonalized->value())) : std::nullopt,
66
66
  subscriptionOffers != nullptr ? std::make_optional([&]() {
67
67
  size_t __size = subscriptionOffers->size();
68
- std::vector<NitroSubscriptionOffer> __vector;
68
+ std::vector<AndroidSubscriptionOfferInput> __vector;
69
69
  __vector.reserve(__size);
70
70
  for (size_t __i = 0; __i < __size; __i++) {
71
71
  auto __element = subscriptionOffers->getElement(__i);
@@ -99,10 +99,10 @@ namespace margelo::nitro::iap {
99
99
  value.isOfferPersonalized.has_value() ? jni::JBoolean::valueOf(value.isOfferPersonalized.value()) : nullptr,
100
100
  value.subscriptionOffers.has_value() ? [&]() {
101
101
  size_t __size = value.subscriptionOffers.value().size();
102
- jni::local_ref<jni::JArrayClass<JNitroSubscriptionOffer>> __array = jni::JArrayClass<JNitroSubscriptionOffer>::newArray(__size);
102
+ jni::local_ref<jni::JArrayClass<JAndroidSubscriptionOfferInput>> __array = jni::JArrayClass<JAndroidSubscriptionOfferInput>::newArray(__size);
103
103
  for (size_t __i = 0; __i < __size; __i++) {
104
104
  const auto& __element = value.subscriptionOffers.value()[__i];
105
- __array->setElement(__i, *JNitroSubscriptionOffer::fromCpp(__element));
105
+ __array->setElement(__i, *JAndroidSubscriptionOfferInput::fromCpp(__element));
106
106
  }
107
107
  return __array;
108
108
  }() : nullptr,
@@ -0,0 +1,39 @@
1
+ ///
2
+ /// JRequestPurchaseResult.cpp
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
+ #include "JRequestPurchaseResult.hpp"
9
+
10
+ namespace margelo::nitro::iap {
11
+ /**
12
+ * Converts JRequestPurchaseResult to std::variant<PurchaseAndroid, PurchaseIOS, std::vector<std::variant<PurchaseAndroid, PurchaseIOS>>>
13
+ */
14
+ std::variant<PurchaseAndroid, PurchaseIOS, std::vector<std::variant<PurchaseAndroid, PurchaseIOS>>> JRequestPurchaseResult::toCpp() const {
15
+ if (isInstanceOf(JRequestPurchaseResult_impl::First::javaClassStatic())) {
16
+ // It's a `PurchaseAndroid`
17
+ auto jniValue = static_cast<const JRequestPurchaseResult_impl::First*>(this)->getValue();
18
+ return jniValue->toCpp();
19
+ } else if (isInstanceOf(JRequestPurchaseResult_impl::Second::javaClassStatic())) {
20
+ // It's a `PurchaseIOS`
21
+ auto jniValue = static_cast<const JRequestPurchaseResult_impl::Second*>(this)->getValue();
22
+ return jniValue->toCpp();
23
+ } else if (isInstanceOf(JRequestPurchaseResult_impl::Third::javaClassStatic())) {
24
+ // It's a `std::vector<std::variant<PurchaseAndroid, PurchaseIOS>>`
25
+ auto jniValue = static_cast<const JRequestPurchaseResult_impl::Third*>(this)->getValue();
26
+ return [&]() {
27
+ size_t __size = jniValue->size();
28
+ std::vector<std::variant<PurchaseAndroid, PurchaseIOS>> __vector;
29
+ __vector.reserve(__size);
30
+ for (size_t __i = 0; __i < __size; __i++) {
31
+ auto __element = jniValue->getElement(__i);
32
+ __vector.push_back(__element->toCpp());
33
+ }
34
+ return __vector;
35
+ }();
36
+ }
37
+ throw std::invalid_argument("Variant is unknown Kotlin instance!");
38
+ }
39
+ } // namespace margelo::nitro::iap
@@ -8,82 +8,97 @@
8
8
  #pragma once
9
9
 
10
10
  #include <fbjni/fbjni.h>
11
- #include "RequestPurchaseResult.hpp"
11
+ #include <variant>
12
12
 
13
- #include "IapPlatform.hpp"
14
- #include "JIapPlatform.hpp"
15
- #include "JPurchase.hpp"
16
- #include "JPurchaseAndroid.hpp"
17
- #include "JPurchaseIOS.hpp"
18
- #include "JPurchaseOfferIOS.hpp"
19
- #include "JPurchaseState.hpp"
20
- #include "JVariant_PurchaseAndroid_PurchaseIOS.hpp"
21
13
  #include "PurchaseAndroid.hpp"
22
14
  #include "PurchaseIOS.hpp"
23
- #include "PurchaseOfferIOS.hpp"
24
- #include "PurchaseState.hpp"
25
- #include <optional>
26
- #include <string>
27
15
  #include <variant>
28
16
  #include <vector>
17
+ #include "JPurchaseAndroid.hpp"
18
+ #include <optional>
19
+ #include <string>
20
+ #include "IapPlatform.hpp"
21
+ #include "JIapPlatform.hpp"
22
+ #include "PurchaseState.hpp"
23
+ #include "JPurchaseState.hpp"
24
+ #include "JPurchaseIOS.hpp"
25
+ #include "PurchaseOfferIOS.hpp"
26
+ #include "JPurchaseOfferIOS.hpp"
27
+ #include "JPurchase.hpp"
29
28
 
30
29
  namespace margelo::nitro::iap {
31
30
 
32
31
  using namespace facebook;
33
32
 
34
33
  /**
35
- * The C++ JNI bridge between the C++ struct "RequestPurchaseResult" and the the Kotlin data class "RequestPurchaseResult".
34
+ * The C++ JNI bridge between the C++ std::variant and the Java class "RequestPurchaseResult".
36
35
  */
37
- struct JRequestPurchaseResult final: public jni::JavaClass<JRequestPurchaseResult> {
36
+ class JRequestPurchaseResult: public jni::JavaClass<JRequestPurchaseResult> {
38
37
  public:
39
38
  static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/iap/RequestPurchaseResult;";
40
39
 
41
- public:
42
- /**
43
- * Convert this Java/Kotlin-based struct to the C++ struct RequestPurchaseResult by copying all values to C++.
44
- */
45
- [[maybe_unused]]
46
- [[nodiscard]]
47
- RequestPurchaseResult toCpp() const {
48
- static const auto clazz = javaClassStatic();
49
- static const auto fieldPurchase = clazz->getField<JVariant_PurchaseAndroid_PurchaseIOS>("purchase");
50
- jni::local_ref<JVariant_PurchaseAndroid_PurchaseIOS> purchase = this->getFieldValue(fieldPurchase);
51
- static const auto fieldPurchases = clazz->getField<jni::JArrayClass<JPurchase>>("purchases");
52
- jni::local_ref<jni::JArrayClass<JPurchase>> purchases = this->getFieldValue(fieldPurchases);
53
- return RequestPurchaseResult(
54
- purchase != nullptr ? std::make_optional(purchase->toCpp()) : std::nullopt,
55
- purchases != nullptr ? std::make_optional([&]() {
56
- size_t __size = purchases->size();
57
- std::vector<std::variant<PurchaseAndroid, PurchaseIOS>> __vector;
58
- __vector.reserve(__size);
59
- for (size_t __i = 0; __i < __size; __i++) {
60
- auto __element = purchases->getElement(__i);
61
- __vector.push_back(__element->toCpp());
62
- }
63
- return __vector;
64
- }()) : std::nullopt
65
- );
40
+ static jni::local_ref<JRequestPurchaseResult> create_0(jni::alias_ref<JPurchaseAndroid> value) {
41
+ static const auto method = javaClassStatic()->getStaticMethod<JRequestPurchaseResult(jni::alias_ref<JPurchaseAndroid>)>("create");
42
+ return method(javaClassStatic(), value);
43
+ }
44
+ static jni::local_ref<JRequestPurchaseResult> create_1(jni::alias_ref<JPurchaseIOS> value) {
45
+ static const auto method = javaClassStatic()->getStaticMethod<JRequestPurchaseResult(jni::alias_ref<JPurchaseIOS>)>("create");
46
+ return method(javaClassStatic(), value);
47
+ }
48
+ static jni::local_ref<JRequestPurchaseResult> create_2(jni::alias_ref<jni::JArrayClass<JPurchase>> value) {
49
+ static const auto method = javaClassStatic()->getStaticMethod<JRequestPurchaseResult(jni::alias_ref<jni::JArrayClass<JPurchase>>)>("create");
50
+ return method(javaClassStatic(), value);
66
51
  }
67
52
 
68
- public:
69
- /**
70
- * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
71
- */
72
- [[maybe_unused]]
73
- static jni::local_ref<JRequestPurchaseResult::javaobject> fromCpp(const RequestPurchaseResult& value) {
74
- return newInstance(
75
- value.purchase.has_value() ? JVariant_PurchaseAndroid_PurchaseIOS::fromCpp(value.purchase.value()) : nullptr,
76
- value.purchases.has_value() ? [&]() {
77
- size_t __size = value.purchases.value().size();
53
+ static jni::local_ref<JRequestPurchaseResult> fromCpp(const std::variant<PurchaseAndroid, PurchaseIOS, std::vector<std::variant<PurchaseAndroid, PurchaseIOS>>>& variant) {
54
+ switch (variant.index()) {
55
+ case 0: return create_0(JPurchaseAndroid::fromCpp(std::get<0>(variant)));
56
+ case 1: return create_1(JPurchaseIOS::fromCpp(std::get<1>(variant)));
57
+ case 2: return create_2([&]() {
58
+ size_t __size = std::get<2>(variant).size();
78
59
  jni::local_ref<jni::JArrayClass<JPurchase>> __array = jni::JArrayClass<JPurchase>::newArray(__size);
79
60
  for (size_t __i = 0; __i < __size; __i++) {
80
- const auto& __element = value.purchases.value()[__i];
61
+ const auto& __element = std::get<2>(variant)[__i];
81
62
  __array->setElement(__i, *JPurchase::fromCpp(__element));
82
63
  }
83
64
  return __array;
84
- }() : nullptr
85
- );
65
+ }());
66
+ default: throw std::invalid_argument("Variant holds unknown index! (" + std::to_string(variant.index()) + ")");
67
+ }
86
68
  }
69
+
70
+ [[nodiscard]] std::variant<PurchaseAndroid, PurchaseIOS, std::vector<std::variant<PurchaseAndroid, PurchaseIOS>>> toCpp() const;
87
71
  };
88
72
 
73
+ namespace JRequestPurchaseResult_impl {
74
+ class First: public jni::JavaClass<First, JRequestPurchaseResult> {
75
+ public:
76
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/iap/RequestPurchaseResult$First;";
77
+
78
+ [[nodiscard]] jni::local_ref<JPurchaseAndroid> getValue() const {
79
+ static const auto field = javaClassStatic()->getField<JPurchaseAndroid>("value");
80
+ return getFieldValue(field);
81
+ }
82
+ };
83
+
84
+ class Second: public jni::JavaClass<Second, JRequestPurchaseResult> {
85
+ public:
86
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/iap/RequestPurchaseResult$Second;";
87
+
88
+ [[nodiscard]] jni::local_ref<JPurchaseIOS> getValue() const {
89
+ static const auto field = javaClassStatic()->getField<JPurchaseIOS>("value");
90
+ return getFieldValue(field);
91
+ }
92
+ };
93
+
94
+ class Third: public jni::JavaClass<Third, JRequestPurchaseResult> {
95
+ public:
96
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/iap/RequestPurchaseResult$Third;";
97
+
98
+ [[nodiscard]] jni::local_ref<jni::JArrayClass<JPurchase>> getValue() const {
99
+ static const auto field = javaClassStatic()->getField<jni::JArrayClass<JPurchase>>("value");
100
+ return getFieldValue(field);
101
+ }
102
+ };
103
+ } // namespace JRequestPurchaseResult_impl
89
104
  } // namespace margelo::nitro::iap
@@ -18,6 +18,10 @@
18
18
  #include "NitroPurchase.hpp"
19
19
  #include <optional>
20
20
  #include "JNitroPurchase.hpp"
21
+ #include "IapPlatform.hpp"
22
+ #include "JIapPlatform.hpp"
23
+ #include "PurchaseState.hpp"
24
+ #include "JPurchaseState.hpp"
21
25
  #include "JNitroReceiptValidationResultAndroid.hpp"
22
26
 
23
27
  namespace margelo::nitro::iap {
@@ -1,5 +1,5 @@
1
1
  ///
2
- /// NitroSubscriptionOffer.kt
2
+ /// AndroidSubscriptionOfferInput.kt
3
3
  /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
4
  /// https://github.com/mrousavy/nitro
5
5
  /// Copyright © 2025 Marc Rousavy @ Margelo
@@ -13,20 +13,20 @@ import com.margelo.nitro.core.*
13
13
 
14
14
 
15
15
  /**
16
- * Represents the JavaScript object/struct "NitroSubscriptionOffer".
16
+ * Represents the JavaScript object/struct "AndroidSubscriptionOfferInput".
17
17
  */
18
18
  @DoNotStrip
19
19
  @Keep
20
- data class NitroSubscriptionOffer
20
+ data class AndroidSubscriptionOfferInput
21
21
  @DoNotStrip
22
22
  @Keep
23
23
  constructor(
24
24
  @DoNotStrip
25
25
  @Keep
26
- val sku: String,
26
+ val offerToken: String,
27
27
  @DoNotStrip
28
28
  @Keep
29
- val offerToken: String
29
+ val sku: String
30
30
  ) {
31
31
  /* main constructor */
32
32
  }
@@ -54,7 +54,7 @@ abstract class HybridRnIapSpec: HybridObject() {
54
54
 
55
55
  @DoNotStrip
56
56
  @Keep
57
- abstract fun requestPurchase(request: NitroPurchaseRequest): Promise<RequestPurchaseResult>
57
+ abstract fun requestPurchase(request: NitroPurchaseRequest): Promise<RequestPurchaseResult?>
58
58
 
59
59
  @DoNotStrip
60
60
  @Keep
@@ -23,7 +23,7 @@ data class NitroAvailablePurchasesAndroidOptions
23
23
  constructor(
24
24
  @DoNotStrip
25
25
  @Keep
26
- val type: String?
26
+ val type: NitroAvailablePurchasesAndroidType?
27
27
  ) {
28
28
  /* main constructor */
29
29
  }
@@ -0,0 +1,21 @@
1
+ ///
2
+ /// NitroAvailablePurchasesAndroidType.kt
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
+ package com.margelo.nitro.iap
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.proguard.annotations.DoNotStrip
12
+
13
+ /**
14
+ * Represents the JavaScript enum/union "NitroAvailablePurchasesAndroidType".
15
+ */
16
+ @DoNotStrip
17
+ @Keep
18
+ enum class NitroAvailablePurchasesAndroidType(@DoNotStrip @Keep val value: Int) {
19
+ INAPP(0),
20
+ SUBS(1);
21
+ }
@@ -47,7 +47,7 @@ data class NitroProduct
47
47
  val price: Double?,
48
48
  @DoNotStrip
49
49
  @Keep
50
- val platform: String,
50
+ val platform: IapPlatform,
51
51
  @DoNotStrip
52
52
  @Keep
53
53
  val typeIOS: String?,
@@ -59,25 +59,25 @@ data class NitroProduct
59
59
  val jsonRepresentationIOS: String?,
60
60
  @DoNotStrip
61
61
  @Keep
62
- val subscriptionPeriodUnitIOS: String?,
62
+ val introductoryPriceIOS: String?,
63
63
  @DoNotStrip
64
64
  @Keep
65
- val subscriptionPeriodNumberIOS: Double?,
65
+ val introductoryPriceAsAmountIOS: Double?,
66
66
  @DoNotStrip
67
67
  @Keep
68
- val introductoryPriceIOS: String?,
68
+ val introductoryPriceNumberOfPeriodsIOS: Double?,
69
69
  @DoNotStrip
70
70
  @Keep
71
- val introductoryPriceAsAmountIOS: Double?,
71
+ val introductoryPricePaymentModeIOS: String?,
72
72
  @DoNotStrip
73
73
  @Keep
74
- val introductoryPricePaymentModeIOS: String?,
74
+ val introductoryPriceSubscriptionPeriodIOS: String?,
75
75
  @DoNotStrip
76
76
  @Keep
77
- val introductoryPriceNumberOfPeriodsIOS: Double?,
77
+ val subscriptionPeriodNumberIOS: Double?,
78
78
  @DoNotStrip
79
79
  @Keep
80
- val introductoryPriceSubscriptionPeriodIOS: String?,
80
+ val subscriptionPeriodUnitIOS: String?,
81
81
  @DoNotStrip
82
82
  @Keep
83
83
  val originalPriceAndroid: String?,
@@ -86,15 +86,15 @@ data class NitroProduct
86
86
  val originalPriceAmountMicrosAndroid: Double?,
87
87
  @DoNotStrip
88
88
  @Keep
89
- val introductoryPriceValueAndroid: Double?,
90
- @DoNotStrip
91
- @Keep
92
89
  val introductoryPriceCyclesAndroid: Double?,
93
90
  @DoNotStrip
94
91
  @Keep
95
92
  val introductoryPricePeriodAndroid: String?,
96
93
  @DoNotStrip
97
94
  @Keep
95
+ val introductoryPriceValueAndroid: Double?,
96
+ @DoNotStrip
97
+ @Keep
98
98
  val subscriptionPeriodAndroid: String?,
99
99
  @DoNotStrip
100
100
  @Keep
@@ -35,13 +35,13 @@ data class NitroPurchase
35
35
  val purchaseToken: String?,
36
36
  @DoNotStrip
37
37
  @Keep
38
- val platform: String,
38
+ val platform: IapPlatform,
39
39
  @DoNotStrip
40
40
  @Keep
41
41
  val quantity: Double,
42
42
  @DoNotStrip
43
43
  @Keep
44
- val purchaseState: String,
44
+ val purchaseState: PurchaseState,
45
45
  @DoNotStrip
46
46
  @Keep
47
47
  val isAutoRenewing: Boolean,
@@ -23,16 +23,16 @@ data class NitroReceiptValidationAndroidOptions
23
23
  constructor(
24
24
  @DoNotStrip
25
25
  @Keep
26
- val packageName: String,
26
+ val accessToken: String,
27
27
  @DoNotStrip
28
28
  @Keep
29
- val productToken: String,
29
+ val isSub: Boolean?,
30
30
  @DoNotStrip
31
31
  @Keep
32
- val accessToken: String,
32
+ val packageName: String,
33
33
  @DoNotStrip
34
34
  @Keep
35
- val isSub: Boolean?
35
+ val productToken: String
36
36
  ) {
37
37
  /* main constructor */
38
38
  }
@@ -32,13 +32,13 @@ data class NitroReceiptValidationResultAndroid
32
32
  val cancelDate: Double?,
33
33
  @DoNotStrip
34
34
  @Keep
35
- val cancelReason: String,
35
+ val cancelReason: String?,
36
36
  @DoNotStrip
37
37
  @Keep
38
38
  val deferredDate: Double?,
39
39
  @DoNotStrip
40
40
  @Keep
41
- val deferredSku: Double?,
41
+ val deferredSku: String?,
42
42
  @DoNotStrip
43
43
  @Keep
44
44
  val freeTrialEndDate: Double,
@@ -35,7 +35,7 @@ data class NitroRequestPurchaseAndroid
35
35
  val isOfferPersonalized: Boolean?,
36
36
  @DoNotStrip
37
37
  @Keep
38
- val subscriptionOffers: Array<NitroSubscriptionOffer>?,
38
+ val subscriptionOffers: Array<AndroidSubscriptionOfferInput>?,
39
39
  @DoNotStrip
40
40
  @Keep
41
41
  val replacementModeAndroid: Double?,
@@ -7,26 +7,44 @@
7
7
 
8
8
  package com.margelo.nitro.iap
9
9
 
10
- import androidx.annotation.Keep
11
10
  import com.facebook.proguard.annotations.DoNotStrip
12
- import com.margelo.nitro.core.*
13
11
 
14
12
 
15
13
  /**
16
- * Represents the JavaScript object/struct "RequestPurchaseResult".
14
+ * Represents the TypeScript variant "PurchaseAndroid|PurchaseIOS|Array<Purchase>".
17
15
  */
16
+ @Suppress("ClassName")
18
17
  @DoNotStrip
19
- @Keep
20
- data class RequestPurchaseResult
18
+ sealed class RequestPurchaseResult {
21
19
  @DoNotStrip
22
- @Keep
23
- constructor(
20
+ data class First(@DoNotStrip val value: PurchaseAndroid): RequestPurchaseResult()
21
+ @DoNotStrip
22
+ data class Second(@DoNotStrip val value: PurchaseIOS): RequestPurchaseResult()
23
+ @DoNotStrip
24
+ data class Third(@DoNotStrip val value: Array<Purchase>): RequestPurchaseResult()
25
+
26
+ inline fun <reified T> getAs(): T? = when (this) {
27
+ is First -> value as? T
28
+ is Second -> value as? T
29
+ is Third -> value as? T
30
+ }
31
+
32
+ val isFirst: Boolean
33
+ get() = this is First
34
+ val isSecond: Boolean
35
+ get() = this is Second
36
+ val isThird: Boolean
37
+ get() = this is Third
38
+
39
+ companion object {
40
+ @JvmStatic
41
+ @DoNotStrip
42
+ fun create(value: PurchaseAndroid): RequestPurchaseResult = First(value)
43
+ @JvmStatic
24
44
  @DoNotStrip
25
- @Keep
26
- val purchase: Variant_PurchaseAndroid_PurchaseIOS?,
45
+ fun create(value: PurchaseIOS): RequestPurchaseResult = Second(value)
46
+ @JvmStatic
27
47
  @DoNotStrip
28
- @Keep
29
- val purchases: Array<Purchase>?
30
- ) {
31
- /* main constructor */
48
+ fun create(value: Array<Purchase>): RequestPurchaseResult = Third(value)
49
+ }
32
50
  }
@@ -37,10 +37,10 @@ namespace margelo::nitro::iap::bridge::swift {
37
37
  };
38
38
  }
39
39
 
40
- // pragma MARK: std::function<void(const RequestPurchaseResult& /* result */)>
41
- Func_void_RequestPurchaseResult create_Func_void_RequestPurchaseResult(void* _Nonnull swiftClosureWrapper) noexcept {
42
- auto swiftClosure = NitroIap::Func_void_RequestPurchaseResult::fromUnsafe(swiftClosureWrapper);
43
- return [swiftClosure = std::move(swiftClosure)](const RequestPurchaseResult& result) mutable -> void {
40
+ // pragma MARK: std::function<void(const std::optional<std::variant<PurchaseAndroid, PurchaseIOS, std::vector<std::variant<PurchaseAndroid, PurchaseIOS>>>>& /* result */)>
41
+ Func_void_std__optional_std__variant_PurchaseAndroid__PurchaseIOS__std__vector_std__variant_PurchaseAndroid__PurchaseIOS____ create_Func_void_std__optional_std__variant_PurchaseAndroid__PurchaseIOS__std__vector_std__variant_PurchaseAndroid__PurchaseIOS____(void* _Nonnull swiftClosureWrapper) noexcept {
42
+ auto swiftClosure = NitroIap::Func_void_std__optional_std__variant_PurchaseAndroid__PurchaseIOS__std__vector_std__variant_PurchaseAndroid__PurchaseIOS____::fromUnsafe(swiftClosureWrapper);
43
+ return [swiftClosure = std::move(swiftClosure)](const std::optional<std::variant<PurchaseAndroid, PurchaseIOS, std::vector<std::variant<PurchaseAndroid, PurchaseIOS>>>>& result) mutable -> void {
44
44
  swiftClosure.call(result);
45
45
  };
46
46
  }