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

feat(GiniHealthSDK): Customize name of the PDF QR Code File #790

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 @@ -37,6 +37,9 @@ public final class GiniHealthConfiguration: NSObject {
*/
public override init() {
super.init()
DispatchQueue.main.async {
self.paymentPDFFileName = NSLocalizedStringPreferredFormat(Constants.defaultPaymentPDFFileKey, comment: "")
}
}

// MARK: - Payment component view
Expand Down Expand Up @@ -160,11 +163,34 @@ public final class GiniHealthConfiguration: NSObject {
Client's configuration provided from the server
*/
var clientConfiguration: ClientConfiguration?

/**
Custom payment information pdf file provided through the QR code flow.
Customization rulles:
- Number of characters for the file name: 25
- Limit characters to letters, numbers, underscore and dash
*/
public var paymentPDFFileName: String = "" {
didSet {
if !isValidPDFFilename(paymentPDFFileName) {
paymentPDFFileName = NSLocalizedStringPreferredFormat(Constants.defaultPaymentPDFFileKey, comment: "")
}
}
}
}

extension GiniHealthConfiguration {
private func isValidPDFFilename(_ fileName: String) -> Bool {
let regex = "^[a-zA-Z0-9_-]{1,25}$" // Allows letters, numbers, underscore, and dash, max 25 characters
let response = NSPredicate(format: "SELF MATCHES %@", regex).evaluate(with: fileName)
return response
}
}

extension GiniHealthConfiguration {
private enum Constants {
static let defaultButtonsHeight = 56.0
static let minimumButtonsHeight = 44.0
static let defaultPaymentPDFFileKey = "gini.health.paymentcomponent.share.invoice.pdf.filename.default"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ extension PaymentComponentsController {
do {
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
guard let docDirectoryPath = paths.first else { return nil}
let pdfFileName = fileName + Constants.pdfExtension
let pdfFileName = GiniHealthConfiguration.shared.paymentPDFFileName + Constants.pdfExtension
let pdfPath = docDirectoryPath.appendingPathComponent(pdfFileName)
try data.write(to: pdfPath)
return pdfPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@
"gini.health.paymentcomponent.share.invoice.bottom.sheet.title" = "Teilen Sie diesen QR-Zahlungscode mit Ihrer Banking-App";
"gini.health.paymentcomponent.share.invoice.bottom.sheet.description" = "Alternativ können Sin ein Screenshot von dieser Seite machen mit der Fotoüberweisung Funktion der [BANK] öffnen.";
"gini.health.paymentcomponent.share.invoice.bottom.sheet.continue.button.text" = "Mit der [BANK]-App teilen";
"gini.health.paymentcomponent.share.invoice.pdf.filename.default" = "Zahlungsinformationen";
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@
"gini.health.paymentcomponent.share.invoice.bottom.sheet.title" = "Teile diesen QR-Zahlungscode mit deiner Banking-App";
"gini.health.paymentcomponent.share.invoice.bottom.sheet.description" = "Alternativ kannst du ein Screenshot von dieser Seite machen und mit der Fotoüberweisung Funktion der [BANK] öffnen.";
"gini.health.paymentcomponent.share.invoice.bottom.sheet.continue.button.text" = "Mit der [BANK]-App teilen";
"gini.health.paymentcomponent.share.invoice.pdf.filename.default" = "Zahlungsinformationen";
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@
"gini.health.paymentcomponent.share.invoice.bottom.sheet.title" = "Share this QR payment code with your banking app";
"gini.health.paymentcomponent.share.invoice.bottom.sheet.description" = "Or take a screenshot and upload it directly in your [BANK] app using the Photo Payment functionality";
"gini.health.paymentcomponent.share.invoice.bottom.sheet.continue.button.text" = "Share with [BANK] app";
"gini.health.paymentcomponent.share.invoice.pdf.filename.default" = "payment-information";
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,9 @@ extension AppCoordinator: DebugMenuDelegate {
giniHealthConfiguration.customLocalization = localization
health.setConfiguration(giniHealthConfiguration)
}

func didCustomizeQRCodePDFFilename(filename: String) {
giniHealthConfiguration.paymentPDFFileName = filename
health.setConfiguration(giniHealthConfiguration)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enum SwitchType {
protocol DebugMenuDelegate: AnyObject {
func didChangeSwitchValue(type: SwitchType, isOn: Bool)
func didPickNewLocalization(localization: GiniLocalization)
func didCustomizeQRCodePDFFilename(filename: String) // New delegate method
}

class DebugMenuViewController: UIViewController {
Expand Down Expand Up @@ -58,6 +59,17 @@ class DebugMenuViewController: UIViewController {
private var closeButtonSwitch: UISwitch!
private lazy var closeButtonRow: UIStackView = stackView(axis: .horizontal, subviews: [closeButtonOptionLabel, closeButtonSwitch])

private lazy var qrFilenameOptionLabel: UILabel = rowTitle("QR PDF Filename")
private lazy var qrFilenameTextField: UITextField = {
let textField = UITextField()
textField.translatesAutoresizingMaskIntoConstraints = false
textField.placeholder = "Enter filename"
textField.borderStyle = .roundedRect
textField.addTarget(self, action: #selector(qrFilenameTextFieldChanged(_:)), for: .editingChanged)
return textField
}()
private lazy var qrFilenameRow: UIStackView = stackView(axis: .horizontal, subviews: [qrFilenameOptionLabel, qrFilenameTextField])

weak var delegate: DebugMenuDelegate?

init(showReviewScreen: Bool,
Expand Down Expand Up @@ -92,7 +104,7 @@ class DebugMenuViewController: UIViewController {
view.backgroundColor = UIColor(named: "background")

let spacer = UIView()
let mainStackView = stackView(axis: .vertical, subviews: [titleLabel, localizationRow, reviewScreenRow, bottomPaymentComponentEditableRow, closeButtonRow, spacer])
let mainStackView = stackView(axis: .vertical, subviews: [titleLabel, localizationRow, reviewScreenRow, bottomPaymentComponentEditableRow, closeButtonRow, qrFilenameRow, spacer])
view.addSubview(mainStackView)

NSLayoutConstraint.activate([
Expand All @@ -104,9 +116,16 @@ class DebugMenuViewController: UIViewController {
localizationRow.heightAnchor.constraint(equalToConstant: rowHeight),
reviewScreenRow.heightAnchor.constraint(equalToConstant: rowHeight),
bottomPaymentComponentEditableRow.heightAnchor.constraint(equalToConstant: rowHeight),
closeButtonRow.heightAnchor.constraint(equalToConstant: rowHeight)
closeButtonRow.heightAnchor.constraint(equalToConstant: rowHeight),
qrFilenameRow.heightAnchor.constraint(equalToConstant: rowHeight)
])
}

@objc private func qrFilenameTextFieldChanged(_ sender: UITextField) {
if let filename = sender.text {
delegate?.didCustomizeQRCodePDFFilename(filename: filename)
}
}
}

private extension DebugMenuViewController {
Expand Down