react-native-payengine 2.0.17 → 2.0.18-alpha.2

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 (157) hide show
  1. package/README.md +96 -65
  2. package/android/.gradle/checksums/checksums.lock +0 -0
  3. package/android/.gradle/checksums/md5-checksums.bin +0 -0
  4. package/android/.gradle/checksums/sha1-checksums.bin +0 -0
  5. package/android/build.gradle +2 -2
  6. package/android/src/main/java/com/reactnativepayengine/v2/RNPayEngineNative.kt +65 -3
  7. package/android/src/main/java/com/reactnativepayengine/v2/securefields/RNPEEvents.kt +1 -0
  8. package/android/src/main/java/com/reactnativepayengine/v2/securefields/bankaccount/RNBankAccountViewManager.kt +16 -3
  9. package/android/src/main/java/com/reactnativepayengine/v2/securefields/creditcard/RNPECreditCardViewManager.kt +15 -4
  10. package/ios/PayEngineSDK.xcframework/Info.plist +5 -5
  11. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Headers/KDataCollector.h +4 -25
  12. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Headers/KountAnalyticsViewController.h +0 -20
  13. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Headers/KountPrivate.h +61 -0
  14. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Headers/PayEngineSDK-Swift.h +430 -149
  15. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Info.plist +0 -0
  16. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios.abi.json +1785 -5517
  17. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios.private.swiftinterface +35 -129
  18. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios.private.swiftinterface-e +35 -129
  19. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  20. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios.swiftinterface +35 -129
  21. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios.swiftinterface-e +35 -129
  22. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/PayEngineSDK +0 -0
  23. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/VGSCollectSDK_VGSCollectSDK.bundle/Assets.car +0 -0
  24. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/VGSCollectSDK_VGSCollectSDK.bundle/Info.plist +0 -0
  25. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Headers/KDataCollector.h +4 -25
  26. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Headers/KountAnalyticsViewController.h +0 -20
  27. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Headers/KountPrivate.h +61 -0
  28. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Headers/PayEngineSDK-Swift.h +860 -298
  29. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Info.plist +0 -0
  30. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios-simulator.abi.json +1785 -5517
  31. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +35 -129
  32. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface-e +35 -129
  33. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  34. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios-simulator.swiftinterface +35 -129
  35. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/arm64-apple-ios-simulator.swiftinterface-e +35 -129
  36. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/x86_64-apple-ios-simulator.abi.json +1785 -5517
  37. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +35 -129
  38. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface-e +35 -129
  39. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  40. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +35 -129
  41. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Modules/PayEngineSDK.swiftmodule/x86_64-apple-ios-simulator.swiftinterface-e +35 -129
  42. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/PayEngineSDK +0 -0
  43. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/VGSCollectSDK_VGSCollectSDK.bundle/Assets.car +0 -0
  44. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/VGSCollectSDK_VGSCollectSDK.bundle/Info.plist +0 -0
  45. package/ios/Sources/Classes/RNPEEventEmitter.swift +1 -1
  46. package/ios/Sources/Classes/RNPayEngineNative.swift +125 -64
  47. package/ios/Sources/Classes/SecureFields/RNPEEvents.swift +1 -0
  48. package/ios/Sources/Payengine.m +6 -0
  49. package/lib/commonjs/components/PayEngine.js +1 -1
  50. package/lib/commonjs/components/PayEngine.js.map +1 -1
  51. package/lib/commonjs/components/v2/ApplePay/PEApplePayButton.js +124 -0
  52. package/lib/commonjs/components/v2/ApplePay/PEApplePayButton.js.map +1 -1
  53. package/lib/commonjs/components/v2/ApplePay/PEApplePayInterfaces.js +78 -0
  54. package/lib/commonjs/components/v2/ApplePay/PEApplePayInterfaces.js.map +1 -1
  55. package/lib/commonjs/components/v2/GooglePay/PEGooglePayAddress.js.map +1 -1
  56. package/lib/commonjs/components/v2/GooglePay/PEGooglePayButton.js +53 -0
  57. package/lib/commonjs/components/v2/GooglePay/PEGooglePayButton.js.map +1 -1
  58. package/lib/commonjs/components/v2/PEPaymentRequest.js +121 -0
  59. package/lib/commonjs/components/v2/PEPaymentRequest.js.map +1 -1
  60. package/lib/commonjs/components/v2/PayEngineNative.js +182 -4
  61. package/lib/commonjs/components/v2/PayEngineNative.js.map +1 -1
  62. package/lib/commonjs/components/v2/PayEngineProvider.js +52 -0
  63. package/lib/commonjs/components/v2/PayEngineProvider.js.map +1 -1
  64. package/lib/commonjs/components/v2/SecureFields/BankAccountView.js +71 -0
  65. package/lib/commonjs/components/v2/SecureFields/BankAccountView.js.map +1 -1
  66. package/lib/commonjs/components/v2/SecureFields/CreditCardView.js +82 -0
  67. package/lib/commonjs/components/v2/SecureFields/CreditCardView.js.map +1 -1
  68. package/lib/commonjs/components/v2/SecureFields/IPEField.js.map +1 -1
  69. package/lib/commonjs/components/v2/SecureFields/ITokenizationData.js.map +1 -1
  70. package/lib/commonjs/components/v2/SecureFields/PEBankAccount.js.map +1 -1
  71. package/lib/commonjs/components/v2/SecureFields/PECard.js.map +1 -1
  72. package/lib/commonjs/components/v2/SecureFields/PEKeyboardType.js +20 -3
  73. package/lib/commonjs/components/v2/SecureFields/PEKeyboardType.js.map +1 -1
  74. package/lib/commonjs/index.js +17 -13
  75. package/lib/commonjs/index.js.map +1 -1
  76. package/lib/commonjs/interfaces/index.js +20 -0
  77. package/lib/commonjs/interfaces/index.js.map +1 -1
  78. package/lib/commonjs/utils/index.js +26 -0
  79. package/lib/commonjs/utils/index.js.map +1 -1
  80. package/lib/module/components/PayEngine.js +1 -1
  81. package/lib/module/components/PayEngine.js.map +1 -1
  82. package/lib/module/components/v2/ApplePay/PEApplePayButton.js +124 -0
  83. package/lib/module/components/v2/ApplePay/PEApplePayButton.js.map +1 -1
  84. package/lib/module/components/v2/ApplePay/PEApplePayInterfaces.js +75 -0
  85. package/lib/module/components/v2/ApplePay/PEApplePayInterfaces.js.map +1 -1
  86. package/lib/module/components/v2/GooglePay/PEGooglePayAddress.js.map +1 -1
  87. package/lib/module/components/v2/GooglePay/PEGooglePayButton.js +53 -0
  88. package/lib/module/components/v2/GooglePay/PEGooglePayButton.js.map +1 -1
  89. package/lib/module/components/v2/PEPaymentRequest.js +119 -0
  90. package/lib/module/components/v2/PEPaymentRequest.js.map +1 -1
  91. package/lib/module/components/v2/PayEngineNative.js +184 -5
  92. package/lib/module/components/v2/PayEngineNative.js.map +1 -1
  93. package/lib/module/components/v2/PayEngineProvider.js +51 -0
  94. package/lib/module/components/v2/PayEngineProvider.js.map +1 -1
  95. package/lib/module/components/v2/SecureFields/BankAccountView.js +71 -0
  96. package/lib/module/components/v2/SecureFields/BankAccountView.js.map +1 -1
  97. package/lib/module/components/v2/SecureFields/CreditCardView.js +82 -0
  98. package/lib/module/components/v2/SecureFields/CreditCardView.js.map +1 -1
  99. package/lib/module/components/v2/SecureFields/IPEField.js.map +1 -1
  100. package/lib/module/components/v2/SecureFields/ITokenizationData.js.map +1 -1
  101. package/lib/module/components/v2/SecureFields/PEBankAccount.js.map +1 -1
  102. package/lib/module/components/v2/SecureFields/PECard.js.map +1 -1
  103. package/lib/module/components/v2/SecureFields/PEKeyboardType.js +16 -1
  104. package/lib/module/components/v2/SecureFields/PEKeyboardType.js.map +1 -1
  105. package/lib/module/index.js +10 -5
  106. package/lib/module/index.js.map +1 -1
  107. package/lib/module/interfaces/index.js +19 -0
  108. package/lib/module/interfaces/index.js.map +1 -1
  109. package/lib/module/utils/index.js +27 -0
  110. package/lib/module/utils/index.js.map +1 -1
  111. package/lib/typescript/components/PayEngine.d.ts +1 -1
  112. package/lib/typescript/components/v2/ApplePay/PEApplePayButton.d.ts +217 -12
  113. package/lib/typescript/components/v2/ApplePay/PEApplePayInterfaces.d.ts +180 -1
  114. package/lib/typescript/components/v2/GooglePay/PEGooglePayAddress.d.ts +30 -0
  115. package/lib/typescript/components/v2/GooglePay/PEGooglePayButton.d.ts +99 -0
  116. package/lib/typescript/components/v2/PEPaymentRequest.d.ts +130 -9
  117. package/lib/typescript/components/v2/PayEngineNative.d.ts +165 -7
  118. package/lib/typescript/components/v2/PayEngineProvider.d.ts +51 -0
  119. package/lib/typescript/components/v2/SecureFields/BankAccountView.d.ts +103 -0
  120. package/lib/typescript/components/v2/SecureFields/CreditCardView.d.ts +114 -0
  121. package/lib/typescript/components/v2/SecureFields/IPEField.d.ts +49 -0
  122. package/lib/typescript/components/v2/SecureFields/ITokenizationData.d.ts +14 -0
  123. package/lib/typescript/components/v2/SecureFields/PEBankAccount.d.ts +36 -0
  124. package/lib/typescript/components/v2/SecureFields/PECard.d.ts +44 -0
  125. package/lib/typescript/components/v2/SecureFields/PEKeyboardType.d.ts +16 -1
  126. package/lib/typescript/index.d.ts +11 -5
  127. package/lib/typescript/interfaces/index.d.ts +35 -1
  128. package/lib/typescript/utils/index.d.ts +21 -0
  129. package/package.json +6 -3
  130. package/src/components/PayEngine.tsx +1 -1
  131. package/src/components/v2/ApplePay/PEApplePayButton.tsx +225 -12
  132. package/src/components/v2/ApplePay/PEApplePayInterfaces.ts +221 -8
  133. package/src/components/v2/GooglePay/PEGooglePayAddress.ts +39 -1
  134. package/src/components/v2/GooglePay/PEGooglePayButton.tsx +113 -9
  135. package/src/components/v2/PEPaymentRequest.ts +151 -13
  136. package/src/components/v2/PayEngineNative.tsx +196 -9
  137. package/src/components/v2/PayEngineProvider.tsx +52 -1
  138. package/src/components/v2/SecureFields/BankAccountView.tsx +108 -1
  139. package/src/components/v2/SecureFields/CreditCardView.tsx +118 -1
  140. package/src/components/v2/SecureFields/IPEField.ts +55 -0
  141. package/src/components/v2/SecureFields/ITokenizationData.ts +17 -2
  142. package/src/components/v2/SecureFields/PEBankAccount.ts +42 -0
  143. package/src/components/v2/SecureFields/PECard.ts +52 -0
  144. package/src/components/v2/SecureFields/PEKeyboardType.ts +18 -1
  145. package/src/index.tsx +23 -5
  146. package/src/interfaces/index.ts +40 -2
  147. package/src/utils/index.ts +21 -0
  148. package/android/.gradle/6.1.1/executionHistory/executionHistory.lock +0 -0
  149. package/android/.gradle/6.1.1/fileChanges/last-build.bin +0 -0
  150. package/android/.gradle/6.1.1/fileHashes/fileHashes.lock +0 -0
  151. package/android/.gradle/6.1.1/gc.properties +0 -0
  152. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Headers/CustomWindow.h +0 -25
  153. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Headers/UIControl+CustomControl.h +0 -33
  154. package/ios/PayEngineSDK.xcframework/ios-arm64/PayEngineSDK.framework/Headers/UIViewController+TouchControl.h +0 -27
  155. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Headers/CustomWindow.h +0 -25
  156. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Headers/UIControl+CustomControl.h +0 -33
  157. package/ios/PayEngineSDK.xcframework/ios-arm64_x86_64-simulator/PayEngineSDK.framework/Headers/UIViewController+TouchControl.h +0 -27
@@ -1,23 +1,96 @@
1
- import { NativeModules, Platform } from "react-native";
1
+ import { NativeEventEmitter, NativeModules, Platform } from "react-native";
2
2
  import { PayProvider } from "../../interfaces";
3
3
 
4
- const { RNPayEngineNative } = NativeModules;
4
+ const { RNPayEngineNative, RNPEEventEmitter } = NativeModules;
5
5
 
6
+ /**
7
+ * Represents an access token used for authenticating with the PayEngine SDK.
8
+ *
9
+ * @remarks
10
+ * The access token contains the actual token string and the duration (in seconds)
11
+ * for which the token remains valid. This is typically retrieved from your backend
12
+ * and used for making authenticated requests.
13
+ *
14
+ * @property accessToken - The access token string.
15
+ * @property expiresIn - The time (in seconds) until the token expires.
16
+ *
17
+ * @category PayEngine
18
+ */
19
+ export type AccessToken = {
20
+ accessToken: string;
21
+ expiresIn: number;
22
+ };
23
+
24
+ /**
25
+ * A callback function that provides an access token to the PayEngine SDK.
26
+ *
27
+ * @returns A promise resolving to a valid {@link AccessToken}.
28
+ *
29
+ * @category PayEngine
30
+ */
31
+ export type FetchAccessTokenCallback = () => Promise<AccessToken>;
32
+
33
+ /**
34
+ * Provides an interface for interacting with the native PayEngine SDK.
35
+ *
36
+ * @remarks
37
+ * `PayEngineNative` acts as a bridge between your React Native JavaScript code and
38
+ * the native PayEngine SDKs on iOS and Android. It utilizes React Native's
39
+ * Native Modules and platform channels to enable core payment functionalities.
40
+ *
41
+ * These include:
42
+ * - Fraud monitoring
43
+ * - Browser/device info retrieval
44
+ * - Support detection for Apple Pay and Google Pay
45
+ *
46
+ *
47
+ * @category PayEngine
48
+ */
6
49
  export default class PayEngineNative {
7
- static async createFraudMonitorSession(merchantId: string) {
50
+ private static emitter = new NativeEventEmitter(RNPEEventEmitter);
51
+
52
+ private static isFetchCallbackListenerRegistered = false;
53
+
54
+ private static fetchAccessTokenCallback: FetchAccessTokenCallback | null = null;
55
+
56
+
57
+ private constructor() { }
58
+
59
+ /**
60
+ * Retrieves a fraud monitoring session ID from the native PayEngine SDK.
61
+ *
62
+ *
63
+ * @param merchantId - The unique identifier for the merchant.
64
+ * @returns A `Promise<string>` containing the fraud monitoring session ID.
65
+ */
66
+ static async createFraudMonitorSession(merchantId: string): Promise<string> {
8
67
  return RNPayEngineNative.createFraudMonitorSession(merchantId);
9
68
  }
10
69
 
11
- static async getBrowserInfo() {
70
+ /**
71
+ * Retrieves browser-related information from the native PayEngine SDK.
72
+ *
73
+ * @returns A `Promise<string>` containing browser and device details.
74
+ *
75
+ */
76
+ static async getBrowserInfo(): Promise<string> {
12
77
  return RNPayEngineNative.getBrowserInfo();
13
78
  }
14
79
 
15
80
  /**
16
- * @deprecated use userCanPay instead
17
- * @param merchantId
18
- * @returns
81
+ * @deprecated Use {@link PayEngineNative.userCanPay} instead.
82
+ *
83
+ * Checks if platform-native payments (Apple Pay or Google Pay) are supported on the current device.
84
+ *
85
+ * @remarks
86
+ * This method has been deprecated in favor of {@link PayEngineNative.userCanPay}, which allows specifying
87
+ * the payment provider explicitly.
88
+ *
89
+ * @param merchantId - The unique identifier for the merchant.
90
+ * @returns A `Promise<boolean>` indicating whether the platform-specific payment method is supported.
91
+ *
19
92
  */
20
- static async isPlatformPaySupported(merchantId: string) {
93
+ static async isPlatformPaySupported(merchantId: string): Promise<boolean> {
21
94
  if (Platform.OS === 'ios') {
22
95
  return await RNPayEngineNative.isApplePaySupported(merchantId);
23
96
  } else if (Platform.OS === 'android') {
@@ -26,7 +99,22 @@ export default class PayEngineNative {
26
99
  return false;
27
100
  }
28
101
 
29
- static async userCanPay(provider: PayProvider, merchantId: string) {
102
+ /**
103
+ * Checks if the user can make payments using Apple Pay (iOS) or Google Pay (Android).
104
+ *
105
+ * @remarks
106
+ * This method verifies whether the current device and platform support the selected payment provider.
107
+ * It performs a platform-specific check using the native PayEngine SDK for either Apple Pay or Google Pay.
108
+ *
109
+ * ## Supported Providers
110
+ * - `PayProvider.googlePay` (Android only)
111
+ * - `PayProvider.applePay` (iOS only)
112
+ *
113
+ * @param provider - The payment provider to check support for.
114
+ * @param merchantId - The unique identifier for the merchant.
115
+ * @returns A `Promise<boolean>` indicating whether the selected payment method is supported.
116
+ */
117
+ static async userCanPay(provider: PayProvider, merchantId: string): Promise<boolean> {
30
118
  if (provider == PayProvider.applePay && Platform.OS == 'ios') {
31
119
  return await RNPayEngineNative.isApplePaySupported(merchantId);
32
120
  } else if (provider === PayProvider.googlePay && Platform.OS === 'android') {
@@ -34,4 +122,103 @@ export default class PayEngineNative {
34
122
  }
35
123
  return false;
36
124
  }
125
+
126
+
127
+ /**
128
+ * Sets the callback function that provides an access token when required by PayEngine.
129
+ *
130
+ * @remarks
131
+ * When the PayEngine SDK needs an access token, it will call this callback function
132
+ * to request the host application to fetch a new token from its backend.
133
+ *
134
+ * The SDK uses this token internally to make calls to merchant related APIs which require merchant's credentials.
135
+ *
136
+ * ## Important:
137
+ * - PayEngine will invoke this callback **whenever an access token is needed or needs to be refreshed**.
138
+ * - The integrator must ensure that the token retrieval logic is secure and efficient in their backend.
139
+ * - For more details on how to retrieve the access token from Payengine, refer to the official documentation:
140
+ * [PayEngine Merchant Session](https://docs.payengine.co/merchant-session#obtaining-a-new-merchant-session)
141
+ *
142
+ * ## Example Usage
143
+ * ```ts
144
+ * const fetchAccessToken = async (): Promise<AccessToken> => {
145
+ * try {
146
+ * // Make a network request to your server to fetch the token
147
+ * // Your server then makes a request to Payengine securely and returns the results back in response
148
+ * const response = await fetch("https://yourserver.com/accessToken");
149
+ *
150
+ * if (!response.ok) {
151
+ * throw new Error(`Server responded with status ${response.status}`);
152
+ * }
153
+ *
154
+ * const data = await response.json();
155
+ *
156
+ * // Extract the token and expiration from your server's response
157
+ * const token = data.access_token;
158
+ * const expiresIn = data.expires_in;
159
+ *
160
+ * return { accessToken: token, expiresIn };
161
+ * } catch (e) {
162
+ * throw new Error("Failed to fetch access token: " + e);
163
+ * }
164
+ * };
165
+ *
166
+ * // This is where you supply the callback to the SDK
167
+ * PayEngineNative.setFetchAccessTokenCallback(fetchAccessToken);
168
+ * ```
169
+ *
170
+ * @param callback - A function that returns a `Promise<AccessToken>`. The function must handle
171
+ * errors properly in case token retrieval fails.
172
+ */
173
+ static async setFetchAccessTokenCallback(callback: FetchAccessTokenCallback) {
174
+ PayEngineNative.fetchAccessTokenCallback = callback;
175
+
176
+ if (!PayEngineNative.isFetchCallbackListenerRegistered) {
177
+ PayEngineNative.emitter.addListener("fetchAccessToken", async () => {
178
+ try {
179
+ const result = await PayEngineNative.fetchAccessTokenCallback!();
180
+ RNPayEngineNative.provideFetchAccessTokenResult(result);
181
+ } catch (error) {
182
+ RNPayEngineNative.provideFetchAccessTokenResult(null);
183
+ }
184
+ });
185
+ PayEngineNative.isFetchCallbackListenerRegistered = true;
186
+ }
187
+
188
+
189
+ RNPayEngineNative.configureFetchAccessTokenCallback();
190
+ }
191
+
192
+ /**
193
+ * Logs out the current merchant by invalidating the access token.
194
+ *
195
+ * @remarks
196
+ * While access tokens automatically expire, it's **strongly recommended** to explicitly invalidate
197
+ * them when a merchant's session ends on the server.
198
+ *
199
+ * Relying solely on token expiration can introduce **security vulnerabilities**
200
+ * and result in a **suboptimal user experience**.
201
+ *
202
+ * Calling this method ensures that the merchant's session is terminated,
203
+ * preventing any further authenticated requests until a new login is performed.
204
+ *
205
+ * For more details, refer to the official documentation:
206
+ * [PayEngine Merchant Session](https://docs.payengine.co/merchant-session)
207
+ *
208
+ * ## Example Usage
209
+ * ```ts
210
+ * const merchantId = "your_merchant_id_here";
211
+ * await PayEngineNative.logout(merchantId);
212
+ * console.log("Merchant session terminated.");
213
+ * ```
214
+ *
215
+ * This ensures that no further authenticated requests can be made
216
+ * until a new access token is fetched.
217
+ *
218
+ * @param merchantId - The unique identifier of the merchant whose session should be invalidated.
219
+ * @returns A `Promise` indicating the completion of the logout process.
220
+ */
221
+ static async logout(merchantId: string): Promise<void> {
222
+ return RNPayEngineNative.logout(merchantId);
223
+ }
37
224
  }
@@ -6,6 +6,57 @@ const { RNPayEngineNative } = NativeModules;
6
6
 
7
7
  const PayEngineContext = createContext<IPayEngineConfig | undefined>(undefined);
8
8
 
9
+ /**
10
+ * A provider that initializes and manages PayEngine's configuration across the app.
11
+ *
12
+ * `PayEngineProvider` ensures that PayEngine's SDK is properly set up by loading
13
+ * the necessary configurations before rendering the app. It must wrap the root widget
14
+ * for the payment functionalities to work correctly.
15
+ *
16
+ * ## Usage
17
+ *
18
+ * Before using PayEngine in your application, wrap your app inside [PayEngineProvider]
19
+ * and pass an `IPayEngineConfig` instance containing your public key, script URL, and optional log level.
20
+ *
21
+ * ```tsx
22
+ * const PE_CONFIG: IPayEngineConfig = {
23
+ * publicKey: PUBLIC_KEY,
24
+ * scriptURL: "https://staging-sandbox.payengine.dev/",
25
+ * logLevel: 1,
26
+ * };
27
+ *
28
+ * return (
29
+ * <PayEngineProvider config={PE_CONFIG}>
30
+ * <NavigationContainer>
31
+ * <DrawerNavigator />
32
+ * </NavigationContainer>
33
+ * </PayEngineProvider>
34
+ * );
35
+ * ```
36
+ *
37
+ * ## How It Works
38
+ *
39
+ * 1. The `PayEngineProvider` component accepts a configuration object (`IPayEngineConfig`) containing
40
+ * the `publicKey`, `scriptURL`, and `logLevel`.
41
+ * 2. It initializes the PayEngine SDK with the `publicKey`
42
+ * and `scriptURL` from the configuration.
43
+ * 3. The provider uses the `React.useEffect` hook to ensure that the configuration is set up
44
+ * before rendering the children.
45
+ * 4. While loading the configuration, an `ActivityIndicator` is displayed. Once the SDK is set up,
46
+ * it renders the provided child components.
47
+ *
48
+ * ## Properties:
49
+ *
50
+ * - **`config`**: The configuration required for PayEngine (type: `IPayEngineConfig`).
51
+ * - `publicKey`: The public key for authentication.
52
+ * - `scriptURL`: The URL for the PayEngine script.
53
+ * - `logLevel`: The log level for debugging (optional).
54
+ *
55
+ * - **`children`**: The child components or widgets to be rendered after PayEngine is initialized.
56
+ *
57
+ *
58
+ * @category SecureFields
59
+ */
9
60
  const PayEngineProvider = ({ config, children }: { config: IPayEngineConfig, children: React.ReactNode }) => {
10
61
  const [loading, setLoading] = React.useState(true);
11
62
 
@@ -22,7 +73,7 @@ const PayEngineProvider = ({ config, children }: { config: IPayEngineConfig, chi
22
73
  return <PayEngineContext.Provider value={config}>
23
74
  {loading ? <ActivityIndicator /> : children}
24
75
  </PayEngineContext.Provider>
25
- }
76
+ };
26
77
 
27
78
  export {
28
79
  PayEngineContext,
@@ -1,6 +1,6 @@
1
1
 
2
2
  import * as React from 'react';
3
- import { requireNativeComponent, NativeModules, NativeEventEmitter, ViewProps, findNodeHandle, UIManager, ActivityIndicator, Platform } from 'react-native';
3
+ import { requireNativeComponent, NativeModules, NativeEventEmitter, type ViewProps, findNodeHandle, UIManager, ActivityIndicator, Platform } from 'react-native';
4
4
  import type IPEField from './IPEField';
5
5
  import type PEBankAccount from './PEBankAccount';
6
6
  import type ITokenizationData from './ITokenizationData';
@@ -18,16 +18,123 @@ const RNPEBankAccountViewManager = UIManager[COMPONENT_NAME]
18
18
 
19
19
  const peEventEmitter = new NativeEventEmitter(RNPEEventEmitter);
20
20
 
21
+ /**
22
+ * Props for the `PEBankAccountView` component.
23
+ *
24
+ * Allows optional configuration of additional input fields that can be rendered
25
+ * alongside the standard bank account fields.
26
+ *
27
+ * These fields can be used to collect extra information such as account holder type,
28
+ * billing address, or custom metadata required by the merchant.
29
+ *
30
+ * @category SecureFields
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const fields: IPEField[] = [
35
+ * {
36
+ * name: "accountHolderType",
37
+ * type: "text",
38
+ * placeholder: "Account Holder Type",
39
+ * keyboardType: PEKeyboardType.Alphabet,
40
+ * isRequired: false
41
+ * }
42
+ * ];
43
+ *
44
+ * <PEBankAccountView additionalFields={fields} />
45
+ * ```
46
+ */
21
47
  export interface PEBankAccountViewProps {
48
+ /**
49
+ * (Optional) A list of additional fields to be displayed in the bank account form.
50
+ *
51
+ * These are rendered below the standard account number and routing number fields.
52
+ */
22
53
  additionalFields?: IPEField[];
23
54
  }
24
55
 
56
+
57
+ /**
58
+ * Provides methods to control and interact with the PayEngine Bank Account input view.
59
+ *
60
+ * This interface defines methods for submitting bank account details for tokenization
61
+ * and managing keyboard visibility.
62
+ *
63
+ * @category SecureFields
64
+ */
25
65
  export interface PEBankAccountViewMethods {
66
+ /**
67
+ * Submits the entered bank account information to PayEngine for tokenization.
68
+ *
69
+ * @param data - Optional merchant info and additional metadata.
70
+ * @returns A promise that resolves to a tokenized bank account object (`PEBankAccount`).
71
+ *
72
+ * @example
73
+ * ```ts
74
+ * const result = await bankAccountRef.current?.submit({
75
+ * merchantId: "merchant_456",
76
+ * additionalData: { accountType: "checking" }
77
+ * });
78
+ * ```
79
+ */
26
80
  submit: (data: ITokenizationData) => Promise<PEBankAccount>;
81
+
82
+ /**
83
+ * Programmatically displays the keyboard for the bank account input fields.
84
+ */
27
85
  showKeyboard: () => void;
86
+
87
+ /**
88
+ * Programmatically hides the keyboard for the bank account input fields.
89
+ */
28
90
  hideKeyboard: () => void;
29
91
  }
30
92
 
93
+
94
+ /**
95
+ * A secure form widget for entering a customer's bank account information.
96
+ *
97
+ * [PEBankAccountView] provides a UI component for securely collecting bank account details.
98
+ * It does not store data locally and instead tokenizes the information using PayEngine.
99
+ *
100
+ * ## Features:
101
+ * - Securely collects bank account details.
102
+ * - Supports additional customizable fields.
103
+ * - Provides methods to show/hide the keyboard.
104
+ * - Allows tokenizing the entered data for safe storage.
105
+ *
106
+ * ## Usage Example:
107
+ *
108
+ * ```tsx
109
+ * const formRef = React.createRef<PEBankAccountViewMethods>();
110
+ *
111
+ * return (
112
+ * <View style={styles.container}>
113
+ * <Text>Welcome to PayEngine React Native SDK example</Text>
114
+ * <View style={{ width: '100%' }}>
115
+ * <PEBankAccountView ref={formRef} />
116
+ * <Button disabled={submitting} onPress={() => createBankAccount()} title="Create Bank Account" />
117
+ * </View>
118
+ * <ScrollView style={{ flex: 1, width: '100%', backgroundColor: 'lightyellow', padding: 10, marginVertical: 20 }}>
119
+ * <Text>{JSON.stringify(secureFieldsResult, null, 4)}</Text>
120
+ * </ScrollView>
121
+ * </View>
122
+ * );
123
+ * ```
124
+ *
125
+ * ## How It Works:
126
+ * 1. Create an instance of [PEBankAccountView], optionally passing additional fields.
127
+ * 2. Display the form inside your widget tree.
128
+ * 3. Use [showKeyboard] and [hideKeyboard] to manage input focus.
129
+ * 4. Call [submit] to securely send the bank account data and receive a token.
130
+ *
131
+ * ## Methods:
132
+ * - **`showKeyboard()`**: Manually shows the on-screen keyboard.
133
+ * - **`hideKeyboard()`**: Hides the on-screen keyboard.
134
+ * - **`submit()`**: Submits the entered data and retrieves a tokenized version of the bank account data.
135
+ *
136
+ * @category SecureFields
137
+ */
31
138
  export const PEBankAccountView = React.forwardRef<
32
139
  PEBankAccountViewMethods,
33
140
  PEBankAccountViewProps
@@ -1,6 +1,6 @@
1
1
 
2
2
  import * as React from 'react';
3
- import { requireNativeComponent, NativeModules, NativeEventEmitter, ViewProps, Platform, findNodeHandle, UIManager, ActivityIndicator } from 'react-native';
3
+ import { requireNativeComponent, NativeModules, NativeEventEmitter, type ViewProps, Platform, findNodeHandle, UIManager, ActivityIndicator } from 'react-native';
4
4
  import type IPEField from './IPEField';
5
5
  import type PECard from './PECard';
6
6
  import type ITokenizationData from './ITokenizationData';
@@ -17,16 +17,133 @@ const RNPECreditCardView = requireNativeComponent<NativePECreditCardViewProps>(C
17
17
  const RNPECreditCardViewManager = UIManager[COMPONENT_NAME]
18
18
  const peEventEmitter = new NativeEventEmitter(RNPEEventEmitter);
19
19
 
20
+ /**
21
+ * Props for the `PECreditCardView` component.
22
+ *
23
+ * Allows optional configuration of additional input fields that can be rendered
24
+ * alongside the standard credit card fields.
25
+ *
26
+ * These fields can be used to collect extra information such as ZIP code, billing address,
27
+ * or custom metadata required by the merchant.
28
+ *
29
+ * @category SecureFields
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * const fields: IPEField[] = [
34
+ * {
35
+ * name: "zipCode",
36
+ * type: "text",
37
+ * placeholder: "ZIP Code",
38
+ * keyboardType: PEKeyboardType.Numeric,
39
+ * isRequired: true
40
+ * }
41
+ * ];
42
+ *
43
+ * <PECreditCardView additionalFields={fields} />
44
+ * ```
45
+ */
20
46
  export interface PECreditCardViewProps {
47
+ /**
48
+ * (Optional) A list of additional fields to be displayed in the credit card form.
49
+ *
50
+ * These are rendered below the standard card number, expiry, and CVV fields.
51
+ */
21
52
  additionalFields?: IPEField[];
22
53
  }
23
54
 
55
+
56
+ /**
57
+ * Provides methods to control and interact with the PayEngine Credit Card input view.
58
+ *
59
+ * This interface defines methods for submitting credit card details for tokenization
60
+ * and managing keyboard visibility.
61
+ *
62
+ * @category SecureFields
63
+ */
24
64
  export interface PECreditCardViewMethods {
65
+ /**
66
+ * Submits the entered credit card information to PayEngine for tokenization.
67
+ *
68
+ * @param data - Optional merchant info and additional metadata.
69
+ * @returns A promise that resolves to a tokenized credit card object (`PECard`).
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * const result = await creditCardRef.current?.submit({
74
+ * merchantId: "merchant_123",
75
+ * additionalData: { source: "checkout" }
76
+ * });
77
+ * ```
78
+ */
25
79
  submit: (data: ITokenizationData) => Promise<PECard>;
80
+
81
+ /**
82
+ * Programmatically displays the keyboard for the credit card input fields.
83
+ */
26
84
  showKeyboard: () => void;
85
+
86
+ /**
87
+ * Programmatically hides the keyboard for the credit card input fields.
88
+ */
27
89
  hideKeyboard: () => void;
28
90
  }
29
91
 
92
+ /**
93
+ * A secure form for entering a customer's credit card information safely.
94
+ *
95
+ * [PECreditCardView] provides an interface for users to input their credit card details securely.
96
+ * It integrates with PayEngine to tokenize the card details and forward them to a PCI-compliant
97
+ * third party without storing sensitive information locally.
98
+ *
99
+ * ## How It Works
100
+ *
101
+ * 1. Create an instance of [PECreditCardView], optionally passing additional fields.
102
+ * 2. Display the form inside your UI.
103
+ * 3. Once the user enters their details, call [submit] to securely process and retrieve a tokenized version of the card.
104
+ * 4. Use [showKeyboard] and [hideKeyboard] to manually control the keyboard.
105
+ *
106
+ * ## Example Usage
107
+ *
108
+ * ```tsx
109
+ * const formRef = React.createRef<PECreditCardViewMethods>();
110
+ *
111
+ *
112
+ * const additionalFields = [
113
+ * {
114
+ * name: 'address_zip',
115
+ * type: 'text',
116
+ * placeholder: 'Zip code',
117
+ * keyboardType: PEKeyboardType.alphabet,
118
+ * isRequired: true,
119
+ * pattern: '^(?:\\d{5}(?:-\\d{4})?|[ABCEGHJKLMNPRSTVXY]\\d[A-Z] ?\\d[A-Z]\\d)$'
120
+ * }
121
+ * ]
122
+ *
123
+ * return (
124
+ * <View style={styles.container}>
125
+ * <Text>Welcome to PayEngine React Native SDK example</Text>
126
+ * <View style={{ width: '100%' }}>
127
+ * <PECreditCardView ref={formRef} additionalFields={additionalFields} />
128
+ * <Button disabled={submitting} onPress={() => createCard()} title="Create Card" />
129
+ * <Button onPress={() => formRef.current?.showKeyboard()} title="Show keyboard" />
130
+ * <Button onPress={() => formRef.current?.hideKeyboard()} title="Hide keyboard" />
131
+ * </View>
132
+ * <ScrollView style={{ flex: 1, width: '100%', backgroundColor: 'lightyellow', padding: 10, marginVertical: 20 }}>
133
+ * <Text>{JSON.stringify(secureFieldsResult, null, 4)}</Text>
134
+ * </ScrollView>
135
+ * </View>
136
+ * );
137
+ * ```
138
+ *
139
+ * ## Features:
140
+ * - Securely collects credit card details.
141
+ * - Supports additional customizable fields.
142
+ * - Provides methods to show/hide the keyboard.
143
+ * - Allows submitting the entered data for tokenization and safe storage.
144
+ *
145
+ * @category SecureFields
146
+ */
30
147
  export const PECreditCardView = React.forwardRef<
31
148
  PECreditCardViewMethods,
32
149
  PECreditCardViewProps
@@ -1,12 +1,67 @@
1
1
  import type PEKeyboardType from "./PEKeyboardType";
2
2
 
3
+ /**
4
+ * Represents an input field in the PayEngine system.
5
+ *
6
+ * The `IPEField` interface defines a form field with properties such as
7
+ * its name, type, placeholder, keyboard type, whether it is required, and
8
+ * an optional validation pattern.
9
+ *
10
+ * @category SecureFields
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const emailField: IPEField = {
15
+ * name: "email",
16
+ * type: "text",
17
+ * placeholder: "Enter your email",
18
+ * keyboardType: PEKeyboardType.Alphabet,
19
+ * isRequired: true,
20
+ * pattern: "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"
21
+ * };
22
+ * ```
23
+ */
3
24
  interface IPEField {
25
+ /**
26
+ * The unique identifier for the field.
27
+ *
28
+ * Typically used as the key when submitting form data.
29
+ */
4
30
  name: string;
31
+
32
+ /**
33
+ * The type of the field (e.g., "text", "password", "email").
34
+ *
35
+ * Defines how the field’s value should be interpreted.
36
+ */
5
37
  type: string;
38
+
39
+ /**
40
+ * The placeholder text shown when the field is empty.
41
+ */
6
42
  placeholder: string;
43
+
44
+ /**
45
+ * Specifies the type of keyboard to display for this field.
46
+ *
47
+ * Example: `PEKeyboardType.Numeric`, `PEKeyboardType.Alphabet`
48
+ */
7
49
  keyboardType: PEKeyboardType;
50
+
51
+ /**
52
+ * Indicates whether the field is required for form submission.
53
+ *
54
+ * If `true`, the field must be filled in with a valid value.
55
+ */
8
56
  isRequired: boolean;
57
+
58
+ /**
59
+ * Optional regular expression used to validate the field's value.
60
+ *
61
+ * If omitted, no validation is enforced.
62
+ */
9
63
  pattern?: string;
10
64
  }
11
65
 
66
+
12
67
  export default IPEField;
@@ -1,7 +1,22 @@
1
+ /**
2
+ * Represents the data used for tokenizing a credit card or bank account.
3
+ *
4
+ * This interface allows passing additional metadata or specifying the merchant
5
+ * for whom the data is being tokenized.
6
+ *
7
+ * @category SecureFields
8
+ */
1
9
  interface ITokenizationData {
10
+ /**
11
+ * (Optional) The merchant ID on behalf of whom the tokenization is performed.
12
+ */
2
13
  merchantId?: string;
3
- additionalData?: {
4
- [key: string]: string
14
+
15
+ /**
16
+ * (Optional) A key-value map of additional metadata to include in the request.
17
+ */
18
+ additionalData?: {
19
+ [key: string]: string;
5
20
  };
6
21
  }
7
22