Skip to content

Commit de5e4a1

Browse files
authored
Merge pull request #6393 from woocommerce/try/debug-remove-card-bug
[Mobile Payments] Ensure card has been removed before attempting a payment
2 parents 0f14c71 + 4b2721d commit de5e4a1

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

Hardware/Hardware/CardReader/StripeCardReader/StripeCardReaderService.swift

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,27 @@ extension StripeCardReaderService: CardReaderService {
211211
// a single value or it will fail.
212212
// This isn't enforced by the type system, but it is guaranteed as long as all the
213213
// steps produce a Future.
214-
return createPaymentIntent(parameters)
215-
.flatMap { intent in
214+
215+
// If a card was left from a previous payment attempt, we want that removed before we initiate a new payment.
216+
// However, a new payment probably means a new subscription to readerEvents, which won't rely the old `.removeCard`
217+
// message. If there is a card inserted, we manually send a display message prompting to remove the card,
218+
// and wait for that before continuing.
219+
if isChipCardInserted {
220+
sendReaderEvent(CardReaderEvent.make(displayMessage: .removeCard))
221+
}
222+
return waitForInsertedCardToBeRemoved()
223+
.flatMap {
224+
self.createPaymentIntent(parameters)
225+
}.flatMap { intent in
216226
self.collectPaymentMethod(intent: intent)
217227
}.flatMap { intent in
218228
self.processPayment(intent: intent)
219229
}.flatMap { intent in
220-
self.waitForInsertedCardToBeRemoved(intent: intent)
221-
}.eraseToAnyPublisher()
230+
self.waitForInsertedCardToBeRemoved()
231+
.map { intent }
232+
}
233+
.map(PaymentIntent.init(intent:))
234+
.eraseToAnyPublisher()
222235
}
223236

224237
public func cancelPaymentIntent() -> Future<Void, Error> {
@@ -406,15 +419,15 @@ private extension StripeCardReaderService {
406419
}
407420
}
408421

409-
func waitForInsertedCardToBeRemoved(intent: PaymentIntent) -> Future<PaymentIntent, Error> {
422+
func waitForInsertedCardToBeRemoved() -> Future<Void, Error> {
410423
return Future() { [weak self] promise in
411424
guard let self = self else {
412425
return
413426
}
414427

415428
// If there is no chip card inserted, it is ok to immediatedly return. The payment method may have been swipe or tap.
416429
if !self.isChipCardInserted {
417-
return promise(.success(intent))
430+
return promise(.success(()))
418431
}
419432

420433
self.timerCancellable = Timer.publish(every: 1, tolerance: 0.1, on: .main, in: .default)
@@ -423,13 +436,13 @@ private extension StripeCardReaderService {
423436
.sink(receiveValue: { _ in
424437
if !self.isChipCardInserted {
425438
self.timerCancellable?.cancel()
426-
return promise(.success(intent))
439+
return promise(.success(()))
427440
}
428441
})
429442
}
430443
}
431444

432-
func processPayment(intent: StripeTerminal.PaymentIntent) -> Future<PaymentIntent, Error> {
445+
func processPayment(intent: StripeTerminal.PaymentIntent) -> Future<StripeTerminal.PaymentIntent, Error> {
433446
return Future() { [weak self] promise in
434447
Terminal.shared.processPayment(intent) { (intent, error) in
435448
if let error = error {
@@ -438,7 +451,7 @@ private extension StripeCardReaderService {
438451
}
439452

440453
if let intent = intent {
441-
promise(.success(PaymentIntent(intent: intent)))
454+
promise(.success(intent))
442455
self?.activePaymentIntent = nil
443456
}
444457
}

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- [*] Reviews: Fixed missing product information on first load [https://github.com/woocommerce/woocommerce-ios/pull/6367]
1919
- [internal] Removed the feature flag for My store tab UI updates. Please smoke test the store stats and top performers in the "My store" tab to make sure everything works as before. [https://github.com/woocommerce/woocommerce-ios/pull/6334]
2020
- [*] In-Person Payments: Add support for accepting payments on bookable products [https://github.com/woocommerce/woocommerce-ios/pull/6364]
21+
- [*] In-Person Payments: Fixed issue where payment could be stuck prompting to remove the card if the payment was declined and retried before removing the card.
2122

2223
8.6
2324
-----

0 commit comments

Comments
 (0)