From 305e4fac4ca862da711178a3fc7a880b5b17f1e5 Mon Sep 17 00:00:00 2001 From: atavism Date: Tue, 3 Oct 2023 02:41:45 -0700 Subject: [PATCH] Change purchase request body to json (#919) --- .../getlantern/lantern/util/PaymentsUtil.kt | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/android/app/src/main/kotlin/org/getlantern/lantern/util/PaymentsUtil.kt b/android/app/src/main/kotlin/org/getlantern/lantern/util/PaymentsUtil.kt index cc04b5fc4..d116a0dac 100644 --- a/android/app/src/main/kotlin/org/getlantern/lantern/util/PaymentsUtil.kt +++ b/android/app/src/main/kotlin/org/getlantern/lantern/util/PaymentsUtil.kt @@ -281,33 +281,32 @@ class PaymentsUtil(private val activity: Activity) { } ?: "usd" Logger.d(TAG, "Sending purchase request: provider $provider; plan ID: $planID; currency: $currency") val session = session - val formBody: FormBody.Builder = FormBody.Builder() - .add("idempotencyKey", System.currentTimeMillis().toString()) - .add("provider", provider.toString().lowercase()) - .add("email", email) - .add("plan", planID) - .add("currency", currency.lowercase()) - .add("deviceName", session.deviceName()) + val json: JsonObject = JsonObject() + json.addProperty("idempotencyKey", System.currentTimeMillis().toString()) + json.addProperty("provider", provider.toString().lowercase()) + json.addProperty("email", email) + json.addProperty("plan", planID) + json.addProperty("currency", currency.lowercase()) + json.addProperty("deviceName", session.deviceName()) when (provider) { PaymentProvider.Stripe -> { val stripePublicKey = session.stripePubKey() - stripePublicKey?.let { formBody.add("stripePublicKey", stripePublicKey) } - formBody.add("stripeEmail", email) - formBody.add("stripeToken", token) - formBody.add("token", token) + stripePublicKey?.let { json.addProperty("stripePublicKey", stripePublicKey) } + json.addProperty("stripeEmail", email) + json.addProperty("stripeToken", token) + json.addProperty("token", token) } PaymentProvider.GooglePlay -> { - formBody.add("token", token) + json.addProperty("token", token) } PaymentProvider.ResellerCode -> { + Logger.d(TAG, "Received reseller code purchase request") val resellerCode = LanternApp.getSession().resellerCode() - resellerCode?.let { - formBody.add("provider", "reseller-code") - formBody.add("resellerCode", resellerCode) - } + json.addProperty("provider", "reseller-code") + json.addProperty("resellerCode", resellerCode!!) } else -> {} @@ -315,7 +314,7 @@ class PaymentsUtil(private val activity: Activity) { lanternClient.post( LanternHttpClient.createProUrl("/purchase"), - formBody.build(), + LanternHttpClient.createJsonBody(json), object : ProCallback { override fun onSuccess(response: Response?, result: JsonObject?) { @@ -328,6 +327,7 @@ class PaymentsUtil(private val activity: Activity) { } override fun onFailure(t: Throwable?, error: ProError?) { + Logger.e(TAG, "Error with purchase request: $error") Datadog.addError("Error with purchase request: $error", t, mapOf( "provider" to provider.toString().lowercase(), "plan" to planID,