Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Fix jsonData parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
a.ignatov committed Aug 9, 2023
1 parent d7b89e7 commit 2f022fe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
3 changes: 1 addition & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@
<EditText
android:id="@+id/edit_api_url"
style="@style/CPEditText"
android:hint="https://api.cloudpayments.ru/"
android:text=""/>
android:hint="https://api.cloudpayments.ru/"/>

<TextView
style="@style/CPETextView"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package ru.cloudpayments.sdk.viewmodel

import android.util.Log
import androidx.lifecycle.MutableLiveData
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.google.gson.JsonParser
import com.google.gson.JsonSyntaxException
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import ru.cloudpayments.sdk.api.CloudpaymentsApi
Expand All @@ -16,6 +18,7 @@ import ru.cloudpayments.sdk.configuration.PaymentData
import ru.cloudpayments.sdk.ui.dialogs.PaymentProcessStatus
import javax.inject.Inject


internal class PaymentProcessViewModel(
private val paymentData: PaymentData,
private val cryptogram: String,
Expand All @@ -34,15 +37,12 @@ internal class PaymentProcessViewModel(

fun pay() {

val jsonDataMap: HashMap<String, Any> = if (paymentData.jsonData != null && paymentData.jsonData.isNotEmpty()) {
Gson().fromJson(paymentData.jsonData, object : TypeToken<HashMap<String?, Any?>?>() {}.type)
} else {
HashMap()
}

val jsonDataString = if (jsonDataMap != null) {
Gson().toJson(jsonDataMap)
} else {
val jsonDataString: String = try {
val parser = JsonParser()
val jsonElement = parser.parse(paymentData.jsonData)
Gson().toJson(jsonElement)
} catch (e: JsonSyntaxException) {
Log.e("CloudPaymentsSDK", "JsonSyntaxException in JsonData")
""
}

Expand Down Expand Up @@ -103,15 +103,12 @@ internal class PaymentProcessViewModel(

fun getTinkoffQrPayLink() {

val jsonDataMap: HashMap<String, Any> = if (paymentData.jsonData != null && paymentData.jsonData.isNotEmpty()) {
Gson().fromJson(paymentData.jsonData, object : TypeToken<HashMap<String?, Any?>?>() {}.type)
} else {
HashMap()
}

val jsonDataString = if (jsonDataMap != null) {
Gson().toJson(jsonDataMap)
} else {
val jsonDataString: String = try {
val parser = JsonParser()
val jsonElement = parser.parse(paymentData.jsonData)
Gson().toJson(jsonElement)
} catch (e: JsonSyntaxException) {
Log.e("CloudPaymentsSDK", "JsonSyntaxException in JsonData")
""
}

Expand Down

0 comments on commit 2f022fe

Please sign in to comment.