Skip to content

Commit

Permalink
Disable wallet filtering for dashboard.
Browse files Browse the repository at this point in the history
  • Loading branch information
nschris-stripe committed Oct 23, 2024
1 parent 6e9d7e1 commit e3206a4
Show file tree
Hide file tree
Showing 12 changed files with 786 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ extension EmbeddedPaymentElement {
/// - Note: This doesn't affect mandates displayed in the form sheet.
public var embeddedViewDisplaysMandateText: Bool = true

/// Controls whether to filter out wallet payment methods from the saved payment method list.
@_spi(DashboardOnly) public var disableWalletPaymentMethodFiltering: Bool = false

/// Initializes a Configuration with default values
public init(formSheetAction: FormSheetAction) {
self.formSheetAction = formSheetAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ protocol PaymentElementConfiguration: PaymentMethodRequirementProvider {
var allowsRemovalOfLastSavedPaymentMethod: Bool { get set }
var cardBrandAcceptance: PaymentSheet.CardBrandAcceptance { get set }
var analyticPayload: [String: Any] { get }
var disableWalletPaymentMethodFiltering: Bool { get set }
}

extension PaymentElementConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ extension PaymentSheet {
}
}

/// Controls whether to filter out wallet payment methods from the saved payment method list.
@_spi(DashboardOnly) public var disableWalletPaymentMethodFiltering: Bool = false

/// Initializes a Configuration with default values
public init() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ final class PaymentSheetLoader {
// Remove cards that originated from Apple Pay, Google Pay, Link
paymentMethods = paymentMethods.filter { paymentMethod in
let isWalletCard = paymentMethod.type == .card && [.applePay, .googlePay, .link].contains(paymentMethod.card?.wallet?.type)
return !isWalletCard
return !isWalletCard || configuration.disableWalletPaymentMethodFiltering
}
// Add in our deduped Link PMs, if any
paymentMethods += dedupedLinkPaymentMethods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,53 @@ final class PaymentSheetLoaderTest: STPNetworkStubbingTestCase {
wait(for: [loadExpectation], timeout: STPTestingNetworkRequestTimeout)
}

func testPaymentSheetLoadDoesNotFilterSavedApplePayCardsWhenDisabled() async throws {
let apiClient = STPAPIClient(publishableKey: STPTestingJPPublishableKey)
var configuration = PaymentSheet.Configuration()
configuration.apiClient = apiClient
configuration.disableWalletPaymentMethodFiltering = true
// A hardcoded test Customer
let testCustomerID = "cus_OtOGvD0ZVacBoj"

// Create a new EK for the Customer
let customerAndEphemeralKey = try await STPTestingAPIClient.shared().fetchCustomerAndEphemeralKey(customerID: testCustomerID, merchantCountry: "jp")
configuration.customer = .init(id: testCustomerID, ephemeralKeySecret: customerAndEphemeralKey.ephemeralKeySecret)

// This is a saved Apple Pay card:
let savedApplePayCard = "pm_1O5bTlIq2LmpyICoB8eZH4BJ"
// This is a normal saved card:
let savedNonApplePayCard = "card_1O5upWIq2LmpyICo9tQmU9xY"

// Check that the test Customer has the expected cards
let checkCustomerExpectation = expectation(description: "Check test customer")
apiClient.listPaymentMethods(forCustomer: testCustomerID, using: customerAndEphemeralKey.ephemeralKeySecret) { paymentMethods, _ in
XCTAssertEqual(paymentMethods?.first?.stripeId, savedApplePayCard)
XCTAssertEqual(paymentMethods?.last?.stripeId, savedNonApplePayCard)
checkCustomerExpectation.fulfill()
}
await fulfillment(of: [checkCustomerExpectation])

// Load PaymentSheet...
let loadExpectation = XCTestExpectation(description: "Load PaymentSheet")
let confirmHandler: PaymentSheet.IntentConfiguration.ConfirmHandler = {_, _, _ in
XCTFail("Confirm handler shouldn't be called.")
}
let intentConfig = PaymentSheet.IntentConfiguration(mode: .payment(amount: 1000, currency: "JPY"), confirmHandler: confirmHandler)
PaymentSheetLoader.load(mode: .deferredIntent(intentConfig), configuration: configuration, analyticsHelper: .init(isCustom: false, configuration: configuration), integrationShape: .flowController) { result in
loadExpectation.fulfill()
switch result {
case .success(let loadResult):
// ...check that it only loads the one normal saved card
XCTAssertEqual(loadResult.savedPaymentMethods.count, 2)
XCTAssertEqual(loadResult.savedPaymentMethods.map(\.stripeId), [savedApplePayCard, savedNonApplePayCard])
case .failure:
XCTFail()
}
}
await fulfillment(of: [loadExpectation], timeout: STPTestingNetworkRequestTimeout)

}

func testPaymentSheetLoadFiltersSavedApplePayCards() async throws {
let apiClient = STPAPIClient(publishableKey: STPTestingJPPublishableKey)
var configuration = PaymentSheet.Configuration()
Expand Down Expand Up @@ -238,6 +285,7 @@ final class PaymentSheetLoaderTest: STPNetworkStubbingTestCase {
}
}
await fulfillment(of: [loadExpectation], timeout: STPTestingNetworkRequestTimeout)

}

func testPaymentSheetLoadWithExternalPaymentMethods() async throws {
Expand All @@ -249,7 +297,7 @@ final class PaymentSheetLoaderTest: STPNetworkStubbingTestCase {
// ...with valid external payment methods configured...
configuration.externalPaymentMethodConfiguration = .init(
externalPaymentMethods: ["external_paypal"],
externalPaymentMethodConfirmHandler: { _, _, _ in /* no-op */ }
externalPaymentMethodConfirmHandler: { _, _, _ in /* no-op */ }
)
PaymentSheetLoader.load(mode: .paymentIntentClientSecret(clientSecret), configuration: configuration, analyticsHelper: .init(integrationShape: .complete, configuration: configuration), integrationShape: .complete) { result in
expectation.fulfill()
Expand Down Expand Up @@ -290,7 +338,7 @@ final class PaymentSheetLoaderTest: STPNetworkStubbingTestCase {
// ...with invalid external payment methods configured...
configuration.externalPaymentMethodConfiguration = .init(
externalPaymentMethods: ["external_invalid_value"],
externalPaymentMethodConfirmHandler: { _, _, _ in /* no-op */ }
externalPaymentMethodConfirmHandler: { _, _, _ in /* no-op */ }
)
PaymentSheetLoader.load(mode: .paymentIntentClientSecret(clientSecret), configuration: configuration, analyticsHelper: .init(integrationShape: .flowController, configuration: configuration), integrationShape: .flowController) { result in
expectation.fulfill()
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e3206a4

Please sign in to comment.