@gmisoftware/react-native-pay 0.0.7 → 0.0.9

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.
@@ -1,6 +1,7 @@
1
1
  import type { PaymentRequest, PaymentResult, PaymentItem, GooglePayEnvironment } from '../types';
2
2
  export interface UsePaymentCheckoutConfig {
3
3
  merchantIdentifier: string;
4
+ merchantName?: string;
4
5
  countryCode?: string;
5
6
  currencyCode?: string;
6
7
  supportedNetworks?: string[];
@@ -67,16 +67,12 @@ const utils_1 = require("../utils");
67
67
  * ```
68
68
  */
69
69
  function usePaymentCheckout(config) {
70
- // Payment status state
71
70
  const [status, setStatus] = (0, react_1.useState)(null);
72
71
  const [isCheckingStatus, setIsCheckingStatus] = (0, react_1.useState)(true);
73
- // Cart state
74
72
  const [items, setItems] = (0, react_1.useState)([]);
75
- // Payment state
76
73
  const [isProcessing, setIsProcessing] = (0, react_1.useState)(false);
77
74
  const [result, setResult] = (0, react_1.useState)(null);
78
75
  const [error, setError] = (0, react_1.useState)(null);
79
- // Check payment status on mount
80
76
  (0, react_1.useEffect)(() => {
81
77
  try {
82
78
  const paymentStatus = HybridPaymentHandler.payServiceStatus();
@@ -90,14 +86,13 @@ function usePaymentCheckout(config) {
90
86
  setIsCheckingStatus(false);
91
87
  }
92
88
  }, []);
93
- // Calculate total
94
89
  const total = (0, react_1.useMemo)(() => (0, utils_1.calculateTotal)(items), [items]);
95
- // Build payment request
96
90
  const paymentRequest = (0, react_1.useMemo)(() => {
97
- const { merchantIdentifier, countryCode = 'US', currencyCode = 'USD', supportedNetworks = ['visa', 'mastercard', 'amex', 'discover'], merchantCapabilities = ['3DS'], googlePayEnvironment, googlePayGateway, googlePayGatewayMerchantId, } = config;
91
+ const { merchantIdentifier, merchantName, countryCode = 'US', currencyCode = 'USD', supportedNetworks = ['visa', 'mastercard', 'amex', 'discover'], merchantCapabilities = ['3DS'], googlePayEnvironment, googlePayGateway, googlePayGatewayMerchantId, } = config;
98
92
  return {
99
93
  merchantIdentifier,
100
94
  countryCode,
95
+ merchantName,
101
96
  currencyCode,
102
97
  supportedNetworks,
103
98
  merchantCapabilities,
@@ -125,7 +120,6 @@ function usePaymentCheckout(config) {
125
120
  const clearItems = (0, react_1.useCallback)(() => {
126
121
  setItems([]);
127
122
  }, []);
128
- // Start payment
129
123
  const startPayment = (0, react_1.useCallback)(async () => {
130
124
  if (items.length === 0) {
131
125
  const emptyCartError = new Error('Cart is empty');
@@ -152,7 +146,6 @@ function usePaymentCheckout(config) {
152
146
  setIsProcessing(false);
153
147
  }
154
148
  }, [items, paymentRequest]);
155
- // Reset all state
156
149
  const reset = (0, react_1.useCallback)(() => {
157
150
  setIsProcessing(false);
158
151
  setResult(null);
@@ -41,6 +41,7 @@ export interface PaymentToken {
41
41
  }
42
42
  export interface PaymentRequest {
43
43
  merchantIdentifier: string;
44
+ merchantName?: string;
44
45
  countryCode: string;
45
46
  currencyCode: string;
46
47
  paymentItems: PaymentItem[];
@@ -41,6 +41,8 @@ namespace margelo::nitro::pay {
41
41
  static const auto clazz = javaClassStatic();
42
42
  static const auto fieldMerchantIdentifier = clazz->getField<jni::JString>("merchantIdentifier");
43
43
  jni::local_ref<jni::JString> merchantIdentifier = this->getFieldValue(fieldMerchantIdentifier);
44
+ static const auto fieldMerchantName = clazz->getField<jni::JString>("merchantName");
45
+ jni::local_ref<jni::JString> merchantName = this->getFieldValue(fieldMerchantName);
44
46
  static const auto fieldCountryCode = clazz->getField<jni::JString>("countryCode");
45
47
  jni::local_ref<jni::JString> countryCode = this->getFieldValue(fieldCountryCode);
46
48
  static const auto fieldCurrencyCode = clazz->getField<jni::JString>("currencyCode");
@@ -67,6 +69,7 @@ namespace margelo::nitro::pay {
67
69
  jni::local_ref<jni::JString> googlePayGatewayMerchantId = this->getFieldValue(fieldGooglePayGatewayMerchantId);
68
70
  return PaymentRequest(
69
71
  merchantIdentifier->toStdString(),
72
+ merchantName != nullptr ? std::make_optional(merchantName->toStdString()) : std::nullopt,
70
73
  countryCode->toStdString(),
71
74
  currencyCode->toStdString(),
72
75
  [&]() {
@@ -124,12 +127,13 @@ namespace margelo::nitro::pay {
124
127
  */
125
128
  [[maybe_unused]]
126
129
  static jni::local_ref<JPaymentRequest::javaobject> fromCpp(const PaymentRequest& value) {
127
- using JSignature = JPaymentRequest(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JArrayClass<JPaymentItem>>, jni::alias_ref<jni::JArrayClass<jni::JString>>, jni::alias_ref<jni::JArrayClass<jni::JString>>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JArrayClass<JPaymentItem>>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<JGooglePayEnvironment>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>);
130
+ using JSignature = JPaymentRequest(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JArrayClass<JPaymentItem>>, jni::alias_ref<jni::JArrayClass<jni::JString>>, jni::alias_ref<jni::JArrayClass<jni::JString>>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JArrayClass<JPaymentItem>>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<JGooglePayEnvironment>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>);
128
131
  static const auto clazz = javaClassStatic();
129
132
  static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
130
133
  return create(
131
134
  clazz,
132
135
  jni::make_jstring(value.merchantIdentifier),
136
+ value.merchantName.has_value() ? jni::make_jstring(value.merchantName.value()) : nullptr,
133
137
  jni::make_jstring(value.countryCode),
134
138
  jni::make_jstring(value.currencyCode),
135
139
  [&]() {
@@ -22,6 +22,9 @@ data class PaymentRequest(
22
22
  val merchantIdentifier: String,
23
23
  @DoNotStrip
24
24
  @Keep
25
+ val merchantName: String?,
26
+ @DoNotStrip
27
+ @Keep
25
28
  val countryCode: String,
26
29
  @DoNotStrip
27
30
  @Keep
@@ -65,8 +68,8 @@ data class PaymentRequest(
65
68
  @Keep
66
69
  @Suppress("unused")
67
70
  @JvmStatic
68
- private fun fromCpp(merchantIdentifier: String, countryCode: String, currencyCode: String, paymentItems: Array<PaymentItem>, merchantCapabilities: Array<String>, supportedNetworks: Array<String>, shippingType: String?, shippingMethods: Array<PaymentItem>?, billingContactRequired: Boolean?, shippingContactRequired: Boolean?, googlePayEnvironment: GooglePayEnvironment?, googlePayGateway: String?, googlePayGatewayMerchantId: String?): PaymentRequest {
69
- return PaymentRequest(merchantIdentifier, countryCode, currencyCode, paymentItems, merchantCapabilities, supportedNetworks, shippingType, shippingMethods, billingContactRequired, shippingContactRequired, googlePayEnvironment, googlePayGateway, googlePayGatewayMerchantId)
71
+ private fun fromCpp(merchantIdentifier: String, merchantName: String?, countryCode: String, currencyCode: String, paymentItems: Array<PaymentItem>, merchantCapabilities: Array<String>, supportedNetworks: Array<String>, shippingType: String?, shippingMethods: Array<PaymentItem>?, billingContactRequired: Boolean?, shippingContactRequired: Boolean?, googlePayEnvironment: GooglePayEnvironment?, googlePayGateway: String?, googlePayGatewayMerchantId: String?): PaymentRequest {
72
+ return PaymentRequest(merchantIdentifier, merchantName, countryCode, currencyCode, paymentItems, merchantCapabilities, supportedNetworks, shippingType, shippingMethods, billingContactRequired, shippingContactRequired, googlePayEnvironment, googlePayGateway, googlePayGatewayMerchantId)
70
73
  }
71
74
  }
72
75
  }
@@ -18,8 +18,14 @@ public extension PaymentRequest {
18
18
  /**
19
19
  * Create a new instance of `PaymentRequest`.
20
20
  */
21
- init(merchantIdentifier: String, countryCode: String, currencyCode: String, paymentItems: [PaymentItem], merchantCapabilities: [String], supportedNetworks: [String], shippingType: String?, shippingMethods: [PaymentItem]?, billingContactRequired: Bool?, shippingContactRequired: Bool?, googlePayEnvironment: GooglePayEnvironment?, googlePayGateway: String?, googlePayGatewayMerchantId: String?) {
22
- self.init(std.string(merchantIdentifier), std.string(countryCode), std.string(currencyCode), { () -> bridge.std__vector_PaymentItem_ in
21
+ init(merchantIdentifier: String, merchantName: String?, countryCode: String, currencyCode: String, paymentItems: [PaymentItem], merchantCapabilities: [String], supportedNetworks: [String], shippingType: String?, shippingMethods: [PaymentItem]?, billingContactRequired: Bool?, shippingContactRequired: Bool?, googlePayEnvironment: GooglePayEnvironment?, googlePayGateway: String?, googlePayGatewayMerchantId: String?) {
22
+ self.init(std.string(merchantIdentifier), { () -> bridge.std__optional_std__string_ in
23
+ if let __unwrappedValue = merchantName {
24
+ return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
25
+ } else {
26
+ return .init()
27
+ }
28
+ }(), std.string(countryCode), std.string(currencyCode), { () -> bridge.std__vector_PaymentItem_ in
23
29
  var __vector = bridge.create_std__vector_PaymentItem_(paymentItems.count)
24
30
  for __item in paymentItems {
25
31
  __vector.push_back(__item)
@@ -99,6 +105,30 @@ public extension PaymentRequest {
99
105
  }
100
106
  }
101
107
 
108
+ var merchantName: String? {
109
+ @inline(__always)
110
+ get {
111
+ return { () -> String? in
112
+ if bridge.has_value_std__optional_std__string_(self.__merchantName) {
113
+ let __unwrapped = bridge.get_std__optional_std__string_(self.__merchantName)
114
+ return String(__unwrapped)
115
+ } else {
116
+ return nil
117
+ }
118
+ }()
119
+ }
120
+ @inline(__always)
121
+ set {
122
+ self.__merchantName = { () -> bridge.std__optional_std__string_ in
123
+ if let __unwrappedValue = newValue {
124
+ return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
125
+ } else {
126
+ return .init()
127
+ }
128
+ }()
129
+ }
130
+ }
131
+
102
132
  var countryCode: String {
103
133
  @inline(__always)
104
134
  get {
@@ -29,9 +29,9 @@ namespace margelo::nitro::pay { struct PaymentItem; }
29
29
  namespace margelo::nitro::pay { enum class GooglePayEnvironment; }
30
30
 
31
31
  #include <string>
32
+ #include <optional>
32
33
  #include "PaymentItem.hpp"
33
34
  #include <vector>
34
- #include <optional>
35
35
  #include "GooglePayEnvironment.hpp"
36
36
 
37
37
  namespace margelo::nitro::pay {
@@ -42,6 +42,7 @@ namespace margelo::nitro::pay {
42
42
  struct PaymentRequest {
43
43
  public:
44
44
  std::string merchantIdentifier SWIFT_PRIVATE;
45
+ std::optional<std::string> merchantName SWIFT_PRIVATE;
45
46
  std::string countryCode SWIFT_PRIVATE;
46
47
  std::string currencyCode SWIFT_PRIVATE;
47
48
  std::vector<PaymentItem> paymentItems SWIFT_PRIVATE;
@@ -57,7 +58,7 @@ namespace margelo::nitro::pay {
57
58
 
58
59
  public:
59
60
  PaymentRequest() = default;
60
- explicit PaymentRequest(std::string merchantIdentifier, std::string countryCode, std::string currencyCode, std::vector<PaymentItem> paymentItems, std::vector<std::string> merchantCapabilities, std::vector<std::string> supportedNetworks, std::optional<std::string> shippingType, std::optional<std::vector<PaymentItem>> shippingMethods, std::optional<bool> billingContactRequired, std::optional<bool> shippingContactRequired, std::optional<GooglePayEnvironment> googlePayEnvironment, std::optional<std::string> googlePayGateway, std::optional<std::string> googlePayGatewayMerchantId): merchantIdentifier(merchantIdentifier), countryCode(countryCode), currencyCode(currencyCode), paymentItems(paymentItems), merchantCapabilities(merchantCapabilities), supportedNetworks(supportedNetworks), shippingType(shippingType), shippingMethods(shippingMethods), billingContactRequired(billingContactRequired), shippingContactRequired(shippingContactRequired), googlePayEnvironment(googlePayEnvironment), googlePayGateway(googlePayGateway), googlePayGatewayMerchantId(googlePayGatewayMerchantId) {}
61
+ explicit PaymentRequest(std::string merchantIdentifier, std::optional<std::string> merchantName, std::string countryCode, std::string currencyCode, std::vector<PaymentItem> paymentItems, std::vector<std::string> merchantCapabilities, std::vector<std::string> supportedNetworks, std::optional<std::string> shippingType, std::optional<std::vector<PaymentItem>> shippingMethods, std::optional<bool> billingContactRequired, std::optional<bool> shippingContactRequired, std::optional<GooglePayEnvironment> googlePayEnvironment, std::optional<std::string> googlePayGateway, std::optional<std::string> googlePayGatewayMerchantId): merchantIdentifier(merchantIdentifier), merchantName(merchantName), countryCode(countryCode), currencyCode(currencyCode), paymentItems(paymentItems), merchantCapabilities(merchantCapabilities), supportedNetworks(supportedNetworks), shippingType(shippingType), shippingMethods(shippingMethods), billingContactRequired(billingContactRequired), shippingContactRequired(shippingContactRequired), googlePayEnvironment(googlePayEnvironment), googlePayGateway(googlePayGateway), googlePayGatewayMerchantId(googlePayGatewayMerchantId) {}
61
62
  };
62
63
 
63
64
  } // namespace margelo::nitro::pay
@@ -71,6 +72,7 @@ namespace margelo::nitro {
71
72
  jsi::Object obj = arg.asObject(runtime);
72
73
  return margelo::nitro::pay::PaymentRequest(
73
74
  JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "merchantIdentifier")),
75
+ JSIConverter<std::optional<std::string>>::fromJSI(runtime, obj.getProperty(runtime, "merchantName")),
74
76
  JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "countryCode")),
75
77
  JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, "currencyCode")),
76
78
  JSIConverter<std::vector<margelo::nitro::pay::PaymentItem>>::fromJSI(runtime, obj.getProperty(runtime, "paymentItems")),
@@ -88,6 +90,7 @@ namespace margelo::nitro {
88
90
  static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::pay::PaymentRequest& arg) {
89
91
  jsi::Object obj(runtime);
90
92
  obj.setProperty(runtime, "merchantIdentifier", JSIConverter<std::string>::toJSI(runtime, arg.merchantIdentifier));
93
+ obj.setProperty(runtime, "merchantName", JSIConverter<std::optional<std::string>>::toJSI(runtime, arg.merchantName));
91
94
  obj.setProperty(runtime, "countryCode", JSIConverter<std::string>::toJSI(runtime, arg.countryCode));
92
95
  obj.setProperty(runtime, "currencyCode", JSIConverter<std::string>::toJSI(runtime, arg.currencyCode));
93
96
  obj.setProperty(runtime, "paymentItems", JSIConverter<std::vector<margelo::nitro::pay::PaymentItem>>::toJSI(runtime, arg.paymentItems));
@@ -111,6 +114,7 @@ namespace margelo::nitro {
111
114
  return false;
112
115
  }
113
116
  if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "merchantIdentifier"))) return false;
117
+ if (!JSIConverter<std::optional<std::string>>::canConvert(runtime, obj.getProperty(runtime, "merchantName"))) return false;
114
118
  if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "countryCode"))) return false;
115
119
  if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, "currencyCode"))) return false;
116
120
  if (!JSIConverter<std::vector<margelo::nitro::pay::PaymentItem>>::canConvert(runtime, obj.getProperty(runtime, "paymentItems"))) return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gmisoftware/react-native-pay",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "author": "gmi.software",
5
5
  "repository": {
6
6
  "type": "git",