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 — Part 3 | Emitting UI–agnostic payment states in CardReaderPaymentController #12877

Merged
merged 26 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8829f5a
Introduce `CardReaderPaymentState` model emitted by `CardReaderPaymen…
samiuelson Nov 5, 2024
a22d662
Introduce `CardReaderPaymentState` model
samiuelson Nov 6, 2024
95eba27
Map payment flow error to `PaymentFailed` state
samiuelson Nov 6, 2024
df1cf58
Emit `FetchingOrderFailed` state as `paymentState`
samiuelson Nov 6, 2024
d174491
Emit `LoadingData` state as `paymentState`
samiuelson Nov 6, 2024
f2f688f
Emit `CollectingPayment` state as `paymentState`
samiuelson Nov 6, 2024
8190ba7
Emit `ProcessingPayment` state as `paymentState`
samiuelson Nov 6, 2024
cc752b0
Emit `CapturingPayment` state as `paymentState`
samiuelson Nov 6, 2024
873479f
Fix detekt's issues
samiuelson Nov 6, 2024
899eb1d
Emit `ReFetchingOrder` as `paymentState`
samiuelson Nov 7, 2024
ee5ece5
Emit `SharingReceipt` as `paymentState`
samiuelson Nov 7, 2024
051aa78
Emit `PrintingReceipt` as `paymentState`
samiuelson Nov 7, 2024
0f5b68b
Emit `PaymentSuccessful` as `paymentState`
samiuelson Nov 7, 2024
677ed80
Emit remaining states as `paymentState`
samiuelson Nov 7, 2024
bc36059
Format code
samiuelson Nov 7, 2024
c2a4599
Clean up code
samiuelson Nov 7, 2024
76e5f9d
Fix detekt's complaints
samiuelson Nov 8, 2024
152d9e0
Update sut instances in unit test
samiuelson Nov 8, 2024
a3ea1d8
Revert interac tracking code
samiuelson Nov 8, 2024
980d649
Add `onCancel` prop to `CollectingInteracRefund`
samiuelson Nov 12, 2024
d3577a2
Merge branch 'custom-payment-ui-2' into custom-payment-ui-3
samiuelson Nov 13, 2024
c26ed71
Extract `nameForTracking` from the state model
samiuelson Nov 14, 2024
7fe2991
Fix tracking logic – add missing names
samiuelson Nov 14, 2024
44115aa
Extract `::trackCancelledFlow` into use case class
samiuelson Nov 14, 2024
f756819
Merge branch 'custom-payment-ui-2' into custom-payment-ui-3
samiuelson Nov 15, 2024
0c4e9ec
Rename `CardReaderTrackCanceledFlow` -> `CardReaderTrackCanceledFlowA…
samiuelson Nov 19, 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 @@ -1080,16 +1080,22 @@ class CardReaderPaymentController(

private fun trackCancelledFlow(state: CardReaderPaymentOrRefundState) {
when (state) {
is CardReaderPaymentOrRefundState.TrackableState -> {
when (state) {
is CardReaderPaymentState ->
tracker.trackPaymentCancelled(state.nameForTracking)
is CardReaderInteracRefundState ->
tracker.trackInteracRefundCancelled(state.nameForTracking)
is CardReaderPaymentState, is CardReaderInteracRefundState -> {
val nameForTracking = when (state) {
is CardReaderPaymentState.CollectingPayment -> "Collecting"
is CardReaderPaymentState.PaymentCapturing -> "Capturing"
is CardReaderPaymentState.ProcessingPayment -> "Processing"
is CardReaderInteracRefundState.CollectingInteracRefund -> "Collecting"
is CardReaderInteracRefundState.LoadingData -> "Loading"
is CardReaderInteracRefundState.ProcessingInteracRefund -> "Processing"
else -> null
}
if (nameForTracking == null) {
WooLog.e(WooLog.T.CARD_READER, "Invalid state received")
Copy link
Contributor

Choose a reason for hiding this comment

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

Btw, I'd consider to track this case too, just instead of passing hard coded string we could pass state's name there

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 like the idea, but I would prefer to implement it out of this PR, and refactoring process because it would affect the existing business logic—it would require modifying unit tests.

Reported issue: https://github.com/orgs/woocommerce/projects/278/views/1?visibleFields=%5B%22Title%22%2C%22Assignees%22%2C%22Status%22%2C143176801%2C%22Linked+pull+requests%22%5D&pane=issue&itemId=87370857&issue=woocommerce%7Cwoocommerce-android%7C12930

} else {
tracker.trackInteracRefundCancelled(nameForTracking)
samiuelson marked this conversation as resolved.
Show resolved Hide resolved
}
}

else -> WooLog.e(WooLog.T.CARD_READER, "Invalid state received")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,72 +5,48 @@ import com.woocommerce.android.ui.payments.cardreader.payment.InteracRefundFlowE
import com.woocommerce.android.ui.payments.cardreader.payment.PaymentFlowError

sealed class CardReaderPaymentOrRefundState {
samiuelson marked this conversation as resolved.
Show resolved Hide resolved
interface TrackableState {
val nameForTracking: String
}

sealed class CardReaderPaymentState : CardReaderPaymentOrRefundState() {
data class LoadingData(val onCancel: () -> Unit,) : CardReaderPaymentState(), TrackableState {
override val nameForTracking: String = "Loading"
}
data class LoadingData(val onCancel: () -> Unit) : CardReaderPaymentState()

data object ReFetchingOrder : CardReaderPaymentState()

sealed class CollectingPayment(
open val amountWithCurrencyLabel: String,
@StringRes open val cardReaderHint: Int? = null,
) : CardReaderPaymentState(), TrackableState {
) : CardReaderPaymentState() {
data class BuiltInReaderCollectPaymentState(
override val amountWithCurrencyLabel: String,
override val cardReaderHint: Int? = null,
) : CollectingPayment(amountWithCurrencyLabel, cardReaderHint) {
override val nameForTracking: String
get() = "Collecting"
}
) : CollectingPayment(amountWithCurrencyLabel, cardReaderHint)

data class ExternalReaderCollectPaymentState(
override val amountWithCurrencyLabel: String,
override val cardReaderHint: Int? = null,
val onCancel: (() -> Unit)
) : CollectingPayment(amountWithCurrencyLabel, cardReaderHint) {
override val nameForTracking: String
get() = "Collecting"
}
) : CollectingPayment(amountWithCurrencyLabel, cardReaderHint)
}

sealed class ProcessingPayment(
open val amountWithCurrencyLabel: String,
) : CardReaderPaymentState(), TrackableState {
) : CardReaderPaymentState() {
data class BuiltInReaderProcessingPayment(override val amountWithCurrencyLabel: String) :
ProcessingPayment(amountWithCurrencyLabel) {
override val nameForTracking: String
get() = "Processing"
}
ProcessingPayment(amountWithCurrencyLabel)

data class ExternalReaderProcessingPayment(
override val amountWithCurrencyLabel: String,
val onCancel: () -> Unit
) : ProcessingPayment(amountWithCurrencyLabel) {
override val nameForTracking: String
get() = "Processing"
}
) : ProcessingPayment(amountWithCurrencyLabel)
}

data class PrintingReceipt(val amountWithCurrencyLabel: String) : CardReaderPaymentState()

sealed class PaymentCapturing(open val amountWithCurrencyLabel: String) :
CardReaderPaymentState(), TrackableState {
CardReaderPaymentState() {
data class BuiltInReaderPaymentCapturing(override val amountWithCurrencyLabel: String) :
PaymentCapturing(amountWithCurrencyLabel) {
override val nameForTracking: String
get() = "Capturing"
}
PaymentCapturing(amountWithCurrencyLabel)

data class ExternalReaderPaymentCapturing(override val amountWithCurrencyLabel: String) :
PaymentCapturing(amountWithCurrencyLabel) {
override val nameForTracking: String
get() = "Capturing"
}
PaymentCapturing(amountWithCurrencyLabel)
}

sealed class PaymentSuccessful(
Expand Down Expand Up @@ -145,23 +121,17 @@ sealed class CardReaderPaymentOrRefundState {
}

sealed class CardReaderInteracRefundState : CardReaderPaymentOrRefundState() {
data class LoadingData(val onCancel: () -> Unit) : CardReaderInteracRefundState(), TrackableState {
override val nameForTracking: String = "Loading"
}
data class LoadingData(val onCancel: () -> Unit) : CardReaderInteracRefundState()

data class CollectingInteracRefund(
val amountWithCurrencyLabel: String,
val onCancel: () -> Unit,
@StringRes val cardReaderHint: Int? = null,
) : CardReaderInteracRefundState(), TrackableState {
override val nameForTracking: String = "Collecting"
}
) : CardReaderInteracRefundState()

data class ProcessingInteracRefund(
val amountWithCurrencyLabel: String,
) : CardReaderInteracRefundState(), TrackableState {
override val nameForTracking: String = "Processing"
}
) : CardReaderInteracRefundState()

data class InteracRefundFailure(
val amountWithCurrencyLabel: String?,
Expand Down
Loading