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

Disable wallet filtering for dashboard. #4169

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
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,52 @@ 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(integrationShape: .flowController, 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

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
Loading