Skip to content

Commit

Permalink
Merge pull request #749 from gini/fix-RC-bugs-reported
Browse files Browse the repository at this point in the history
fix(GiniHealthSDK): Fix RC bugs reported
  • Loading branch information
ValentinaIancu-Gini authored Dec 20, 2024
2 parents c8084f7 + 5d1900a commit f7b8a2b
Show file tree
Hide file tree
Showing 20 changed files with 212 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let package = Package(
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(name: "GiniHealthAPILibrary", url: "https://github.com/gini/health-api-library-ios.git", .exact("5.0.0")),
.package(name: "GiniUtilites", url: "https://github.com/gini/utilites-ios.git", .exact("1.1.0")),
.package(name: "GiniUtilites", url: "https://github.com/gini/utilites-ios.git", .exact("2.0.0")),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
//


public let GiniInternalPaymentSDKVersion = "1.0.0"
public let GiniInternalPaymentSDKVersion = "1.1.0"
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public struct PaymentInfoConfiguration {
}

public struct PaymentInfoStrings {
let giniWebsiteText : String
let giniWebsiteText: String
let giniURLText: String

let questionsTitleText: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ public final class PaymentInfoViewModel {
let attributedString = attributedString
let giniRange = (attributedString.string as NSString).range(of: strings.giniWebsiteText)
attributedString.addLinkToRange(link: strings.giniURLText,
color: configuration.linksColor,
range: giniRange,
linkFont: linkFont,
textToRemove: Constants.linkTextToRemove)
let privacyPolicyRange = (attributedString.string as NSString).range(of: strings.answerPrivacyPolicyText)
attributedString.addLinkToRange(link: strings.privacyPolicyURLText,
color: configuration.linksColor,
range: privacyPolicyRange,
linkFont: linkFont,
textToRemove: Constants.linkTextToRemove)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public protocol PaymentReviewActionProtocol {
func updatedPaymentProvider(_ paymentProvider: PaymentProvider)
func openMoreInformationViewController()
func presentShareInvoiceBottomSheet(paymentRequestId: String, paymentInfo: PaymentInfo)
func paymentReviewClosed(with previousPresentedView: PaymentComponentScreenType?)
}

/**
Expand Down Expand Up @@ -123,6 +124,7 @@ public class PaymentReviewModel: NSObject {
let bottomSheetConfiguration: BottomSheetConfiguration
let showPaymentReviewCloseButton: Bool
var displayMode: DisplayMode
var previousPaymentComponentScreenType: PaymentComponentScreenType?

public init(delegate: PaymentReviewProtocol,
bottomSheetsProvider: BottomSheetsProviderProtocol,
Expand All @@ -142,7 +144,8 @@ public class PaymentReviewModel: NSObject {
poweredByGiniConfiguration: PoweredByGiniConfiguration,
poweredByGiniStrings: PoweredByGiniStrings,
bottomSheetConfiguration: BottomSheetConfiguration,
showPaymentReviewCloseButton: Bool) {
showPaymentReviewCloseButton: Bool,
previousPaymentComponentScreenType: PaymentComponentScreenType?) {
self.delegate = delegate
self.bottomSheetsProvider = bottomSheetsProvider
self.configuration = configuration
Expand All @@ -164,6 +167,11 @@ public class PaymentReviewModel: NSObject {
self.selectionStyleInputFieldConfiguration = selectionStyleInputFieldConfiguration
self.bottomSheetConfiguration = bottomSheetConfiguration
self.displayMode = document != nil ? .documentCollection : .bottomSheet
self.previousPaymentComponentScreenType = previousPaymentComponentScreenType
}

func viewDidDisappear() {
delegate?.paymentReviewClosed(with: previousPaymentComponentScreenType)
}

func getCellViewModel(at indexPath: IndexPath) -> PageCollectionCellViewModel {
Expand Down Expand Up @@ -313,6 +321,7 @@ extension PaymentReviewModel: BanksSelectionProtocol {
This function notifies the delegate to open the "More Information" view controller.
*/
public func didTapOnMoreInformation() {
previousPaymentComponentScreenType = .bankPicker
delegate?.openMoreInformationViewController()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public final class PaymentReviewViewController: BottomSheetViewController, UIGes
private lazy var closeButton = buildCloseButton()
private lazy var infoBar = buildInfoBar()
private lazy var infoBarLabel = buildInfoBarLabel()
private lazy var containerCollectionView = buildContainerCollectionView()
private var isInfoBarHidden = true
lazy var paymentInfoContainerView = buildPaymentInfoContainerView()
lazy var collectionView = buildCollectionView()
Expand Down Expand Up @@ -62,6 +61,10 @@ public final class PaymentReviewViewController: BottomSheetViewController, UIGes
showInfoBar()
showInfoBarOnce = false
}
if model.previousPaymentComponentScreenType == .bankPicker {
model.openBankSelectionBottomSheet()
model.previousPaymentComponentScreenType = nil
}
}

fileprivate func setupViewModel() {
Expand Down Expand Up @@ -131,7 +134,9 @@ public final class PaymentReviewViewController: BottomSheetViewController, UIGes
}

override public func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
unsubscribeFromNotifications()
model.viewDidDisappear()
}

public override var preferredStatusBarStyle: UIStatusBarStyle {
Expand Down Expand Up @@ -354,14 +359,6 @@ fileprivate extension PaymentReviewViewController {

//MARK: - Collection View Container
fileprivate extension PaymentReviewViewController {
func buildContainerCollectionView() -> UIStackView {
let container = UIStackView(arrangedSubviews: [collectionView, pageControl])
container.spacing = 0
container.axis = .vertical
container.distribution = .fill
return container
}

func buildCollectionView() -> UICollectionView {
let flowLayout = UICollectionViewFlowLayout()
flowLayout.minimumInteritemSpacing = Constants.collectionViewPadding
Expand All @@ -380,26 +377,34 @@ fileprivate extension PaymentReviewViewController {
let control = UIPageControl()
control.pageIndicatorTintColor = model.configuration.pageIndicatorTintColor
control.currentPageIndicatorTintColor = model.configuration.currentPageIndicatorTintColor
control.backgroundColor = model.configuration.backgroundColor
control.backgroundColor = .clear
control.hidesForSinglePage = true
control.numberOfPages = model.document?.pageCount ?? 0
return control
}

func layoutContainerCollectionView() {
containerCollectionView.translatesAutoresizingMaskIntoConstraints = false
mainView.addSubview(containerCollectionView)
mainView.sendSubviewToBack(containerCollectionView)
collectionView.translatesAutoresizingMaskIntoConstraints = false
pageControl.translatesAutoresizingMaskIntoConstraints = false
mainView.addSubview(pageControl)
mainView.sendSubviewToBack(pageControl)

mainView.addSubview(collectionView)
mainView.sendSubviewToBack(collectionView)

let navigationBarHeight = self.navigationController?.navigationBar.frame.maxY ?? 0

NSLayoutConstraint.activate([
containerCollectionView.leadingAnchor.constraint(equalTo: mainView.leadingAnchor),
containerCollectionView.trailingAnchor.constraint(equalTo: mainView.trailingAnchor),
containerCollectionView.topAnchor.constraint(equalTo: mainView.topAnchor),
containerCollectionView.bottomAnchor.constraint(equalTo: paymentInfoContainerView.topAnchor, constant: Constants.collectionViewBottomPadding),
collectionView.leadingAnchor.constraint(equalTo: mainView.leadingAnchor),
collectionView.trailingAnchor.constraint(equalTo: mainView.trailingAnchor),
collectionView.topAnchor.constraint(equalTo: mainView.topAnchor, constant: navigationBarHeight),
collectionView.bottomAnchor.constraint(equalTo: paymentInfoContainerView.topAnchor, constant: Constants.collectionViewBottomPadding),

pageControl.heightAnchor.constraint(equalToConstant: Constants.pageControlHeight),
collectionView.widthAnchor.constraint(equalTo: containerCollectionView.widthAnchor),
collectionView.heightAnchor.constraint(equalTo: containerCollectionView.heightAnchor),
pageControl.bottomAnchor.constraint(equalTo: collectionView.bottomAnchor, constant: -Constants.collectionViewPadding),
pageControl.centerXAnchor.constraint(equalTo: mainView.centerXAnchor),
collectionView.widthAnchor.constraint(equalTo: collectionView.widthAnchor),
collectionView.heightAnchor.constraint(equalTo: collectionView.heightAnchor),
paymentInfoContainerView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
paymentInfoContainerView.trailingAnchor.constraint(equalTo: view.trailingAnchor)
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import UIKit

extension NSMutableAttributedString {
public func addLinkToRange(link: String, range: NSRange, linkFont: UIFont, textToRemove: String?) {
var attributes: [NSAttributedString.Key: Any] = [.font: linkFont]
public func addLinkToRange(link: String, color: UIColor, range: NSRange, linkFont: UIFont, textToRemove: String?) {
var attributes: [NSAttributedString.Key: Any] = [.font: linkFont, .foregroundColor: color]
if range.length > 0, let url = URL(string: link) {
attributes[.link] = url
self.addAttributes(attributes, range: range)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
// Copyright © 2024 Gini GmbH. All rights reserved.
//

public let GiniUtilitesVersion = "1.1.0"
public let GiniUtilitesVersion = "2.0.0"
4 changes: 2 additions & 2 deletions HealthSDK/GiniHealthSDK/Package-release.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ let package = Package(
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(name: "GiniHealthAPILibrary", url: "https://github.com/gini/health-api-library-ios.git", .exact("5.0.0")),
.package(name: "GiniInternalPaymentSDK", url: "https://github.com/gini/internal-payment-sdk-ios", .exact("1.0.0")),
.package(name: "GiniUtilites", url: "https://github.com/gini/utilites-ios.git", .exact("1.1.0")),
.package(name: "GiniInternalPaymentSDK", url: "https://github.com/gini/internal-payment-sdk-ios", .exact("1.1.0")),
.package(name: "GiniUtilites", url: "https://github.com/gini/utilites-ios.git", .exact("2.0.0")),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ extension PaymentComponentsController {
if previousPresentedViews.count > 0, previousPresentedViews.first != .paymentReview {
previousPresentedViews.removeAll()
}
previousPresentedViews.insert(.bankPicker)
let paymentProvidersBottomViewModel = BanksBottomViewModel(paymentProviders: paymentProviders,
selectedPaymentProvider: healthSelectedPaymentProvider,
configuration: configurationProvider.bankSelectionConfiguration,
Expand Down Expand Up @@ -182,7 +181,8 @@ extension PaymentComponentsController {
*/
func loadPaymentReviewScreenFor(trackingDelegate: GiniHealthTrackingDelegate?,
completion: @escaping (UIViewController?, GiniHealthError?) -> Void) {
previousPresentedViews.insert(.paymentReview)
previousPresentedViews.append(.paymentReview)
let previousPaymentComponentScreenType: PaymentComponentScreenType? = previousPresentedViews.contains(.bankPicker) ? .bankPicker : nil
if !GiniHealthConfiguration.shared.useInvoiceWithoutDocument {
guard let documentId else {
completion(nil, nil)
Expand All @@ -197,26 +197,35 @@ extension PaymentComponentsController {
completion(nil, nil)
return
}
self.preparePaymentReviewViewController(data: data, paymentInfo: nil, completion: completion)
self.preparePaymentReviewViewController(data: data,
paymentInfo: nil,
previousPaymentComponentScreenType: previousPaymentComponentScreenType,
completion: completion)
case .failure(let error):
completion(nil, error)
}
}
} else {
loadPaymentReviewScreenWithoutDocument(paymentInfo: paymentInfo, trackingDelegate: trackingDelegate, completion: completion)
loadPaymentReviewScreenWithoutDocument(paymentInfo: paymentInfo,
trackingDelegate: trackingDelegate,
previousPaymentComponentScreenType: previousPaymentComponentScreenType,
completion: completion)
}
}

private func loadPaymentReviewScreenWithoutDocument(paymentInfo: GiniInternalPaymentSDK.PaymentInfo?,
trackingDelegate: GiniHealthTrackingDelegate?,
previousPaymentComponentScreenType: PaymentComponentScreenType? = nil,
completion: @escaping (UIViewController?, GiniHealthError?) -> Void) {
preparePaymentReviewViewController(data: nil,
paymentInfo: paymentInfo,
previousPaymentComponentScreenType: previousPaymentComponentScreenType,
completion: completion)
}

private func preparePaymentReviewViewController(data: DataForReview?,
paymentInfo: GiniInternalPaymentSDK.PaymentInfo?,
previousPaymentComponentScreenType: PaymentComponentScreenType? = nil,
completion: @escaping (UIViewController?, GiniHealthError?) -> Void) {
guard let healthSelectedPaymentProvider else {
completion(nil, nil)
Expand All @@ -240,7 +249,8 @@ extension PaymentComponentsController {
poweredByGiniConfiguration: configurationProvider.poweredByGiniConfiguration,
poweredByGiniStrings: stringsProvider.poweredByGiniStrings,
bottomSheetConfiguration: configurationProvider.bottomSheetConfiguration,
showPaymentReviewCloseButton: configurationProvider.showPaymentReviewCloseButton)
showPaymentReviewCloseButton: configurationProvider.showPaymentReviewCloseButton,
previousPaymentComponentScreenType: previousPaymentComponentScreenType)

let vc = PaymentReviewViewController.instantiate(viewModel: viewModel,
selectedPaymentProvider: healthSelectedPaymentProvider)
Expand Down Expand Up @@ -309,6 +319,7 @@ extension PaymentComponentsController {
shareInvoiceBottomViewModel.viewDelegate = self
shareInvoiceBottomViewModel.documentId = documentId
let shareInvoiceBottomView = ShareInvoiceBottomView(viewModel: shareInvoiceBottomViewModel, bottomSheetConfiguration: configurationProvider.bottomSheetConfiguration)
shareInvoiceBottomSheet = shareInvoiceBottomView
return shareInvoiceBottomView
}

Expand All @@ -324,6 +335,18 @@ extension PaymentComponentsController {
storeDefaultPaymentProvider(paymentProvider: provider)
}
}

/**
Notifies the controller that the Payment Review Screen has closed, enabling the cleanup of stored data used to manage various flows.
*/
public func paymentReviewClosed(with previousPresentedView: PaymentComponentScreenType?) {
shareInvoiceBottomSheet = nil
if previousPresentedView == .bankPicker {
previousPresentedViews.append(.bankPicker)
} else {
previousPresentedViews.removeAll()
}
}

/**
Opens the more information view controller by notifying the view delegate. This method is used when opening the More Information screen inside the bank selection bottom sheet that's presented in the Payment Review Screen.
Expand Down Expand Up @@ -399,7 +422,12 @@ extension PaymentComponentsController {
return
}

self?.sharePDF(pdfURL: pdfPath, paymentRequestId: paymentRequestId, viewController: viewController) { [weak self] (activity, _, _, _) in
self?.sharePDF(pdfURL: pdfPath, paymentRequestId: paymentRequestId, viewController: viewController) { [weak self] (activity, actionOnShareSheet, _, _) in
if !actionOnShareSheet {
guard let shareInvoiceBottomSheet = self?.shareInvoiceBottomSheet else { return }
self?.dismissAndPresent(viewController: shareInvoiceBottomSheet, animated: false)
}

guard activity != nil else {
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ protocol PaymentComponentsProtocol {
func checkIfDocumentIsPayable(docId: String, completion: @escaping (Result<Bool, GiniHealthError>) -> Void)
func paymentView() -> UIView
func bankSelectionBottomSheet() -> UIViewController
func loadPaymentReviewScreenFor(trackingDelegate: GiniHealthTrackingDelegate?, completion: @escaping (UIViewController?, GiniHealthError?) -> Void)
func loadPaymentReviewScreenFor(trackingDelegate: GiniHealthTrackingDelegate?,
previousPaymentComponentScreenType: PaymentComponentScreenType?,
completion: @escaping (UIViewController?, GiniHealthError?) -> Void)
func paymentInfoViewController() -> UIViewController
func paymentViewBottomSheet() -> UIViewController
}
Expand Down Expand Up @@ -98,7 +100,7 @@ public final class PaymentComponentsController: BottomSheetsProviderProtocol, Gi
}

/// Previous presented view
var previousPresentedViews: Set<PaymentComponentScreenType> = []
var previousPresentedViews: [PaymentComponentScreenType] = []
// Client's navigation controller provided in order to handle all HealthSDK flows
weak var navigationControllerProvided: UINavigationController?
// Payment Information from the invoice that contains a document or not
Expand All @@ -107,7 +109,9 @@ public final class PaymentComponentsController: BottomSheetsProviderProtocol, Gi
var documentId: String?
// Errors stack received from API. We will show them for the clients
var errors: [String] = []


// Store Share Bottom Sheet for dismissed native share modal
var shareInvoiceBottomSheet: ShareInvoiceBottomView?
/**
Initializer of the Payment Component Controller class.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
// Copyright © 2024 Gini GmbH. All rights reserved.
//

public let GiniHealthSDKVersion = "5.0.0"
public let GiniHealthSDKVersion = "5.0.1"
Loading

0 comments on commit f7b8a2b

Please sign in to comment.