From 147f711138e9d310ed488174943980b341dbda22 Mon Sep 17 00:00:00 2001 From: Aleksandras Kostarevas Date: Mon, 29 Apr 2024 15:19:43 -0400 Subject: [PATCH] Update payment flow to work --- build.gradle | 4 ++ java/res/values/strings-uix.xml | 2 + .../latin/payment/PaymentCompleteActivity.kt | 7 +--- .../latin/uix/settings/pages/Payment.kt | 37 +++++++++++++------ 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/build.gradle b/build.gradle index 20507f723..4851cba13 100644 --- a/build.gradle +++ b/build.gradle @@ -126,6 +126,8 @@ android { buildConfigField "boolean", "IS_PLAYSTORE_BUILD", "false" buildConfigField "boolean", "UPDATE_CHECKING", "true" getIsDefault().set(true) + + buildConfigField "String", "PAYMENT_URL", "\"\"" } playstore { dimension "buildType" @@ -134,6 +136,8 @@ android { buildConfigField "boolean", "IS_PLAYSTORE_BUILD", "true" buildConfigField "boolean", "UPDATE_CHECKING", "false" + + buildConfigField "String", "PAYMENT_URL", "\"\"" } } diff --git a/java/res/values/strings-uix.xml b/java/res/values/strings-uix.xml index 59048af8d..09076f795 100644 --- a/java/res/values/strings-uix.xml +++ b/java/res/values/strings-uix.xml @@ -72,4 +72,6 @@ Payment Failed to verify license. If you believe this to be an error, please contact us. Thank you for using the paid version of FUTO Keyboard! + Note: If you already paid for either FUTO Keyboard or FUTO Voice Input in the past, feel free to tap I already paid. + If you just paid, your payment may still be processing, you should get an email with more information. \ No newline at end of file diff --git a/java/src/org/futo/inputmethod/latin/payment/PaymentCompleteActivity.kt b/java/src/org/futo/inputmethod/latin/payment/PaymentCompleteActivity.kt index 0655f3c82..15cec7862 100644 --- a/java/src/org/futo/inputmethod/latin/payment/PaymentCompleteActivity.kt +++ b/java/src/org/futo/inputmethod/latin/payment/PaymentCompleteActivity.kt @@ -95,12 +95,7 @@ class PaymentCompleteActivity : ComponentActivity() { val targetData = intent.dataString if((targetData?.startsWith("futo-keyboard://license/") == true) || (targetData?.startsWith("futo-voice-input://license/") == true)) { - /*if(StatePayment.instance.setPaymentLicenseUrl(targetData)) { - onPaid(targetData) - } else { - onInvalidKey() - }*/ - TODO() + onPaid("activate") } else { Log.e("PaymentCompleteActivity", "futo-keyboard launched with invalid targetData $targetData") finish() diff --git a/java/src/org/futo/inputmethod/latin/uix/settings/pages/Payment.kt b/java/src/org/futo/inputmethod/latin/uix/settings/pages/Payment.kt index 28bdeb891..645849396 100644 --- a/java/src/org/futo/inputmethod/latin/uix/settings/pages/Payment.kt +++ b/java/src/org/futo/inputmethod/latin/uix/settings/pages/Payment.kt @@ -3,11 +3,15 @@ package org.futo.inputmethod.latin.uix.settings.pages import android.app.Activity import android.content.Context import android.content.Intent +import android.widget.Toast import androidx.compose.foundation.background +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.width import androidx.compose.foundation.shape.RoundedCornerShape @@ -117,7 +121,7 @@ fun ParagraphText(it: String, modifier: Modifier = Modifier) { } @Composable -fun PaymentText() { +fun PaymentText(verbose: Boolean) { val numDaysInstalled = useNumberOfDaysInstalled() // Doesn't make sense to say "You've been using for ... days" if it's less than seven days @@ -128,6 +132,10 @@ fun PaymentText() { } ParagraphText(stringResource(R.string.payment_text_2)) + + if(verbose) { + ParagraphText(stringResource(R.string.payment_text_3)) + } } suspend fun pushNoticeReminderTime(context: Context, days: Float) { @@ -194,13 +202,15 @@ fun ConditionalUnpaidNoticeInVoiceInputWindow(onClose: (() -> Unit)? = null) { @Composable @Preview -fun UnpaidNotice(onPay: () -> Unit = { }, onAlreadyPaid: () -> Unit = { }) { +fun UnpaidNotice(openMenu: () -> Unit = { }) { Surface( color = MaterialTheme.colorScheme.surfaceVariant, modifier = Modifier + .clickable { openMenu() } .fillMaxWidth() - .padding(24.dp, 8.dp), shape = RoundedCornerShape(4.dp) + .padding(24.dp, 8.dp), shape = RoundedCornerShape(24.dp) ) { Column(modifier = Modifier.padding(8.dp, 0.dp)) { + Spacer(modifier = Modifier.height(8.dp)) Text( stringResource(R.string.unpaid_title), modifier = Modifier.padding(8.dp), @@ -208,7 +218,7 @@ fun UnpaidNotice(onPay: () -> Unit = { }, onAlreadyPaid: () -> Unit = { }) { color = MaterialTheme.colorScheme.onBackground ) - PaymentText() + PaymentText(false) Row( modifier = Modifier @@ -217,14 +227,14 @@ fun UnpaidNotice(onPay: () -> Unit = { }, onAlreadyPaid: () -> Unit = { }) { ) { Box(modifier = Modifier.weight(1.0f)) { - Button(onClick = onPay, modifier = Modifier.align(Center)) { + Button(onClick = openMenu, modifier = Modifier.align(Center)) { Text(stringResource(R.string.pay_now)) } } Box(modifier = Modifier.weight(1.0f)) { Button( - onClick = onAlreadyPaid, colors = ButtonDefaults.buttonColors( + onClick = openMenu, colors = ButtonDefaults.buttonColors( containerColor = MaterialTheme.colorScheme.secondary, contentColor = MaterialTheme.colorScheme.onSecondary ), modifier = Modifier.align(Center) @@ -242,9 +252,7 @@ fun UnpaidNotice(onPay: () -> Unit = { }, onAlreadyPaid: () -> Unit = { }) { @Preview fun ConditionalUnpaidNoticeWithNav(navController: NavController = rememberNavController()) { UnpaidNoticeCondition { - UnpaidNotice(onPay = { - navController.navigate("payment") - }, onAlreadyPaid = { + UnpaidNotice(openMenu = { navController.navigate("payment") }) } @@ -271,6 +279,8 @@ fun PaymentThankYouScreen(onExit: () -> Unit = { }) { } ParagraphText(stringResource(R.string.purchase_will_help_body)) + ParagraphText(stringResource(R.string.payment_processing_note)) + Box(modifier = Modifier .fillMaxWidth() .padding(16.dp, 8.dp)) { @@ -355,14 +365,19 @@ fun PaymentScreen( ScrollableList { ScreenTitle(stringResource(R.string.payment_title), showBack = true, navController = navController) - PaymentText() + PaymentText(true) val context = LocalContext.current Column(modifier = Modifier.fillMaxWidth()) { Row(modifier = Modifier.padding(8.dp, 0.dp)) { Button( onClick = { - TODO() + if(BuildConfig.PAYMENT_URL.isNotBlank()) { + context.openURI(BuildConfig.PAYMENT_URL) + } else { + val toast = Toast.makeText(context, "Payment is unsupported on this build", Toast.LENGTH_SHORT) + toast.show() + } }, modifier = Modifier .weight(1.0f) .padding(8.dp)