@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
@@ -0,0 +1,131 @@
1
+ buildscript {
2
+ ext.kotlin_version = '1.9.24'
3
+ repositories {
4
+ google()
5
+ mavenCentral()
6
+ }
7
+
8
+ dependencies {
9
+ classpath 'com.android.tools.build:gradle:8.1.0'
10
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11
+ }
12
+ }
13
+
14
+ def isNewArchitectureEnabled() {
15
+ return rootProject.hasProperty("newArchEnabled") && rootProject.getProperty("newArchEnabled") == "true"
16
+ }
17
+
18
+ apply plugin: 'com.android.library'
19
+ apply plugin: 'kotlin-android'
20
+
21
+ if (isNewArchitectureEnabled()) {
22
+ apply plugin: "com.facebook.react"
23
+ }
24
+
25
+ def getExtOrDefault(name) {
26
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['YunoSdk_' + name]
27
+ }
28
+
29
+ def getExtOrIntegerDefault(name) {
30
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties['YunoSdk_' + name]).toInteger()
31
+ }
32
+
33
+ def supportsNamespace() {
34
+ def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
35
+ def major = parsed[0].toInteger()
36
+ def minor = parsed[1].toInteger()
37
+
38
+ // Namespace support was added in 7.3.0
39
+ return (major == 7 && minor >= 3) || major >= 8
40
+ }
41
+
42
+ android {
43
+ if (supportsNamespace()) {
44
+ namespace "com.yunosdkreactnative"
45
+
46
+ sourceSets {
47
+ main {
48
+ manifest.srcFile "src/main/AndroidManifestNew.xml"
49
+ }
50
+ }
51
+ }
52
+
53
+ compileSdkVersion getExtOrIntegerDefault('compileSdkVersion')
54
+
55
+ defaultConfig {
56
+ minSdkVersion getExtOrIntegerDefault('minSdkVersion')
57
+ targetSdkVersion getExtOrIntegerDefault('targetSdkVersion')
58
+ }
59
+
60
+ buildTypes {
61
+ release {
62
+ minifyEnabled false
63
+ }
64
+ }
65
+
66
+ lintOptions {
67
+ disable 'GradleCompatible'
68
+ }
69
+
70
+ compileOptions {
71
+ sourceCompatibility JavaVersion.VERSION_17
72
+ targetCompatibility JavaVersion.VERSION_17
73
+ }
74
+
75
+ kotlinOptions {
76
+ jvmTarget = '17'
77
+ }
78
+
79
+ kotlin {
80
+ jvmToolchain(17)
81
+ }
82
+
83
+ buildFeatures {
84
+ compose true
85
+ }
86
+
87
+ composeOptions {
88
+ kotlinCompilerExtensionVersion = "1.5.14"
89
+ }
90
+ }
91
+
92
+ repositories {
93
+ mavenCentral()
94
+ google()
95
+ maven {
96
+ url "https://yunopayments.jfrog.io/artifactory/snapshots-libs-release"
97
+ }
98
+ }
99
+
100
+ def kotlin_version = getExtOrDefault('kotlinVersion')
101
+
102
+ dependencies {
103
+ // For < 0.71, this will be from the local maven repo
104
+ // For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
105
+ //noinspection GradleDynamicVersion
106
+ implementation 'com.facebook.react:react-native:+'
107
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
108
+
109
+ // Yuno Android SDK
110
+ implementation "com.yuno.payments:android-sdk:2.7.0"
111
+ implementation "androidx.appcompat:appcompat:1.6.1"
112
+
113
+ // Jetpack Compose (required for YunoPaymentMethodsViewManager)
114
+ implementation platform('androidx.compose:compose-bom:2023.10.01')
115
+ implementation 'androidx.compose.ui:ui'
116
+ implementation 'androidx.compose.ui:ui-tooling-preview'
117
+ implementation 'androidx.compose.foundation:foundation' // For Column, verticalScroll, etc.
118
+ implementation 'androidx.activity:activity-compose:1.8.2'
119
+
120
+ // Gson for JSON serialization
121
+ implementation 'com.google.code.gson:gson:2.10.1'
122
+ }
123
+
124
+ if (isNewArchitectureEnabled()) {
125
+ react {
126
+ jsRootDir = file("../src/")
127
+ libraryName = "YunoSdk"
128
+ codegenJavaPackageName = "com.yunosdkreactnative"
129
+ }
130
+ }
131
+
@@ -0,0 +1,5 @@
1
+ YunoSdk_kotlinVersion=1.9.25
2
+ YunoSdk_minSdkVersion=21
3
+ YunoSdk_targetSdkVersion=33
4
+ YunoSdk_compileSdkVersion=34
5
+
@@ -0,0 +1,4 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="com.yunosdkreactnative">
3
+ </manifest>
4
+
@@ -0,0 +1,194 @@
1
+ package com.yunosdkreactnative
2
+
3
+ import android.view.View
4
+ import android.widget.LinearLayout
5
+ import androidx.compose.ui.platform.ComposeView
6
+ import androidx.compose.foundation.layout.Column
7
+ import androidx.compose.foundation.layout.fillMaxSize
8
+ import androidx.compose.foundation.rememberScrollState
9
+ import androidx.compose.foundation.verticalScroll
10
+ import androidx.compose.ui.Modifier
11
+ import com.facebook.react.bridge.Arguments
12
+ import com.facebook.react.bridge.ReactApplicationContext
13
+ import com.facebook.react.bridge.ReactContext
14
+ import com.facebook.react.bridge.ReadableArray
15
+ import com.facebook.react.bridge.WritableMap
16
+ import com.facebook.react.uimanager.SimpleViewManager
17
+ import com.facebook.react.uimanager.ThemedReactContext
18
+ import com.facebook.react.uimanager.annotations.ReactProp
19
+ import com.facebook.react.uimanager.events.RCTEventEmitter
20
+ import com.facebook.react.modules.core.DeviceEventManagerModule
21
+ import com.yuno.presentation.core.components.PaymentMethodListViewComponent
22
+ import com.yuno.sdk.payments.updateCheckoutSession
23
+
24
+ /**
25
+ * ViewManager for YunoPaymentMethodsView.
26
+ *
27
+ * This component embeds the native Yuno SDK PaymentMethodListViewComponent
28
+ * into React Native, allowing developers to display payment methods in their app.
29
+ *
30
+ * Similar to Flutter's implementation using Platform Views.
31
+ */
32
+ class YunoPaymentMethodsViewManager(
33
+ private val reactContext: ReactApplicationContext
34
+ ) : SimpleViewManager<View>() {
35
+
36
+ companion object {
37
+ private const val TAG = "YunoPaymentMethodsViewManager"
38
+ const val REACT_CLASS = "YunoPaymentMethodsView"
39
+
40
+ // Event names
41
+ private const val EVENT_ON_PAYMENT_SELECTED = "onPaymentMethodSelected"
42
+ private const val EVENT_ON_ERROR = "onPaymentMethodError"
43
+ }
44
+
45
+ override fun getName(): String = REACT_CLASS
46
+
47
+ /**
48
+ * Creates the native view that embeds the Yuno PaymentMethodListViewComponent.
49
+ */
50
+ override fun createViewInstance(reactContext: ThemedReactContext): View {
51
+
52
+ // Get current activity
53
+ val activity = reactContext.currentActivity
54
+ if (activity == null) {
55
+ // Return empty view as fallback
56
+ return View(reactContext)
57
+ }
58
+
59
+ // Create ComposeView to embed Jetpack Compose component
60
+ val composeView = ComposeView(reactContext).apply {
61
+ layoutParams = LinearLayout.LayoutParams(
62
+ LinearLayout.LayoutParams.MATCH_PARENT,
63
+ LinearLayout.LayoutParams.MATCH_PARENT // Changed to MATCH_PARENT for scrolling
64
+ )
65
+
66
+ // Set the Compose content with the native Yuno component wrapped in a scrollable Column
67
+ setContent {
68
+ val scrollState = rememberScrollState()
69
+ Column(
70
+ modifier = Modifier
71
+ .fillMaxSize()
72
+ .verticalScroll(scrollState)
73
+ ) {
74
+ PaymentMethodListViewComponent(
75
+ activity = activity,
76
+ onPaymentSelected = { isSelected ->
77
+ emitPaymentSelectedEvent(reactContext, isSelected)
78
+ },
79
+ onUnEnrollSuccess = {
80
+ }
81
+ )
82
+ }
83
+ }
84
+ }
85
+
86
+ return composeView
87
+ }
88
+
89
+ /**
90
+ * Sets the checkout session and updates the native SDK.
91
+ * This must be called before the payment methods can be displayed.
92
+ */
93
+ @ReactProp(name = "checkoutSession")
94
+ fun setCheckoutSession(view: View, checkoutSession: String?) {
95
+ if (checkoutSession == null) {
96
+ return
97
+ }
98
+
99
+
100
+ // Store for later use with country code
101
+ view.setTag("checkout_session".hashCode(), checkoutSession)
102
+
103
+ // Update if we also have country code
104
+ val countryCode = view.getTag("country_code".hashCode()) as? String
105
+ if (countryCode != null) {
106
+ updateCheckoutSessionInActivity(view, checkoutSession, countryCode)
107
+ }
108
+ }
109
+
110
+ /**
111
+ * Sets the country code for the payment methods.
112
+ */
113
+ @ReactProp(name = "countryCode")
114
+ fun setCountryCode(view: View, countryCode: String?) {
115
+ if (countryCode == null) {
116
+ return
117
+ }
118
+
119
+
120
+ // Store for later use with checkout session
121
+ view.setTag("country_code".hashCode(), countryCode)
122
+
123
+ // Update if we also have checkout session
124
+ val checkoutSession = view.getTag("checkout_session".hashCode()) as? String
125
+ if (checkoutSession != null) {
126
+ updateCheckoutSessionInActivity(view, checkoutSession, countryCode)
127
+ }
128
+ }
129
+
130
+ /**
131
+ * Updates the checkout session in the current activity.
132
+ */
133
+ private fun updateCheckoutSessionInActivity(
134
+ view: View,
135
+ checkoutSession: String,
136
+ countryCode: String
137
+ ) {
138
+ val context = view.context as? ThemedReactContext
139
+ val activity = context?.currentActivity
140
+
141
+ if (activity == null) {
142
+ emitErrorEvent(context, "Activity not available")
143
+ return
144
+ }
145
+
146
+ try {
147
+ activity.updateCheckoutSession(
148
+ checkoutSession = checkoutSession,
149
+ countryCode = countryCode
150
+ )
151
+ } catch (e: Exception) {
152
+ emitErrorEvent(context, e.message ?: "Unknown error")
153
+ }
154
+ }
155
+
156
+ /**
157
+ * Emits an event when a payment method is selected.
158
+ */
159
+ private fun emitPaymentSelectedEvent(context: ReactContext, isSelected: Boolean) {
160
+ val event: WritableMap = Arguments.createMap().apply {
161
+ putBoolean("isSelected", isSelected)
162
+ }
163
+
164
+ context
165
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
166
+ .emit(EVENT_ON_PAYMENT_SELECTED, event)
167
+ }
168
+
169
+ /**
170
+ * Emits an error event.
171
+ */
172
+ private fun emitErrorEvent(context: ReactContext?, message: String) {
173
+ if (context == null) return
174
+
175
+ val event: WritableMap = Arguments.createMap().apply {
176
+ putString("message", message)
177
+ }
178
+
179
+ context
180
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
181
+ .emit(EVENT_ON_ERROR, event)
182
+ }
183
+
184
+ /**
185
+ * Export event names to JavaScript.
186
+ */
187
+ override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any> {
188
+ return mutableMapOf(
189
+ EVENT_ON_PAYMENT_SELECTED to mapOf("registrationName" to "onPaymentMethodSelected"),
190
+ EVENT_ON_ERROR to mapOf("registrationName" to "onPaymentMethodError")
191
+ )
192
+ }
193
+ }
194
+