Skip to content

Commit

Permalink
Changes per review #2005
Browse files Browse the repository at this point in the history
  • Loading branch information
amy-at-kickstarter committed Mar 28, 2024
1 parent f68029a commit cbd6aa2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

public extension GraphAPI.ApplePayInput {
extension GraphAPI.ApplePayInput {
static func from(_ input: ApplePayParams?) -> GraphAPI.ApplePayInput? {
guard let input = input else { return nil }
return GraphAPI.ApplePayInput(
Expand Down
31 changes: 6 additions & 25 deletions Library/ViewModels/PostCampaignCheckoutViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -343,37 +343,19 @@ public class PostCampaignCheckoutViewModel: PostCampaignCheckoutViewModelType,

// MARK: CompleteOnSessionCheckout

let completeCheckoutWithExistingCardInput: Signal<GraphAPI.CompleteOnSessionCheckoutInput, Never> = Signal
.combineLatest(self.confirmPaymentSuccessfulProperty.signal.skipNil(), checkoutId, selectedExistingCard)
let completeCheckoutWithCreditCardInput: Signal<GraphAPI.CompleteOnSessionCheckoutInput, Never> = Signal
.combineLatest(self.confirmPaymentSuccessfulProperty.signal.skipNil(), checkoutId, selectedCard)
.map { (
clientSecret: String,
checkoutId: String,
selectedCard: (source: PaymentSourceSelected, paymentMethodId: String, isNewPaymentMethod: Bool)?
selectedCard: (source: PaymentSourceSelected, paymentMethodId: String, isNewPaymentMethod: Bool)
) -> GraphAPI.CompleteOnSessionCheckoutInput in

GraphAPI
.CompleteOnSessionCheckoutInput(
checkoutId: encodeToBase64("Checkout-\(checkoutId)"),
paymentIntentClientSecret: clientSecret,
paymentSourceId: selectedCard?.paymentMethodId,
paymentSourceReusable: true,
applePay: nil
)
}

let completeCheckoutWithNewCardInput: Signal<GraphAPI.CompleteOnSessionCheckoutInput, Never> = Signal
.combineLatest(self.confirmPaymentSuccessfulProperty.signal.skipNil(), checkoutId, selectedNewCard)
.map { (
clientSecret: String,
checkoutId: String,
_: (source: PaymentSourceSelected, paymentMethodId: String, isNewPaymentMethod: Bool)?
) -> GraphAPI.CompleteOnSessionCheckoutInput in

GraphAPI
.CompleteOnSessionCheckoutInput(
checkoutId: encodeToBase64("Checkout-\(checkoutId)"),
paymentIntentClientSecret: clientSecret,
paymentSourceId: nil,
paymentSourceId: selectedCard.isNewPaymentMethod ? nil : selectedCard.paymentMethodId,
paymentSourceReusable: true,
applePay: nil
)
Expand All @@ -384,15 +366,14 @@ public class PostCampaignCheckoutViewModel: PostCampaignCheckoutViewModelType,

let checkoutCompleteSignal = Signal
.merge(
completeCheckoutWithExistingCardInput,
completeCheckoutWithNewCardInput
completeCheckoutWithCreditCardInput
// completeCheckoutWithApplePayInput
)
.switchMap { input in
AppEnvironment.current.apiService.completeOnSessionCheckout(input: input).materialize()
}

self.checkoutComplete = checkoutCompleteSignal.signal.ignoreValues()
self.checkoutComplete = checkoutCompleteSignal.signal.values().ignoreValues()
self.checkoutError = checkoutCompleteSignal.signal.errors()
}

Expand Down

0 comments on commit cbd6aa2

Please sign in to comment.