Skip to content

Commit

Permalink
Added DestinationGroup type to the SessionDataSource
Browse files Browse the repository at this point in the history
  • Loading branch information
OsamaRabie committed Nov 28, 2023
1 parent 98f83e7 commit 5256c67
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -312,7 +313,6 @@ extension ExampleViewController: SettingsTableViewControlerDelegate {
// MARK: - SessionDataSource
extension ExampleViewController: SessionDataSource {


internal var setCardScannerIconVisible: Bool {
return true
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion goSellSDK.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '[email protected]' }
goSellSDK.homepage = 'https://github.com/Tap-Payments/goSellSDK-iOS'
Expand Down
18 changes: 16 additions & 2 deletions goSellSDK/Core/API/Internal/Models/PaymentOptionsRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Copyright © 2019 Tap Payments. All rights reserved.
//

import TapCardVlidatorKit_iOS

internal struct PaymentOptionsRequest {

// MARK: - Internal -
Expand All @@ -22,6 +24,9 @@ internal struct PaymentOptionsRequest {
/// Taxes.
internal var taxes: [Tax]?

/// Taxes.
internal var supportedPaymentMethods: [String]?

/// Items currency.
internal let currency: Currency?

Expand All @@ -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?,
Expand All @@ -57,7 +62,8 @@ internal struct PaymentOptionsRequest {
customer: String?,
destinationGroup: DestinationGroup?,
paymentType: PaymentType?,
topup: Topup?
topup: Topup?,
supportedPaymentMethods: [String]?

) {

Expand All @@ -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 {

Expand Down Expand Up @@ -98,6 +105,7 @@ internal struct PaymentOptionsRequest {
case destinationGroup = "destinations"
case paymentType = "payment_type"
case topup = "topup"
case supportedPaymentMethods = "supported_payment_methods"
}

// MARK: Properties
Expand Down Expand Up @@ -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)


Expand Down
21 changes: 11 additions & 10 deletions goSellSDK/Core/UI/Internal/Process/Process.DataManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? [],
Expand All @@ -668,7 +669,8 @@ internal extension Process {
customer: customer.identifier,
destinationGroup: destinationsGroup,
paymentType: paymentType,
topup: topup)
topup: topup,
supportedPaymentMethods: supportedPaymentMethods)

return paymentRequest
}
Expand Down Expand Up @@ -841,9 +843,7 @@ internal extension Process {
let amountedSelectedCurrency = self.selectedCurrency

let fee = Process.AmountCalculator<PaymentClass>.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)
Expand Down Expand Up @@ -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 ?? [],
Expand All @@ -1295,7 +1295,8 @@ internal extension Process {
customer: nonnullDataSource.customer?.identifier,
destinationGroup: destinationsGroup,
paymentType: paymentType,
topup: topup)
topup: topup,
supportedPaymentMethods: supportedPaymentMethods)

return paymentRequest
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ internal extension CardInputTableViewCellModel {

private struct Constants {

fileprivate static let binNumberLength = 6
fileprivate static let binNumberLength = 8

//@available(*, unavailable) private init() { }
}
Expand Down
7 changes: 6 additions & 1 deletion goSellSDK/Core/UI/Public/Protocols/SessionDataSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 }
Expand All @@ -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 }

Expand Down

0 comments on commit 5256c67

Please sign in to comment.