-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Introduce IntegrationConfigurable #4081
Changes from 1 commit
f12ff59
8d7f39a
a4ba6b6
d119ee2
bae9e15
d2e1d58
d86a5e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ import Foundation | |
final class PaymentSheetAnalyticsHelper { | ||
let analyticsClient: STPAnalyticsClient | ||
let isCustom: Bool | ||
let configuration: PaymentSheet.Configuration | ||
let configuration: IntegrationConfigurable | ||
|
||
// Vars set later as PaymentSheet successfully loads, etc. | ||
var intent: Intent? | ||
|
@@ -22,7 +22,7 @@ final class PaymentSheetAnalyticsHelper { | |
|
||
init( | ||
isCustom: Bool, | ||
configuration: PaymentSheet.Configuration, | ||
configuration: IntegrationConfigurable, | ||
analyticsClient: STPAnalyticsClient = .sharedClient | ||
) { | ||
self.isCustom = isCustom | ||
|
@@ -354,3 +354,36 @@ extension PaymentSheet.Configuration { | |
return payload | ||
} | ||
} | ||
|
||
extension EmbeddedPaymentElement.Configuration { | ||
/// Serializes the configuration into a safe dictionary containing no PII for analytics logging | ||
var analyticPayload: [String: Any] { | ||
var payload = [String: Any]() | ||
payload["allows_delayed_payment_methods"] = allowsDelayedPaymentMethods | ||
payload["apple_pay_config"] = applePay != nil | ||
payload["style"] = style.rawValue | ||
payload["customer"] = customer != nil | ||
payload["customer_access_provider"] = customer?.customerAccessProvider.analyticValue | ||
payload["return_url"] = returnURL != nil | ||
payload["default_billing_details"] = defaultBillingDetails != PaymentSheet.BillingDetails() | ||
payload["save_payment_method_opt_in_behavior"] = savePaymentMethodOptInBehavior.description | ||
payload["appearance"] = appearance.analyticPayload | ||
payload["billing_details_collection_configuration"] = billingDetailsCollectionConfiguration.analyticPayload | ||
payload["preferred_networks"] = preferredNetworks?.map({ STPCardBrandUtilities.apiValue(from: $0) }).joined(separator: ", ") | ||
payload["form_sheet_action"] = formSheetAction.analyticValue | ||
payload["hide_mandate_text"] = hidesMandateText | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note these new embedded only params. |
||
|
||
return payload | ||
} | ||
} | ||
|
||
extension EmbeddedPaymentElement.Configuration.FormSheetAction { | ||
var analyticValue: String { | ||
switch self { | ||
case .confirm: | ||
return "confirm" | ||
case .continue: | ||
return "continue" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -244,7 +244,7 @@ class CustomerAddPaymentMethodViewController: UIViewController { | |
isSettingUp: true, | ||
countryCode: nil, | ||
savePaymentMethodConsentBehavior: savePaymentMethodConsentBehavior, | ||
analyticsHelper: .init(isCustom: false, configuration: .init()) // Just use a dummy analytics helper; we don't look at these analytics. | ||
analyticsHelper: .init(isCustom: false, configuration: PaymentSheet.Configuration.init()) // Just use a dummy analytics helper; we don't look at these analytics. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add https://jira.corp.stripe.com/browse/MOBILESDK-2548 to this comment |
||
).make() | ||
formElement.delegate = self | ||
return formElement | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// IntegrationConfigurable.swift | ||
// StripePaymentSheet | ||
// | ||
// Created by Nick Porter on 10/1/24. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
@_spi(STP) import StripePayments | ||
|
||
/// Represents shared configuration properties shared between integration surfaces in mobile payment element. | ||
/// - Note: See the concrete implementations of `IntegrationConfigurable` for detailed doc comments. | ||
/// - Note: Not currently used by CustomerSheet. | ||
protocol IntegrationConfigurable: PaymentMethodRequirementProvider { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Open to naming suggestions There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's call it PaymentElementConfiguration? I think that's the most accurate name, since this is Configuration for all Mobile Payment Element integration variants. We just need to start thinking of PaymentSheet, FlowController, EmbeddedPaymentElement as Payment Element variants. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This means we should probably rename things like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree on renaming other PaymentSheet prefixed classes, maybe something we should tackle when we rename the module. |
||
var allowsDelayedPaymentMethods: Bool { get set } | ||
var allowsPaymentMethodsRequiringShippingAddress: Bool { get set } | ||
var apiClient: STPAPIClient { get set } | ||
var applePay: PaymentSheet.ApplePayConfiguration? { get set } | ||
var primaryButtonColor: UIColor? { get set } | ||
var primaryButtonLabel: String? { get set } | ||
var style: PaymentSheet.UserInterfaceStyle { get set } | ||
var customer: PaymentSheet.CustomerConfiguration? { get set } | ||
var merchantDisplayName: String { get set } | ||
var returnURL: String? { get set } | ||
var defaultBillingDetails: PaymentSheet.BillingDetails { get set } | ||
var savePaymentMethodOptInBehavior: PaymentSheet.SavePaymentMethodOptInBehavior { get set } | ||
var appearance: PaymentSheet.Appearance { get set } | ||
var shippingDetails: () -> AddressViewController.AddressDetails? { get set } | ||
var preferredNetworks: [STPCardBrand]? { get set } | ||
var userOverrideCountry: String? { get set } | ||
var billingDetailsCollectionConfiguration: PaymentSheet.BillingDetailsCollectionConfiguration { get set } | ||
var removeSavedPaymentMethodMessage: String? { get set } | ||
var externalPaymentMethodConfiguration: PaymentSheet.ExternalPaymentMethodConfiguration? { get set } | ||
var paymentMethodOrder: [String]? { get set } | ||
var allowsRemovalOfLastSavedPaymentMethod: Bool { get set } | ||
var analyticPayload: [String: Any] { get } | ||
} | ||
|
||
extension IntegrationConfigurable { | ||
|
||
/// Returns `true` if the merchant requires the collection of _any_ billing detail fields - name, phone, email, address. | ||
func requiresBillingDetailCollection() -> Bool { | ||
return billingDetailsCollectionConfiguration.name == .always | ||
|| billingDetailsCollectionConfiguration.phone == .always | ||
|| billingDetailsCollectionConfiguration.email == .always | ||
|| billingDetailsCollectionConfiguration.address == .full | ||
} | ||
|
||
var fulfilledRequirements: [PaymentMethodTypeRequirement] { | ||
var reqs = [PaymentMethodTypeRequirement]() | ||
if returnURL != nil { reqs.append(.returnURL) } | ||
if allowsDelayedPaymentMethods { reqs.append(.userSupportsDelayedPaymentMethods) } | ||
if allowsPaymentMethodsRequiringShippingAddress { reqs.append(.shippingAddress) } | ||
if FinancialConnectionsSDKAvailability.isFinancialConnectionsSDKAvailable { | ||
reqs.append(.financialConnectionsSDK) | ||
} | ||
return reqs | ||
} | ||
} | ||
|
||
extension PaymentSheet.Configuration: IntegrationConfigurable {} | ||
extension EmbeddedPaymentElement.Configuration: IntegrationConfigurable {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should keep this
PaymentSheet.Configuration
? I'm not sure this class can reasonably also handle analytics for EMPEThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah looking at the class more, it'll be pretty hard. We'll want some embedded specific one.