Skip to content

Commit

Permalink
Add promo disclaimer in Instant Debits form
Browse files Browse the repository at this point in the history
  • Loading branch information
tillh-stripe committed Dec 6, 2024
1 parent 5d9d753 commit bde6b12
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ class CustomerAddPaymentMethodViewController: UIViewController {
isSettingUp: true,
countryCode: nil,
savePaymentMethodConsentBehavior: savePaymentMethodConsentBehavior,
analyticsHelper: nil
analyticsHelper: nil,
paymentMethodIncentive: nil
).make()
formElement.delegate = self
return formElement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class PaymentSheetFormFactory {
let cardBrandChoiceEligible: Bool
let savePaymentMethodConsentBehavior: SavePaymentMethodConsentBehavior
let analyticsHelper: PaymentSheetAnalyticsHelper?
let paymentMethodIncentive: PaymentMethodIncentive?

var shouldDisplaySaveCheckbox: Bool {
switch savePaymentMethodConsentBehavior {
Expand Down Expand Up @@ -95,7 +96,8 @@ class PaymentSheetFormFactory {
isSettingUp: intent.isSettingUp,
countryCode: elementsSession.countryCode(overrideCountry: configuration.overrideCountry),
savePaymentMethodConsentBehavior: elementsSession.savePaymentMethodConsentBehavior,
analyticsHelper: analyticsHelper)
analyticsHelper: analyticsHelper,
paymentMethodIncentive: elementsSession.incentive)
}

required init(
Expand All @@ -110,7 +112,8 @@ class PaymentSheetFormFactory {
isSettingUp: Bool,
countryCode: String?,
savePaymentMethodConsentBehavior: SavePaymentMethodConsentBehavior,
analyticsHelper: PaymentSheetAnalyticsHelper?
analyticsHelper: PaymentSheetAnalyticsHelper?,
paymentMethodIncentive: PaymentMethodIncentive?
) {
self.configuration = configuration
self.paymentMethod = paymentMethod
Expand All @@ -129,6 +132,7 @@ class PaymentSheetFormFactory {
self.cardBrandChoiceEligible = cardBrandChoiceEligible
self.savePaymentMethodConsentBehavior = savePaymentMethodConsentBehavior
self.analyticsHelper = analyticsHelper
self.paymentMethodIncentive = paymentMethodIncentive
}

func make() -> PaymentMethodElement {
Expand Down Expand Up @@ -662,6 +666,8 @@ extension PaymentSheetFormFactory {
let shouldHideEmailField = billingConfiguration.email == .never &&
configuration.defaultBillingDetails.email?.isEmpty == false
let emailElement = shouldHideEmailField ? nil : makeEmail()

let incentive = paymentMethodIncentive?.takeIfAppliesTo(paymentMethod)

return InstantDebitsPaymentMethodElement(
configuration: configuration,
Expand All @@ -670,6 +676,8 @@ extension PaymentSheetFormFactory {
emailElement: emailElement,
phoneElement: phoneElement,
addressElement: addressElement,
incentive: incentive,
isPaymentIntent: isPaymentIntent,
theme: theme
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ final class InstantDebitsPaymentMethodElement: ContainerElement {
emailElement: PaymentMethodElementWrapper<TextFieldElement>?,
phoneElement: PaymentMethodElementWrapper<PhoneNumberElement>?,
addressElement: PaymentMethodElementWrapper<AddressSectionElement>?,
incentive: PaymentMethodIncentive?,
isPaymentIntent: Bool,
theme: ElementsAppearance = .default
) {
self.configuration = configuration
Expand All @@ -189,6 +191,14 @@ final class InstantDebitsPaymentMethodElement: ContainerElement {
self.linkedBank = nil
self.linkedBankInfoSectionElement.view.isHidden = true
self.theme = theme

let promoDisclaimerElement = incentive.flatMap {
let label = ElementsUI.makeNoticeTextField(theme: theme)
label.attributedText = $0.promoDisclaimerText(with: theme, isPaymentIntent: isPaymentIntent)
label.textContainerInset = .zero
label.textContainer.lineFragmentPadding = 0
return StaticElement(view: label)
}

let allElements: [Element?] = [
titleElement,
Expand All @@ -197,6 +207,7 @@ final class InstantDebitsPaymentMethodElement: ContainerElement {
phoneElement,
addressElement,
linkedBankInfoSectionElement,
promoDisclaimerElement,
]
let autoSectioningElements = allElements.compactMap { $0 }
self.formElement = FormElement(
Expand Down Expand Up @@ -319,3 +330,44 @@ private extension PaymentSheet.Address {
state?.isEmpty == false
}
}

private extension PaymentMethodIncentive {

func promoDisclaimerText(
with appearance: ElementsAppearance,
isPaymentIntent: Bool
) -> NSAttributedString {
let baseString = if isPaymentIntent {
STPLocalizedString(
"Get %@ back when you pay with your bank. <terms>See\u{00a0}terms</terms>",
"Disclaimer for when a promotion is available for paying with a bank account. e.g. 'Get $5 back when […]'"
)
} else {
STPLocalizedString(
"Get %@ back when you pay for the first time with your bank. <terms>See\u{00a0}terms</terms>",
"Disclaimer for when a promotion is available for setting up a bank account. e.g. 'Get $5 back when […]'"
)
}

let string = String(format: baseString, displayText)

let links = [
"terms": URL(string: "https://link.com/promotion-terms")!,
]

let formattedString = STPStringUtils.applyLinksToString(template: string, links: links)

let style = NSMutableParagraphStyle()
style.alignment = .left
formattedString.addAttributes(
[
.paragraphStyle: style,
.font: UIFont.preferredFont(forTextStyle: .footnote),
.foregroundColor: appearance.colors.secondaryText,
],
range: NSRange(location: 0, length: formattedString.length)
)

return formattedString
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ Section header for address fields */
/* Content for alert popup prompting to confirm removing a saved bank account. e.g. 'Bank account •••• 4242' */
"Bank account •••• %@" = "Bank account •••• %@";

/* Disclaimer for when a promotion is available for paying with a bank account. e.g. 'Get $5 back when […]' */
"Get %@ back when you pay with your bank. <terms>See\u{00a0}terms</terms>" = "Get %@ back when you pay with your bank. <terms>See\u{00a0}terms</terms>";

/* Disclaimer for when a promotion is available for setting up a bank account. e.g. 'Get $5 back when […]' */
"Get %@ back when you pay for the first time with your bank. <terms>See\u{00a0}terms</terms>" = "Get %@ back when you pay for the first time with your bank. <terms>See\u{00a0}terms</terms>";

/* Label for a checkbox that makes customers billing address same as their shipping address */
"Billing address is same as shipping" = "Billing address is same as shipping";

Expand Down

0 comments on commit bde6b12

Please sign in to comment.