Skip to content

Commit

Permalink
Change purchase request body to json (#919)
Browse files Browse the repository at this point in the history
  • Loading branch information
atavism authored Oct 3, 2023
1 parent 58d04a8 commit 305e4fa
Showing 1 changed file with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,41 +281,40 @@ 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 -> {}
}

lanternClient.post(
LanternHttpClient.createProUrl("/purchase"),
formBody.build(),
LanternHttpClient.createJsonBody(json),
object : ProCallback {

override fun onSuccess(response: Response?, result: JsonObject?) {
Expand All @@ -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,
Expand Down

0 comments on commit 305e4fa

Please sign in to comment.