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

[NT-489] Default card selection improvement #931

Merged
merged 4 commits into from
Nov 7, 2019

Conversation

justinswart
Copy link
Contributor

📲 What

Fixes an issue where the first stored card was always selected in any context where the payment method could be set even when it was not used to back the project.

🤔 Why

Our logic for handling this was a bit shortsighted in that it would simply select the first card in the list every time. Instead we need to confirm that the card was in fact used to back the project and hasn't since been removed.

🛠 How

Updated our logic for this to take into account the PaymentSource of the Backing and if it's set, check that the card is still an available payment source.

✅ Acceptance criteria

  • Back a project and delete the payment method used to back the project. When navigating to change your payment source, there shouldn't be any payment source selected by default and the Confirm button should be disabled.
  • Back a project using Apple Pay. Similarly there shouldn't be any default payment method selected when changing.

let cardIsSelected = cardAndSelectedCard
.map(==)
let cardIsSelected = Signal.merge(
creditCard.mapConst(false),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Emitting false here to ensure that the card has a title even though we're not setting a selected card.

guard let cardBrand = card.type?.rawValue else { return nil }

let isAvailableCardType = availableCardTypes.contains(cardBrand)

return (card, isAvailableCardType, project.location.displayableName)
}

guard let backing = project.personalization.backing else {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If this project hasn't been backed then we do just select the first card.

Copy link
Contributor

@Scollaco Scollaco left a comment

Choose a reason for hiding this comment

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

Good job, Justin. I just left a couple of suggestions and questions 😄

backedCard = cards.first
}

return (data, backedCard)
Copy link
Contributor

Choose a reason for hiding this comment

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

Here I think we could simply use

let backedCard = cards.first(where: { $0.id == backing.paymentSource?.id })

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lol thanks that's much better

func testReloadPaymentMethods_LoggedIn_ApplePayCapable_isTrue_BackedCardRemoved() {
let filteredCards = GraphUserCreditCard.template.storedCards.nodes
.filter { $0.id != GraphUserCreditCard.visa.id
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you put the } on the same line?

self.applePayButtonHidden.assertValues([false])
self.reloadPaymentMethodsCards.assertValue(response.me.storedCards.nodes)
self.reloadPaymentMethodsAvailableCardTypes.assertValues([
[true, true, true, true, true, false, true]
Copy link
Contributor

@Scollaco Scollaco Nov 6, 2019

Choose a reason for hiding this comment

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

Why is there an unavailable card? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just the Project template's available card types, I copied this test from the one above it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh cool!

@justinswart justinswart merged commit 2d74b79 into master Nov 7, 2019
@justinswart justinswart deleted the handle-removed-payment-method branch November 7, 2019 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants