Skip to content

Commit

Permalink
Revert "add adding payment method to the checkout screen"
Browse files Browse the repository at this point in the history
This reverts commit 7368952.
  • Loading branch information
mtgriego committed Mar 28, 2024
1 parent 7368952 commit 5d7d18e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 248 deletions.
3 changes: 0 additions & 3 deletions app/src/main/graphql/checkout.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ mutation CompleteOnSessionCheckout($checkoutId: ID!, $paymentIntentClientSecret:
completeOnSessionCheckout(input:{ checkoutId: $checkoutId, paymentIntentClientSecret: $paymentIntentClientSecret, paymentSourceId: $paymentSourceId } ) {
checkout {
id
backing {
requiresAction
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,8 @@ open class MockApolloClientV2 : ApolloClientTypeV2 {
override fun completeOnSessionCheckout(
checkoutId: String,
paymentIntentClientSecret: String,
paymentSourceId: String?
): io.reactivex.Observable<Pair<String, Boolean>> {
paymentSourceId: String
): io.reactivex.Observable<String> {
return io.reactivex.Observable.empty()
}

Expand Down
16 changes: 7 additions & 9 deletions app/src/main/java/com/kickstarter/services/KSApolloClientV2.kt
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ interface ApolloClientTypeV2 {
fun completeOnSessionCheckout(
checkoutId: String,
paymentIntentClientSecret: String,
paymentSourceId: String?
): Observable<Pair<String, Boolean>>
paymentSourceId: String
): Observable<String>

fun createAttributionEvent(eventInput: CreateAttributionEventData): Observable<Boolean>
}
Expand Down Expand Up @@ -1565,10 +1565,10 @@ class KSApolloClientV2(val service: ApolloClient, val gson: Gson) : ApolloClient
override fun completeOnSessionCheckout(
checkoutId: String,
paymentIntentClientSecret: String,
paymentSourceId: String?
): Observable<Pair<String, Boolean>> {
paymentSourceId: String
): Observable<String> {
return Observable.defer {
val ps = PublishSubject.create<Pair<String, Boolean>>()
val ps = PublishSubject.create<String>()

this.service.mutate(
CompleteOnSessionCheckoutMutation.builder()
Expand All @@ -1585,10 +1585,8 @@ class KSApolloClientV2(val service: ApolloClient, val gson: Gson) : ApolloClient
if (response.hasErrors()) {
ps.onError(Exception(response.errors?.first()?.message))
} else {
response.data?.completeOnSessionCheckout()?.checkout()?.id()?.let { checkoutId ->
response.data?.completeOnSessionCheckout()?.checkout()?.backing()?.requiresAction()?.let { requiresAction ->
ps.onNext(Pair(checkoutId, requiresAction))
}
response.data?.completeOnSessionCheckout()?.checkout()?.id()?.let {
ps.onNext(it)
} ?: ps.onError(Exception("Checkout ID was null"))
}
ps.onComplete()
Expand Down
125 changes: 0 additions & 125 deletions app/src/main/java/com/kickstarter/ui/activities/ProjectPageActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,10 @@ import com.kickstarter.libs.utils.ApplicationUtils
import com.kickstarter.libs.utils.ViewUtils
import com.kickstarter.libs.utils.extensions.addToDisposable
import com.kickstarter.libs.utils.extensions.getEnvironment
import com.kickstarter.libs.utils.extensions.getPaymentSheetConfiguration
import com.kickstarter.libs.utils.extensions.showLatePledgeFlow
import com.kickstarter.libs.utils.extensions.toVisibility
import com.kickstarter.models.Project
import com.kickstarter.models.Reward
import com.kickstarter.models.StoredCard
import com.kickstarter.ui.IntentKey
import com.kickstarter.ui.activities.compose.projectpage.ProjectPledgeButtonAndFragmentContainer
import com.kickstarter.ui.adapters.ProjectPagerAdapter
Expand All @@ -74,7 +72,6 @@ import com.kickstarter.ui.extensions.finishWithAnimation
import com.kickstarter.ui.extensions.hideKeyboard
import com.kickstarter.ui.extensions.selectPledgeFragment
import com.kickstarter.ui.extensions.setUpConnectivityStatusCheck
import com.kickstarter.ui.extensions.showErrorToast
import com.kickstarter.ui.extensions.showSnackbar
import com.kickstarter.ui.extensions.startRootCommentsActivity
import com.kickstarter.ui.extensions.startUpdatesActivity
Expand All @@ -90,19 +87,11 @@ import com.kickstarter.viewmodels.projectpage.LatePledgeCheckoutViewModel
import com.kickstarter.viewmodels.projectpage.PagerTabConfig
import com.kickstarter.viewmodels.projectpage.ProjectPageViewModel
import com.kickstarter.viewmodels.projectpage.RewardsSelectionViewModel
import com.stripe.android.ApiResultCallback
import com.stripe.android.PaymentIntentResult
import com.stripe.android.Stripe
import com.stripe.android.StripeIntentResult
import com.stripe.android.paymentsheet.PaymentSheet
import com.stripe.android.paymentsheet.PaymentSheetResult
import com.stripe.android.paymentsheet.model.PaymentOption
import com.stripe.android.view.CardInputWidget
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.CompositeDisposable
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.launch
import timber.log.Timber

class ProjectPageActivity :
AppCompatActivity(),
Expand All @@ -129,9 +118,6 @@ class ProjectPageActivity :
private lateinit var addOnsViewModelFactory: AddOnsViewModel.Factory
private val addOnsViewModel: AddOnsViewModel by viewModels { addOnsViewModelFactory }

private lateinit var stripe: Stripe
private lateinit var flowController: PaymentSheet.FlowController

private val projectShareLabelString = R.string.project_accessibility_button_share_label
private val projectShareCopyString = R.string.project_share_twitter_message
private val projectStarConfirmationString = R.string.project_star_confirmation
Expand Down Expand Up @@ -170,16 +156,9 @@ class ProjectPageActivity :
confirmDetailsViewModelFactory = ConfirmDetailsViewModel.Factory(env)
addOnsViewModelFactory = AddOnsViewModel.Factory(env)
latePledgeCheckoutViewModelFactory = LatePledgeCheckoutViewModel.Factory(env)
stripe = requireNotNull(env.stripe())
env
}

flowController = PaymentSheet.FlowController.create(
activity = this,
paymentOptionCallback = ::onPaymentOption,
paymentResultCallback = ::onPaymentSheetResult
)

this.ksString = requireNotNull(environment?.ksString())

viewModel.configureWith(intent)
Expand Down Expand Up @@ -546,22 +525,6 @@ class ProjectPageActivity :
val userStoredCards = latePledgeCheckoutUIState.storeCards
val userEmail = latePledgeCheckoutUIState.userEmail

LaunchedEffect(Unit) {
latePledgeCheckoutViewModel.clientSecretForNewPaymentMethod.collect {
flowControllerPresentPaymentOption(it)
}
}

LaunchedEffect(Unit) {
latePledgeCheckoutViewModel.paymentRequiresAction.collect {
stripeNextAction(it)
}
}

latePledgeCheckoutViewModel.provideErrorAction { message ->
showToastError(message)
}

val pagerState = rememberPagerState(initialPage = 0, pageCount = { 4 })

this@ProjectPageActivity.onBackPressedDispatcher.addCallback {
Expand Down Expand Up @@ -651,7 +614,6 @@ class ProjectPageActivity :
latePledgeCheckoutViewModel.onPledgeButtonClicked(selectedCard = selectedCard, project = projectData.project(), totalAmount = totalAmount)
},
onAddPaymentMethodClicked = {
latePledgeCheckoutViewModel.onAddNewCardClicked(project = projectData.project(), totalAmount = totalAmount)
}
)
}
Expand Down Expand Up @@ -1123,96 +1085,9 @@ class ProjectPageActivity :
}
}

// Update the UI with the returned PaymentOption
private fun onPaymentOption(paymentOption: PaymentOption?) {
paymentOption?.let {
val storedCard = StoredCard.Builder(
lastFourDigits = paymentOption.label.takeLast(4),
resourceId = paymentOption.drawableResourceId,
clientSetupId = "-1"
).build()
latePledgeCheckoutViewModel.onNewCardSuccessfullyAdded(storedCard)
Timber.d(" ${this.javaClass.canonicalName} onPaymentOption with ${storedCard.lastFourDigits()} and ${storedCard.clientSetupId()}")
flowController.confirm()
}
}

private fun onPaymentSheetResult(paymentSheetResult: PaymentSheetResult) {
when (paymentSheetResult) {
is PaymentSheetResult.Canceled -> {
showErrorToast(
applicationContext,
binding.pledgeContainerCompose,
getString(R.string.general_error_oops)
)
}

is PaymentSheetResult.Failed -> {
val errorMessage = paymentSheetResult.error.localizedMessage ?: getString(R.string.general_error_something_wrong)
showErrorToast(
applicationContext,
binding.pledgeContainerCompose,
errorMessage
)
}

is PaymentSheetResult.Completed -> {
}
}
}

private fun stripeNextAction(it: String) {
try {
// - PaymentIntent format
if (it.contains("pi_")) {
stripe.handleNextActionForPayment(this, it)
} else {
// - SetupIntent format
stripe.handleNextActionForSetupIntent(this, it)
}
} catch (exception: Exception) {
FirebaseCrashlytics.getInstance().recordException(exception)
}
}

private fun flowControllerPresentPaymentOption(clientSecret: String) {
flowController.configureWithPaymentIntent(
paymentIntentClientSecret = clientSecret,
configuration = getPaymentSheetConfiguration(),
callback = ::onConfigured
)
}

// error is not used by is needed in the callback object
private fun onConfigured(success: Boolean, error: Throwable?) {
if (success) {
flowController.presentPaymentOptions()
} else {
showToastError()
}
}

private fun showToastError(message: String? = null) {
showErrorToast(applicationContext, binding.pledgeContainerCompose, message ?: getString(R.string.general_error_something_wrong))
}

override fun onActivityResult(requestCode: Int, resultCode: Int, intent: Intent?) {
super.onActivityResult(requestCode, resultCode, intent)
viewModel.activityResult(create(requestCode, resultCode, intent))
stripe.onPaymentResult(
requestCode, intent,
object : ApiResultCallback<PaymentIntentResult> {
override fun onSuccess(result: PaymentIntentResult) {
if (result.outcome == StripeIntentResult.Outcome.SUCCEEDED) {
// Go to thanks page
} else showToastError()
}

override fun onError(e: Exception) {
showToastError()
}
}
)
}

override fun onDestroy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ fun CheckoutScreen(
var (selectedOption, onOptionSelected) = remember {
mutableStateOf(
storedCards.firstOrNull {
project.acceptedCardType(it.type()) || it.isFromPaymentSheet()
project.acceptedCardType(
it.type()
)
}
)
}
Expand Down
Loading

0 comments on commit 5d7d18e

Please sign in to comment.