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 all 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
2 changes: 1 addition & 1 deletion RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
- [*] When entering a wrong WordPress.com account for login, retrying will bring the step back to the email input screen [https://github.com/woocommerce/woocommerce-android/pull/13024]
- [Internal] Replaces a function in WCSSRExt that then removes the need for commons-io dependency. [https://github.com/woocommerce/woocommerce-android/pull/13073]
- [Internal] Removes coupons feature announcement banner [https://github.com/woocommerce/woocommerce-android/pull/13077]

- [Internal] Updated androidx-compose-bom to 2024.09.00 [https://github.com/woocommerce/woocommerce-android/pull/13060]
- [**] Improved UX of card reader payment flow in Point of Sale, allowing faster payment collection [https://github.com/woocommerce/woocommerce-android/pull/12977]

-----
21.2
Expand Down
3 changes: 3 additions & 0 deletions WooCommerce/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,9 @@ dependencies {

coreLibraryDesugaring(libs.android.desugar)

// Lottie
implementation(libs.lottie.compose)

// CameraX
implementation(libs.androidx.camera.camera2)
implementation(libs.androidx.camera.lifecycle)
Expand Down
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 @@ -523,25 +520,21 @@ 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()
}
} else {
triggerEvent(ShowCardReaderTutorial(arguments.cardReaderFlowParam, arguments.cardReaderType))
val param = arguments.cardReaderFlowParam
when {
param is CardReaderFlowParam.WooPosConnection -> returnToWooPos()
!connected -> triggerEvent(ExitWithResult(false))
else -> 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 @@ -5,7 +5,6 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.asLiveData
import androidx.lifecycle.map
import androidx.lifecycle.viewModelScope
import com.woocommerce.android.AppPrefs
import com.woocommerce.android.cardreader.CardReaderManager
import com.woocommerce.android.cardreader.payments.PaymentData
Expand Down Expand Up @@ -68,7 +67,6 @@ class CardReaderPaymentViewModel @Inject constructor(
}

private val paymentController = CardReaderPaymentController(
scope = viewModelScope,
cardReaderManager = cardReaderManager,
orderRepository = orderRepository,
selectedSite = selectedSite,
Expand Down Expand Up @@ -120,15 +118,12 @@ class CardReaderPaymentViewModel @Inject constructor(
fun retry(orderId: Long, billingEmail: String, paymentData: PaymentData, amountLabel: String) =
paymentController.retry(orderId, billingEmail, paymentData, amountLabel)

@VisibleForTesting
fun reFetchOrder() = paymentController.reFetchOrder()

fun onViewCreated() = paymentController.onViewCreated()

fun onPrintResult(result: PrintJobResult) = paymentController.onPrintResult(result)

@VisibleForTesting(otherwise = VisibleForTesting.PROTECTED)
public override fun onCleared() = paymentController.onCleared()
public override fun onCleared() = paymentController.stop()

fun onBackPressed() = paymentController.onBackPressed()
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,16 @@ import com.woocommerce.android.util.PrintHtmlHelper.PrintJobResult.FAILED
import com.woocommerce.android.util.PrintHtmlHelper.PrintJobResult.STARTED
import com.woocommerce.android.util.WooLog
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.wordpress.android.fluxc.store.WooCommerceStore
Expand All @@ -88,7 +92,6 @@ private const val CANADA_FEE_FLAT_IN_CENTS = 15L

@Suppress("LongParameterList", "LargeClass")
class CardReaderPaymentController(
private val scope: CoroutineScope,
private val cardReaderManager: CardReaderManager,
private val orderRepository: OrderDetailRepository,
private val selectedSite: SelectedSite,
Expand All @@ -113,6 +116,8 @@ class CardReaderPaymentController(
private val cardReaderType: CardReaderType,
private val isTTPPaymentInProgress: KMutableProperty0<Boolean>,
) {
private var scope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)

private val _paymentState: MutableStateFlow<CardReaderPaymentOrRefundState> =
MutableStateFlow(CardReaderPaymentState.LoadingData(::onCancelPaymentFlow))
val paymentState: StateFlow<CardReaderPaymentOrRefundState> = _paymentState
Expand All @@ -123,10 +128,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 All @@ -135,6 +136,8 @@ class CardReaderPaymentController(
}

fun start() {
scope.cancel()
scope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
if (cardReaderManager.readerStatus.value is CardReaderStatus.Connected) {
startFlowWhenReaderConnected()
} else {
Expand Down Expand Up @@ -457,20 +460,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 Expand Up @@ -792,10 +785,11 @@ class CardReaderPaymentController(
}
}

fun onCleared() {
fun stop() {
paymentDataForRetry?.let {
cardReaderManager.cancelPayment(it)
}
scope.cancel()
}

fun onBackPressed() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package com.woocommerce.android.ui.payments.cardreader.payment.controller

import com.woocommerce.android.AppPrefs
import com.woocommerce.android.cardreader.CardReaderManager
import com.woocommerce.android.tools.SelectedSite
import com.woocommerce.android.ui.orders.details.OrderDetailRepository
import com.woocommerce.android.ui.payments.cardreader.CardReaderCountryConfigProvider
import com.woocommerce.android.ui.payments.cardreader.onboarding.CardReaderFlowParam.PaymentOrRefund
import com.woocommerce.android.ui.payments.cardreader.onboarding.CardReaderFlowParam.PaymentOrRefund.Payment.PaymentType
import com.woocommerce.android.ui.payments.cardreader.onboarding.CardReaderOnboardingChecker
import com.woocommerce.android.ui.payments.cardreader.onboarding.CardReaderType
import com.woocommerce.android.ui.payments.cardreader.payment.CardReaderInteracRefundErrorMapper
import com.woocommerce.android.ui.payments.cardreader.payment.CardReaderInteracRefundableChecker
import com.woocommerce.android.ui.payments.cardreader.payment.CardReaderPaymentCollectibilityChecker
import com.woocommerce.android.ui.payments.cardreader.payment.CardReaderPaymentErrorMapper
import com.woocommerce.android.ui.payments.cardreader.payment.CardReaderPaymentOrderHelper
import com.woocommerce.android.ui.payments.receipt.PaymentReceiptHelper
import com.woocommerce.android.ui.payments.receipt.PaymentReceiptShare
import com.woocommerce.android.ui.payments.tracking.CardReaderTrackingInfoKeeper
import com.woocommerce.android.ui.payments.tracking.PaymentsFlowTracker
import com.woocommerce.android.util.CoroutineDispatchers
import com.woocommerce.android.util.CurrencyFormatter
import org.wordpress.android.fluxc.store.WooCommerceStore
import javax.inject.Inject
import kotlin.reflect.KMutableProperty0

class CardReaderPaymentControllerFactory @Inject constructor(
private val cardReaderManager: CardReaderManager,
private val orderRepository: OrderDetailRepository,
private val selectedSite: SelectedSite,
private val appPrefs: AppPrefs = AppPrefs,
private val paymentCollectibilityChecker: CardReaderPaymentCollectibilityChecker,
private val interacRefundableChecker: CardReaderInteracRefundableChecker,
private val tracker: PaymentsFlowTracker,
private val trackCancelledFlow: CardReaderTrackCanceledFlowAction,
private val currencyFormatter: CurrencyFormatter,
private val errorMapper: CardReaderPaymentErrorMapper,
private val interacRefundErrorMapper: CardReaderInteracRefundErrorMapper,
private val wooStore: WooCommerceStore,
private val dispatchers: CoroutineDispatchers,
private val cardReaderTrackingInfoKeeper: CardReaderTrackingInfoKeeper,
private val paymentStateProvider: CardReaderPaymentStateProvider,
private val cardReaderPaymentOrderHelper: CardReaderPaymentOrderHelper,
private val paymentReceiptHelper: PaymentReceiptHelper,
private val cardReaderOnboardingChecker: CardReaderOnboardingChecker,
private val cardReaderConfigProvider: CardReaderCountryConfigProvider,
private val paymentReceiptShare: PaymentReceiptShare,
) {
fun create(
orderId: Long,
paymentType: PaymentType,
isTTPPaymentInProgress: KMutableProperty0<Boolean>,
): CardReaderPaymentController = CardReaderPaymentController(
cardReaderManager = cardReaderManager,
orderRepository = orderRepository,
selectedSite = selectedSite,
appPrefs = appPrefs,
paymentCollectibilityChecker = paymentCollectibilityChecker,
interacRefundableChecker = interacRefundableChecker,
tracker = tracker,
trackCancelledFlow = trackCancelledFlow,
currencyFormatter = currencyFormatter,
errorMapper = errorMapper,
interacRefundErrorMapper = interacRefundErrorMapper,
wooStore = wooStore,
dispatchers = dispatchers,
cardReaderTrackingInfoKeeper = cardReaderTrackingInfoKeeper,
paymentStateProvider = paymentStateProvider,
cardReaderPaymentOrderHelper = cardReaderPaymentOrderHelper,
paymentReceiptHelper = paymentReceiptHelper,
cardReaderOnboardingChecker = cardReaderOnboardingChecker,
cardReaderConfigProvider = cardReaderConfigProvider,
paymentReceiptShare = paymentReceiptShare,
paymentOrRefund = PaymentOrRefund.Payment(
orderId = orderId,
paymentType = paymentType
),
cardReaderType = CardReaderType.EXTERNAL,
isTTPPaymentInProgress = isTTPPaymentInProgress,
)
}
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 All @@ -41,11 +36,6 @@ data class NavigateToOrderDetails(
val orderId: Long
) : MultiLiveEvent.Event()

sealed class ReturnResultToWooPos : MultiLiveEvent.Event() {
data object Success : ReturnResultToWooPos()
data object Failure : ReturnResultToWooPos()
}

data class NavigateToTapToPaySummary(
val order: Order
) : MultiLiveEvent.Event()
Expand Down
Loading
Loading