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

Determine "Apple Pay capable" based on available card types from the project #805

Merged
merged 18 commits into from
Sep 3, 2019
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
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
4 changes: 4 additions & 0 deletions Configs/Secrets.swift.example
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@ public enum Secrets {
public static let staging = "staging.com"
public static let development = "development.kickstarter.com"
}

public enum ApplePay {
public static let merchantIdentifier = "merchant.kickstarter"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,20 @@ final class PledgePaymentMethodsViewController: UIViewController {

self.messageDisplayingDelegate?.pledgeViewController(self, didErrorWith: errorMessage)
}

self.applePayButton.rac.hidden = self.viewModel.outputs.applePayButtonHidden
}

// MARK: - Configuration

func configureWith(_ user: User) {
self.viewModel.inputs.configureWith(user)
func configure(with value: (user: User, project: Project)) {
let pledgePaymentMethodsValue = PledgePaymentMethodsValue(
user: value.user,
project: value.project,
applePayCapable: PKPaymentAuthorizationViewController.applePayCapable(for: value.project)
)

self.viewModel.inputs.configureWith(pledgePaymentMethodsValue)
}

// MARK: - Actions
Expand Down
6 changes: 3 additions & 3 deletions Kickstarter-iOS/Views/Controllers/PledgeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ final class PledgeViewController: UIViewController, MessageBannerViewControllerP
self?.summaryViewController.configureWith(value: (project, pledgeTotal))
}

self.viewModel.outputs.configurePaymentMethodsViewControllerWithUser
self.viewModel.outputs.configurePaymentMethodsViewControllerWithValue
.observeForUI()
.observeValues { [weak self] user in
self?.paymentMethodsViewController.configureWith(user)
.observeValues { [weak self] value in
self?.paymentMethodsViewController.configure(with: value)
}

self.sessionStartedObserver = NotificationCenter.default
Expand Down
12 changes: 8 additions & 4 deletions Kickstarter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@
77CD8981217FA01B003066DA /* ProjectPamphletContentViewControllerConversionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77CD8980217FA01B003066DA /* ProjectPamphletContentViewControllerConversionTests.swift */; };
77D7A739214187A9003F258C /* SettingsSwitchCellType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77D7A738214187A9003F258C /* SettingsSwitchCellType.swift */; };
77DB532A2215D0AA0078991C /* GraphUserCreditCardTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77DB53292215D0AA0078991C /* GraphUserCreditCardTests.swift */; };
77E023D62305E02C00C63444 /* PKPaymentAuthorizationViewControllerHelpersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77E023D52305E02C00C63444 /* PKPaymentAuthorizationViewControllerHelpersTests.swift */; };
77E44B7421823A56006446B8 /* ChangePasswordInput.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77E44B7321823A56006446B8 /* ChangePasswordInput.swift */; };
77E6440120F64F0B005F6B38 /* HelpDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77E6440020F64F0B005F6B38 /* HelpDataSource.swift */; };
77E6440320F65074005F6B38 /* HelpViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77E6440220F65074005F6B38 /* HelpViewController.swift */; };
Expand Down Expand Up @@ -658,7 +659,7 @@
A7ED20641E83256700BFFA01 /* RootViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7ED205F1E83256700BFFA01 /* RootViewModelTests.swift */; };
A7ED20651E83256700BFFA01 /* UpdatePreviewViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7ED20601E83256700BFFA01 /* UpdatePreviewViewModelTests.swift */; };
A7ED20661E83256700BFFA01 /* UpdateViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7ED20611E83256700BFFA01 /* UpdateViewModelTests.swift */; };
A7EDEE571D83453F00780B34 /* PKPaymentAuthorizationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7EDEE561D83453F00780B34 /* PKPaymentAuthorizationViewController.swift */; };
A7EDEE571D83453F00780B34 /* PKPaymentAuthorizationViewController+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7EDEE561D83453F00780B34 /* PKPaymentAuthorizationViewController+Helpers.swift */; };
A7F441AD1D005A9400FE6FC5 /* ActivitiesViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F4418E1D005A9400FE6FC5 /* ActivitiesViewModel.swift */; };
A7F441AF1D005A9400FE6FC5 /* ActivityFriendBackingViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F4418F1D005A9400FE6FC5 /* ActivityFriendBackingViewModel.swift */; };
A7F441B31D005A9400FE6FC5 /* ActivityProjectStatusViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7F441911D005A9400FE6FC5 /* ActivityProjectStatusViewModel.swift */; };
Expand Down Expand Up @@ -1565,6 +1566,7 @@
77CD8980217FA01B003066DA /* ProjectPamphletContentViewControllerConversionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProjectPamphletContentViewControllerConversionTests.swift; sourceTree = "<group>"; };
77D7A738214187A9003F258C /* SettingsSwitchCellType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsSwitchCellType.swift; sourceTree = "<group>"; };
77DB53292215D0AA0078991C /* GraphUserCreditCardTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GraphUserCreditCardTests.swift; sourceTree = "<group>"; };
77E023D52305E02C00C63444 /* PKPaymentAuthorizationViewControllerHelpersTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PKPaymentAuthorizationViewControllerHelpersTests.swift; sourceTree = "<group>"; };
77E44B7321823A56006446B8 /* ChangePasswordInput.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChangePasswordInput.swift; sourceTree = "<group>"; };
77E6440020F64F0B005F6B38 /* HelpDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HelpDataSource.swift; sourceTree = "<group>"; };
77E6440220F65074005F6B38 /* HelpViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HelpViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1985,7 +1987,7 @@
A7ED205F1E83256700BFFA01 /* RootViewModelTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RootViewModelTests.swift; sourceTree = "<group>"; };
A7ED20601E83256700BFFA01 /* UpdatePreviewViewModelTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdatePreviewViewModelTests.swift; sourceTree = "<group>"; };
A7ED20611E83256700BFFA01 /* UpdateViewModelTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdateViewModelTests.swift; sourceTree = "<group>"; };
A7EDEE561D83453F00780B34 /* PKPaymentAuthorizationViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PKPaymentAuthorizationViewController.swift; sourceTree = "<group>"; };
A7EDEE561D83453F00780B34 /* PKPaymentAuthorizationViewController+Helpers.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "PKPaymentAuthorizationViewController+Helpers.swift"; sourceTree = "<group>"; };
A7F4418E1D005A9400FE6FC5 /* ActivitiesViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActivitiesViewModel.swift; sourceTree = "<group>"; };
A7F4418F1D005A9400FE6FC5 /* ActivityFriendBackingViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActivityFriendBackingViewModel.swift; sourceTree = "<group>"; };
A7F441901D005A9400FE6FC5 /* ActivityFriendFollowCellViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ActivityFriendFollowCellViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3050,7 +3052,8 @@
A7ED1F1C1E830FDC00BFFA01 /* PaginateTests.swift */,
373AB25C222A0D8900769FC2 /* PasswordValidation.swift */,
373AB25E222A0DAC00769FC2 /* PasswordValidationTests.swift */,
A7EDEE561D83453F00780B34 /* PKPaymentAuthorizationViewController.swift */,
A7EDEE561D83453F00780B34 /* PKPaymentAuthorizationViewController+Helpers.swift */,
77E023D52305E02C00C63444 /* PKPaymentAuthorizationViewControllerHelpersTests.swift */,
A7B11A761D79F03300A5036E /* PKPaymentRequest.swift */,
A7ED1F1D1E830FDC00BFFA01 /* PKPaymentRequestTests.swift */,
D78E0355229305E20043E92F /* PledgeStateCTAType.swift */,
Expand Down Expand Up @@ -4628,7 +4631,7 @@
A755116C1C8642C3005355CF /* UIPress-Extensions.swift in Sources */,
D798A6AE21656D970053D097 /* Currency.swift in Sources */,
77F6E73521222E7C005A5C55 /* EmailFrequency.swift in Sources */,
A7EDEE571D83453F00780B34 /* PKPaymentAuthorizationViewController.swift in Sources */,
A7EDEE571D83453F00780B34 /* PKPaymentAuthorizationViewController+Helpers.swift in Sources */,
D0237C2622BD7B540092C792 /* PledgeSummaryViewModel.swift in Sources */,
01A7A4C01C9690220036E553 /* UITextField+LocalizedPlaceholderKey.swift in Sources */,
0176E13B1C9742FD009CA092 /* UIBarButtonItem.swift in Sources */,
Expand Down Expand Up @@ -4720,6 +4723,7 @@
A7ED1FE41E831C5C00BFFA01 /* EmptyStatesViewModelTests.swift in Sources */,
D04AACA8218BB72100CF713E /* FindFriendsCellViewModelTests.swift in Sources */,
D04AACA6218BB72100CF713E /* ChangePasswordViewModelTests.swift in Sources */,
77E023D62305E02C00C63444 /* PKPaymentAuthorizationViewControllerHelpersTests.swift in Sources */,
A7ED20041E831C5C00BFFA01 /* UpdateDraftViewModelTests.swift in Sources */,
A7ED1F4B1E831BA200BFFA01 /* TestCase.swift in Sources */,
A7ED1FBE1E831C5C00BFFA01 /* ProjectNotificationCellViewModelTests.swift in Sources */,
Expand Down
4 changes: 3 additions & 1 deletion KsApi/models/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Prelude
import Runes

public struct Project {
public var availableCardTypes: [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.

This is optional because the project JSON object we get from the /discover endpoint doesn't have this field (it's only a partial project), and we use the same Project model to decode that payload.

Copy link
Contributor

Choose a reason for hiding this comment

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

I suppose we could also consider coalescing an empty array if we wanted this to be non-optional 🤔 but I guess having nil here is more explicit about not having the information rather than there are no available card types.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I'd rather keep it nil to make it clear that the info is not available.

public var blurb: String
public var category: Category
public var country: Country
Expand Down Expand Up @@ -188,7 +189,8 @@ extension Project: CustomDebugStringConvertible {
extension Project: Argo.Decodable {
public static func decode(_ json: JSON) -> Decoded<Project> {
let tmp1 = curry(Project.init)
<^> json <| "blurb"
<^> json <||? "available_card_types"
<*> json <| "blurb"
<*> ((json <| "category" >>- decodeToGraphCategory) as Decoded<Category>)
<*> Project.Country.decode(json)
<*> json <| "creator"
Expand Down
Loading