Skip to content

Commit

Permalink
MBL-1123: Supply Stripe credentials in PostCampaignCheckoutViewContro…
Browse files Browse the repository at this point in the history
…ller
  • Loading branch information
amy-at-kickstarter committed Mar 25, 2024
1 parent bdfb97c commit 5e9baef
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import KsApi
import Library
import Prelude
import Stripe
import UIKit

private enum PostCampaignCheckoutLayout {
Expand Down Expand Up @@ -204,6 +205,13 @@ final class PostCampaignCheckoutViewController: UIViewController {
}

self.paymentMethodsViewController.view.rac.hidden = self.viewModel.outputs.paymentMethodsViewHidden

self.viewModel.outputs.configureStripeIntegration
.observeForUI()
.observeValues { merchantIdentifier, publishableKey in
STPAPIClient.shared.publishableKey = publishableKey
STPAPIClient.shared.configuration.appleMerchantIdentifier = merchantIdentifier
}
}

// MARK: - Functions
Expand Down
15 changes: 15 additions & 0 deletions Library/ViewModels/PostCampaignCheckoutViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public protocol PostCampaignCheckoutViewModelOutputs {
var goToLoginSignup: Signal<(LoginIntent, Project, Reward?), Never> { get }
var paymentMethodsViewHidden: Signal<Bool, Never> { get }
var showWebHelp: Signal<HelpType, Never> { get }
var configureStripeIntegration: Signal<StripeConfigurationData, Never> { get }
}

public protocol PostCampaignCheckoutViewModelType {
Expand Down Expand Up @@ -116,6 +117,19 @@ public class PostCampaignCheckoutViewModel: PostCampaignCheckoutViewModelType,
)
return (rewardsData, data.bonusAmount, pledgeData)
}

self.configureStripeIntegration = Signal.combineLatest(
initialData,
context
)
.filter { !$1.paymentMethodsViewHidden }
.ignoreValues()
.map { _ in
(
Secrets.ApplePay.merchantIdentifier,
AppEnvironment.current.environmentType.stripePublishableKey
)
}
}

// MARK: - Inputs
Expand Down Expand Up @@ -163,6 +177,7 @@ public class PostCampaignCheckoutViewModel: PostCampaignCheckoutViewModelType,
public let goToLoginSignup: Signal<(LoginIntent, Project, Reward?), Never>
public let paymentMethodsViewHidden: Signal<Bool, Never>
public let showWebHelp: Signal<HelpType, Never>
public let configureStripeIntegration: Signal<StripeConfigurationData, Never>

public var inputs: PostCampaignCheckoutViewModelInputs { return self }
public var outputs: PostCampaignCheckoutViewModelOutputs { return self }
Expand Down

0 comments on commit 5e9baef

Please sign in to comment.