From 5256c677ab13967fdb29c283b52ae9f4eac72727 Mon Sep 17 00:00:00 2001 From: O Rabie Date: Tue, 28 Nov 2023 13:34:23 +0300 Subject: [PATCH] Added DestinationGroup type to the SessionDataSource --- .../Controllers/ExampleViewController.swift | 8 ++----- goSellSDK.podspec | 2 +- .../Models/PaymentOptionsRequest.swift | 18 ++++++++++++++-- .../Process/Process.DataManager.swift | 21 ++++++++++--------- ...putTableViewCellModel+DataValidation.swift | 2 +- .../Public/Protocols/SessionDataSource.swift | 7 ++++++- 6 files changed, 37 insertions(+), 21 deletions(-) diff --git a/Example/goSellSDKExample/Controllers/ExampleViewController.swift b/Example/goSellSDKExample/Controllers/ExampleViewController.swift index b1456c46..5c3e4532 100644 --- a/Example/goSellSDKExample/Controllers/ExampleViewController.swift +++ b/Example/goSellSDKExample/Controllers/ExampleViewController.swift @@ -56,6 +56,7 @@ import class UIKit.UIVisualEffect.UIVisualEffect import class UIKit.UIVisualEffectView.UIVisualEffectView import goSellSDK import UIKit +import TapCardVlidatorKit_iOS internal class ExampleViewController: BaseViewController { @@ -312,7 +313,6 @@ extension ExampleViewController: SettingsTableViewControlerDelegate { // MARK: - SessionDataSource extension ExampleViewController: SessionDataSource { - internal var setCardScannerIconVisible: Bool { return true } @@ -357,11 +357,7 @@ extension ExampleViewController: SessionDataSource { return self.selectedPaymentItems } - - internal var destinations: [Destination]? { - - return self.paymentSettings.dataSource.destinations - } + internal var uiModeDisplay: UIModeDisplayEnum { return .followDevice diff --git a/goSellSDK.podspec b/goSellSDK.podspec index 093361e0..9fc0a064 100644 --- a/goSellSDK.podspec +++ b/goSellSDK.podspec @@ -6,7 +6,7 @@ Pod::Spec.new do |goSellSDK| goSellSDK.name = 'goSellSDK' goSellSDK.summary = 'goSell SDK for iOS' goSellSDK.requires_arc = true - goSellSDK.version = '2.3.27' + goSellSDK.version = '2.3.28' goSellSDK.license = { :type => 'MIT', :file => 'LICENSE' } goSellSDK.author = { 'Tap Payments' => 'hello@tap.company' } goSellSDK.homepage = 'https://github.com/Tap-Payments/goSellSDK-iOS' diff --git a/goSellSDK/Core/API/Internal/Models/PaymentOptionsRequest.swift b/goSellSDK/Core/API/Internal/Models/PaymentOptionsRequest.swift index 1264ac48..29b535cb 100644 --- a/goSellSDK/Core/API/Internal/Models/PaymentOptionsRequest.swift +++ b/goSellSDK/Core/API/Internal/Models/PaymentOptionsRequest.swift @@ -5,6 +5,8 @@ // Copyright © 2019 Tap Payments. All rights reserved. // +import TapCardVlidatorKit_iOS + internal struct PaymentOptionsRequest { // MARK: - Internal - @@ -22,6 +24,9 @@ internal struct PaymentOptionsRequest { /// Taxes. internal var taxes: [Tax]? + /// Taxes. + internal var supportedPaymentMethods: [String]? + /// Items currency. internal let currency: Currency? @@ -44,7 +49,7 @@ internal struct PaymentOptionsRequest { internal init(customer: String?) { - self.init(transactionMode: nil, amount: nil, items: nil, shipping: nil, taxes: nil, currency: nil, merchantID: nil, customer: customer, destinationGroup: nil, paymentType: nil, topup:nil) + self.init(transactionMode: nil, amount: nil, items: nil, shipping: nil, taxes: nil, currency: nil, merchantID: nil, customer: customer, destinationGroup: nil, paymentType: nil, topup:nil, supportedPaymentMethods: nil) } internal init(transactionMode: TransactionMode?, @@ -57,7 +62,8 @@ internal struct PaymentOptionsRequest { customer: String?, destinationGroup: DestinationGroup?, paymentType: PaymentType?, - topup: Topup? + topup: Topup?, + supportedPaymentMethods: [String]? ) { @@ -70,6 +76,7 @@ internal struct PaymentOptionsRequest { self.destinationGroup = destinationGroup self.paymentType = paymentType self.topup = topup + self.supportedPaymentMethods = supportedPaymentMethods if let nonnullItems = items, nonnullItems.count > 0 { @@ -98,6 +105,7 @@ internal struct PaymentOptionsRequest { case destinationGroup = "destinations" case paymentType = "payment_type" case topup = "topup" + case supportedPaymentMethods = "supported_payment_methods" } // MARK: Properties @@ -148,6 +156,12 @@ extension PaymentOptionsRequest: Encodable { try container.encodeIfPresent(self.destinationGroup, forKey: .destinationGroup) } + + if let paymentMethods:[String] = self.supportedPaymentMethods, + paymentMethods.count > 0 { + + try container.encodeIfPresent(paymentMethods.map{ $0.uppercased() }, forKey: .supportedPaymentMethods) + } try container.encodeIfPresent(self.paymentType?.description.uppercased(), forKey: .paymentType) diff --git a/goSellSDK/Core/UI/Internal/Process/Process.DataManager.swift b/goSellSDK/Core/UI/Internal/Process/Process.DataManager.swift index 5cf21639..4b935beb 100644 --- a/goSellSDK/Core/UI/Internal/Process/Process.DataManager.swift +++ b/goSellSDK/Core/UI/Internal/Process/Process.DataManager.swift @@ -656,8 +656,9 @@ internal extension Process { let paymentType = nonnullDataSource.paymentType ?? nil let topup = nonnullDataSource.topup ?? nil + let supportedPaymentMethods:[String] = []//nonnullDataSource.supportedPaymentMethods?.map{ $0.uppercased() } ?? [] /// the API is using destinationsGroup not destinations - let destinationsGroup = DestinationGroup(destinations: destinations) + let destinationsGroup = destinations let paymentRequest = PaymentOptionsRequest(transactionMode: transactionMode, amount: nonnullDataSource.amount, items: nonnullDataSource.items ?? [], @@ -668,7 +669,8 @@ internal extension Process { customer: customer.identifier, destinationGroup: destinationsGroup, paymentType: paymentType, - topup: topup) + topup: topup, + supportedPaymentMethods: supportedPaymentMethods) return paymentRequest } @@ -841,9 +843,7 @@ internal extension Process { let amountedSelectedCurrency = self.selectedCurrency let fee = Process.AmountCalculator.extraFeeAmount(from: paymentOption.extraFees, in: amountedCurrency) - let destinations = dataSource.destinations ?? nil - /// the API is using destinationsGroup not destinations - let destinationsGroup = (destinations?.count ?? 0 > 0) ? DestinationGroup(destinations: destinations)!: nil + let destinationsGroup = dataSource.destinations ?? nil let order = Order(identifier: orderID) @@ -1279,12 +1279,12 @@ internal extension Process { let shipping = nonnullDataSource.shipping ?? nil let taxes = nonnullDataSource.taxes ?? nil - let destinations = nonnullDataSource.destinations ?? nil - /// the API is using destinationsGroup not destinations - let destinationsGroup = DestinationGroup(destinations: destinations) + let destinationsGroup = nonnullDataSource.destinations ?? nil + let paymentType = nonnullDataSource.paymentType ?? nil let topup = nonnullDataSource.topup ?? nil - + let supportedPaymentMethods:[String] = []//nonnullDataSource.supportedPaymentMethods?.map{ $0.uppercased() } ?? [] + let paymentRequest = PaymentOptionsRequest(transactionMode: transactionMode, amount: nonnullDataSource.amount, items: nonnullDataSource.items ?? [], @@ -1295,7 +1295,8 @@ internal extension Process { customer: nonnullDataSource.customer?.identifier, destinationGroup: destinationsGroup, paymentType: paymentType, - topup: topup) + topup: topup, + supportedPaymentMethods: supportedPaymentMethods) return paymentRequest } diff --git a/goSellSDK/Core/UI/Internal/View Models/CardInputTableViewCellModel+DataValidation.swift b/goSellSDK/Core/UI/Internal/View Models/CardInputTableViewCellModel+DataValidation.swift index 6210dab1..997f96b8 100644 --- a/goSellSDK/Core/UI/Internal/View Models/CardInputTableViewCellModel+DataValidation.swift +++ b/goSellSDK/Core/UI/Internal/View Models/CardInputTableViewCellModel+DataValidation.swift @@ -102,7 +102,7 @@ internal extension CardInputTableViewCellModel { private struct Constants { - fileprivate static let binNumberLength = 6 + fileprivate static let binNumberLength = 8 //@available(*, unavailable) private init() { } } diff --git a/goSellSDK/Core/UI/Public/Protocols/SessionDataSource.swift b/goSellSDK/Core/UI/Public/Protocols/SessionDataSource.swift index 9260e41c..be67d112 100644 --- a/goSellSDK/Core/UI/Public/Protocols/SessionDataSource.swift +++ b/goSellSDK/Core/UI/Public/Protocols/SessionDataSource.swift @@ -7,6 +7,7 @@ import enum PassKit.PKPaymentButtonType import enum PassKit.PKPaymentButtonStyle import class PassKit.PKPaymentToken +import TapCardVlidatorKit_iOS /// Payment data source. @objc public protocol SessionDataSource: class, NSObjectProtocol { @@ -56,7 +57,7 @@ import class PassKit.PKPaymentToken @objc optional var items: [PaymentItem]? { get } /// List of merchant desired destination accounts to receive money from payment transactions. - @objc optional var destinations: [Destination]? { get } + @objc optional var destinations: DestinationGroup? { get } /// Merchant ID. Optional. Useful when you have multiple Tap accounts and would like to do the `switch` on the fly within the single app. @objc optional var merchantID: String? { get } @@ -79,6 +80,10 @@ import class PassKit.PKPaymentToken /// Post URL. The URL that will be called by Tap system notifying that payment has succeed or failed. @objc optional var postURL: URL? { get } + /// The allowed payment methods (VISA, AMEX, KNET, ETC.) . if not passed, then all enabled payment methods will be allowed + /// It is an raw value if the enum CardBrand so for example [CardBrand.KNET.rawValue] + //@objc optional var supportedPaymentMethods: [String] { get } + /// Description of the payment. @objc optional var paymentDescription: String? { get }