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

Relink/flowcontroller #4227

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
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 @@ -36,6 +36,7 @@ struct PaymentSheetTestPlayground: View {
.textInputAutocapitalization(.never)
}
SettingView(setting: $playgroundController.settings.linkMode)
SettingView(setting: $playgroundController.settings.useNativeLink)
SettingView(setting: $playgroundController.settings.userOverrideCountry)
SettingView(setting: $playgroundController.settings.externalPaymentMethods)
SettingView(setting: $playgroundController.settings.preferredNetworksEnabled)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,13 @@ struct PaymentSheetTestPlaygroundSettings: Codable, Equatable {
case passthrough
}

enum LinkNativeMode: String, PickerEnum {
static var enumName: String { "Native Link" }

case on
case off
}

enum UserOverrideCountry: String, PickerEnum {
static var enumName: String { "UserOverrideCountry (debug only)" }

Expand Down Expand Up @@ -449,6 +456,7 @@ struct PaymentSheetTestPlaygroundSettings: Codable, Equatable {
var defaultBillingAddress: DefaultBillingAddress
var customEmail: String?
var linkMode: LinkMode
var useNativeLink: LinkNativeMode
var userOverrideCountry: UserOverrideCountry
var customCtaLabel: String?
var paymentMethodConfigurationId: String?
Expand Down Expand Up @@ -493,6 +501,7 @@ struct PaymentSheetTestPlaygroundSettings: Codable, Equatable {
defaultBillingAddress: .off,
customEmail: nil,
linkMode: .passthrough,
useNativeLink: .off,
userOverrideCountry: .off,
customCtaLabel: nil,
paymentMethodConfigurationId: nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class PlaygroundController: ObservableObject {
configuration.applePay = applePayConfiguration
configuration.customer = customerConfiguration
configuration.appearance = appearance
configuration.forceEnableNativeLink = settings.useNativeLink == .on
if settings.userOverrideCountry != .off {
configuration.userOverrideCountry = settings.userOverrideCountry.rawValue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Created by Eduardo Urias on 2/27/23.
//

@_spi(STP) import StripeCore
@_spi(STP) import StripePayments
@testable import StripePaymentSheet
import XCTest

Expand Down Expand Up @@ -38,4 +40,23 @@ final class STPPaymentMethodBillingDetailsTests: XCTestCase {
XCTAssertNil(params["state"])
XCTAssertNil(params["country"])
}

func testCreateLinkBillingAddress() {
let billingAddress = BillingAddress(
name: "Name",
line1: "Line 1",
line2: "Line 2",
city: "City",
state: "State",
countryCode: "Country"
)
let billingDetails = STPPaymentMethodBillingDetails.init(billingAddress: billingAddress, email: "[email protected]")!
XCTAssertEqual(billingDetails.name, "Name")
XCTAssertEqual(billingDetails.address?.line1, "Line 1")
XCTAssertEqual(billingDetails.address?.line2, "Line 2")
XCTAssertEqual(billingDetails.address?.city, "City")
XCTAssertEqual(billingDetails.address?.state, "State")
XCTAssertEqual(billingDetails.address?.country, "Country")
XCTAssertEqual(billingDetails.email, "[email protected]")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

import Foundation

@_spi(STP) public struct BillingAddress: Encodable {
let name: String?
let line1: String?
let line2: String?
let city: String?
let state: String?
let postalCode: String?
let countryCode: String?
@_spi(STP) public struct BillingAddress: Codable {
@_spi(STP) public let name: String?
@_spi(STP) public let line1: String?
@_spi(STP) public let line2: String?
@_spi(STP) public let city: String?
@_spi(STP) public let state: String?
@_spi(STP) public let postalCode: String?
@_spi(STP) public let countryCode: String?

@_spi(STP) public init(
name: String? = nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
2E4C37C73AD202C8A3DD2E4E /* LoadingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 51FF291A25EA43D4D100983B /* LoadingViewController.swift */; };
2EC9C94DD8D62E4F4EFC8AB8 /* IntentStatusPollerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 990304EF35A0EE37DCE20D5B /* IntentStatusPollerTest.swift */; };
311AC53D6C76953E9B70148A /* ConsumerSession+PublishableKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2D61B52BFA201D25E8F6428 /* ConsumerSession+PublishableKey.swift */; };
313D00C82CD9972F00A8E6B0 /* PayWithNativeLinkController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 313D00C72CD9972F00A8E6B0 /* PayWithNativeLinkController.swift */; };
313F5F832B0BE5FD00BD98A9 /* Docs.docc in Sources */ = {isa = PBXBuildFile; fileRef = 313F5F822B0BE5FD00BD98A9 /* Docs.docc */; };
3147CEBB2CC07E960067B5E4 /* LinkUtils.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3147CEBA2CC07E960067B5E4 /* LinkUtils.swift */; };
3147CEC02CC080570067B5E4 /* LinkInMemoryCookieStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3147CEBD2CC080570067B5E4 /* LinkInMemoryCookieStore.swift */; };
Expand Down Expand Up @@ -85,6 +86,7 @@
3147CEF72CC1D3700067B5E4 /* PayWithLinkViewController-VerifyAccountViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3147CEEB2CC1D3700067B5E4 /* PayWithLinkViewController-VerifyAccountViewController.swift */; };
3147CEFE2CC1D3A60067B5E4 /* PayWithLinkViewController-WalletViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3147CEFD2CC1D3A60067B5E4 /* PayWithLinkViewController-WalletViewModelTests.swift */; };
3147CF012CC1D4350067B5E4 /* PaymentSheet-Configuration+Link.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3147CF002CC1D4350067B5E4 /* PaymentSheet-Configuration+Link.swift */; };
315673E72CD3024F00BA08BC /* PaymentSheet+Link.swift in Sources */ = {isa = PBXBuildFile; fileRef = 315673E62CD3024F00BA08BC /* PaymentSheet+Link.swift */; };
31699A812BE183B30048677F /* DownloadManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31699A802BE183B30048677F /* DownloadManager.swift */; };
31699A832BE183D40048677F /* DownloadManagerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 31699A822BE183D40048677F /* DownloadManagerTest.swift */; };
316B33122B5F171C0008D2E5 /* UserDefaults+StripePaymentSheetTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 316B33112B5F171C0008D2E5 /* UserDefaults+StripePaymentSheetTest.swift */; };
Expand Down Expand Up @@ -459,6 +461,7 @@
2DF75FD35820E7556EC34D15 /* hu */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hu; path = hu.lproj/Localizable.strings; sourceTree = "<group>"; };
2E2B99961C09E31383C9FCE9 /* mt */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = mt; path = mt.lproj/Localizable.strings; sourceTree = "<group>"; };
2E42F31D392C0AED757D6239 /* StripePaymentSheet.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = StripePaymentSheet.framework; sourceTree = BUILT_PRODUCTS_DIR; };
313D00C72CD9972F00A8E6B0 /* PayWithNativeLinkController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PayWithNativeLinkController.swift; sourceTree = "<group>"; };
313F5F822B0BE5FD00BD98A9 /* Docs.docc */ = {isa = PBXFileReference; lastKnownFileType = folder.documentationcatalog; path = Docs.docc; sourceTree = "<group>"; };
3147CEBA2CC07E960067B5E4 /* LinkUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkUtils.swift; sourceTree = "<group>"; };
3147CEBC2CC080570067B5E4 /* LinkCookieStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkCookieStore.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -492,6 +495,7 @@
3147CEED2CC1D3700067B5E4 /* PayWithLinkViewController-WalletViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PayWithLinkViewController-WalletViewModel.swift"; sourceTree = "<group>"; };
3147CEFD2CC1D3A60067B5E4 /* PayWithLinkViewController-WalletViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PayWithLinkViewController-WalletViewModelTests.swift"; sourceTree = "<group>"; };
3147CF002CC1D4350067B5E4 /* PaymentSheet-Configuration+Link.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PaymentSheet-Configuration+Link.swift"; sourceTree = "<group>"; };
315673E62CD3024F00BA08BC /* PaymentSheet+Link.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PaymentSheet+Link.swift"; sourceTree = "<group>"; };
3168698F2C61B0F5EC1240FE /* sl-SI */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = "sl-SI"; path = "sl-SI.lproj/Localizable.strings"; sourceTree = "<group>"; };
31699A802BE183B30048677F /* DownloadManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DownloadManager.swift; sourceTree = "<group>"; };
31699A822BE183D40048677F /* DownloadManagerTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DownloadManagerTest.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1025,6 +1029,7 @@
6B680A2FF197F612D065F16C /* PaymentSheet.swift */,
5CD1A451B238C1D1ADAA72EC /* PaymentSheet+API.swift */,
0D447E18D1066195679B7956 /* PaymentSheet+DeferredAPI.swift */,
315673E62CD3024F00BA08BC /* PaymentSheet+Link.swift */,
BBB6BEFBCE1116B85B564574 /* PaymentSheet+PaymentMethodAvailability.swift */,
B9A9FDAE66ADA08D85D74E19 /* PaymentSheet+SwiftUI.swift */,
B61FFE76D0960C7F1E34B405 /* PaymentSheetAppearance.swift */,
Expand Down Expand Up @@ -1543,6 +1548,7 @@
children = (
52185F7315D3C4089D3465BD /* LinkPaymentController.swift */,
B41560E0599A68A84F5C76D2 /* PaymentSheet-LinkConfirmOption.swift */,
313D00C72CD9972F00A8E6B0 /* PayWithNativeLinkController.swift */,
5DCFBC65AF58423E0E8DD04A /* PayWithLinkController.swift */,
);
path = Link;
Expand Down Expand Up @@ -2028,6 +2034,7 @@
B63B2CF52BFBEEAD003810F3 /* PaymentMethodFormViewController.swift in Sources */,
31CC9B972CB5F74A00E84A38 /* LinkNavigationBar.swift in Sources */,
31CC9B982CB5F74A00E84A38 /* LinkNoticeView.swift in Sources */,
315673E72CD3024F00BA08BC /* PaymentSheet+Link.swift in Sources */,
31CC9B9A2CB5F74A00E84A38 /* LinkToast.swift in Sources */,
31CC9B9C2CB5F74A00E84A38 /* LinkBadgeView.swift in Sources */,
108846A3D8EFD1D4DCC0DDBC /* NSAttributedString+Stripe.swift in Sources */,
Expand Down Expand Up @@ -2137,6 +2144,7 @@
3147CECB2CC1BF550067B5E4 /* LinkPaymentMethodPicker-CellContentView.swift in Sources */,
3147CECC2CC1BF550067B5E4 /* LinkPaymentMethodPicker-Cell.swift in Sources */,
3147CECD2CC1BF550067B5E4 /* LinkPaymentMethodPicker-Header.swift in Sources */,
313D00C82CD9972F00A8E6B0 /* PayWithNativeLinkController.swift in Sources */,
3147CECE2CC1BF550067B5E4 /* LinkPaymentMethodPicker-RadioButton.swift in Sources */,
3147CECF2CC1BF550067B5E4 /* LinkPaymentMethodPicker-AddButton.swift in Sources */,
FB653AA92B68F73344835A50 /* Intent.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,7 @@ extension PaymentSheetLinkAccount {
}

let params = STPPaymentMethodParams(type: .link)
params.billingDetails = STPPaymentMethodBillingDetails(billingAddress: paymentDetails.billingAddress, email: paymentDetails.billingEmailAddress)
params.link?.paymentDetailsID = paymentDetails.stripeID
params.link?.credentials = ["consumer_session_client_secret": currentSession.clientSecret]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,34 @@ typealias ConsumerSessionWithPaymentDetails = (session: ConsumerSession, payment
final class ConsumerPaymentDetails: Decodable {
let stripeID: String
let details: Details
let billingAddress: BillingAddress?
let billingEmailAddress: String?
var isDefault: Bool

// TODO(link) : Billing address

init(stripeID: String,
details: Details,
billingAddress: BillingAddress?,
billingEmailAddress: String?,
isDefault: Bool) {
self.stripeID = stripeID
self.details = details
self.billingAddress = billingAddress
self.billingEmailAddress = billingEmailAddress
self.isDefault = isDefault
}

private enum CodingKeys: String, CodingKey {
case stripeID = "id"
case billingAddress = "billing_address"
case billingEmailAddress = "billing_email_address"
case isDefault
}

init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
self.stripeID = try container.decode(String.self, forKey: .stripeID)
self.billingAddress = try? container.decode(BillingAddress.self, forKey: .billingAddress)
self.billingEmailAddress = try? container.decode(String.self, forKey: .billingEmailAddress)
// The payment details are included in the dictionary, so we pass the whole dict to Details
self.details = try decoder.singleValueContainer().decode(Details.self)
self.isDefault = try container.decode(Bool.self, forKey: .isDefault)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2021 Stripe, Inc. All rights reserved.
//

@_spi(STP) import StripePayments
@_spi(STP) import StripePaymentsUI
@_spi(STP) import StripeUICore
import UIKit
Expand All @@ -22,10 +23,8 @@ extension LinkPaymentMethodPicker {
var paymentMethod: ConsumerPaymentDetails? {
didSet {
switch paymentMethod?.details {
case .card:
// TODO(link): Needs refactor
// case .card(let card):
// cardBrandView.cardBrand = card.stpBrand
case .card(let card):
cardBrandView.setCardBrand(STPCard.brand(from: card.brand))
bankIconView.isHidden = true
cardBrandView.isHidden = false
primaryLabel.text = paymentMethod?.paymentSheetLabel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,13 @@ extension PayWithLinkViewController {
var configuration = context.configuration
configuration.linkPaymentMethodsOnly = true
configuration.appearance = LinkUI.appearance
// TODO(link): Update elementsSession, formCache, analyticsHelper, and paymentMethodTypes
assertionFailure("Not yet implemented")
return AddPaymentMethodViewController(
intent: context.intent,
// TODO(link): Update elementsSession
elementsSession: .makeBackupElementsSession(allResponseFields: [:], paymentMethodTypes: []),
elementsSession: context.elementsSession,
configuration: configuration,
paymentMethodTypes: [.stripe(.card)],
formCache: .init(),
analyticsHelper: .init(integrationShape: .complete, configuration: configuration),
formCache: .init(), // We don't want to share a form cache with the containing PaymentSheet
analyticsHelper: context.analyticsHelper,
delegate: self
)
}()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,8 @@ extension PayWithLinkViewController {
case .success(let account):
self?.coordinator?.accountUpdated(account)
STPAnalyticsClient.sharedClient.logLinkSignupComplete()
case .failure: break
// TODO(link): Fix signup failure logging
// STPAnalyticsClient.sharedClient.logLinkSignupFailure()
case .failure(let error):
STPAnalyticsClient.sharedClient.logLinkSignupFailure(error: error)
}

self?.signUpButton.isLoading = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ protocol PayWithLinkViewControllerDelegate: AnyObject {
func payWithLinkViewControllerDidConfirm(
_ payWithLinkViewController: PayWithLinkViewController,
intent: Intent,
elementsSession: STPElementsSession,
with paymentOption: PaymentOption,
completion: @escaping (PaymentSheetResult, STPAnalyticsClient.DeferredIntentConfirmationType?) -> Void
)
Expand Down Expand Up @@ -67,6 +68,7 @@ final class PayWithLinkViewController: UINavigationController {
let shouldFinishOnClose: Bool
let callToAction: ConfirmButton.CallToActionType
var lastAddedPaymentDetails: ConsumerPaymentDetails?
var analyticsHelper: PaymentSheetAnalyticsHelper

/// Creates a new Context object.
/// - Parameters:
Expand All @@ -76,20 +78,23 @@ final class PayWithLinkViewController: UINavigationController {
/// - shouldOfferApplePay: Whether or not to show Apple Pay as a payment option.
/// - shouldFinishOnClose: Whether or not Link should finish with `.canceled` result instead of returning to Payment Sheet when the close button is tapped.
/// - callToAction: A custom CTA to display on the confirm button. If `nil`, will display `intent`'s default CTA.
/// - analyticsHelper: An instance of `AnalyticsHelper` to use for logging.
init(
intent: Intent,
elementsSession: STPElementsSession,
configuration: PaymentSheet.Configuration,
shouldOfferApplePay: Bool,
shouldFinishOnClose: Bool,
callToAction: ConfirmButton.CallToActionType?
callToAction: ConfirmButton.CallToActionType?,
analyticsHelper: PaymentSheetAnalyticsHelper
) {
self.intent = intent
self.elementsSession = elementsSession
self.configuration = configuration
self.shouldOfferApplePay = shouldOfferApplePay
self.shouldFinishOnClose = shouldFinishOnClose
self.callToAction = callToAction ?? intent.callToAction
self.analyticsHelper = analyticsHelper
}
}

Expand Down Expand Up @@ -117,7 +122,8 @@ final class PayWithLinkViewController: UINavigationController {
configuration: PaymentSheet.Configuration,
shouldOfferApplePay: Bool = false,
shouldFinishOnClose: Bool = false,
callToAction: ConfirmButton.CallToActionType? = nil
callToAction: ConfirmButton.CallToActionType? = nil,
analyticsHelper: PaymentSheetAnalyticsHelper
) {
self.init(
context: Context(
Expand All @@ -126,7 +132,8 @@ final class PayWithLinkViewController: UINavigationController {
configuration: configuration,
shouldOfferApplePay: shouldOfferApplePay,
shouldFinishOnClose: shouldFinishOnClose,
callToAction: callToAction
callToAction: callToAction,
analyticsHelper: analyticsHelper
)
)
}
Expand Down Expand Up @@ -292,6 +299,7 @@ extension PayWithLinkViewController: PayWithLinkCoordinating {
payWithLinkDelegate?.payWithLinkViewControllerDidConfirm(
self,
intent: context.intent,
elementsSession: context.elementsSession,
with: PaymentOption.link(
option: .withPaymentDetails(account: linkAccount, paymentDetails: paymentDetails)
)
Expand All @@ -306,6 +314,7 @@ extension PayWithLinkViewController: PayWithLinkCoordinating {
payWithLinkDelegate?.payWithLinkViewControllerDidConfirm(
self,
intent: context.intent,
elementsSession: context.elementsSession,
with: .applePay
) { [weak self] result, _ in
// TODO(link): Log confirmation type here
Expand Down
Loading
Loading