Skip to content

Commit

Permalink
Roll back CountryInfo and SourceTypeValue type names to make PR more …
Browse files Browse the repository at this point in the history
…clean
  • Loading branch information
Andrei Solovev committed Feb 14, 2024
1 parent 10d3d9d commit fbcdb3d
Show file tree
Hide file tree
Showing 33 changed files with 114 additions and 114 deletions.
10 changes: 5 additions & 5 deletions ExampleApp/Models/Tools.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import OmiseSDK
struct PaymentPreset {
var paymentAmount: Int64
var paymentCurrency: Currency
var allowedPaymentMethods: [SourceType]
var allowedPaymentMethods: [SourceTypeValue]

static let thailandPreset = PaymentPreset(
paymentAmount: 5_000_00,
Expand Down Expand Up @@ -35,19 +35,19 @@ class Tool: NSObject {

static let thailandPaymentAmount: Int64 = PaymentPreset.thailandPreset.paymentAmount
static let thailandPaymentCurrency: String = PaymentPreset.thailandPreset.paymentCurrency.code
static let thailandAllowedPaymentMethods: [SourceType] = PaymentPreset.thailandPreset.allowedPaymentMethods
static let thailandAllowedPaymentMethods: [SourceTypeValue] = PaymentPreset.thailandPreset.allowedPaymentMethods

static let japanPaymentAmount: Int64 = PaymentPreset.japanPreset.paymentAmount
static let japanPaymentCurrency: String = PaymentPreset.japanPreset.paymentCurrency.code
static let japanAllowedPaymentMethods: [SourceType] = PaymentPreset.japanPreset.allowedPaymentMethods
static let japanAllowedPaymentMethods: [SourceTypeValue] = PaymentPreset.japanPreset.allowedPaymentMethods

static let singaporePaymentAmount: Int64 = PaymentPreset.singaporePreset.paymentAmount
static let singaporePaymentCurrency: String = PaymentPreset.singaporePreset.paymentCurrency.code
static let singaporeAllowedPaymentMethods: [SourceType] = PaymentPreset.singaporePreset.allowedPaymentMethods
static let singaporeAllowedPaymentMethods: [SourceTypeValue] = PaymentPreset.singaporePreset.allowedPaymentMethods

static let malaysiaPaymentAmount: Int64 = PaymentPreset.malaysiaPreset.paymentAmount
static let malaysiaPaymentCurrency: String = PaymentPreset.malaysiaPreset.paymentCurrency.code
static let malaysiaAllowedPaymentMethods: [SourceType] = PaymentPreset.malaysiaPreset.allowedPaymentMethods
static let malaysiaAllowedPaymentMethods: [SourceTypeValue] = PaymentPreset.malaysiaPreset.allowedPaymentMethods

static func imageWith(size: CGSize, color: UIColor) -> UIImage? {
return Tool.imageWith(size: size) { (context) in
Expand Down
2 changes: 1 addition & 1 deletion ExampleApp/Views/BaseViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class BaseViewController: UIViewController {
var paymentAmount: Int64 = 0
var paymentCurrencyCode: String = ""
var usesCapabilityDataForPaymentMethods = false
var allowedPaymentMethods: [SourceType] = []
var allowedPaymentMethods: [SourceTypeValue] = []

required init?(coder: NSCoder) {
self.usesCapabilityDataForPaymentMethods = true
Expand Down
2 changes: 1 addition & 1 deletion ExampleApp/Views/CustomCreditCardFormViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class CustomCreditCardFormViewController: UIViewController {
}

private func setupBillingAddressFields() {
countryCodeField.placeholder = "Country Code (ex. \"TH\")"
countryCodeField.placeholder = "CountryInfo Code (ex. \"TH\")"
street1Field.placeholder = "Street"
street2Field.placeholder = "Street 2"
cityField.placeholder = "City"
Expand Down
6 changes: 3 additions & 3 deletions ExampleApp/Views/PaymentSettingTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class PaymentSettingTableViewController: UITableViewController {
}
}

var allowedPaymentMethods: Set<SourceType> = [] {
var allowedPaymentMethods: Set<SourceTypeValue> = [] {
willSet {
guard isViewLoaded else {
return
Expand Down Expand Up @@ -264,7 +264,7 @@ extension PaymentSettingTableViewController {
}

// swiftlint:disable:next function_body_length
func paymentSource(for cell: UITableViewCell) -> SourceType? {
func paymentSource(for cell: UITableViewCell) -> SourceTypeValue? {
switch cell {
case internetBankingBAYPaymentCell:
return .internetBankingBAY
Expand Down Expand Up @@ -356,7 +356,7 @@ extension PaymentSettingTableViewController {
}

// swiftlint:disable:next function_body_length
func cell(for paymentSource: SourceType) -> UITableViewCell? {
func cell(for paymentSource: SourceTypeValue) -> UITableViewCell? {
switch paymentSource {
case .internetBankingBAY:
return internetBankingBAYPaymentCell
Expand Down
2 changes: 1 addition & 1 deletion ExampleApp/Views/ProductDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ProductDetailViewController: BaseViewController {
client.capability { (result) in
if case .success(let capability) = result {
self.capability = capability
print("Capability Country: \(capability.countryCode)")
print("Capability CountryInfo: \(capability.countryCode)")
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions OmiseSDK/AtomeFormViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ class AtomeFormViewModel: AtomeFormViewModelProtocol, CountryListViewModelProtoc
]

// MARK: CountryListViewModelProtocol
lazy var countries: [Country] = Country.sortedAll
lazy var countries: [CountryInfo] = CountryInfo.sortedAll

lazy var selectedCountry: Country? = OmiseSDK.shared.country {
lazy var selectedCountry: CountryInfo? = OmiseSDK.shared.country {
didSet {
if let selectedCountry = selectedCountry {
onSelectCountry(selectedCountry)
}
}
}
var onSelectCountry: (Country) -> Void = { _ in }
var onSelectCountry: (CountryInfo) -> Void = { _ in }

var countryListViewModel: CountryListViewModelProtocol { return self }

Expand Down
6 changes: 3 additions & 3 deletions OmiseSDK/CountryListViewModelProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation

protocol CountryListViewModelProtocol {
var countries: [Country] { get }
var selectedCountry: Country? { get set }
var onSelectCountry: (Country) -> Void { get set }
var countries: [CountryInfo] { get }
var selectedCountry: CountryInfo? { get set }
var onSelectCountry: (CountryInfo) -> Void { get set }
}
6 changes: 3 additions & 3 deletions OmiseSDK/CreditCardFormViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ class CreditCardFormViewModel: CreditCardFormViewModelProtocol, CountryListViewM
var countryListViewModel: CountryListViewModelProtocol { return self }

// MARK: CountryListViewModelProtocol
lazy var countries: [Country] = Country.sortedAll
lazy var countries: [CountryInfo] = CountryInfo.sortedAll

lazy var selectedCountry: Country? = OmiseSDK.shared.country {
lazy var selectedCountry: CountryInfo? = OmiseSDK.shared.country {
didSet {
if let selectedCountry = selectedCountry {
onSelectCountry(selectedCountry)
}
}
}
var onSelectCountry: (Country) -> Void = { _ in }
var onSelectCountry: (CountryInfo) -> Void = { _ in }

func error(for field: AddressField, validate text: String?) -> String? {
guard isAddressFieldsVisible else { return nil }
Expand Down
6 changes: 3 additions & 3 deletions OmiseSDK/InstallmentBankingSourceChooserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import UIKit
import os

// swiftlint:disable:next type_name
class InstallmentBankingSourceChooserViewController: AdaptableStaticTableViewController<SourceType>,
class InstallmentBankingSourceChooserViewController: AdaptableStaticTableViewController<SourceTypeValue>,
PaymentSourceChooser,
PaymentChooserUI {
var flowSession: PaymentCreatorFlowSession?

override var showingValues: [SourceType] {
override var showingValues: [SourceTypeValue] {
didSet {
os_log("Installment Brand Chooser: Showing options - %{private}@",
log: uiLogObject,
Expand Down Expand Up @@ -37,7 +37,7 @@ class InstallmentBankingSourceChooserViewController: AdaptableStaticTableViewCon
navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
}

override func staticIndexPath(forValue value: SourceType) -> IndexPath {
override func staticIndexPath(forValue value: SourceTypeValue) -> IndexPath {
switch value {
case .installmentBBL:
return IndexPath(row: 0, section: 0)
Expand Down
4 changes: 2 additions & 2 deletions OmiseSDK/InstallmentsNumberOfTermsChooserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import os
class InstallmentsNumberOfTermsChooserViewController: UITableViewController, PaymentSourceChooser, PaymentChooserUI {
var flowSession: PaymentCreatorFlowSession?

var sourceType: SourceType? {
var sourceType: SourceTypeValue? {
didSet {
os_log("Installment Chooser: Showing options - %{private}@",
log: uiLogObject,
Expand All @@ -22,7 +22,7 @@ class InstallmentsNumberOfTermsChooserViewController: UITableViewController, Pay
}

// swiftlint:disable:next function_body_length
func headerTitle(for sourceType: SourceType) -> String {
func headerTitle(for sourceType: SourceTypeValue) -> String {
switch sourceType {
case .installmentBAY:
return NSLocalizedString(
Expand Down
6 changes: 3 additions & 3 deletions OmiseSDK/InternetBankingSourceChooserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import UIKit
import os

// swiftlint:disable:next type_name
class InternetBankingSourceChooserViewController: AdaptableStaticTableViewController<SourceType>,
class InternetBankingSourceChooserViewController: AdaptableStaticTableViewController<SourceTypeValue>,
PaymentSourceChooser,
PaymentChooserUI {
var flowSession: PaymentCreatorFlowSession?

override var showingValues: [SourceType] {
override var showingValues: [SourceTypeValue] {
didSet {
os_log("Internet Banking Chooser: Showing options - %{private}@",
log: uiLogObject,
Expand Down Expand Up @@ -37,7 +37,7 @@ class InternetBankingSourceChooserViewController: AdaptableStaticTableViewContro
navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
}

override func staticIndexPath(forValue value: SourceType) -> IndexPath {
override func staticIndexPath(forValue value: SourceTypeValue) -> IndexPath {
switch value {
case .internetBankingBBL:
return IndexPath(row: 0, section: 0)
Expand Down
6 changes: 3 additions & 3 deletions OmiseSDK/MobileBankingSourceChooserViewController.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import UIKit
import os

class MobileBankingSourceChooserViewController: AdaptableStaticTableViewController<SourceType>,
class MobileBankingSourceChooserViewController: AdaptableStaticTableViewController<SourceTypeValue>,
PaymentSourceChooser,
PaymentChooserUI {
var flowSession: PaymentCreatorFlowSession?

override var showingValues: [SourceType] {
override var showingValues: [SourceTypeValue] {
didSet {
os_log("Mobile Banking Chooser: Showing options - %{private}@",
log: uiLogObject,
Expand Down Expand Up @@ -36,7 +36,7 @@ class MobileBankingSourceChooserViewController: AdaptableStaticTableViewControll
navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)
}

override func staticIndexPath(forValue value: SourceType) -> IndexPath {
override func staticIndexPath(forValue value: SourceTypeValue) -> IndexPath {
switch value {
case .mobileBankingBAY:
return IndexPath(row: 0, section: 0)
Expand Down
8 changes: 4 additions & 4 deletions OmiseSDK/PaymentChooserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ enum PaymentChooserOption: CaseIterable, Equatable, CustomStringConvertible {

extension PaymentChooserOption {
// swiftlint:disable:next function_body_length
fileprivate static func paymentOptions(for sourceType: SourceType) -> [PaymentChooserOption] {
fileprivate static func paymentOptions(for sourceType: SourceTypeValue) -> [PaymentChooserOption] {
switch sourceType {
case .trueMoneyWallet:
return [.truemoney]
Expand Down Expand Up @@ -235,7 +235,7 @@ class PaymentChooserViewController: AdaptableStaticTableViewController<PaymentCh
updateShowingValues()
}
}
var allowedPaymentMethods: [SourceType] = [] {
var allowedPaymentMethods: [SourceTypeValue] = [] {
didSet {
updateShowingValues()
}
Expand Down Expand Up @@ -500,7 +500,7 @@ class PaymentChooserViewController: AdaptableStaticTableViewController<PaymentCh
showsCreditCardPayment = capability.cardPaymentMethod != nil

allowedPaymentMethods = capability.paymentMethods.compactMap {
SourceType(rawValue: $0.name)
SourceTypeValue(rawValue: $0.name)
}

updateShowingValues()
Expand Down Expand Up @@ -538,7 +538,7 @@ class PaymentChooserViewController: AdaptableStaticTableViewController<PaymentCh
}

private extension PaymentChooserViewController {
func paymentOptions(from sourceTypes: [SourceType]) -> [PaymentChooserOption] {
func paymentOptions(from sourceTypes: [SourceTypeValue]) -> [PaymentChooserOption] {
let paymentOptions: [PaymentChooserOption] = sourceTypes.reduce(into: []) { (result, sourceType) in
let paymentOptions = PaymentChooserOption.paymentOptions(for: sourceType)
for paymentOption in paymentOptions where !result.contains(paymentOption) {
Expand Down
22 changes: 11 additions & 11 deletions OmiseSDK/PaymentCreatorController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class PaymentCreatorController: UINavigationController {

/// Available Source payment options to let user to choose.
/// The default value is the default available payment method for merchant in Thailand
public var allowedPaymentMethods: [SourceType] = PaymentCreatorController.thailandDefaultAvailableSourceMethods {
public var allowedPaymentMethods: [SourceTypeValue] = PaymentCreatorController.thailandDefaultAvailableSourceMethods {
didSet {
paymentChooserViewController.allowedPaymentMethods = allowedPaymentMethods
}
Expand Down Expand Up @@ -119,7 +119,7 @@ public class PaymentCreatorController: UINavigationController {
publicKey: String,
amount: Int64,
currency: Currency,
allowedPaymentMethods: [SourceType],
allowedPaymentMethods: [SourceTypeValue],
paymentDelegate: PaymentCreatorControllerDelegate?
) -> PaymentCreatorController {
let storyboard = UIStoryboard(name: "OmiseSDK", bundle: .omiseSDK)
Expand Down Expand Up @@ -433,7 +433,7 @@ extension PaymentCreatorController: PaymentCreatorFlowSessionDelegate {
}

extension PaymentCreatorController {
public static let thailandDefaultAvailableSourceMethods: [SourceType] = [
public static let thailandDefaultAvailableSourceMethods: [SourceTypeValue] = [
.internetBankingBAY,
.internetBankingBBL,
.mobileBankingSCB,
Expand All @@ -457,17 +457,17 @@ extension PaymentCreatorController {
.shopeePayJumpApp
]

public static let japanDefaultAvailableSourceMethods: [SourceType] = [
public static let japanDefaultAvailableSourceMethods: [SourceTypeValue] = [
.eContext,
.payPay
]

public static let singaporeDefaultAvailableSourceMethods: [SourceType] = [
public static let singaporeDefaultAvailableSourceMethods: [SourceTypeValue] = [
.payNow,
.shopeePayJumpApp
]

public static let malaysiaDefaultAvailableSourceMethods: [SourceType] = [
public static let malaysiaDefaultAvailableSourceMethods: [SourceTypeValue] = [
.fpx,
.installmentMBB,
.touchNGo,
Expand All @@ -480,13 +480,13 @@ extension PaymentCreatorController {
.duitNowOBW
]

public static let internetBankingAvailablePaymentMethods: [SourceType] = [
public static let internetBankingAvailablePaymentMethods: [SourceTypeValue] = [
.internetBankingBAY,
.internetBankingBBL
]

// swiftlint:disable:next identifier_name
public static let installmentsBankingAvailablePaymentMethods: [SourceType] = [
public static let installmentsBankingAvailablePaymentMethods: [SourceTypeValue] = [
.installmentBAY,
.installmentFirstChoice,
.installmentBBL,
Expand All @@ -498,15 +498,15 @@ extension PaymentCreatorController {
.installmentUOB
]

public static let billPaymentAvailablePaymentMethods: [SourceType] = [
public static let billPaymentAvailablePaymentMethods: [SourceTypeValue] = [
.billPaymentTescoLotus
]

public static let barcodeAvailablePaymentMethods: [SourceType] = [
public static let barcodeAvailablePaymentMethods: [SourceTypeValue] = [
.barcodeAlipay
]

public static let mobileBankingAvailablePaymentMethods: [SourceType] = [
public static let mobileBankingAvailablePaymentMethods: [SourceTypeValue] = [
.mobileBankingSCB,
.mobileBankingKBank,
.mobileBankingBAY,
Expand Down
4 changes: 2 additions & 2 deletions OmiseSDK/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Credit Card
"CreditCard.field.country" = "Country or region";
"CreditCard.field.country" = "CountryInfo or region";
"CreditCard.field.address" = "Address";
"CreditCard.field.city" = "City";
"CreditCard.field.state" = "State";
Expand All @@ -14,7 +14,7 @@
"Atome.field.name" = "Name";
"Atome.field.email" = "Email";
"Atome.field.phoneNumber" = "Phone Number";
"Atome.field.country" = "Country";
"Atome.field.country" = "CountryInfo";
"Atome.field.city" = "City";
"Atome.field.postalCode" = "Postal code";
"Atome.field.state" = "State";
Expand Down
12 changes: 6 additions & 6 deletions OmiseSDK/Sources/Models/Country.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

public struct Country: Codable, Equatable {
public struct CountryInfo: Codable, Equatable {
public let name: String
public let code: String

Expand All @@ -21,18 +21,18 @@ public struct Country: Codable, Equatable {
}
}

extension Country {
extension CountryInfo {
public static var avsCodes: [String] = ["US", "CA", "GB"]

public static var sortedAll: [Country] = {
Country.all.sorted {
public static var sortedAll: [CountryInfo] = {
CountryInfo.all.sorted {
$0.name.localizedCompare($1.name) == .orderedAscending
}
}()
}

extension Country {
public static var all: [Country] = [
extension CountryInfo {
public static var all: [CountryInfo] = [
.init(name: "Afghanistan", code: "AF"),
.init(name: "Åland Islands", code: "AX"),
.init(name: "Albania", code: "AL"),
Expand Down
Loading

0 comments on commit fbcdb3d

Please sign in to comment.