feaet(ios): add optional text footer to payment screens
This commit is contained in:
parent
e29dfea13a
commit
7c6e0dc706
@ -73,6 +73,7 @@
|
|||||||
<source-file src="src/ios/StripePaymentOptions.swift" />
|
<source-file src="src/ios/StripePaymentOptions.swift" />
|
||||||
<source-file src="src/ios/StripePaymentsPluginConfig.swift" />
|
<source-file src="src/ios/StripePaymentsPluginConfig.swift" />
|
||||||
<source-file src="src/ios/StripePaymentsPlugin.swift" />
|
<source-file src="src/ios/StripePaymentsPlugin.swift" />
|
||||||
|
<source-file src="src/ios/StripePaymentContextFooterView.swift" />
|
||||||
</platform>
|
</platform>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
54
src/ios/StripePaymentContextFooterView.swift
Normal file
54
src/ios/StripePaymentContextFooterView.swift
Normal file
@ -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
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -50,6 +50,8 @@ import Stripe
|
|||||||
PluginConfig.appleMerchantId = dict["appleMerchantId"] as? String ?? ""
|
PluginConfig.appleMerchantId = dict["appleMerchantId"] as? String ?? ""
|
||||||
PluginConfig.companyName = dict["companyName"] as? String ?? ""
|
PluginConfig.companyName = dict["companyName"] as? String ?? ""
|
||||||
PluginConfig.maximumKeyRetries = dict["maximumKeyRetries"] as? Int ?? 0
|
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] {
|
if let headersDict = dict["extraHTTPHeaders"] as? [String:String] {
|
||||||
PluginConfig.extraHTTPHeaders = headersDict
|
PluginConfig.extraHTTPHeaders = headersDict
|
||||||
@ -114,6 +116,13 @@ import Stripe
|
|||||||
paymentContext.paymentCurrency = paymentOptions.currency
|
paymentContext.paymentCurrency = paymentOptions.currency
|
||||||
paymentContext.paymentCountry = paymentOptions.country
|
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
|
// 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
|
// 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
|
// has been created from the payment method. All that has happened is the user entered
|
||||||
|
@ -10,6 +10,8 @@ public class StripePaymentsPluginConfig {
|
|||||||
public var appleMerchantId: String = ""
|
public var appleMerchantId: String = ""
|
||||||
public var companyName: String = ""
|
public var companyName: String = ""
|
||||||
public var maximumKeyRetries: Int = 0
|
public var maximumKeyRetries: Int = 0
|
||||||
|
public var paymentOptionsFooter: String = ""
|
||||||
|
public var addCardFooter: String = ""
|
||||||
public var extraHTTPHeaders: [String:String] = [:]
|
public var extraHTTPHeaders: [String:String] = [:]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user