@@ -8,17 +8,21 @@ import com.woocommerce.android.cardreader.CardReaderStore.CapturePaymentResponse
88import com.woocommerce.android.cardreader.config.CardReaderConfigFactory
99import com.woocommerce.android.cardreader.config.CardReaderConfigForSupportedCountry
1010import com.woocommerce.android.cardreader.internal.payments.actions.CancelPaymentAction
11- import com.woocommerce.android.cardreader.internal.payments.actions.CollectPaymentAction
12- import com.woocommerce.android.cardreader.internal.payments.actions.CollectPaymentAction.CollectPaymentStatus
1311import com.woocommerce.android.cardreader.internal.payments.actions.CreatePaymentAction
1412import com.woocommerce.android.cardreader.internal.payments.actions.CreatePaymentAction.CreatePaymentStatus.Failure
1513import com.woocommerce.android.cardreader.internal.payments.actions.CreatePaymentAction.CreatePaymentStatus.Success
16- import com.woocommerce.android.cardreader.internal.payments.actions.ProcessPaymentAction
17- import com.woocommerce.android.cardreader.internal.payments.actions.ProcessPaymentAction.ProcessPaymentStatus
14+ import com.woocommerce.android.cardreader.internal.payments.actions.ProcessPaymentIntentAction
15+ import com.woocommerce.android.cardreader.internal.payments.actions.ProcessPaymentIntentAction.ProcessPaymentIntentStatus
1816import com.woocommerce.android.cardreader.internal.wrappers.TerminalWrapper
1917import com.woocommerce.android.cardreader.payments.CardPaymentStatus
20- import com.woocommerce.android.cardreader.payments.CardPaymentStatus.*
18+ import com.woocommerce.android.cardreader.payments.CardPaymentStatus.CapturingPayment
2119import com.woocommerce.android.cardreader.payments.CardPaymentStatus.CardPaymentStatusErrorType.Generic
20+ import com.woocommerce.android.cardreader.payments.CardPaymentStatus.InitializingPayment
21+ import com.woocommerce.android.cardreader.payments.CardPaymentStatus.PaymentCompleted
22+ import com.woocommerce.android.cardreader.payments.CardPaymentStatus.PaymentFailed
23+ import com.woocommerce.android.cardreader.payments.CardPaymentStatus.PaymentMethodType
24+ import com.woocommerce.android.cardreader.payments.CardPaymentStatus.ProcessingPayment
25+ import com.woocommerce.android.cardreader.payments.CardPaymentStatus.ProcessingPaymentCompleted
2226import com.woocommerce.android.cardreader.payments.PaymentData
2327import com.woocommerce.android.cardreader.payments.PaymentInfo
2428import kotlinx.coroutines.flow.Flow
@@ -30,8 +34,7 @@ internal class PaymentManager(
3034 private val terminalWrapper : TerminalWrapper ,
3135 private val cardReaderStore : CardReaderStore ,
3236 private val createPaymentAction : CreatePaymentAction ,
33- private val collectPaymentAction : CollectPaymentAction ,
34- private val processPaymentAction : ProcessPaymentAction ,
37+ private val processPaymentIntentAction : ProcessPaymentIntentAction ,
3538 private val cancelPaymentAction : CancelPaymentAction ,
3639 private val paymentUtils : PaymentUtils ,
3740 private val errorMapper : PaymentErrorMapper ,
@@ -68,10 +71,9 @@ internal class PaymentManager(
6871 return @flow
6972 }
7073
71- if (paymentIntent.status == PaymentIntentStatus .REQUIRES_PAYMENT_METHOD ) {
72- paymentIntent = collectPayment(paymentIntent)
73- }
74- if (paymentIntent.status == PaymentIntentStatus .REQUIRES_CONFIRMATION ) {
74+ if (paymentIntent.status == PaymentIntentStatus .REQUIRES_PAYMENT_METHOD ||
75+ paymentIntent.status == PaymentIntentStatus .REQUIRES_CONFIRMATION
76+ ) {
7577 paymentIntent = processPayment(paymentIntent)
7678 }
7779
@@ -125,29 +127,15 @@ internal class PaymentManager(
125127 return paymentIntent
126128 }
127129
128- private suspend fun FlowCollector<CardPaymentStatus>.collectPayment (
129- paymentIntent : PaymentIntent
130- ): PaymentIntent {
131- var result = paymentIntent
132- emit(CollectingPayment )
133- collectPaymentAction.collectPayment(paymentIntent).collect {
134- when (it) {
135- is CollectPaymentStatus .Failure -> emit(errorMapper.mapTerminalError(paymentIntent, it.exception))
136- is CollectPaymentStatus .Success -> result = it.paymentIntent
137- }
138- }
139- return result
140- }
141-
142130 private suspend fun FlowCollector<CardPaymentStatus>.processPayment (
143131 paymentIntent : PaymentIntent
144132 ): PaymentIntent {
145133 var result = paymentIntent
146134 emit(ProcessingPayment )
147- processPaymentAction.processPayment (paymentIntent).collect {
135+ processPaymentIntentAction.processPaymentIntent (paymentIntent).collect {
148136 when (it) {
149- is ProcessPaymentStatus .Failure -> emit(errorMapper.mapTerminalError(paymentIntent, it.exception))
150- is ProcessPaymentStatus .Success -> {
137+ is ProcessPaymentIntentStatus .Failure -> emit(errorMapper.mapTerminalError(paymentIntent, it.exception))
138+ is ProcessPaymentIntentStatus .Success -> {
151139 val paymentMethodType = determinePaymentMethodType(it)
152140 emit(ProcessingPaymentCompleted (paymentMethodType))
153141 result = it.paymentIntent
@@ -188,7 +176,7 @@ internal class PaymentManager(
188176 }
189177 }
190178
191- private fun determinePaymentMethodType (status : ProcessPaymentStatus .Success ): PaymentMethodType {
179+ private fun determinePaymentMethodType (status : ProcessPaymentIntentStatus .Success ): PaymentMethodType {
192180 val charge = status.paymentIntent.getCharges().firstOrNull()
193181 return when {
194182 charge?.paymentMethodDetails?.interacPresentDetails != null -> PaymentMethodType .INTERAC_PRESENT
0 commit comments