@gmisoftware/react-native-pay 0.0.4
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/NitroPay.podspec +31 -0
- package/README.md +455 -0
- package/android/CMakeLists.txt +29 -0
- package/android/build.gradle +144 -0
- package/android/fix-prefab.gradle +51 -0
- package/android/gradle.properties +8 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/margelo/nitro/pay/Constants.kt +49 -0
- package/android/src/main/java/com/margelo/nitro/pay/GooglePayButtonFactory.kt +95 -0
- package/android/src/main/java/com/margelo/nitro/pay/GooglePayRequestBuilder.kt +170 -0
- package/android/src/main/java/com/margelo/nitro/pay/HybridGooglePayButton.kt +146 -0
- package/android/src/main/java/com/margelo/nitro/pay/HybridPaymentHandler.kt +184 -0
- package/android/src/main/java/com/margelo/nitro/pay/NitroPayPackage.kt +26 -0
- package/android/src/main/java/com/margelo/nitro/pay/PaymentMapper.kt +89 -0
- package/app.plugin.js +1 -0
- package/ios/ApplePayButtonFactory.swift +53 -0
- package/ios/Bridge.h +8 -0
- package/ios/HybridApplePayButton.swift +60 -0
- package/ios/HybridPaymentHandler.swift +248 -0
- package/ios/PassKitTypeMapper.swift +192 -0
- package/lib/hooks/index.d.ts +7 -0
- package/lib/hooks/index.js +10 -0
- package/lib/hooks/usePaymentCheckout.d.ts +95 -0
- package/lib/hooks/usePaymentCheckout.js +183 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +29 -0
- package/lib/plugin/index.d.ts +4 -0
- package/lib/plugin/index.js +10 -0
- package/lib/plugin/type.d.ts +4 -0
- package/lib/plugin/type.js +2 -0
- package/lib/plugin/withApplePay.d.ts +4 -0
- package/lib/plugin/withApplePay.js +32 -0
- package/lib/plugin/withGooglePay.d.ts +4 -0
- package/lib/plugin/withGooglePay.js +24 -0
- package/lib/specs/ApplePayButton.nitro.d.ts +13 -0
- package/lib/specs/ApplePayButton.nitro.js +2 -0
- package/lib/specs/GooglePayButton.nitro.d.ts +14 -0
- package/lib/specs/GooglePayButton.nitro.js +2 -0
- package/lib/specs/PaymentHandler.nitro.d.ts +10 -0
- package/lib/specs/PaymentHandler.nitro.js +2 -0
- package/lib/types/Contact.d.ts +51 -0
- package/lib/types/Contact.js +6 -0
- package/lib/types/Payment.d.ts +67 -0
- package/lib/types/Payment.js +6 -0
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.js +18 -0
- package/lib/utils/index.d.ts +4 -0
- package/lib/utils/index.js +20 -0
- package/lib/utils/paymentHelpers.d.ts +144 -0
- package/lib/utils/paymentHelpers.js +190 -0
- package/nitro.json +30 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/NitroPay+autolinking.cmake +87 -0
- package/nitrogen/generated/android/NitroPay+autolinking.gradle +27 -0
- package/nitrogen/generated/android/NitroPayOnLoad.cpp +58 -0
- package/nitrogen/generated/android/NitroPayOnLoad.hpp +25 -0
- package/nitrogen/generated/android/c++/JCNContact.hpp +202 -0
- package/nitrogen/generated/android/c++/JCNContactType.hpp +59 -0
- package/nitrogen/generated/android/c++/JCNLabeledEmailAddress.hpp +62 -0
- package/nitrogen/generated/android/c++/JCNLabeledPhoneNumber.hpp +64 -0
- package/nitrogen/generated/android/c++/JCNLabeledPostalAddress.hpp +64 -0
- package/nitrogen/generated/android/c++/JCNPhoneNumber.hpp +57 -0
- package/nitrogen/generated/android/c++/JCNPostalAddress.hpp +78 -0
- package/nitrogen/generated/android/c++/JFunc_void.hpp +74 -0
- package/nitrogen/generated/android/c++/JGooglePayButtonTheme.hpp +59 -0
- package/nitrogen/generated/android/c++/JGooglePayButtonType.hpp +77 -0
- package/nitrogen/generated/android/c++/JGooglePayEnvironment.hpp +59 -0
- package/nitrogen/generated/android/c++/JHybridGooglePayButtonSpec.cpp +96 -0
- package/nitrogen/generated/android/c++/JHybridGooglePayButtonSpec.hpp +71 -0
- package/nitrogen/generated/android/c++/JHybridPaymentHandlerSpec.cpp +154 -0
- package/nitrogen/generated/android/c++/JHybridPaymentHandlerSpec.hpp +66 -0
- package/nitrogen/generated/android/c++/JPKSecureElementPass.hpp +96 -0
- package/nitrogen/generated/android/c++/JPassActivationState.hpp +68 -0
- package/nitrogen/generated/android/c++/JPayServiceStatus.hpp +61 -0
- package/nitrogen/generated/android/c++/JPaymentItem.hpp +67 -0
- package/nitrogen/generated/android/c++/JPaymentItemType.hpp +59 -0
- package/nitrogen/generated/android/c++/JPaymentMethod.hpp +97 -0
- package/nitrogen/generated/android/c++/JPaymentMethodType.hpp +68 -0
- package/nitrogen/generated/android/c++/JPaymentNetwork.hpp +86 -0
- package/nitrogen/generated/android/c++/JPaymentRequest.hpp +181 -0
- package/nitrogen/generated/android/c++/JPaymentResult.hpp +97 -0
- package/nitrogen/generated/android/c++/JPaymentToken.hpp +91 -0
- package/nitrogen/generated/android/c++/views/JHybridGooglePayButtonStateUpdater.cpp +68 -0
- package/nitrogen/generated/android/c++/views/JHybridGooglePayButtonStateUpdater.hpp +49 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/CNContact.kt +96 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/CNContactType.kt +21 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/CNLabeledEmailAddress.kt +39 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/CNLabeledPhoneNumber.kt +39 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/CNLabeledPostalAddress.kt +39 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/CNPhoneNumber.kt +36 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/CNPostalAddress.kt +51 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/Func_void.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/GooglePayButtonTheme.kt +21 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/GooglePayButtonType.kt +27 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/GooglePayEnvironment.kt +21 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/HybridGooglePayButtonSpec.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/HybridPaymentHandlerSpec.kt +61 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/NitroPayOnLoad.kt +35 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PKSecureElementPass.kt +63 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PassActivationState.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PayServiceStatus.kt +39 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentItem.kt +42 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentItemType.kt +21 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentMethod.kt +48 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentMethodType.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentNetwork.kt +30 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentRequest.kt +72 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentResult.kt +45 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/PaymentToken.kt +42 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/views/HybridGooglePayButtonManager.kt +50 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/pay/views/HybridGooglePayButtonStateUpdater.kt +23 -0
- package/nitrogen/generated/ios/NitroPay+autolinking.rb +60 -0
- package/nitrogen/generated/ios/NitroPay-Swift-Cxx-Bridge.cpp +73 -0
- package/nitrogen/generated/ios/NitroPay-Swift-Cxx-Bridge.hpp +415 -0
- package/nitrogen/generated/ios/NitroPay-Swift-Cxx-Umbrella.hpp +116 -0
- package/nitrogen/generated/ios/NitroPayAutolinking.mm +41 -0
- package/nitrogen/generated/ios/NitroPayAutolinking.swift +40 -0
- package/nitrogen/generated/ios/c++/HybridApplePayButtonSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridApplePayButtonSpecSwift.hpp +92 -0
- package/nitrogen/generated/ios/c++/HybridPaymentHandlerSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridPaymentHandlerSpecSwift.hpp +148 -0
- package/nitrogen/generated/ios/c++/views/HybridApplePayButtonComponent.mm +106 -0
- package/nitrogen/generated/ios/swift/ApplePayButtonStyle.swift +44 -0
- package/nitrogen/generated/ios/swift/ApplePayButtonType.swift +84 -0
- package/nitrogen/generated/ios/swift/CNContact.swift +329 -0
- package/nitrogen/generated/ios/swift/CNContactType.swift +40 -0
- package/nitrogen/generated/ios/swift/CNLabeledEmailAddress.swift +65 -0
- package/nitrogen/generated/ios/swift/CNLabeledPhoneNumber.swift +65 -0
- package/nitrogen/generated/ios/swift/CNLabeledPostalAddress.swift +65 -0
- package/nitrogen/generated/ios/swift/CNPhoneNumber.swift +35 -0
- package/nitrogen/generated/ios/swift/CNPostalAddress.swift +204 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_PaymentResult.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
- package/nitrogen/generated/ios/swift/GooglePayEnvironment.swift +40 -0
- package/nitrogen/generated/ios/swift/HybridApplePayButtonSpec.swift +51 -0
- package/nitrogen/generated/ios/swift/HybridApplePayButtonSpec_cxx.swift +175 -0
- package/nitrogen/generated/ios/swift/HybridPaymentHandlerSpec.swift +52 -0
- package/nitrogen/generated/ios/swift/HybridPaymentHandlerSpec_cxx.swift +155 -0
- package/nitrogen/generated/ios/swift/PKSecureElementPass.swift +191 -0
- package/nitrogen/generated/ios/swift/PassActivationState.swift +52 -0
- package/nitrogen/generated/ios/swift/PayServiceStatus.swift +46 -0
- package/nitrogen/generated/ios/swift/PaymentItem.swift +57 -0
- package/nitrogen/generated/ios/swift/PaymentItemType.swift +40 -0
- package/nitrogen/generated/ios/swift/PaymentMethod.swift +134 -0
- package/nitrogen/generated/ios/swift/PaymentMethodType.swift +52 -0
- package/nitrogen/generated/ios/swift/PaymentNetwork.swift +76 -0
- package/nitrogen/generated/ios/swift/PaymentRequest.swift +341 -0
- package/nitrogen/generated/ios/swift/PaymentResult.swift +118 -0
- package/nitrogen/generated/ios/swift/PaymentToken.swift +57 -0
- package/nitrogen/generated/shared/c++/ApplePayButtonStyle.hpp +80 -0
- package/nitrogen/generated/shared/c++/ApplePayButtonType.hpp +120 -0
- package/nitrogen/generated/shared/c++/CNContact.hpp +168 -0
- package/nitrogen/generated/shared/c++/CNContactType.hpp +76 -0
- package/nitrogen/generated/shared/c++/CNLabeledEmailAddress.hpp +80 -0
- package/nitrogen/generated/shared/c++/CNLabeledPhoneNumber.hpp +82 -0
- package/nitrogen/generated/shared/c++/CNLabeledPostalAddress.hpp +82 -0
- package/nitrogen/generated/shared/c++/CNPhoneNumber.hpp +75 -0
- package/nitrogen/generated/shared/c++/CNPostalAddress.hpp +96 -0
- package/nitrogen/generated/shared/c++/GooglePayButtonTheme.hpp +76 -0
- package/nitrogen/generated/shared/c++/GooglePayButtonType.hpp +100 -0
- package/nitrogen/generated/shared/c++/GooglePayEnvironment.hpp +76 -0
- package/nitrogen/generated/shared/c++/HybridApplePayButtonSpec.cpp +26 -0
- package/nitrogen/generated/shared/c++/HybridApplePayButtonSpec.hpp +73 -0
- package/nitrogen/generated/shared/c++/HybridGooglePayButtonSpec.cpp +28 -0
- package/nitrogen/generated/shared/c++/HybridGooglePayButtonSpec.hpp +75 -0
- package/nitrogen/generated/shared/c++/HybridPaymentHandlerSpec.cpp +23 -0
- package/nitrogen/generated/shared/c++/HybridPaymentHandlerSpec.hpp +74 -0
- package/nitrogen/generated/shared/c++/PKSecureElementPass.hpp +114 -0
- package/nitrogen/generated/shared/c++/PassActivationState.hpp +88 -0
- package/nitrogen/generated/shared/c++/PayServiceStatus.hpp +79 -0
- package/nitrogen/generated/shared/c++/PaymentItem.hpp +85 -0
- package/nitrogen/generated/shared/c++/PaymentItemType.hpp +76 -0
- package/nitrogen/generated/shared/c++/PaymentMethod.hpp +103 -0
- package/nitrogen/generated/shared/c++/PaymentMethodType.hpp +88 -0
- package/nitrogen/generated/shared/c++/PaymentNetwork.hpp +112 -0
- package/nitrogen/generated/shared/c++/PaymentRequest.hpp +130 -0
- package/nitrogen/generated/shared/c++/PaymentResult.hpp +90 -0
- package/nitrogen/generated/shared/c++/PaymentToken.hpp +85 -0
- package/nitrogen/generated/shared/c++/views/HybridApplePayButtonComponent.cpp +111 -0
- package/nitrogen/generated/shared/c++/views/HybridApplePayButtonComponent.hpp +111 -0
- package/nitrogen/generated/shared/c++/views/HybridGooglePayButtonComponent.cpp +123 -0
- package/nitrogen/generated/shared/c++/views/HybridGooglePayButtonComponent.hpp +112 -0
- package/nitrogen/generated/shared/json/ApplePayButtonConfig.json +12 -0
- package/nitrogen/generated/shared/json/GooglePayButtonConfig.json +13 -0
- package/package.json +116 -0
- package/react-native.config.js +16 -0
- package/src/hooks/index.ts +12 -0
- package/src/hooks/usePaymentCheckout.ts +281 -0
- package/src/index.ts +32 -0
- package/src/plugin/index.ts +17 -0
- package/src/plugin/type.ts +4 -0
- package/src/plugin/withApplePay.ts +44 -0
- package/src/plugin/withGooglePay.ts +41 -0
- package/src/specs/ApplePayButton.nitro.ts +37 -0
- package/src/specs/GooglePayButton.nitro.ts +34 -0
- package/src/specs/PaymentHandler.nitro.ts +13 -0
- package/src/types/Contact.ts +58 -0
- package/src/types/Payment.ts +104 -0
- package/src/types/index.ts +2 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/paymentHelpers.ts +215 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridGooglePayButtonSpec.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/HybridObject.hpp>)
|
|
11
|
+
#include <NitroModules/HybridObject.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
// Forward declaration of `GooglePayButtonType` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::pay { enum class GooglePayButtonType; }
|
|
18
|
+
// Forward declaration of `GooglePayButtonTheme` to properly resolve imports.
|
|
19
|
+
namespace margelo::nitro::pay { enum class GooglePayButtonTheme; }
|
|
20
|
+
|
|
21
|
+
#include "GooglePayButtonType.hpp"
|
|
22
|
+
#include "GooglePayButtonTheme.hpp"
|
|
23
|
+
#include <optional>
|
|
24
|
+
#include <functional>
|
|
25
|
+
|
|
26
|
+
namespace margelo::nitro::pay {
|
|
27
|
+
|
|
28
|
+
using namespace margelo::nitro;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* An abstract base class for `GooglePayButton`
|
|
32
|
+
* Inherit this class to create instances of `HybridGooglePayButtonSpec` in C++.
|
|
33
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
34
|
+
* @example
|
|
35
|
+
* ```cpp
|
|
36
|
+
* class HybridGooglePayButton: public HybridGooglePayButtonSpec {
|
|
37
|
+
* public:
|
|
38
|
+
* HybridGooglePayButton(...): HybridObject(TAG) { ... }
|
|
39
|
+
* // ...
|
|
40
|
+
* };
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
class HybridGooglePayButtonSpec: public virtual HybridObject {
|
|
44
|
+
public:
|
|
45
|
+
// Constructor
|
|
46
|
+
explicit HybridGooglePayButtonSpec(): HybridObject(TAG) { }
|
|
47
|
+
|
|
48
|
+
// Destructor
|
|
49
|
+
~HybridGooglePayButtonSpec() override = default;
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
// Properties
|
|
53
|
+
virtual GooglePayButtonType getButtonType() = 0;
|
|
54
|
+
virtual void setButtonType(GooglePayButtonType buttonType) = 0;
|
|
55
|
+
virtual GooglePayButtonTheme getTheme() = 0;
|
|
56
|
+
virtual void setTheme(GooglePayButtonTheme theme) = 0;
|
|
57
|
+
virtual std::optional<double> getRadius() = 0;
|
|
58
|
+
virtual void setRadius(std::optional<double> radius) = 0;
|
|
59
|
+
virtual std::optional<std::function<void()>> getOnPress() = 0;
|
|
60
|
+
virtual void setOnPress(const std::optional<std::function<void()>>& onPress) = 0;
|
|
61
|
+
|
|
62
|
+
public:
|
|
63
|
+
// Methods
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
protected:
|
|
67
|
+
// Hybrid Setup
|
|
68
|
+
void loadHybridMethods() override;
|
|
69
|
+
|
|
70
|
+
protected:
|
|
71
|
+
// Tag for logging
|
|
72
|
+
static constexpr auto TAG = "GooglePayButton";
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
} // namespace margelo::nitro::pay
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridPaymentHandlerSpec.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 "HybridPaymentHandlerSpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::pay {
|
|
11
|
+
|
|
12
|
+
void HybridPaymentHandlerSpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridMethod("payServiceStatus", &HybridPaymentHandlerSpec::payServiceStatus);
|
|
18
|
+
prototype.registerHybridMethod("startPayment", &HybridPaymentHandlerSpec::startPayment);
|
|
19
|
+
prototype.registerHybridMethod("canMakePayments", &HybridPaymentHandlerSpec::canMakePayments);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
} // namespace margelo::nitro::pay
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridPaymentHandlerSpec.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/HybridObject.hpp>)
|
|
11
|
+
#include <NitroModules/HybridObject.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
// Forward declaration of `PayServiceStatus` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::pay { struct PayServiceStatus; }
|
|
18
|
+
// Forward declaration of `PaymentResult` to properly resolve imports.
|
|
19
|
+
namespace margelo::nitro::pay { struct PaymentResult; }
|
|
20
|
+
// Forward declaration of `PaymentRequest` to properly resolve imports.
|
|
21
|
+
namespace margelo::nitro::pay { struct PaymentRequest; }
|
|
22
|
+
|
|
23
|
+
#include "PayServiceStatus.hpp"
|
|
24
|
+
#include "PaymentResult.hpp"
|
|
25
|
+
#include <NitroModules/Promise.hpp>
|
|
26
|
+
#include "PaymentRequest.hpp"
|
|
27
|
+
#include <string>
|
|
28
|
+
#include <vector>
|
|
29
|
+
|
|
30
|
+
namespace margelo::nitro::pay {
|
|
31
|
+
|
|
32
|
+
using namespace margelo::nitro;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* An abstract base class for `PaymentHandler`
|
|
36
|
+
* Inherit this class to create instances of `HybridPaymentHandlerSpec` in C++.
|
|
37
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
38
|
+
* @example
|
|
39
|
+
* ```cpp
|
|
40
|
+
* class HybridPaymentHandler: public HybridPaymentHandlerSpec {
|
|
41
|
+
* public:
|
|
42
|
+
* HybridPaymentHandler(...): HybridObject(TAG) { ... }
|
|
43
|
+
* // ...
|
|
44
|
+
* };
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
class HybridPaymentHandlerSpec: public virtual HybridObject {
|
|
48
|
+
public:
|
|
49
|
+
// Constructor
|
|
50
|
+
explicit HybridPaymentHandlerSpec(): HybridObject(TAG) { }
|
|
51
|
+
|
|
52
|
+
// Destructor
|
|
53
|
+
~HybridPaymentHandlerSpec() override = default;
|
|
54
|
+
|
|
55
|
+
public:
|
|
56
|
+
// Properties
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
public:
|
|
60
|
+
// Methods
|
|
61
|
+
virtual PayServiceStatus payServiceStatus() = 0;
|
|
62
|
+
virtual std::shared_ptr<Promise<PaymentResult>> startPayment(const PaymentRequest& request) = 0;
|
|
63
|
+
virtual bool canMakePayments(const std::vector<std::string>& usingNetworks) = 0;
|
|
64
|
+
|
|
65
|
+
protected:
|
|
66
|
+
// Hybrid Setup
|
|
67
|
+
void loadHybridMethods() override;
|
|
68
|
+
|
|
69
|
+
protected:
|
|
70
|
+
// Tag for logging
|
|
71
|
+
static constexpr auto TAG = "PaymentHandler";
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
} // namespace margelo::nitro::pay
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// PKSecureElementPass.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 `PassActivationState` to properly resolve imports.
|
|
27
|
+
namespace margelo::nitro::pay { enum class PassActivationState; }
|
|
28
|
+
|
|
29
|
+
#include <string>
|
|
30
|
+
#include "PassActivationState.hpp"
|
|
31
|
+
#include <optional>
|
|
32
|
+
|
|
33
|
+
namespace margelo::nitro::pay {
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A struct which can be represented as a JavaScript object (PKSecureElementPass).
|
|
37
|
+
*/
|
|
38
|
+
struct PKSecureElementPass {
|
|
39
|
+
public:
|
|
40
|
+
std::string primaryAccountIdentifier SWIFT_PRIVATE;
|
|
41
|
+
std::string primaryAccountNumberSuffix SWIFT_PRIVATE;
|
|
42
|
+
std::string deviceAccountIdentifier SWIFT_PRIVATE;
|
|
43
|
+
std::string deviceAccountNumberSuffix SWIFT_PRIVATE;
|
|
44
|
+
PassActivationState passActivationState SWIFT_PRIVATE;
|
|
45
|
+
std::optional<std::string> devicePassIdentifier SWIFT_PRIVATE;
|
|
46
|
+
std::optional<std::string> pairedTerminalIdentifier SWIFT_PRIVATE;
|
|
47
|
+
std::string passTypeIdentifier SWIFT_PRIVATE;
|
|
48
|
+
std::string serialNumber SWIFT_PRIVATE;
|
|
49
|
+
std::optional<std::string> organizationName SWIFT_PRIVATE;
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
PKSecureElementPass() = default;
|
|
53
|
+
explicit PKSecureElementPass(std::string primaryAccountIdentifier, std::string primaryAccountNumberSuffix, std::string deviceAccountIdentifier, std::string deviceAccountNumberSuffix, PassActivationState passActivationState, std::optional<std::string> devicePassIdentifier, std::optional<std::string> pairedTerminalIdentifier, std::string passTypeIdentifier, std::string serialNumber, std::optional<std::string> organizationName): primaryAccountIdentifier(primaryAccountIdentifier), primaryAccountNumberSuffix(primaryAccountNumberSuffix), deviceAccountIdentifier(deviceAccountIdentifier), deviceAccountNumberSuffix(deviceAccountNumberSuffix), passActivationState(passActivationState), devicePassIdentifier(devicePassIdentifier), pairedTerminalIdentifier(pairedTerminalIdentifier), passTypeIdentifier(passTypeIdentifier), serialNumber(serialNumber), organizationName(organizationName) {}
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
} // namespace margelo::nitro::pay
|
|
57
|
+
|
|
58
|
+
namespace margelo::nitro {
|
|
59
|
+
|
|
60
|
+
// C++ PKSecureElementPass <> JS PKSecureElementPass (object)
|
|
61
|
+
template <>
|
|
62
|
+
struct JSIConverter<margelo::nitro::pay::PKSecureElementPass> final {
|
|
63
|
+
static inline margelo::nitro::pay::PKSecureElementPass fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
64
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
65
|
+
return margelo::nitro::pay::PKSecureElementPass(
|
|
66
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "primaryAccountIdentifier")),
|
|
67
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "primaryAccountNumberSuffix")),
|
|
68
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "deviceAccountIdentifier")),
|
|
69
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "deviceAccountNumberSuffix")),
|
|
70
|
+
JSIConverter<margelo::nitro::pay::PassActivationState>::fromJSI(runtime, obj.getProperty(runtime, "passActivationState")),
|
|
71
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "devicePassIdentifier")),
|
|
72
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "pairedTerminalIdentifier")),
|
|
73
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "passTypeIdentifier")),
|
|
74
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "serialNumber")),
|
|
75
|
+
JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "organizationName"))
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::pay::PKSecureElementPass& arg) {
|
|
79
|
+
jsi::Object obj(runtime);
|
|
80
|
+
obj.setProperty(runtime, "primaryAccountIdentifier", JSIConverter<std::string>::toJSI(runtime, arg.primaryAccountIdentifier));
|
|
81
|
+
obj.setProperty(runtime, "primaryAccountNumberSuffix", JSIConverter<std::string>::toJSI(runtime, arg.primaryAccountNumberSuffix));
|
|
82
|
+
obj.setProperty(runtime, "deviceAccountIdentifier", JSIConverter<std::string>::toJSI(runtime, arg.deviceAccountIdentifier));
|
|
83
|
+
obj.setProperty(runtime, "deviceAccountNumberSuffix", JSIConverter<std::string>::toJSI(runtime, arg.deviceAccountNumberSuffix));
|
|
84
|
+
obj.setProperty(runtime, "passActivationState", JSIConverter<margelo::nitro::pay::PassActivationState>::toJSI(runtime, arg.passActivationState));
|
|
85
|
+
obj.setProperty(runtime, "devicePassIdentifier", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.devicePassIdentifier));
|
|
86
|
+
obj.setProperty(runtime, "pairedTerminalIdentifier", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.pairedTerminalIdentifier));
|
|
87
|
+
obj.setProperty(runtime, "passTypeIdentifier", JSIConverter<std::string>::toJSI(runtime, arg.passTypeIdentifier));
|
|
88
|
+
obj.setProperty(runtime, "serialNumber", JSIConverter<std::string>::toJSI(runtime, arg.serialNumber));
|
|
89
|
+
obj.setProperty(runtime, "organizationName", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.organizationName));
|
|
90
|
+
return obj;
|
|
91
|
+
}
|
|
92
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
93
|
+
if (!value.isObject()) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
jsi::Object obj = value.getObject(runtime);
|
|
97
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "primaryAccountIdentifier"))) return false;
|
|
101
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "primaryAccountNumberSuffix"))) return false;
|
|
102
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "deviceAccountIdentifier"))) return false;
|
|
103
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "deviceAccountNumberSuffix"))) return false;
|
|
104
|
+
if (!JSIConverter<margelo::nitro::pay::PassActivationState>::canConvert(runtime, obj.getProperty(runtime, "passActivationState"))) return false;
|
|
105
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "devicePassIdentifier"))) return false;
|
|
106
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "pairedTerminalIdentifier"))) return false;
|
|
107
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "passTypeIdentifier"))) return false;
|
|
108
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "serialNumber"))) return false;
|
|
109
|
+
if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "organizationName"))) return false;
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// PassActivationState.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::pay {
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* An enum which can be represented as a JavaScript union (PassActivationState).
|
|
30
|
+
*/
|
|
31
|
+
enum class PassActivationState {
|
|
32
|
+
ACTIVATED SWIFT_NAME(activated) = 0,
|
|
33
|
+
REQUIRESACTIVATION SWIFT_NAME(requiresactivation) = 1,
|
|
34
|
+
ACTIVATING SWIFT_NAME(activating) = 2,
|
|
35
|
+
SUSPENDED SWIFT_NAME(suspended) = 3,
|
|
36
|
+
DEACTIVATED SWIFT_NAME(deactivated) = 4,
|
|
37
|
+
} CLOSED_ENUM;
|
|
38
|
+
|
|
39
|
+
} // namespace margelo::nitro::pay
|
|
40
|
+
|
|
41
|
+
namespace margelo::nitro {
|
|
42
|
+
|
|
43
|
+
// C++ PassActivationState <> JS PassActivationState (union)
|
|
44
|
+
template <>
|
|
45
|
+
struct JSIConverter<margelo::nitro::pay::PassActivationState> final {
|
|
46
|
+
static inline margelo::nitro::pay::PassActivationState fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
47
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
|
|
48
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
49
|
+
case hashString("activated"): return margelo::nitro::pay::PassActivationState::ACTIVATED;
|
|
50
|
+
case hashString("requiresActivation"): return margelo::nitro::pay::PassActivationState::REQUIRESACTIVATION;
|
|
51
|
+
case hashString("activating"): return margelo::nitro::pay::PassActivationState::ACTIVATING;
|
|
52
|
+
case hashString("suspended"): return margelo::nitro::pay::PassActivationState::SUSPENDED;
|
|
53
|
+
case hashString("deactivated"): return margelo::nitro::pay::PassActivationState::DEACTIVATED;
|
|
54
|
+
default: [[unlikely]]
|
|
55
|
+
throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum PassActivationState - invalid value!");
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::pay::PassActivationState arg) {
|
|
59
|
+
switch (arg) {
|
|
60
|
+
case margelo::nitro::pay::PassActivationState::ACTIVATED: return JSIConverter<std::string>::toJSI(runtime, "activated");
|
|
61
|
+
case margelo::nitro::pay::PassActivationState::REQUIRESACTIVATION: return JSIConverter<std::string>::toJSI(runtime, "requiresActivation");
|
|
62
|
+
case margelo::nitro::pay::PassActivationState::ACTIVATING: return JSIConverter<std::string>::toJSI(runtime, "activating");
|
|
63
|
+
case margelo::nitro::pay::PassActivationState::SUSPENDED: return JSIConverter<std::string>::toJSI(runtime, "suspended");
|
|
64
|
+
case margelo::nitro::pay::PassActivationState::DEACTIVATED: return JSIConverter<std::string>::toJSI(runtime, "deactivated");
|
|
65
|
+
default: [[unlikely]]
|
|
66
|
+
throw std::invalid_argument("Cannot convert PassActivationState to JS - invalid value: "
|
|
67
|
+
+ std::to_string(static_cast<int>(arg)) + "!");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
71
|
+
if (!value.isString()) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
|
|
75
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
76
|
+
case hashString("activated"):
|
|
77
|
+
case hashString("requiresActivation"):
|
|
78
|
+
case hashString("activating"):
|
|
79
|
+
case hashString("suspended"):
|
|
80
|
+
case hashString("deactivated"):
|
|
81
|
+
return true;
|
|
82
|
+
default:
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// PayServiceStatus.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
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
namespace margelo::nitro::pay {
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A struct which can be represented as a JavaScript object (PayServiceStatus).
|
|
34
|
+
*/
|
|
35
|
+
struct PayServiceStatus {
|
|
36
|
+
public:
|
|
37
|
+
bool canMakePayments SWIFT_PRIVATE;
|
|
38
|
+
bool canSetupCards SWIFT_PRIVATE;
|
|
39
|
+
|
|
40
|
+
public:
|
|
41
|
+
PayServiceStatus() = default;
|
|
42
|
+
explicit PayServiceStatus(bool canMakePayments, bool canSetupCards): canMakePayments(canMakePayments), canSetupCards(canSetupCards) {}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
} // namespace margelo::nitro::pay
|
|
46
|
+
|
|
47
|
+
namespace margelo::nitro {
|
|
48
|
+
|
|
49
|
+
// C++ PayServiceStatus <> JS PayServiceStatus (object)
|
|
50
|
+
template <>
|
|
51
|
+
struct JSIConverter<margelo::nitro::pay::PayServiceStatus> final {
|
|
52
|
+
static inline margelo::nitro::pay::PayServiceStatus fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
53
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
54
|
+
return margelo::nitro::pay::PayServiceStatus(
|
|
55
|
+
JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, "canMakePayments")),
|
|
56
|
+
JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, "canSetupCards"))
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::pay::PayServiceStatus& arg) {
|
|
60
|
+
jsi::Object obj(runtime);
|
|
61
|
+
obj.setProperty(runtime, "canMakePayments", JSIConverter<bool>::toJSI(runtime, arg.canMakePayments));
|
|
62
|
+
obj.setProperty(runtime, "canSetupCards", JSIConverter<bool>::toJSI(runtime, arg.canSetupCards));
|
|
63
|
+
return obj;
|
|
64
|
+
}
|
|
65
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
66
|
+
if (!value.isObject()) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
jsi::Object obj = value.getObject(runtime);
|
|
70
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, "canMakePayments"))) return false;
|
|
74
|
+
if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, "canSetupCards"))) return false;
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// PaymentItem.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 `PaymentItemType` to properly resolve imports.
|
|
27
|
+
namespace margelo::nitro::pay { enum class PaymentItemType; }
|
|
28
|
+
|
|
29
|
+
#include <string>
|
|
30
|
+
#include "PaymentItemType.hpp"
|
|
31
|
+
|
|
32
|
+
namespace margelo::nitro::pay {
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A struct which can be represented as a JavaScript object (PaymentItem).
|
|
36
|
+
*/
|
|
37
|
+
struct PaymentItem {
|
|
38
|
+
public:
|
|
39
|
+
std::string label SWIFT_PRIVATE;
|
|
40
|
+
double amount SWIFT_PRIVATE;
|
|
41
|
+
PaymentItemType type SWIFT_PRIVATE;
|
|
42
|
+
|
|
43
|
+
public:
|
|
44
|
+
PaymentItem() = default;
|
|
45
|
+
explicit PaymentItem(std::string label, double amount, PaymentItemType type): label(label), amount(amount), type(type) {}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
} // namespace margelo::nitro::pay
|
|
49
|
+
|
|
50
|
+
namespace margelo::nitro {
|
|
51
|
+
|
|
52
|
+
// C++ PaymentItem <> JS PaymentItem (object)
|
|
53
|
+
template <>
|
|
54
|
+
struct JSIConverter<margelo::nitro::pay::PaymentItem> final {
|
|
55
|
+
static inline margelo::nitro::pay::PaymentItem fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
56
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
57
|
+
return margelo::nitro::pay::PaymentItem(
|
|
58
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "label")),
|
|
59
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "amount")),
|
|
60
|
+
JSIConverter<margelo::nitro::pay::PaymentItemType>::fromJSI(runtime, obj.getProperty(runtime, "type"))
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::pay::PaymentItem& arg) {
|
|
64
|
+
jsi::Object obj(runtime);
|
|
65
|
+
obj.setProperty(runtime, "label", JSIConverter<std::string>::toJSI(runtime, arg.label));
|
|
66
|
+
obj.setProperty(runtime, "amount", JSIConverter<double>::toJSI(runtime, arg.amount));
|
|
67
|
+
obj.setProperty(runtime, "type", JSIConverter<margelo::nitro::pay::PaymentItemType>::toJSI(runtime, arg.type));
|
|
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::string>::canConvert(runtime, obj.getProperty(runtime, "label"))) return false;
|
|
79
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "amount"))) return false;
|
|
80
|
+
if (!JSIConverter<margelo::nitro::pay::PaymentItemType>::canConvert(runtime, obj.getProperty(runtime, "type"))) return false;
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// PaymentItemType.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::pay {
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* An enum which can be represented as a JavaScript union (PaymentItemType).
|
|
30
|
+
*/
|
|
31
|
+
enum class PaymentItemType {
|
|
32
|
+
FINAL SWIFT_NAME(final) = 0,
|
|
33
|
+
PENDING SWIFT_NAME(pending) = 1,
|
|
34
|
+
} CLOSED_ENUM;
|
|
35
|
+
|
|
36
|
+
} // namespace margelo::nitro::pay
|
|
37
|
+
|
|
38
|
+
namespace margelo::nitro {
|
|
39
|
+
|
|
40
|
+
// C++ PaymentItemType <> JS PaymentItemType (union)
|
|
41
|
+
template <>
|
|
42
|
+
struct JSIConverter<margelo::nitro::pay::PaymentItemType> final {
|
|
43
|
+
static inline margelo::nitro::pay::PaymentItemType 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("final"): return margelo::nitro::pay::PaymentItemType::FINAL;
|
|
47
|
+
case hashString("pending"): return margelo::nitro::pay::PaymentItemType::PENDING;
|
|
48
|
+
default: [[unlikely]]
|
|
49
|
+
throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum PaymentItemType - invalid value!");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::pay::PaymentItemType arg) {
|
|
53
|
+
switch (arg) {
|
|
54
|
+
case margelo::nitro::pay::PaymentItemType::FINAL: return JSIConverter<std::string>::toJSI(runtime, "final");
|
|
55
|
+
case margelo::nitro::pay::PaymentItemType::PENDING: return JSIConverter<std::string>::toJSI(runtime, "pending");
|
|
56
|
+
default: [[unlikely]]
|
|
57
|
+
throw std::invalid_argument("Cannot convert PaymentItemType 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("final"):
|
|
68
|
+
case hashString("pending"):
|
|
69
|
+
return true;
|
|
70
|
+
default:
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
} // namespace margelo::nitro
|