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-209, NT-156] Pledge Button Interaction (Create Backing) #855

Merged
merged 8 commits into from
Sep 27, 2019

Conversation

ifbarrera
Copy link
Contributor

@ifbarrera ifbarrera commented Sep 26, 2019

📲 What

Hooks up the createBacking mutation to the pledge button to allow users to create backings natively.

🤔 Why

So that users can pledge with a stored card.

🛠 How

When the pledge button is tapped, a request is made to the createBacking mutation which creates the pledge. On success, the user is taken to the "Thanks" screen. If an error occurs, the error is displayed in the message banner on the Pledge Screen.

Things to note:

  • this PR does not include a loading state for when the request is in flight
  • this PR does not take ino account validation of the pledge amount
  • some of this code will be refactored in the near future once we merge the createApplePayBacking mutation into the createBacking mutation
  • there's an unrelated but where the first credit card is selected but the pledge button is not enabled. It'll be addressed in separate PR

👀 See

Create Backing Success Create Backing Failure
Lhj7vka5mQ bjJs0LjbZC

✅ Acceptance criteria

  • Navigate to the pledge screen on an account with stored cards. Select a stored card (the pledge button should become enabled). Then tap "Pledge", after a couple seconds you should redirected to the "Thanks" screen.
  • Navigate to the pledge screen on an account with stored cards. Using the network link conditioner, disable your network to 100% loss. Select a card and tap "Pledge". After about 30 seconds, you should see the error banner with the message "Sorry, something went wrong". Note you won't see any sort of loading state, so you just have to wait until the banner shows up.
    Testing RefParam
  • Navigate to the pledge screen on an account with stored cards. Select a stored card (the pledge button should become enabled). Then tap "Pledge", after a couple seconds you should redirected to the "Thanks" screen. In the console, you should see the logs which include the input for the createBacking mutation, which should show a refParam input field a value (ex. discovery_home, recommendations).

…pledge-button-interaction

# Conflicts:
#	Kickstarter-iOS/Views/Controllers/PledgePaymentMethodsViewController.swift
@ifbarrera ifbarrera changed the title [NT-209] Pledge Button Interaction (Create Backing) [NT-209, NT-156] Pledge Button Interaction (Create Backing) Sep 26, 2019
@@ -4,31 +4,32 @@ public struct CreateBackingInput: GraphMutationInput {
let amount: String
let locationId: String?
let paymentSourceId: String
let paymentType: String
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed paymentType because after chatted with the backend team, it's not really an input field (should always be set to credit_card). They plan on removing the field entirely in the near future.

refTag: RefTag?,
paymentSourceId: String
) -> CreateBackingInput {
let pledgeAmountDecimal = Decimal(pledgeAmount)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A lot of this is duplicated from CreateApplePayBackingInput - I decided not to refactor out the shared parts because I know we're planning to consolidate the two mutations in the near future. When we do, we can simply merge the differences from CreateApplePayInput into this input.

.map(CreateBackingInput.input(from:reward:pledgeAmount:selectedShippingRule:refTag:paymentSourceId:))
.switchMap { input in
AppEnvironment.current.apiService.createBacking(input: input)
.ksr_delay(AppEnvironment.current.apiDelayInterval, on: AppEnvironment.current.scheduler)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Notice that we don't care about the result here - since we are moving to a synchronous createBacking mutation, any errors in creating the pledge should come back as regular graph errors.

Copy link
Contributor

@justinswart justinswart left a comment

Choose a reason for hiding this comment

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

Great work on this! Appears to do exactly what is says on the tin!

Worth noting that I entered a pledge amount of 0 and could still hit the button and got an 'Oops, something went wrong error'. But as you mention - this will be resolved in follow-up PRs.


func pledgePaymentMethodsViewControllerDidTapPledgeButton(
_
viewController: PledgePaymentMethodsViewController
Copy link
Contributor

Choose a reason for hiding this comment

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

I know how much you love formatting comments but this is strange 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

-_-


func pledgePaymentMethodsViewControllerDidTapPledgeButton(
_:
PledgePaymentMethodsViewController
Copy link
Contributor

Choose a reason for hiding this comment

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

☝️

}

public func toInputDictionary() -> [String: Any] {
var inputDictionary = [
"amount": amount,
"paymentSourceId": paymentSourceId,
"paymentType": paymentType,
// swiftlint:disable:next line_length
"paymentType": "credit_card", // this is temporary and will be removed once the mutation has been updated
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm guessing we can flag the PaymentType enum for removal too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh yeah good call.

@ifbarrera ifbarrera merged commit 57ddae9 into master Sep 27, 2019
@ifbarrera ifbarrera deleted the pledge-button-interaction branch September 27, 2019 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants