@yuno-payments/yuno-sdk-react-native 1.0.21 → 1.0.22

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.
@@ -3,6 +3,7 @@ package com.yunosdkreactnative
3
3
  import android.app.Activity
4
4
  import android.content.Context
5
5
  import android.util.Log
6
+ import android.widget.Toast
6
7
  import androidx.activity.ComponentActivity
7
8
  import com.facebook.react.bridge.*
8
9
  import com.facebook.react.modules.core.DeviceEventManagerModule
@@ -70,6 +71,10 @@ class YunoSdkModule(private val reactContext: ReactApplicationContext) :
70
71
  @Volatile
71
72
  private var lastPaymentStatus: String? = null
72
73
 
74
+ // Store the API client for headless payment flow (reused between generateToken and getThreeDSecureChallenge)
75
+ @Volatile
76
+ private var headlessApiClient: com.yuno.sdk.ApiClientPayment? = null
77
+
73
78
  // Flag to track if we're starting a fresh payment flow
74
79
  @Volatile
75
80
  private var isPaymentFlowCleared: Boolean = false
@@ -847,6 +852,12 @@ class YunoSdkModule(private val reactContext: ReactApplicationContext) :
847
852
  * @param countryCode The country code for the payment
848
853
  * @param promise Promise to resolve with token or error
849
854
  */
855
+ private fun showToast(message: String) {
856
+ currentActivity?.runOnUiThread {
857
+ Toast.makeText(currentActivity, message, Toast.LENGTH_LONG).show()
858
+ }
859
+ }
860
+
850
861
  @ReactMethod
851
862
  fun generateToken(
852
863
  tokenCollectedData: ReadableMap,
@@ -855,10 +866,12 @@ class YunoSdkModule(private val reactContext: ReactApplicationContext) :
855
866
  promise: Promise
856
867
  ) {
857
868
  try {
869
+ showToast("🚀 generateToken: $checkoutSession")
858
870
  Log.d(TAG, "generateToken called with checkoutSession: $checkoutSession")
859
871
 
860
872
  val activity = currentActivity
861
873
  if (activity == null) {
874
+ showToast("❌ Activity is null")
862
875
  promise.reject("ACTIVITY_UNAVAILABLE", "Current activity is null. Cannot generate token.")
863
876
  return
864
877
  }
@@ -868,14 +881,17 @@ class YunoSdkModule(private val reactContext: ReactApplicationContext) :
868
881
  val jsonString = convertReadableMapToJson(tokenCollectedData)
869
882
  Log.d(TAG, "JSON String: $jsonString")
870
883
  val collectedData = gson.fromJson(jsonString, TokenCollectedData::class.java)
884
+ showToast("📦 Data parsed, calling API...")
871
885
  Log.d(TAG, "Parsed TokenCollectedData: checkoutSession=${collectedData.checkoutSession}, paymentMethod=${collectedData.paymentMethod}")
872
886
 
873
- // Create API client
887
+ // Create API client and store it for later use (e.g., getThreeDSecureChallenge)
874
888
  val apiClient = Yuno.apiClientPayment(
875
889
  checkoutSession = checkoutSession,
876
890
  countryCode = countryCode,
877
891
  context = activity.applicationContext
878
892
  )
893
+ headlessApiClient = apiClient
894
+ showToast("✅ API Client created and stored")
879
895
 
880
896
  // Generate token - pass activity for WebView context
881
897
  apiClient.generateToken(collectedData, activity)
@@ -885,6 +901,7 @@ class YunoSdkModule(private val reactContext: ReactApplicationContext) :
885
901
  when {
886
902
  result.containsKey("token") && result["token"] != null -> {
887
903
  val token = result["token"] as String
904
+ showToast("✅ Token generated!")
888
905
  Log.d(TAG, "✅ Token generated successfully")
889
906
 
890
907
  val response = Arguments.createMap().apply {
@@ -894,25 +911,30 @@ class YunoSdkModule(private val reactContext: ReactApplicationContext) :
894
911
  }
895
912
  result.containsKey("error") && result["error"] != null -> {
896
913
  val error = result["error"] as String
914
+ showToast("❌ Token error: $error")
897
915
  Log.e(TAG, "❌ Token generation failed: $error")
898
916
  promise.reject("TOKEN_GENERATION_ERROR", error)
899
917
  }
900
918
  else -> {
919
+ showToast("❌ Unknown response")
901
920
  Log.e(TAG, "❌ Unknown response from token generation")
902
921
  promise.reject("TOKEN_GENERATION_ERROR", "Unknown error occurred")
903
922
  }
904
923
  }
905
924
  } catch (e: Exception) {
925
+ showToast("❌ Exception: ${e.message}")
906
926
  Log.e(TAG, "❌ Error processing token generation result: ${e.message}")
907
927
  promise.reject("TOKEN_GENERATION_ERROR", e.message)
908
928
  }
909
929
  }
910
930
  .catch { e ->
931
+ showToast("❌ Flow error: ${e.message}")
911
932
  Log.e(TAG, "❌ Flow error in token generation: ${e.message}")
912
933
  promise.reject("TOKEN_GENERATION_ERROR", e.message ?: "Unknown error in token generation flow")
913
934
  }
914
935
  .launchIn(CoroutineScope(Dispatchers.Main))
915
936
  } catch (e: Exception) {
937
+ showToast("❌ Error: ${e.message}")
916
938
  Log.e(TAG, "❌ Error in generateToken: ${e.message}")
917
939
  promise.reject("TOKEN_GENERATION_ERROR", e.message)
918
940
  }
@@ -933,49 +955,61 @@ class YunoSdkModule(private val reactContext: ReactApplicationContext) :
933
955
  promise: Promise
934
956
  ) {
935
957
  try {
958
+ showToast("🔐 get3DS: $checkoutSession")
936
959
  Log.d(TAG, "getThreeDSecureChallenge called with checkoutSession: $checkoutSession")
937
960
 
938
961
  val activity = currentActivity
939
962
  if (activity == null) {
963
+ showToast("❌ Activity is null")
940
964
  promise.reject("ACTIVITY_UNAVAILABLE", "Current activity is null. Cannot get 3DS challenge.")
941
965
  return
942
966
  }
943
967
 
944
- // Create API client
945
- val apiClient = Yuno.apiClientPayment(
968
+ // Reuse existing API client if available (from generateToken), otherwise create new one
969
+ val apiClient = headlessApiClient ?: Yuno.apiClientPayment(
946
970
  checkoutSession = checkoutSession,
947
971
  countryCode = countryCode,
948
972
  context = activity.applicationContext
949
973
  )
950
974
 
975
+ val clientType = if (headlessApiClient != null) "EXISTING" else "NEW"
976
+ showToast("📦 Using $clientType API client")
977
+ Log.d(TAG, "Using ${if (headlessApiClient != null) "existing" else "new"} API client for 3DS challenge")
978
+
951
979
  // Get 3DS challenge - pass activity for WebView context
952
980
  apiClient.getThreeDSecureChallenge(activity, checkoutSession)
953
981
  .asFlow()
954
982
  .onEach { result ->
955
983
  try {
984
+ showToast("📥 Result: type=${result.type}")
956
985
  val response = Arguments.createMap().apply {
957
986
  putString("type", result.type)
958
987
  putString("data", result.data)
959
988
  }
960
989
 
961
990
  if (result.type == "URL") {
991
+ showToast("✅ 3DS URL received!")
962
992
  Log.d(TAG, "✅ 3DS Challenge URL retrieved successfully")
963
993
  promise.resolve(response)
964
994
  } else {
995
+ showToast("❌ 3DS failed: ${result.data}")
965
996
  Log.e(TAG, "❌ 3DS Challenge failed: ${result.data}")
966
997
  promise.reject("THREE_DS_ERROR", result.data)
967
998
  }
968
999
  } catch (e: Exception) {
1000
+ showToast("❌ Exception: ${e.message}")
969
1001
  Log.e(TAG, "❌ Error processing 3DS challenge result: ${e.message}")
970
1002
  promise.reject("THREE_DS_ERROR", e.message)
971
1003
  }
972
1004
  }
973
1005
  .catch { e ->
1006
+ showToast("❌ Flow error: ${e.message}")
974
1007
  Log.e(TAG, "❌ Flow error in 3DS challenge: ${e.message}")
975
1008
  promise.reject("THREE_DS_ERROR", e.message ?: "Unknown error in 3DS challenge flow")
976
1009
  }
977
1010
  .launchIn(CoroutineScope(Dispatchers.Main))
978
1011
  } catch (e: Exception) {
1012
+ showToast("❌ Error: ${e.message}")
979
1013
  Log.e(TAG, "❌ Error in getThreeDSecureChallenge: ${e.message}")
980
1014
  promise.reject("THREE_DS_ERROR", e.message)
981
1015
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuno-payments/yuno-sdk-react-native",
3
- "version": "1.0.21",
3
+ "version": "1.0.22",
4
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
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",