-
Notifications
You must be signed in to change notification settings - Fork 986
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MBL-1573: Checkout Screen (Pledge and update payment method flows for crowdfund) #2096
Merged
+674
−9
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3c24ab5
- New screen for crowdfund checkout
Arkariang 261e498
- New screen loading saved payment methods and user information
Arkariang 949c64a
- Able to pledge successfully
Arkariang 9a59f75
- Create Backing mutation called
Arkariang 64d6fd8
- Recover from bug, selected shipping rule was not being sent to addO…
Arkariang a586382
- Pledge & change payment method already in place
Arkariang 717fdc1
- Tests for FragmentSelection on Checkout Flow
Arkariang 7a714cc
Merge branch 'feature/pledge-redemption-ml1' of github.com:kickstarte…
Arkariang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ package com.kickstarter.services.mutations | |
|
||
import com.kickstarter.models.Backing | ||
import com.kickstarter.models.Reward | ||
import com.kickstarter.models.StoredCard | ||
import com.kickstarter.models.extensions.isFromPaymentSheet | ||
|
||
data class UpdateBackingData( | ||
val backing: Backing, | ||
|
@@ -11,3 +13,41 @@ data class UpdateBackingData( | |
val paymentSourceId: String? = null, | ||
val intentClientSecret: String? = null | ||
) | ||
|
||
/** | ||
* Obtain the data model input that will be send to UpdateBacking mutation | ||
* - When updating payment method with a new payment method using payment sheet | ||
* - When updating payment method with a previously existing payment source | ||
* - Updating any other parameter like location, amount or rewards | ||
*/ | ||
fun getUpdateBackingData( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Package level method |
||
backing: Backing, | ||
amount: String? = null, | ||
locationId: String? = null, | ||
rewardsList: List<Reward> = listOf(), | ||
pMethod: StoredCard? = null | ||
): UpdateBackingData { | ||
return pMethod?.let { card -> | ||
// - Updating the payment method, a new one from PaymentSheet or already existing one | ||
if (card.isFromPaymentSheet()) UpdateBackingData( | ||
backing, | ||
amount, | ||
locationId, | ||
rewardsList, | ||
intentClientSecret = card.clientSetupId() | ||
) | ||
else UpdateBackingData( | ||
backing, | ||
amount, | ||
locationId, | ||
rewardsList, | ||
paymentSourceId = card.id() | ||
) | ||
// - Updating amount, location or rewards | ||
} ?: UpdateBackingData( | ||
backing, | ||
amount, | ||
locationId, | ||
rewardsList | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
app/src/main/java/com/kickstarter/ui/fragments/CrowdfundCheckoutFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package com.kickstarter.ui.fragments | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.ui.platform.ViewCompositionStrategy | ||
import androidx.fragment.app.Fragment | ||
import androidx.fragment.app.viewModels | ||
import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
import com.kickstarter.R | ||
import com.kickstarter.databinding.FragmentCrowdfundCheckoutBinding | ||
import com.kickstarter.libs.utils.RewardUtils | ||
import com.kickstarter.libs.utils.extensions.getEnvironment | ||
import com.kickstarter.models.Project | ||
import com.kickstarter.models.Reward | ||
import com.kickstarter.ui.activities.compose.projectpage.CheckoutScreen | ||
import com.kickstarter.ui.compose.designsystem.KSTheme | ||
import com.kickstarter.ui.compose.designsystem.KickstarterApp | ||
import com.kickstarter.ui.data.PledgeReason | ||
import com.kickstarter.ui.extensions.showErrorToast | ||
import com.kickstarter.ui.fragments.PledgeFragment.PledgeDelegate | ||
import com.kickstarter.viewmodels.projectpage.CheckoutUIState | ||
import com.kickstarter.viewmodels.projectpage.CrowdfundCheckoutViewModel | ||
import com.kickstarter.viewmodels.projectpage.CrowdfundCheckoutViewModel.Factory | ||
|
||
class CrowdfundCheckoutFragment : Fragment() { | ||
|
||
private var binding: FragmentCrowdfundCheckoutBinding? = null | ||
|
||
private lateinit var viewModelFactory: Factory | ||
private val viewModel: CrowdfundCheckoutViewModel by viewModels { | ||
viewModelFactory | ||
} | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||
super.onCreateView(inflater, container, savedInstanceState) | ||
binding = FragmentCrowdfundCheckoutBinding.inflate(inflater, container, false) | ||
|
||
val view = binding?.root | ||
binding?.composeView?.apply { | ||
val environment = this.context.getEnvironment()?.let { env -> | ||
viewModelFactory = Factory(env, bundle = arguments) | ||
viewModel.provideBundle(arguments) | ||
env | ||
} | ||
|
||
viewModel.provideErrorAction { message -> | ||
activity?.runOnUiThread { | ||
showErrorToast(context, this, message ?: getString(R.string.general_error_something_wrong)) | ||
} | ||
} | ||
|
||
// Dispose of the Composition when the view's LifecycleOwner is destroyed | ||
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) | ||
// Compose world | ||
setContent { | ||
KickstarterApp( | ||
useDarkTheme = true | ||
) { | ||
|
||
val checkoutStates = viewModel.crowdfundCheckoutUIState.collectAsStateWithLifecycle( | ||
initialValue = CheckoutUIState() | ||
).value | ||
|
||
val rwList = checkoutStates.selectedRewards | ||
val email = checkoutStates.userEmail | ||
val storedCards = checkoutStates.storeCards | ||
val isLoading = checkoutStates.isLoading | ||
val shippingAmount = checkoutStates.shippingAmount | ||
val totalAmount = checkoutStates.checkoutTotal | ||
val shippingRule = checkoutStates.shippingRule | ||
val bonus = checkoutStates.bonusAmount | ||
|
||
val pledgeData = viewModel.getPledgeData() | ||
val pledgeReason = viewModel.getPledgeReason() ?: PledgeReason.PLEDGE | ||
val project = pledgeData?.projectData()?.project() ?: Project.builder().build() | ||
val selectedRw = pledgeData?.reward() ?: Reward.builder().build() | ||
|
||
val checkoutSuccess = viewModel.checkoutResultState.collectAsStateWithLifecycle().value | ||
val id = checkoutSuccess.first?.id() ?: -1 | ||
|
||
LaunchedEffect(id) { | ||
if (id > 0) { | ||
if (pledgeReason == PledgeReason.PLEDGE) | ||
(activity as PledgeDelegate?)?.pledgeSuccessfullyCreated(checkoutSuccess) | ||
if (pledgeReason == PledgeReason.UPDATE_PAYMENT) | ||
(activity as PledgeDelegate?)?.pledgePaymentSuccessfullyUpdated() | ||
if (pledgeReason == PledgeReason.UPDATE_REWARD || pledgeReason == PledgeReason.UPDATE_PLEDGE) | ||
(activity as PledgeDelegate?)?.pledgeSuccessfullyUpdated() | ||
} | ||
} | ||
|
||
KSTheme { | ||
// TODO: update to display local pickup | ||
// TODO: hide bonus support if 0 | ||
CheckoutScreen( | ||
rewardsList = rwList.map { Pair(it.title() ?: "", it.pledgeAmount().toString()) }, | ||
environment = requireNotNull(environment), | ||
shippingAmount = shippingAmount, | ||
selectedReward = selectedRw, | ||
currentShippingRule = shippingRule, | ||
totalAmount = totalAmount, | ||
totalBonusSupport = bonus, | ||
storedCards = storedCards, | ||
project = project, | ||
email = email, | ||
pledgeReason = pledgeReason, | ||
rewardsHaveShippables = rwList.any { | ||
RewardUtils.isShippable(it) | ||
}, | ||
onPledgeCtaClicked = { | ||
viewModel.pledge() | ||
}, | ||
isLoading = isLoading, | ||
newPaymentMethodClicked = {}, | ||
onDisclaimerItemClicked = {}, | ||
onAccountabilityLinkClicked = {}, | ||
onChangedPaymentMethod = { paymentMethodSelected -> | ||
viewModel.userChangedPaymentMethodSelected(paymentMethodSelected) | ||
} | ||
) | ||
} | ||
} | ||
} | ||
} | ||
return view | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Notice here we can decide which crowdfund flows will use the new UI + VM