Fix bad use of toString in StripeApi.

This commit is contained in:
Alex Hart 2022-03-25 10:00:16 -03:00 committed by Greyson Parrelli
parent 556dc0d1ec
commit e58cea9a26

View file

@ -120,7 +120,7 @@ class StripeApi(
if (response.isSuccessful) {
return response
} else {
val body = response.body()?.toString()
val body = response.body()?.string()
throw StripeError.PostError(
response.code(),
parseErrorCode(body),
@ -150,12 +150,7 @@ class StripeApi(
}
return try {
val jsonBody = JSONObject(body)
Log.d(TAG, "parseDeclineCode: Parsed body with keys: ${jsonBody.keys().asSequence().joinToString(", ")}")
val jsonError = jsonBody.getJSONObject("error")
Log.d(TAG, "parseDeclineCode: Parsed error with keys: ${jsonError.keys().asSequence().joinToString(", ")}")
StripeDeclineCode.getFromCode(jsonError.getString("decline_code"))
StripeDeclineCode.getFromCode(JSONObject(body).getJSONObject("error").getString("decline_code"))
} catch (e: Exception) {
Log.d(TAG, "parseDeclineCode: Failed to parse decline code.", e, true)
null