From 7c6e0dc706485a7c9fe4b5270b42dfe7c6f67b71 Mon Sep 17 00:00:00 2001 From: codinronan Date: Wed, 27 Mar 2019 06:11:33 -0600 Subject: [PATCH] feaet(ios): add optional text footer to payment screens --- plugin.xml | 1 + src/ios/StripePaymentContextFooterView.swift | 54 ++++++++++++++++++++ src/ios/StripePaymentsPlugin.swift | 9 ++++ src/ios/StripePaymentsPluginConfig.swift | 2 + 4 files changed, 66 insertions(+) create mode 100644 src/ios/StripePaymentContextFooterView.swift diff --git a/plugin.xml b/plugin.xml index b8989a3..bbd78ca 100644 --- a/plugin.xml +++ b/plugin.xml @@ -73,6 +73,7 @@ + diff --git a/src/ios/StripePaymentContextFooterView.swift b/src/ios/StripePaymentContextFooterView.swift new file mode 100644 index 0000000..20023b7 --- /dev/null +++ b/src/ios/StripePaymentContextFooterView.swift @@ -0,0 +1,54 @@ +import UIKit +import Stripe + +class StripePaymentContextFooterView: UIView { + + var insetMargins: UIEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10) + + var text: String = "" { + didSet { + textLabel.text = text + } + } + + var theme: STPTheme = STPTheme.default() { + didSet { + textLabel.font = theme.smallFont + textLabel.textColor = theme.secondaryForegroundColor + } + } + + fileprivate let textLabel = UILabel() + + convenience init(text: String, align: NSTextAlignment = .center) { + self.init() + textLabel.numberOfLines = 0 + textLabel.textAlignment = align + textLabel.adjustsFontSizeToFitWidth = true + self.addSubview(textLabel) + + self.text = text + textLabel.text = text + + } + + override func layoutSubviews() { + textLabel.frame = self.bounds.inset(by: insetMargins) + } + + override func sizeThatFits(_ size: CGSize) -> CGSize { + // Add 10 pt border on all sides + var insetSize = size + insetSize.width -= (insetMargins.left + insetMargins.right) + insetSize.height -= (insetMargins.top + insetMargins.bottom) + + var newSize = textLabel.sizeThatFits(insetSize) + + newSize.width += (insetMargins.left + insetMargins.right) + newSize.height += (insetMargins.top + insetMargins.bottom) + + return newSize + } + + +} diff --git a/src/ios/StripePaymentsPlugin.swift b/src/ios/StripePaymentsPlugin.swift index f49b5de..7b13e53 100644 --- a/src/ios/StripePaymentsPlugin.swift +++ b/src/ios/StripePaymentsPlugin.swift @@ -50,6 +50,8 @@ import Stripe PluginConfig.appleMerchantId = dict["appleMerchantId"] as? String ?? "" PluginConfig.companyName = dict["companyName"] as? String ?? "" PluginConfig.maximumKeyRetries = dict["maximumKeyRetries"] as? Int ?? 0 + PluginConfig.paymentOptionsFooter = dict["paymentOptionsFooter"] as? String ?? "" + PluginConfig.addCardFooter = dict["addCardFooter"] as? String ?? "" if let headersDict = dict["extraHTTPHeaders"] as? [String:String] { PluginConfig.extraHTTPHeaders = headersDict @@ -114,6 +116,13 @@ import Stripe paymentContext.paymentCurrency = paymentOptions.currency paymentContext.paymentCountry = paymentOptions.country + if !PluginConfig.paymentOptionsFooter.isEmpty { + paymentContext.paymentOptionsViewControllerFooterView = StripePaymentContextFooterView(text: PluginConfig.paymentOptionsFooter, align: .left) + } + if !PluginConfig.addCardFooter.isEmpty { + paymentContext.addCardViewControllerFooterView = StripePaymentContextFooterView(text: PluginConfig.addCardFooter) + } + // This dialog collects a payment method from the user. When they close it, you get a context // change event with the payment info. NO charge has been created at that point, NO source // has been created from the payment method. All that has happened is the user entered diff --git a/src/ios/StripePaymentsPluginConfig.swift b/src/ios/StripePaymentsPluginConfig.swift index 6825907..54a3c95 100644 --- a/src/ios/StripePaymentsPluginConfig.swift +++ b/src/ios/StripePaymentsPluginConfig.swift @@ -10,6 +10,8 @@ public class StripePaymentsPluginConfig { public var appleMerchantId: String = "" public var companyName: String = "" public var maximumKeyRetries: Int = 0 + public var paymentOptionsFooter: String = "" + public var addCardFooter: String = "" public var extraHTTPHeaders: [String:String] = [:] }