Skip to content
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

[POS][Custom payment UI] – Switch to Payment Controller in POS Totals | Base PR #12977

Open
wants to merge 150 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
150 commits
Select commit Hold shift + click to select a range
67b0866
Remove custom `if (isPos)` from controller
samiuelson Nov 21, 2024
3c6b364
Display `paymentState`s in Totals pane in POS
samiuelson Nov 21, 2024
e3ef8cd
Remove POS payment failure handling
samiuelson Nov 21, 2024
d694e4d
Return result to POS before opening Payment dialog
samiuelson Nov 21, 2024
bcfb651
Pass reader connection result (success/failure) to POS
samiuelson Nov 21, 2024
9f853ff
Throw `IllegalStateException` if POS uses old IPP flow
samiuelson Nov 22, 2024
3593cd1
Update tests in `WooPosTotalsViewModelTest`
samiuelson Nov 22, 2024
05248bf
Satisfy detekt's complaints
samiuelson Nov 22, 2024
d4b7b7a
Start POS reader connection process in `ReaderStatusChecker`
samiuelson Nov 22, 2024
641f39e
Remove POS-specific code in IPP that's unused now
samiuelson Nov 22, 2024
75aa4c0
Remove POS-specific unavailable code
samiuelson Nov 22, 2024
c67d7e2
Rename reader status to `WooPosCardReaderConnectionStatus`
samiuelson Nov 22, 2024
94532ca
Get rid of `WooPosCardReaderFacade.collectPayment()` flow
samiuelson Nov 22, 2024
1024363
Get rid of `WooPosCardReaderFacade.collectPayment()` flow
samiuelson Nov 22, 2024
d390dd4
Remove redundant code
samiuelson Nov 22, 2024
9b78db4
Remove redundant code
samiuelson Nov 22, 2024
49c4d1b
Simplify POS event names and models in IPP
samiuelson Nov 22, 2024
84c687b
Remove redundant code
samiuelson Nov 22, 2024
5c70ada
Remove unused import
samiuelson Nov 22, 2024
e73ba2b
Simplify code
samiuelson Nov 22, 2024
8488745
Remove no more accessed code
samiuelson Nov 22, 2024
7183b09
Remove unused code
samiuelson Nov 22, 2024
814ffe8
Merge branch `custom-payment-ui-5` into `custom-payment-ui-6-use-paym…
samiuelson Nov 26, 2024
41e778b
Simplify code
samiuelson Nov 26, 2024
e67149f
Remove unused code
samiuelson Nov 26, 2024
77984aa
Extract payment controller creation to factory class
samiuelson Nov 26, 2024
43c4675
Satisfy detekt's complaints
samiuelson Nov 27, 2024
1bd9981
Fix typo
samiuelson Nov 27, 2024
31271ac
Merge branch `custom-payment-ui-5` into `custom-payment-ui-6-use-paym…
samiuelson Nov 27, 2024
622dc06
Remove "collect payment" button
samiuelson Nov 30, 2024
b2c0231
Restrict cancelable states by common interface
samiuelson Nov 27, 2024
d1d6e76
Attempt to cancel a payment on back press
samiuelson Nov 28, 2024
347b3b0
Revert "Restrict cancelable states by common interface"
samiuelson Nov 28, 2024
1356746
Use custom, cancelable payment scope
samiuelson Nov 30, 2024
587a190
Update paymentScope to inherit from viewModel scope
samiuelson Dec 2, 2024
608e19f
Remove unused imports
samiuelson Dec 2, 2024
3248e1d
Remove redundant `onClear` implementation
samiuelson Dec 2, 2024
c289e15
Emit "reader not connected" error in ui state
samiuelson Dec 2, 2024
09b3d60
Add unit test:
samiuelson Dec 2, 2024
0c6d3d5
Fix code formatting
samiuelson Dec 2, 2024
15dfcc1
Remove redundant val
samiuelson Dec 2, 2024
e627ac8
Add test:
samiuelson Dec 2, 2024
edf7718
Fix typo
samiuelson Dec 2, 2024
e896a13
Add test:
samiuelson Dec 2, 2024
742dfb6
Build reader not connected error after order created
samiuelson Dec 2, 2024
92fb64b
Render error UI
samiuelson Dec 2, 2024
c98f31a
Update totals screen UI
samiuelson Dec 2, 2024
210de34
Clean up code
samiuelson Dec 2, 2024
ffe29f8
Collect payment automatically after reader connects
samiuelson Dec 2, 2024
259e98e
Satisfy detekt's complaints
samiuelson Dec 2, 2024
9584d89
Add unit test:
samiuelson Dec 3, 2024
b29d02b
Add unit tests:
samiuelson Dec 3, 2024
d0dfeb5
Clean up code
samiuelson Dec 3, 2024
6db93e2
Clean up code
samiuelson Dec 3, 2024
a4f61a4
Update background colors
samiuelson Dec 3, 2024
a2ee75a
Show full screen "Payment processing" state
samiuelson Dec 3, 2024
6aecb6f
Clean up code
samiuelson Dec 3, 2024
4192a2a
Add preview
samiuelson Dec 3, 2024
5c325b6
Clean up code
samiuelson Dec 3, 2024
e9b3f20
Improve preview
samiuelson Dec 3, 2024
aa1a321
Create basic payment failed screen
samiuelson Dec 3, 2024
cde0db7
Show payment failed screen
samiuelson Dec 3, 2024
01b8bab
Update tests
samiuelson Dec 4, 2024
1c2ee96
Satisfy detekt's complaints
samiuelson Dec 4, 2024
502cb4e
Tune up payment failed composable
samiuelson Dec 4, 2024
60c7434
Tune up payment failed composable
samiuelson Dec 4, 2024
ebd6543
Tune up payment failed composable
samiuelson Dec 4, 2024
e73501b
Rename states
samiuelson Dec 4, 2024
56651e2
Ensure failed payment state is always full screen
samiuelson Dec 4, 2024
e05fafd
Implement failed payment "retry" action
samiuelson Dec 4, 2024
d3160ec
Implement failed payment "exit order" action
samiuelson Dec 4, 2024
3fc89e6
Move debug Totals payment state to the top
samiuelson Dec 4, 2024
84f825f
Add home VM test:
samiuelson Dec 4, 2024
447a9e8
Add home VM test:
samiuelson Dec 4, 2024
7ca6439
Add home VM test:
samiuelson Dec 4, 2024
b0d9b39
Add home VM test:
samiuelson Dec 4, 2024
9dad874
Tweak heights of totals boxes
samiuelson Dec 4, 2024
810ea01
Fix typos in test method names
samiuelson Dec 4, 2024
6abc26e
Add Cart VM test:
samiuelson Dec 4, 2024
e1eb05c
Add Totals VM test:
samiuelson Dec 4, 2024
6737f15
Add Totals VM test:
samiuelson Dec 4, 2024
3c3c219
Add Totals VM test:
samiuelson Dec 4, 2024
34d84e5
Add Totals VM test:
samiuelson Dec 4, 2024
2439997
Ensure Cart is cleared in case state is restored
samiuelson Dec 4, 2024
62684c4
Clean up code
samiuelson Dec 4, 2024
77f74b7
Satisfy detekt's complaints
samiuelson Dec 4, 2024
e499d89
Manage payment coroutine scope internally in controller
samiuelson Dec 5, 2024
6046d90
Clean up code
samiuelson Dec 5, 2024
ad83973
Remove unused code
samiuelson Dec 5, 2024
8f715b4
Remove delay(1) from tests
samiuelson Dec 5, 2024
51eb2b2
Use WooPosColors for `paymentProcessingBackground`
samiuelson Dec 5, 2024
100e988
Use WooPosColors for `totalsBackground`
samiuelson Dec 5, 2024
8b4f5f7
Replace hardcoded error message with real one
samiuelson Dec 5, 2024
ba0bcdd
Satisfy detekt's complaints
samiuelson Dec 5, 2024
cf8d030
Get order from db instead of caching in memory
samiuelson Dec 6, 2024
5b12dd8
Improve failed payment "retry" handling
samiuelson Dec 6, 2024
6c35050
Satisfy detekt's complaints
samiuelson Dec 6, 2024
6c2a7e7
Update string value
samiuelson Dec 6, 2024
8040ff9
Handle PaymentCollecting payment state during retry
samiuelson Dec 6, 2024
55925b2
Handle `PaymentCollecting` payment state received during retry
samiuelson Dec 6, 2024
2703d6f
Clean up code
samiuelson Dec 6, 2024
220a050
Implement basic UI for reader initialization states
samiuelson Dec 9, 2024
b3cff58
Tune up the UI
samiuelson Dec 9, 2024
9387be6
Satisfy detekt's complaints
samiuelson Dec 9, 2024
84342ed
Revert mistaken rename
samiuelson Dec 9, 2024
11cf2c2
Revert mistaken rename
samiuelson Dec 9, 2024
e992535
Extract strings to res
samiuelson Dec 10, 2024
ae393fd
Extract strings to res
samiuelson Dec 10, 2024
9f62374
Fix typo
samiuelson Dec 10, 2024
be72c83
Update tests
samiuelson Dec 10, 2024
6a6be05
Show subtitles for `processing` and `capturing` states
samiuelson Dec 10, 2024
052db51
Show lottie animations for payment capturing and processing
samiuelson Dec 10, 2024
f919b57
Revert accidental gradle.properties changes
samiuelson Dec 10, 2024
4de5bae
Animate "reader ready" state in Totals
samiuelson Dec 10, 2024
54e65c6
Revert accidental change to gradle.properties
samiuelson Dec 11, 2024
b183afb
Revert accidental change to gradle.properties
samiuelson Dec 11, 2024
d82111c
Update unit tests
samiuelson Dec 11, 2024
2f4ab2e
Add tests:
samiuelson Dec 11, 2024
0866ff8
Add payment processing screen enter animation
samiuelson Dec 11, 2024
bebd92a
Satisfy detekt's complaints
samiuelson Dec 11, 2024
f388120
Tune up animation
samiuelson Dec 11, 2024
d79fe17
Clean up code
samiuelson Dec 11, 2024
7d0bbf0
Clean up tests
samiuelson Dec 11, 2024
8768414
Remove redundant code
samiuelson Dec 11, 2024
9171931
Remove redundant code
samiuelson Dec 11, 2024
a16613c
Satisfy detekt's complaints
samiuelson Dec 11, 2024
d3b8dfa
Merge pull request #13037 from woocommerce/custom-payment-ui-7-paymen…
samiuelson Dec 11, 2024
b96a66b
Merge pull request #13038 from woocommerce/custom-payment-iu-remove-c…
samiuelson Dec 11, 2024
ca31607
Give color a name
samiuelson Dec 11, 2024
e90dfa3
Merge branch `custom-payment-ui-6-use-payment-controller-in-pos`
samiuelson Dec 11, 2024
4c58cf9
Merge pull request #13053 from woocommerce/custom-payment-ui-8-reader…
samiuelson Dec 11, 2024
5aa3f0b
Merge branch `custom-payment-ui-6-use-payment-controller-in-pos`
samiuelson Dec 11, 2024
1c2ddee
Clean up tests after merge
samiuelson Dec 11, 2024
8b21898
Crash in case order is null illegally
samiuelson Dec 11, 2024
41b3dc8
Merge pull request #13057 from woocommerce/custom-payment-ui-9-paymen…
samiuelson Dec 11, 2024
06faaaa
Merge branch `custom-payment-ui-6-use-payment-controller-in-pos`
samiuelson Dec 11, 2024
ec2b4ab
Merge pull request #13090 from woocommerce/custom-payment-ui-loading-…
samiuelson Dec 11, 2024
bbf8fbe
Merge branch `custom-payment-ui-6-use-payment-controller-in-pos`
samiuelson Dec 11, 2024
93415d7
Merge branch `trunk`
samiuelson Dec 12, 2024
6ead51b
Merge branch `trunk`
samiuelson Dec 12, 2024
0aed6e7
Merge branch `custom-payment-ui-6-use-payment-controller-in-pos`
samiuelson Dec 12, 2024
fadb13d
Rename Processing UI state to InProgress
samiuelson Dec 12, 2024
b1a4dd5
Merge branch 'trunk' into custom-payment-ui-6-use-payment-controller-…
samiuelson Dec 12, 2024
089bc61
Merge branch 'custom-payment-ui-6-use-payment-controller-in-pos' into…
samiuelson Dec 12, 2024
e9d9360
Merge pull request #13100 from woocommerce/custom-payment-ui-payment-…
malinajirka Dec 12, 2024
a2054fc
Remove unused drawable
samiuelson Dec 12, 2024
085cf3d
Update release notes
samiuelson Dec 12, 2024
b90cc07
Extract `isTTPPaymentInProgress` to property delegate
samiuelson Dec 12, 2024
72e3fcb
Merge branch 'trunk' into custom-payment-ui-6-use-payment-controller-…
samiuelson Dec 12, 2024
1c90560
Satisfy detekt's complaints
samiuelson Dec 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,10 @@ class CardReaderConnectDialogFragment : PaymentsBaseDialogFragment(R.layout.card
result = event.data as Boolean,
)
}
is CardReaderConnectEvent.PopBackStackForWooPOS -> {
is CardReaderConnectEvent.ReturnToWooPos -> {
parentFragmentManager.setFragmentResult(
WooPosCardReaderActivity.WOO_POS_CARD_CONNECTION_REQUEST_KEY,
Bundle(),
WooPosCardReaderActivity.WOO_POS_CARD_PAYMENT_REQUEST_KEY,
Bundle()
)
}
is CardReaderConnectEvent.ShowToast ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ sealed class CardReaderConnectEvent : MultiLiveEvent.Event() {

data class OpenGenericWebView(val url: String) : CardReaderConnectEvent()

data object PopBackStackForWooPOS : CardReaderConnectEvent()
data object ReturnToWooPos : MultiLiveEvent.Event()
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ import com.woocommerce.android.ui.payments.cardreader.connect.CardReaderConnectE
import com.woocommerce.android.ui.payments.cardreader.connect.CardReaderConnectEvent.OpenLocationSettings
import com.woocommerce.android.ui.payments.cardreader.connect.CardReaderConnectEvent.OpenPermissionsSettings
import com.woocommerce.android.ui.payments.cardreader.connect.CardReaderConnectEvent.OpenWPComWebView
import com.woocommerce.android.ui.payments.cardreader.connect.CardReaderConnectEvent.PopBackStackForWooPOS
import com.woocommerce.android.ui.payments.cardreader.connect.CardReaderConnectEvent.RequestBluetoothRuntimePermissions
import com.woocommerce.android.ui.payments.cardreader.connect.CardReaderConnectEvent.RequestEnableBluetooth
import com.woocommerce.android.ui.payments.cardreader.connect.CardReaderConnectEvent.RequestLocationPermissions
import com.woocommerce.android.ui.payments.cardreader.connect.CardReaderConnectEvent.ReturnToWooPos
import com.woocommerce.android.ui.payments.cardreader.connect.CardReaderConnectEvent.ShowCardReaderTutorial
import com.woocommerce.android.ui.payments.cardreader.connect.CardReaderConnectEvent.ShowToast
import com.woocommerce.android.ui.payments.cardreader.connect.CardReaderConnectEvent.ShowToastString
Expand All @@ -59,9 +59,6 @@ import com.woocommerce.android.ui.payments.cardreader.connect.CardReaderConnectV
import com.woocommerce.android.ui.payments.cardreader.connect.CardReaderConnectViewState.MultipleExternalReadersFoundState
import com.woocommerce.android.ui.payments.cardreader.connect.CardReaderConnectViewState.ScanningFailedState
import com.woocommerce.android.ui.payments.cardreader.onboarding.CardReaderFlowParam
import com.woocommerce.android.ui.payments.cardreader.onboarding.CardReaderFlowParam.CardReadersHub
import com.woocommerce.android.ui.payments.cardreader.onboarding.CardReaderFlowParam.PaymentOrRefund.Payment
import com.woocommerce.android.ui.payments.cardreader.onboarding.CardReaderFlowParam.PaymentOrRefund.Refund
import com.woocommerce.android.ui.payments.cardreader.onboarding.CardReaderOnboardingChecker
import com.woocommerce.android.ui.payments.cardreader.onboarding.CardReaderType.BUILT_IN
import com.woocommerce.android.ui.payments.cardreader.onboarding.CardReaderType.EXTERNAL
Expand Down Expand Up @@ -527,25 +524,23 @@ class CardReaderConnectViewModel @Inject constructor(
}

private fun exitFlow(connected: Boolean) {
if (!connected) {
when (val param = arguments.cardReaderFlowParam) {
is CardReadersHub, is Refund -> triggerEvent(ExitWithResult(false))
is Payment -> {
if (param.paymentType == Payment.PaymentType.WOO_POS) {
returnToWooPos()
} else {
triggerEvent(ExitWithResult(false))
}
}
CardReaderFlowParam.WooPosConnection -> returnToWooPos()
}
val param = arguments.cardReaderFlowParam
if (param is CardReaderFlowParam.WooPosConnection) {
returnToWooPos()
} else if (!connected) {
samiuelson marked this conversation as resolved.
Show resolved Hide resolved
triggerEvent(ExitWithResult(false))
} else {
triggerEvent(ShowCardReaderTutorial(arguments.cardReaderFlowParam, arguments.cardReaderType))
triggerEvent(
ShowCardReaderTutorial(
arguments.cardReaderFlowParam,
arguments.cardReaderType
)
)
}
}

private fun returnToWooPos() {
triggerEvent(PopBackStackForWooPOS)
triggerEvent(ReturnToWooPos)
}

private fun storeConnectedReader(cardReader: CardReader) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,6 @@ class CardReaderPaymentController(

private var refetchOrderJob: Job? = null

private val CardReaderFlowParam.PaymentOrRefund.isPOS: Boolean
get() = this is CardReaderFlowParam.PaymentOrRefund.Payment &&
this.paymentType == CardReaderFlowParam.PaymentOrRefund.Payment.PaymentType.WOO_POS

private val _event: MutableSharedFlow<CardReaderPaymentEvent> = MutableSharedFlow()
val event: Flow<CardReaderPaymentEvent> = _event

Expand Down Expand Up @@ -459,20 +455,10 @@ class CardReaderPaymentController(
) {
paymentReceiptHelper.storeReceiptUrl(orderId, paymentStatus.receiptUrl)
appPrefs.setCardReaderSuccessfulPaymentTime()
if (paymentOrRefund.isPOS) {
samiuelson marked this conversation as resolved.
Show resolved Hide resolved
scope.launch {
syncOrderStatus(orderId)
triggerEvent(CardReaderPaymentEvent.Exit)
}
} else {
triggerEvent(CardReaderPaymentEvent.PlaySuccessfulPaymentSound)
showPaymentSuccessfulState()
reFetchOrder()
}
}

private suspend fun syncOrderStatus(orderId: Long) {
orderRepository.fetchOrderById(orderId)
triggerEvent(CardReaderPaymentEvent.PlaySuccessfulPaymentSound)
showPaymentSuccessfulState()
reFetchOrder()
}

@VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import com.woocommerce.android.R
import com.woocommerce.android.ui.payments.PaymentsBaseDialogFragment
import com.woocommerce.android.ui.payments.cardreader.statuschecker.CardReaderStatusCheckerViewModel.StatusCheckerEvent.ReturnToWooPos
import com.woocommerce.android.ui.woopos.cardreader.WooPosCardReaderActivity
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
Expand Down Expand Up @@ -66,6 +68,12 @@ class CardReaderStatusCheckerDialogFragment : PaymentsBaseDialogFragment(R.layou
)
)
}
is ReturnToWooPos -> {
parentFragmentManager.setFragmentResult(
WooPosCardReaderActivity.WOO_POS_CARD_PAYMENT_REQUEST_KEY,
Bundle()
)
}
else -> event.isHandled = false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,7 @@ class CardReaderStatusCheckerViewModel
val cardReaderOnboardingParams: CardReaderOnboardingParams,
val cardReaderType: CardReaderType,
) : MultiLiveEvent.Event()

data object ReturnToWooPos : MultiLiveEvent.Event()
samiuelson marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import com.woocommerce.android.extensions.navigateSafely
import com.woocommerce.android.ui.payments.PaymentsBaseDialogFragment
import com.woocommerce.android.ui.payments.cardreader.onboarding.CardReaderFlowParam
import com.woocommerce.android.ui.payments.cardreader.onboarding.CardReaderType.BUILT_IN
import com.woocommerce.android.ui.woopos.cardreader.WooPosCardReaderActivity
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

Expand Down Expand Up @@ -60,12 +59,7 @@ class CardReaderTutorialDialogFragment : PaymentsBaseDialogFragment(R.layout.car
private fun navigateNext() {
when (val param = args.cardReaderFlowParam) {
is CardReaderFlowParam.CardReadersHub -> findNavController().popBackStack()
is CardReaderFlowParam.WooPosConnection -> {
parentFragmentManager.setFragmentResult(
WooPosCardReaderActivity.WOO_POS_CARD_CONNECTION_REQUEST_KEY,
Bundle(),
)
}
is CardReaderFlowParam.WooPosConnection -> error("Not supported param: $param")
is CardReaderFlowParam.PaymentOrRefund -> {
val action = CardReaderTutorialDialogFragmentDirections
.actionCardReaderTutorialDialogFragmentToCardReaderPaymentDialogFragment(param, args.cardReaderType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ data class NavigateToCardReaderPaymentFlow(
val cardReaderType: CardReaderType
) : MultiLiveEvent.Event()

data class SkipScreenInPosAndNavigateToCardReaderPaymentFlow(
samiuelson marked this conversation as resolved.
Show resolved Hide resolved
val cardReaderFlowParam: CardReaderFlowParam.PaymentOrRefund.Payment,
val cardReaderType: CardReaderType
) : MultiLiveEvent.Event()

data class NavigateToCardReaderRefundFlow(
val cardReaderFlowParam: CardReaderFlowParam.PaymentOrRefund.Refund,
val cardReaderType: CardReaderType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import com.woocommerce.android.ui.payments.methodselection.SelectPaymentMethodVi
import com.woocommerce.android.ui.payments.scantopay.ScanToPayDialogFragment
import com.woocommerce.android.ui.payments.taptopay.summary.TapToPaySummaryFragment
import com.woocommerce.android.ui.woopos.cardreader.WooPosCardReaderActivity
import com.woocommerce.android.ui.woopos.cardreader.WooPosCardReaderPaymentStatus
import com.woocommerce.android.util.ChromeCustomTabUtils
import com.woocommerce.android.util.UiHelpers
import com.woocommerce.android.viewmodel.MultiLiveEvent.Event.ShowDialog
Expand Down Expand Up @@ -209,18 +208,6 @@ class SelectPaymentMethodFragment : BaseFragment(R.layout.fragment_select_paymen
findNavController().navigate(action)
}

is SkipScreenInPosAndNavigateToCardReaderPaymentFlow -> {
if (findNavController().currentDestination?.id == R.id.selectPaymentMethodFragment) {
findNavController().navigate(
SelectPaymentMethodFragmentDirections
.actionSelectPaymentMethodFragmentToCardReaderPaymentFlow(
event.cardReaderFlowParam,
event.cardReaderType
)
)
}
}

is NavigateToCardReaderHubFlow -> {
val action =
SelectPaymentMethodFragmentDirections.actionSelectPaymentMethodFragmentToCardReaderHubFlow(
Expand Down Expand Up @@ -293,24 +280,13 @@ class SelectPaymentMethodFragment : BaseFragment(R.layout.fragment_select_paymen
is ReturnResultToWooPos -> {
parentFragmentManager.setFragmentResult(
WooPosCardReaderActivity.WOO_POS_CARD_PAYMENT_REQUEST_KEY,
Bundle().apply {
putParcelable(
WooPosCardReaderActivity.WOO_POS_CARD_PAYMENT_RESULT_KEY,
event.asWooPosCardReaderPaymentResult(),
)
}
Bundle()
)
}
}
}
}

private fun ReturnResultToWooPos.asWooPosCardReaderPaymentResult() =
when (this) {
is ReturnResultToWooPos.Success -> WooPosCardReaderPaymentStatus.Success
else -> WooPosCardReaderPaymentStatus.Failure
}

private fun setupResultHandlers() {
handleDialogResult<Boolean>(
key = CardReaderConnectDialogFragment.KEY_CONNECT_TO_READER_RESULT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class SelectPaymentMethodViewModel @Inject constructor(

when (param.paymentType) {
SIMPLE, ORDER, ORDER_CREATION, TRY_TAP_TO_PAY -> showPaymentState()
WOO_POS -> skipScreenDuringPosFlow()
WOO_POS -> error("Unsupported card reader flow param: $param")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like we can and we should remove this param completely, wdyt?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we can remove it because we want to mark transactions as made in POS in PaymentIntent metadata, in order to track POS TPV (pffQ75-1aV-p2).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I am missing something, but we build payment intent using code from the cardreader module, which you are using via CardReaderPaymentController. So, basically, we will need to pass our "POS" option via that start and then to collectPaymentFlow method. While WOO_POS used to be used only to do different adjustments to the reused IPP flow

}
}
Unit
Expand Down Expand Up @@ -306,10 +306,6 @@ class SelectPaymentMethodViewModel @Inject constructor(
}
}

private fun skipScreenDuringPosFlow() {
triggerEvent(SkipScreenInPosAndNavigateToCardReaderPaymentFlow(cardReaderPaymentFlowParam, EXTERNAL))
}

fun onTapToPayClicked() {
launch {
trackPaymentMethodSelection(VALUE_SIMPLE_PAYMENTS_COLLECT_CARD, VALUE_CARD_READER_TYPE_BUILT_IN)
Expand All @@ -325,6 +321,10 @@ class SelectPaymentMethodViewModel @Inject constructor(
flow = cardReaderPaymentFlowParam.toAnalyticsFlowName(),
)
}
if (cardReaderPaymentFlowParam.paymentType == WOO_POS) {
val result = if (connected) ReturnResultToWooPos.Success else ReturnResultToWooPos.Failure
triggerEvent(result)
}
}

fun onCardReaderPaymentCompleted() {
Expand All @@ -342,19 +342,10 @@ class SelectPaymentMethodViewModel @Inject constructor(
source = AnalyticsTracker.VALUE_SIMPLE_PAYMENTS_SOURCE_PAYMENT_METHOD,
flow = cardReaderPaymentFlowParam.toAnalyticsFlowName(),
)
handleWooPosPaymentFailure()
}
}
}

private fun handleWooPosPaymentFailure() {
// In case payment was initiated from the Woo POS mode, we need to propagate the payment
// result back, to close the SelectPaymentMethodFragment and handle failure on the Woo POS end.
if (cardReaderPaymentFlowParam.paymentType == WOO_POS) {
triggerEvent(ReturnResultToWooPos.Failure)
}
}

fun onScanToPayClicked() {
launch {
trackPaymentMethodSelection(AnalyticsTracker.VALUE_SCAN_TO_PAY_PAYMENT_FLOW)
Expand Down Expand Up @@ -478,7 +469,7 @@ class SelectPaymentMethodViewModel @Inject constructor(
SIMPLE -> NavigateBackToHub(CardReadersHub())
TRY_TAP_TO_PAY -> NavigateToTapToPaySummary(order.first())
ORDER, ORDER_CREATION -> NavigateBackToOrderList(order.first())
WOO_POS -> ReturnResultToWooPos.Success
WOO_POS -> error("Woo POS is expected to use CardReaderPaymentController directly")
}
)
}
Expand Down
Loading
Loading