mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-25 19:29:54 +01:00
Start re-work of play billing checkout flow.
This commit is contained in:
committed by
Greyson Parrelli
parent
b340097f9c
commit
48bd57c56a
@@ -4,12 +4,11 @@ import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.navigation.Navigation
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import org.signal.donations.InAppPaymentType
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.components.settings.DSLConfiguration
|
||||
import org.thoughtcrime.securesms.components.settings.DSLSettingsFragment
|
||||
import org.thoughtcrime.securesms.components.settings.DSLSettingsText
|
||||
import org.thoughtcrime.securesms.components.settings.app.subscription.InAppPaymentCheckoutLauncher.createBackupsCheckoutLauncher
|
||||
import org.thoughtcrime.securesms.components.settings.app.subscription.MessageBackupsCheckoutLauncher.createBackupsCheckoutLauncher
|
||||
import org.thoughtcrime.securesms.components.settings.configure
|
||||
import org.thoughtcrime.securesms.util.RemoteConfig
|
||||
import org.thoughtcrime.securesms.util.adapter.mapping.MappingAdapter
|
||||
@@ -18,7 +17,7 @@ import org.thoughtcrime.securesms.util.navigation.safeNavigate
|
||||
class ChatsSettingsFragment : DSLSettingsFragment(R.string.preferences_chats__chats) {
|
||||
|
||||
private lateinit var viewModel: ChatsSettingsViewModel
|
||||
private lateinit var checkoutLauncher: ActivityResultLauncher<InAppPaymentType>
|
||||
private lateinit var checkoutLauncher: ActivityResultLauncher<Unit>
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
@@ -99,7 +98,7 @@ class ChatsSettingsFragment : DSLSettingsFragment(R.string.preferences_chats__ch
|
||||
if (state.canAccessRemoteBackupsSettings) {
|
||||
Navigation.findNavController(requireView()).safeNavigate(R.id.action_chatsSettingsFragment_to_remoteBackupsSettingsFragment)
|
||||
} else {
|
||||
checkoutLauncher.launch(InAppPaymentType.RECURRING_BACKUP)
|
||||
checkoutLauncher.launch(Unit)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
@@ -62,13 +62,12 @@ import org.signal.core.ui.SignalPreview
|
||||
import org.signal.core.ui.Snackbars
|
||||
import org.signal.core.ui.Texts
|
||||
import org.signal.core.util.money.FiatMoney
|
||||
import org.signal.donations.InAppPaymentType
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.backup.v2.BackupFrequency
|
||||
import org.thoughtcrime.securesms.backup.v2.BackupV2Event
|
||||
import org.thoughtcrime.securesms.backup.v2.ui.subscription.MessageBackupsType
|
||||
import org.thoughtcrime.securesms.components.settings.app.chats.backups.type.BackupsTypeSettingsFragment
|
||||
import org.thoughtcrime.securesms.components.settings.app.subscription.InAppPaymentCheckoutLauncher.createBackupsCheckoutLauncher
|
||||
import org.thoughtcrime.securesms.components.settings.app.subscription.MessageBackupsCheckoutLauncher.createBackupsCheckoutLauncher
|
||||
import org.thoughtcrime.securesms.compose.ComposeFragment
|
||||
import org.thoughtcrime.securesms.conversation.v2.registerForLifecycle
|
||||
import org.thoughtcrime.securesms.database.model.InAppPaymentSubscriberRecord
|
||||
@@ -92,7 +91,7 @@ class RemoteBackupsSettingsFragment : ComposeFragment() {
|
||||
|
||||
private val args: RemoteBackupsSettingsFragmentArgs by navArgs()
|
||||
|
||||
private lateinit var checkoutLauncher: ActivityResultLauncher<InAppPaymentType>
|
||||
private lateinit var checkoutLauncher: ActivityResultLauncher<Unit>
|
||||
|
||||
@Composable
|
||||
override fun FragmentContent() {
|
||||
@@ -119,7 +118,7 @@ class RemoteBackupsSettingsFragment : ComposeFragment() {
|
||||
}
|
||||
|
||||
override fun onEnableBackupsClick() {
|
||||
checkoutLauncher.launch(InAppPaymentType.RECURRING_BACKUP)
|
||||
checkoutLauncher.launch(Unit)
|
||||
}
|
||||
|
||||
override fun onBackUpUsingCellularClick(canUseCellular: Boolean) {
|
||||
|
||||
@@ -30,11 +30,10 @@ import org.signal.core.ui.Rows
|
||||
import org.signal.core.ui.Scaffolds
|
||||
import org.signal.core.ui.SignalPreview
|
||||
import org.signal.core.util.money.FiatMoney
|
||||
import org.signal.donations.InAppPaymentType
|
||||
import org.signal.donations.PaymentSourceType
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.backup.v2.ui.subscription.MessageBackupsType
|
||||
import org.thoughtcrime.securesms.components.settings.app.subscription.InAppPaymentCheckoutLauncher.createBackupsCheckoutLauncher
|
||||
import org.thoughtcrime.securesms.components.settings.app.subscription.MessageBackupsCheckoutLauncher.createBackupsCheckoutLauncher
|
||||
import org.thoughtcrime.securesms.compose.ComposeFragment
|
||||
import org.thoughtcrime.securesms.database.model.InAppPaymentSubscriberRecord
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
@@ -58,7 +57,7 @@ class BackupsTypeSettingsFragment : ComposeFragment() {
|
||||
BackupsTypeSettingsViewModel()
|
||||
}
|
||||
|
||||
private lateinit var checkoutLauncher: ActivityResultLauncher<InAppPaymentType>
|
||||
private lateinit var checkoutLauncher: ActivityResultLauncher<Unit>
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
@@ -92,7 +91,7 @@ class BackupsTypeSettingsFragment : ComposeFragment() {
|
||||
}
|
||||
|
||||
override fun onChangeOrCancelSubscriptionClick() {
|
||||
checkoutLauncher.launch(InAppPaymentType.RECURRING_BACKUP)
|
||||
checkoutLauncher.launch(Unit)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,6 +194,7 @@ private fun BackupsTypeRow(
|
||||
private fun PaymentSourceRow(paymentSourceType: PaymentSourceType) {
|
||||
val paymentSourceTextResId = remember(paymentSourceType) {
|
||||
when (paymentSourceType) {
|
||||
is PaymentSourceType.GooglePlayBilling -> R.string.BackupsTypeSettingsFragment__google_play
|
||||
is PaymentSourceType.Stripe.CreditCard -> R.string.BackupsTypeSettingsFragment__credit_or_debit_card
|
||||
is PaymentSourceType.Stripe.IDEAL -> R.string.BackupsTypeSettingsFragment__iDEAL
|
||||
is PaymentSourceType.Stripe.GooglePay -> R.string.BackupsTypeSettingsFragment__google_pay
|
||||
|
||||
@@ -32,13 +32,12 @@ import org.signal.core.ui.Buttons
|
||||
import org.signal.core.ui.Icons
|
||||
import org.signal.core.ui.Previews
|
||||
import org.signal.core.ui.SignalPreview
|
||||
import org.signal.donations.InAppPaymentType
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.backup.v2.ui.BackupsIconColors
|
||||
import org.thoughtcrime.securesms.backup.v2.ui.subscription.MessageBackupsType
|
||||
import org.thoughtcrime.securesms.backup.v2.ui.subscription.MessageBackupsTypeBlock
|
||||
import org.thoughtcrime.securesms.backup.v2.ui.subscription.testBackupTypes
|
||||
import org.thoughtcrime.securesms.components.settings.app.subscription.InAppPaymentCheckoutLauncher.createBackupsCheckoutLauncher
|
||||
import org.thoughtcrime.securesms.components.settings.app.subscription.MessageBackupsCheckoutLauncher.createBackupsCheckoutLauncher
|
||||
import org.thoughtcrime.securesms.compose.ComposeBottomSheetDialogFragment
|
||||
|
||||
/**
|
||||
@@ -50,7 +49,7 @@ class UpgradeToEnableOptimizedStorageSheet : ComposeBottomSheetDialogFragment()
|
||||
|
||||
private val viewModel: UpgradeToEnableOptimizedStorageViewModel by viewModels()
|
||||
|
||||
private lateinit var checkoutLauncher: ActivityResultLauncher<InAppPaymentType>
|
||||
private lateinit var checkoutLauncher: ActivityResultLauncher<Unit>
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
@@ -63,7 +62,7 @@ class UpgradeToEnableOptimizedStorageSheet : ComposeBottomSheetDialogFragment()
|
||||
UpgradeToEnableOptimizedStorageSheetContent(
|
||||
messageBackupsType = type,
|
||||
onUpgradeNowClick = {
|
||||
checkoutLauncher.launch(InAppPaymentType.RECURRING_BACKUP)
|
||||
checkoutLauncher.launch(Unit)
|
||||
dismissAllowingStateLoss()
|
||||
},
|
||||
onCancelClick = {
|
||||
|
||||
@@ -27,6 +27,7 @@ object DonationSerializationHelper {
|
||||
return PendingOneTimeDonation(
|
||||
badge = Badges.toDatabaseBadge(badge),
|
||||
paymentMethodType = when (paymentSourceType) {
|
||||
PaymentSourceType.GooglePlayBilling -> error("Unsupported payment source.")
|
||||
PaymentSourceType.PayPal -> PendingOneTimeDonation.PaymentMethodType.PAYPAL
|
||||
PaymentSourceType.Stripe.CreditCard, PaymentSourceType.Stripe.GooglePay, PaymentSourceType.Unknown -> PendingOneTimeDonation.PaymentMethodType.CARD
|
||||
PaymentSourceType.Stripe.SEPADebit -> PendingOneTimeDonation.PaymentMethodType.SEPA_DEBIT
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.components.settings.app.subscription
|
||||
|
||||
import org.signal.donations.InAppPaymentType
|
||||
import org.signal.donations.PaymentSourceType
|
||||
import org.thoughtcrime.securesms.dependencies.AppDependencies
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.util.Environment
|
||||
import org.thoughtcrime.securesms.util.LocaleRemoteConfig
|
||||
@@ -25,12 +26,17 @@ object InAppDonations {
|
||||
}
|
||||
|
||||
fun isPaymentSourceAvailable(paymentSourceType: PaymentSourceType, inAppPaymentType: InAppPaymentType): Boolean {
|
||||
if (inAppPaymentType == InAppPaymentType.RECURRING_BACKUP) {
|
||||
return paymentSourceType == PaymentSourceType.GooglePlayBilling && AppDependencies.billingApi.isApiAvailable()
|
||||
}
|
||||
|
||||
return when (paymentSourceType) {
|
||||
PaymentSourceType.PayPal -> isPayPalAvailableForDonateToSignalType(inAppPaymentType)
|
||||
PaymentSourceType.Stripe.CreditCard -> isCreditCardAvailable()
|
||||
PaymentSourceType.Stripe.GooglePay -> isGooglePayAvailable()
|
||||
PaymentSourceType.Stripe.SEPADebit -> isSEPADebitAvailableForDonateToSignalType(inAppPaymentType)
|
||||
PaymentSourceType.Stripe.IDEAL -> isIDEALAvailbleForDonateToSignalType(inAppPaymentType)
|
||||
PaymentSourceType.GooglePlayBilling -> false
|
||||
PaymentSourceType.Unknown -> false
|
||||
}
|
||||
}
|
||||
@@ -40,7 +46,7 @@ object InAppDonations {
|
||||
InAppPaymentType.UNKNOWN -> error("Unsupported type UNKNOWN")
|
||||
InAppPaymentType.ONE_TIME_DONATION, InAppPaymentType.ONE_TIME_GIFT -> RemoteConfig.paypalOneTimeDonations
|
||||
InAppPaymentType.RECURRING_DONATION -> RemoteConfig.paypalRecurringDonations
|
||||
InAppPaymentType.RECURRING_BACKUP -> RemoteConfig.messageBackups && RemoteConfig.paypalRecurringDonations
|
||||
InAppPaymentType.RECURRING_BACKUP -> false
|
||||
} && !LocaleRemoteConfig.isPayPalDisabled()
|
||||
}
|
||||
|
||||
|
||||
@@ -235,6 +235,7 @@ object InAppPaymentsRepository {
|
||||
*/
|
||||
fun PaymentSourceType.toPaymentMethodType(): InAppPaymentData.PaymentMethodType {
|
||||
return when (this) {
|
||||
PaymentSourceType.GooglePlayBilling -> InAppPaymentData.PaymentMethodType.GOOGLE_PLAY_BILLING
|
||||
PaymentSourceType.PayPal -> InAppPaymentData.PaymentMethodType.PAYPAL
|
||||
PaymentSourceType.Stripe.CreditCard -> InAppPaymentData.PaymentMethodType.CARD
|
||||
PaymentSourceType.Stripe.GooglePay -> InAppPaymentData.PaymentMethodType.GOOGLE_PAY
|
||||
@@ -255,6 +256,7 @@ object InAppPaymentsRepository {
|
||||
InAppPaymentData.PaymentMethodType.IDEAL -> PaymentSourceType.Stripe.IDEAL
|
||||
InAppPaymentData.PaymentMethodType.SEPA_DEBIT -> PaymentSourceType.Stripe.SEPADebit
|
||||
InAppPaymentData.PaymentMethodType.UNKNOWN -> PaymentSourceType.Unknown
|
||||
InAppPaymentData.PaymentMethodType.GOOGLE_PLAY_BILLING -> PaymentSourceType.GooglePlayBilling
|
||||
}
|
||||
}
|
||||
|
||||
@@ -571,6 +573,7 @@ object InAppPaymentsRepository {
|
||||
InAppPaymentData.PaymentMethodType.SEPA_DEBIT -> PendingOneTimeDonation.PaymentMethodType.SEPA_DEBIT
|
||||
InAppPaymentData.PaymentMethodType.IDEAL -> PendingOneTimeDonation.PaymentMethodType.IDEAL
|
||||
InAppPaymentData.PaymentMethodType.PAYPAL -> PendingOneTimeDonation.PaymentMethodType.PAYPAL
|
||||
InAppPaymentData.PaymentMethodType.GOOGLE_PLAY_BILLING -> error("One-time donation do not support purchase via Google Play Billing.")
|
||||
},
|
||||
amount = data.amount!!,
|
||||
badge = data.badge!!,
|
||||
@@ -661,6 +664,7 @@ object InAppPaymentsRepository {
|
||||
InAppPaymentData.PaymentMethodType.SEPA_DEBIT -> DonationProcessor.STRIPE
|
||||
InAppPaymentData.PaymentMethodType.IDEAL -> DonationProcessor.STRIPE
|
||||
InAppPaymentData.PaymentMethodType.PAYPAL -> DonationProcessor.PAYPAL
|
||||
InAppPaymentData.PaymentMethodType.GOOGLE_PLAY_BILLING -> error("Google Play Billing does not support donation payments.")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,17 +8,16 @@ package org.thoughtcrime.securesms.components.settings.app.subscription
|
||||
import androidx.activity.result.ActivityResultLauncher
|
||||
import androidx.fragment.app.Fragment
|
||||
import org.signal.core.util.getSerializableCompat
|
||||
import org.signal.donations.InAppPaymentType
|
||||
import org.thoughtcrime.securesms.backup.v2.ui.CreateBackupBottomSheet
|
||||
import org.thoughtcrime.securesms.components.settings.app.subscription.donate.CheckoutFlowActivity
|
||||
import org.thoughtcrime.securesms.backup.v2.ui.subscription.MessageBackupsCheckoutActivity
|
||||
import org.thoughtcrime.securesms.components.settings.app.subscription.donate.InAppPaymentProcessorAction
|
||||
import org.thoughtcrime.securesms.util.BottomSheetUtil
|
||||
|
||||
object InAppPaymentCheckoutLauncher {
|
||||
object MessageBackupsCheckoutLauncher {
|
||||
|
||||
fun Fragment.createBackupsCheckoutLauncher(
|
||||
onCreateBackupBottomSheetResultListener: OnCreateBackupBottomSheetResultListener = {} as OnCreateBackupBottomSheetResultListener
|
||||
): ActivityResultLauncher<InAppPaymentType> {
|
||||
): ActivityResultLauncher<Unit> {
|
||||
childFragmentManager.setFragmentResultListener(CreateBackupBottomSheet.REQUEST_KEY, viewLifecycleOwner) { requestKey, bundle ->
|
||||
if (requestKey == CreateBackupBottomSheet.REQUEST_KEY) {
|
||||
val result = bundle.getSerializableCompat(CreateBackupBottomSheet.REQUEST_KEY, CreateBackupBottomSheet.Result::class.java)
|
||||
@@ -26,7 +25,7 @@ object InAppPaymentCheckoutLauncher {
|
||||
}
|
||||
}
|
||||
|
||||
return registerForActivityResult(CheckoutFlowActivity.Contract()) { result ->
|
||||
return registerForActivityResult(MessageBackupsCheckoutActivity.Contract()) { result ->
|
||||
if (result?.action == InAppPaymentProcessorAction.PROCESS_NEW_IN_APP_PAYMENT || result?.action == InAppPaymentProcessorAction.UPDATE_SUBSCRIPTION) {
|
||||
CreateBackupBottomSheet().show(childFragmentManager, BottomSheetUtil.STANDARD_BOTTOM_SHEET_FRAGMENT_TAG)
|
||||
}
|
||||
@@ -37,7 +37,7 @@ class CheckoutNavHostFragment : NavHostFragment() {
|
||||
InAppPaymentType.UNKNOWN -> error("Unsupported start destination")
|
||||
InAppPaymentType.ONE_TIME_GIFT -> R.id.giftFlowStartFragment
|
||||
InAppPaymentType.ONE_TIME_DONATION, InAppPaymentType.RECURRING_DONATION -> R.id.donateToSignalFragment
|
||||
InAppPaymentType.RECURRING_BACKUP -> R.id.messageBackupsFlowFragment
|
||||
InAppPaymentType.RECURRING_BACKUP -> error("Unsupported start destination")
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -83,6 +83,7 @@ class GatewaySelectorBottomSheet : DSLSettingsBottomSheetFragment() {
|
||||
|
||||
state.gatewayOrderStrategy.orderedGateways.forEach { gateway ->
|
||||
when (gateway) {
|
||||
InAppPaymentData.PaymentMethodType.GOOGLE_PLAY_BILLING -> error("Unsupported payment method.")
|
||||
InAppPaymentData.PaymentMethodType.GOOGLE_PAY -> renderGooglePayButton(state)
|
||||
InAppPaymentData.PaymentMethodType.PAYPAL -> renderPayPalButton(state)
|
||||
InAppPaymentData.PaymentMethodType.CARD -> renderCreditCardButton(state)
|
||||
|
||||
Reference in New Issue
Block a user