@yuno-payments/yuno-sdk-react-native 1.0.16

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 (92) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +621 -0
  3. package/android/build.gradle +131 -0
  4. package/android/gradle.properties +5 -0
  5. package/android/src/main/AndroidManifest.xml +4 -0
  6. package/android/src/main/java/com/yunosdkreactnative/YunoPaymentMethodsViewManager.kt +194 -0
  7. package/android/src/main/java/com/yunosdkreactnative/YunoSdkModule.kt +777 -0
  8. package/android/src/main/java/com/yunosdkreactnative/YunoSdkPackage.kt +24 -0
  9. package/ios/YunoSdk.m +65 -0
  10. package/ios/YunoSdk.podspec +48 -0
  11. package/ios/YunoSdk.swift +442 -0
  12. package/lib/commonjs/YunoPaymentMethods.js +145 -0
  13. package/lib/commonjs/YunoPaymentMethods.js.map +1 -0
  14. package/lib/commonjs/YunoSdk.js +455 -0
  15. package/lib/commonjs/YunoSdk.js.map +1 -0
  16. package/lib/commonjs/core/enums/CardFlow.js +26 -0
  17. package/lib/commonjs/core/enums/CardFlow.js.map +1 -0
  18. package/lib/commonjs/core/enums/YunoLanguage.js +58 -0
  19. package/lib/commonjs/core/enums/YunoLanguage.js.map +1 -0
  20. package/lib/commonjs/core/enums/YunoStatus.js +40 -0
  21. package/lib/commonjs/core/enums/YunoStatus.js.map +1 -0
  22. package/lib/commonjs/core/enums/index.js +27 -0
  23. package/lib/commonjs/core/enums/index.js.map +1 -0
  24. package/lib/commonjs/core/index.js +28 -0
  25. package/lib/commonjs/core/index.js.map +1 -0
  26. package/lib/commonjs/core/types/AndroidConfig.js +2 -0
  27. package/lib/commonjs/core/types/AndroidConfig.js.map +1 -0
  28. package/lib/commonjs/core/types/EnrollmentArguments.js +2 -0
  29. package/lib/commonjs/core/types/EnrollmentArguments.js.map +1 -0
  30. package/lib/commonjs/core/types/IosConfig.js +2 -0
  31. package/lib/commonjs/core/types/IosConfig.js.map +1 -0
  32. package/lib/commonjs/core/types/OneTimeTokenInfo.js +2 -0
  33. package/lib/commonjs/core/types/OneTimeTokenInfo.js.map +1 -0
  34. package/lib/commonjs/core/types/SeamlessArguments.js +6 -0
  35. package/lib/commonjs/core/types/SeamlessArguments.js.map +1 -0
  36. package/lib/commonjs/core/types/StartPayment.js +2 -0
  37. package/lib/commonjs/core/types/StartPayment.js.map +1 -0
  38. package/lib/commonjs/core/types/YunoConfig.js +6 -0
  39. package/lib/commonjs/core/types/YunoConfig.js.map +1 -0
  40. package/lib/commonjs/core/types/index.js +2 -0
  41. package/lib/commonjs/core/types/index.js.map +1 -0
  42. package/lib/commonjs/index.js +36 -0
  43. package/lib/commonjs/index.js.map +1 -0
  44. package/lib/module/YunoPaymentMethods.js +138 -0
  45. package/lib/module/YunoPaymentMethods.js.map +1 -0
  46. package/lib/module/YunoSdk.js +448 -0
  47. package/lib/module/YunoSdk.js.map +1 -0
  48. package/lib/module/core/enums/CardFlow.js +20 -0
  49. package/lib/module/core/enums/CardFlow.js.map +1 -0
  50. package/lib/module/core/enums/YunoLanguage.js +52 -0
  51. package/lib/module/core/enums/YunoLanguage.js.map +1 -0
  52. package/lib/module/core/enums/YunoStatus.js +34 -0
  53. package/lib/module/core/enums/YunoStatus.js.map +1 -0
  54. package/lib/module/core/enums/index.js +4 -0
  55. package/lib/module/core/enums/index.js.map +1 -0
  56. package/lib/module/core/index.js +3 -0
  57. package/lib/module/core/index.js.map +1 -0
  58. package/lib/module/core/types/AndroidConfig.js +2 -0
  59. package/lib/module/core/types/AndroidConfig.js.map +1 -0
  60. package/lib/module/core/types/EnrollmentArguments.js +2 -0
  61. package/lib/module/core/types/EnrollmentArguments.js.map +1 -0
  62. package/lib/module/core/types/IosConfig.js +2 -0
  63. package/lib/module/core/types/IosConfig.js.map +1 -0
  64. package/lib/module/core/types/OneTimeTokenInfo.js +2 -0
  65. package/lib/module/core/types/OneTimeTokenInfo.js.map +1 -0
  66. package/lib/module/core/types/SeamlessArguments.js +2 -0
  67. package/lib/module/core/types/SeamlessArguments.js.map +1 -0
  68. package/lib/module/core/types/StartPayment.js +2 -0
  69. package/lib/module/core/types/StartPayment.js.map +1 -0
  70. package/lib/module/core/types/YunoConfig.js +2 -0
  71. package/lib/module/core/types/YunoConfig.js.map +1 -0
  72. package/lib/module/core/types/index.js +2 -0
  73. package/lib/module/core/types/index.js.map +1 -0
  74. package/lib/module/index.js +4 -0
  75. package/lib/module/index.js.map +1 -0
  76. package/package.json +142 -0
  77. package/src/YunoPaymentMethods.tsx +196 -0
  78. package/src/YunoSdk.ts +518 -0
  79. package/src/core/enums/CardFlow.ts +18 -0
  80. package/src/core/enums/YunoLanguage.ts +50 -0
  81. package/src/core/enums/YunoStatus.ts +32 -0
  82. package/src/core/enums/index.ts +3 -0
  83. package/src/core/index.ts +2 -0
  84. package/src/core/types/AndroidConfig.ts +17 -0
  85. package/src/core/types/EnrollmentArguments.ts +32 -0
  86. package/src/core/types/IosConfig.ts +17 -0
  87. package/src/core/types/OneTimeTokenInfo.ts +207 -0
  88. package/src/core/types/SeamlessArguments.ts +42 -0
  89. package/src/core/types/StartPayment.ts +59 -0
  90. package/src/core/types/YunoConfig.ts +55 -0
  91. package/src/core/types/index.ts +7 -0
  92. package/src/index.ts +17 -0
package/package.json ADDED
@@ -0,0 +1,142 @@
1
+ {
2
+ "name": "@yuno-payments/yuno-sdk-react-native",
3
+ "version": "1.0.16",
4
+ "description": "Yuno React Native SDK empowers you to create seamless payment experiences in your native Android and iOS apps built with React Native.",
5
+ "main": "lib/commonjs/index",
6
+ "module": "lib/module/index",
7
+ "types": "lib/typescript/index.d.ts",
8
+ "react-native": "src/index",
9
+ "source": "src/index",
10
+ "files": [
11
+ "src",
12
+ "lib",
13
+ "android",
14
+ "ios",
15
+ "cpp",
16
+ "*.podspec",
17
+ "!lib/typescript/example",
18
+ "!ios/build",
19
+ "!android/build",
20
+ "!android/gradle",
21
+ "!android/gradlew",
22
+ "!android/gradlew.bat",
23
+ "!android/local.properties",
24
+ "!**/__tests__",
25
+ "!**/__fixtures__",
26
+ "!**/__mocks__",
27
+ "!**/.*"
28
+ ],
29
+ "scripts": {
30
+ "test": "jest",
31
+ "typecheck": "tsc --noEmit",
32
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
33
+ "prepack": "bob build",
34
+ "release": "release-it",
35
+ "example": "yarn --cwd example",
36
+ "bootstrap": "yarn example && yarn install"
37
+ },
38
+ "keywords": [
39
+ "react-native",
40
+ "ios",
41
+ "android",
42
+ "yuno",
43
+ "payments",
44
+ "payment-gateway",
45
+ "payment-sdk",
46
+ "mobile-payments"
47
+ ],
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "https://github.com/yuno-payments/yuno-sdk-react-native.git"
51
+ },
52
+ "author": "Yuno <support@y.uno> (https://y.uno)",
53
+ "license": "MIT",
54
+ "bugs": {
55
+ "url": "https://github.com/yuno-payments/yuno-sdk-react-native/issues"
56
+ },
57
+ "homepage": "https://y.uno",
58
+ "publishConfig": {
59
+ "access": "public"
60
+ },
61
+ "devDependencies": {
62
+ "@react-native-community/eslint-config": "^3.2.0",
63
+ "@release-it/conventional-changelog": "^5.0.0",
64
+ "@types/jest": "^28.1.2",
65
+ "@types/react": "~17.0.21",
66
+ "@types/react-native": "0.70.0",
67
+ "eslint": "^8.4.1",
68
+ "eslint-config-prettier": "^8.5.0",
69
+ "eslint-plugin-prettier": "^4.0.0",
70
+ "jest": "^28.1.1",
71
+ "pod-install": "^0.1.0",
72
+ "prettier": "^2.0.5",
73
+ "react": "18.2.0",
74
+ "react-native": "0.72.0",
75
+ "react-native-builder-bob": "^0.20.0",
76
+ "release-it": "^15.0.0",
77
+ "typescript": "^5.0.2"
78
+ },
79
+ "resolutions": {
80
+ "@types/react": "17.0.21"
81
+ },
82
+ "peerDependencies": {
83
+ "react": "*",
84
+ "react-native": "*"
85
+ },
86
+ "engines": {
87
+ "node": ">= 16.0.0"
88
+ },
89
+ "packageManager": "^yarn@1.22.15",
90
+ "jest": {
91
+ "preset": "react-native",
92
+ "modulePathIgnorePatterns": [
93
+ "<rootDir>/example/node_modules",
94
+ "<rootDir>/lib/"
95
+ ]
96
+ },
97
+ "eslintConfig": {
98
+ "root": true,
99
+ "extends": [
100
+ "@react-native-community",
101
+ "prettier"
102
+ ],
103
+ "rules": {
104
+ "prettier/prettier": [
105
+ "error",
106
+ {
107
+ "quoteProps": "consistent",
108
+ "singleQuote": true,
109
+ "tabWidth": 2,
110
+ "trailingComma": "es5",
111
+ "useTabs": false
112
+ }
113
+ ]
114
+ }
115
+ },
116
+ "eslintIgnore": [
117
+ "node_modules/",
118
+ "lib/"
119
+ ],
120
+ "prettier": {
121
+ "quoteProps": "consistent",
122
+ "singleQuote": true,
123
+ "tabWidth": 2,
124
+ "trailingComma": "es5",
125
+ "useTabs": false
126
+ },
127
+ "react-native-builder-bob": {
128
+ "source": "src",
129
+ "output": "lib",
130
+ "targets": [
131
+ "commonjs",
132
+ "module",
133
+ [
134
+ "typescript",
135
+ {
136
+ "project": "tsconfig.build.json"
137
+ }
138
+ ]
139
+ ]
140
+ }
141
+ }
142
+
@@ -0,0 +1,196 @@
1
+ import React, { useEffect, useCallback } from 'react';
2
+ import {
3
+ requireNativeComponent,
4
+ NativeModules,
5
+ NativeEventEmitter,
6
+ ViewStyle,
7
+ StyleProp,
8
+ Platform,
9
+ } from 'react-native';
10
+
11
+ /**
12
+ * Event emitted when a payment method is selected or deselected.
13
+ */
14
+ export interface PaymentMethodSelectedEvent {
15
+ /** Whether a payment method is currently selected */
16
+ isSelected: boolean;
17
+ }
18
+
19
+ /**
20
+ * Event emitted when an error occurs in the payment methods view.
21
+ */
22
+ export interface PaymentMethodErrorEvent {
23
+ /** Error message */
24
+ message: string;
25
+ }
26
+
27
+ /**
28
+ * Props for the YunoPaymentMethods component.
29
+ */
30
+ export interface YunoPaymentMethodsProps {
31
+ /** Checkout session ID from Yuno API */
32
+ checkoutSession: string;
33
+
34
+ /** ISO country code (e.g., 'US', 'BR', 'CO') */
35
+ countryCode: string;
36
+
37
+ /**
38
+ * Callback invoked when a payment method is selected or deselected.
39
+ * @param event - Event containing selection state
40
+ */
41
+ onPaymentMethodSelected?: (event: PaymentMethodSelectedEvent) => void;
42
+
43
+ /**
44
+ * Callback invoked when an error occurs.
45
+ * @param event - Event containing error information
46
+ */
47
+ onPaymentMethodError?: (event: PaymentMethodErrorEvent) => void;
48
+
49
+ /** Custom styles for the view container */
50
+ style?: StyleProp<ViewStyle>;
51
+ }
52
+
53
+ // Native component interface
54
+ interface NativeYunoPaymentMethodsProps {
55
+ checkoutSession: string;
56
+ countryCode: string;
57
+ style?: StyleProp<ViewStyle>;
58
+ }
59
+
60
+ const LINKING_ERROR =
61
+ `The package '@yuno/yuno-sdk-react-native' doesn't seem to be linked correctly for native views. Make sure:\n\n` +
62
+ Platform.select({ ios: "- Run 'pod install'\n", default: '' }) +
63
+ '- You rebuilt the app after installing the package\n' +
64
+ '- You are not using Expo Go\n' +
65
+ '- The Yuno SDK is properly initialized\n';
66
+
67
+ // Get native module for event emitter
68
+ const YunoSdkNative = NativeModules.YunoSdk;
69
+
70
+ // Create event emitter
71
+ let eventEmitter: NativeEventEmitter | null = null;
72
+ if (YunoSdkNative) {
73
+ eventEmitter = new NativeEventEmitter(YunoSdkNative);
74
+ }
75
+
76
+ // Require the native component
77
+ const NativeYunoPaymentMethodsView = requireNativeComponent<NativeYunoPaymentMethodsProps>(
78
+ 'YunoPaymentMethodsView'
79
+ );
80
+
81
+ /**
82
+ * YunoPaymentMethods Component
83
+ *
84
+ * A React Native component that displays available payment methods using the native Yuno SDK.
85
+ * This component embeds the native `PaymentMethodListViewComponent` from the Yuno Android SDK.
86
+ *
87
+ * **Platform Support:**
88
+ * - ✅ Android (using Jetpack Compose)
89
+ * - ⚠️ iOS (coming soon)
90
+ *
91
+ * **Important:**
92
+ * - The Yuno SDK must be initialized before using this component
93
+ * - Requires a valid `checkoutSession` from the Yuno API
94
+ * - The component will automatically update the checkout session in the native SDK
95
+ *
96
+ * @example
97
+ * ```tsx
98
+ * import { YunoPaymentMethods } from '@yuno/yuno-sdk-react-native';
99
+ *
100
+ * function MyPaymentScreen() {
101
+ * const [checkoutSession, setCheckoutSession] = useState('your_checkout_session_id');
102
+ * const [isMethodSelected, setIsMethodSelected] = useState(false);
103
+ *
104
+ * return (
105
+ * <YunoPaymentMethods
106
+ * checkoutSession={checkoutSession}
107
+ * countryCode="BR"
108
+ * onPaymentMethodSelected={(event) => {
109
+ * setIsMethodSelected(event.isSelected);
110
+ * }}
111
+ * onPaymentMethodError={(event) => {
112
+ * console.error('Error loading payment methods:', event.message);
113
+ * }}
114
+ * style={{ height: 400 }}
115
+ * />
116
+ * );
117
+ * }
118
+ * ```
119
+ *
120
+ * @remarks
121
+ * This component is similar to Flutter's `YunoPaymentMethods` widget.
122
+ * It provides a native UI experience consistent with apps that use the Yuno SDK directly.
123
+ *
124
+ * The native component handles:
125
+ * - Loading available payment methods
126
+ * - Displaying saved payment methods
127
+ * - User interactions and selections
128
+ * - Error states and loading indicators
129
+ *
130
+ * @public
131
+ */
132
+ export const YunoPaymentMethods: React.FC<YunoPaymentMethodsProps> = ({
133
+ checkoutSession,
134
+ countryCode,
135
+ onPaymentMethodSelected,
136
+ onPaymentMethodError,
137
+ style,
138
+ }) => {
139
+ // Set up event listeners
140
+ useEffect(() => {
141
+ if (!eventEmitter) {
142
+ console.warn(LINKING_ERROR);
143
+ return;
144
+ }
145
+
146
+ const subscriptions: any[] = [];
147
+
148
+ // Listen for payment method selection events
149
+ if (onPaymentMethodSelected) {
150
+ const selectionListener = eventEmitter.addListener(
151
+ 'onPaymentMethodSelected',
152
+ (event: PaymentMethodSelectedEvent) => {
153
+ onPaymentMethodSelected(event);
154
+ }
155
+ );
156
+ subscriptions.push(selectionListener);
157
+ }
158
+
159
+ // Listen for error events
160
+ if (onPaymentMethodError) {
161
+ const errorListener = eventEmitter.addListener(
162
+ 'onPaymentMethodError',
163
+ (event: PaymentMethodErrorEvent) => {
164
+ onPaymentMethodError(event);
165
+ }
166
+ );
167
+ subscriptions.push(errorListener);
168
+ }
169
+
170
+ // Cleanup listeners on unmount
171
+ return () => {
172
+ subscriptions.forEach((sub) => {
173
+ if (sub && sub.remove) {
174
+ sub.remove();
175
+ }
176
+ });
177
+ };
178
+ }, [onPaymentMethodSelected, onPaymentMethodError]);
179
+
180
+ // Platform check
181
+ if (Platform.OS !== 'android') {
182
+ console.warn(
183
+ 'YunoPaymentMethods: This component is currently only supported on Android. iOS support coming soon.'
184
+ );
185
+ return null;
186
+ }
187
+
188
+ return (
189
+ <NativeYunoPaymentMethodsView
190
+ checkoutSession={checkoutSession}
191
+ countryCode={countryCode}
192
+ style={style}
193
+ />
194
+ );
195
+ };
196
+