diff --git a/OmiseSDK.xcodeproj/project.pbxproj b/OmiseSDK.xcodeproj/project.pbxproj index 39cbf751..2c906239 100644 --- a/OmiseSDK.xcodeproj/project.pbxproj +++ b/OmiseSDK.xcodeproj/project.pbxproj @@ -98,6 +98,7 @@ 75F2A0BB2A1A60630038FA54 /* AtomeFormViewContext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75F2A0B52A1A5F020038FA54 /* AtomeFormViewContext.swift */; }; 75F2A0C12A1A84900038FA54 /* UIColor+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75F2A0C02A1A84900038FA54 /* UIColor+Helpers.swift */; }; 75F2A0C22A1A87AE0038FA54 /* UIColor+Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75F2A0C02A1A84900038FA54 /* UIColor+Helpers.swift */; }; + 75F8C0B72B1F78E300AE78D9 /* PaymentChooserViewControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 75F8C0B62B1F78E300AE78D9 /* PaymentChooserViewControllerTests.swift */; }; 8A01E48D21059EFF00D73FE6 /* PaymentInformation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A01E48C21059EFF00D73FE6 /* PaymentInformation.swift */; }; 8A01F78B20D90EC5003FC11E /* Client+ObjC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A01F78A20D90EC5003FC11E /* Client+ObjC.swift */; }; 8A01F78E20D91091003FC11E /* OMSTokenRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A01F78D20D91091003FC11E /* OMSTokenRequest.swift */; }; @@ -316,6 +317,7 @@ 75F2A0B32A1A5EAD0038FA54 /* AtomeFormViewModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AtomeFormViewModelProtocol.swift; sourceTree = ""; }; 75F2A0B52A1A5F020038FA54 /* AtomeFormViewContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AtomeFormViewContext.swift; sourceTree = ""; }; 75F2A0C02A1A84900038FA54 /* UIColor+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Helpers.swift"; sourceTree = ""; }; + 75F8C0B62B1F78E300AE78D9 /* PaymentChooserViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentChooserViewControllerTests.swift; sourceTree = ""; }; 8A00FEC21F1DE88600246078 /* README.md */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = ""; tabWidth = 2; }; 8A01E48C21059EFF00D73FE6 /* PaymentInformation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentInformation.swift; sourceTree = ""; }; 8A01F78A20D90EC5003FC11E /* Client+ObjC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Client+ObjC.swift"; sourceTree = ""; }; @@ -882,6 +884,7 @@ isa = PBXGroup; children = ( F615CBF7261565D600E1A2D9 /* CardExpiryDatePickerTests.swift */, + 75F8C0B62B1F78E300AE78D9 /* PaymentChooserViewControllerTests.swift */, ); path = Views; sourceTree = ""; @@ -1349,6 +1352,7 @@ 7509D4E72A1C8E3D0050AB38 /* AtomeFormViewModelTests.swift in Sources */, 7509D4E22A1C876B0050AB38 /* AtomeFormViewContextMockup.swift in Sources */, 8A3C10562159F7FC00BEFD8A /* InvalidCardAPIErrorParsingTestCase.swift in Sources */, + 75F8C0B72B1F78E300AE78D9 /* PaymentChooserViewControllerTests.swift in Sources */, 758244092ACE988700781B3B /* PaymentInformationTestCase.swift in Sources */, 8A37E43620B584D300E2DA18 /* ModelTestCase.swift in Sources */, ); diff --git a/OmiseSDK/PaymentChooserViewController.swift b/OmiseSDK/PaymentChooserViewController.swift index 40ec66a7..fece28b4 100644 --- a/OmiseSDK/PaymentChooserViewController.swift +++ b/OmiseSDK/PaymentChooserViewController.swift @@ -577,17 +577,9 @@ class PaymentChooserViewController: AdaptableStaticTableViewController [PaymentChooserOption] { + let paymentOptions: [PaymentChooserOption] = sourceTypes.reduce(into: []) { (result, sourceType) in + let paymentOptions = PaymentChooserOption.paymentOptions(for: sourceType) + for paymentOption in paymentOptions where !result.contains(paymentOption) { + result.append(paymentOption) + } + } + return paymentOptions + } + + func appendCreditCardPayment(paymentOptions: [PaymentChooserOption]) -> [PaymentChooserOption] { + var filter = paymentOptions + if showsCreditCardPayment { + filter.insert(.creditCard, at: 0) + } + return filter + } + + func filterTrueMoney(paymentOptions: [PaymentChooserOption]) -> [PaymentChooserOption] { + var filter = paymentOptions + if filter.contains(.truemoney) && filter.contains(.truemoneyJumpApp) { + filter.removeAll { $0 == .truemoney } + } + return filter + } +} diff --git a/OmiseSDK/Resources/Base.lproj/OmiseSDK.storyboard b/OmiseSDK/Resources/Base.lproj/OmiseSDK.storyboard index bbd38134..14054bd7 100644 --- a/OmiseSDK/Resources/Base.lproj/OmiseSDK.storyboard +++ b/OmiseSDK/Resources/Base.lproj/OmiseSDK.storyboard @@ -518,7 +518,7 @@ - + @@ -1549,14 +1549,14 @@ - + @@ -3128,7 +3128,7 @@ - + @@ -3695,22 +3695,22 @@ - + - + - + - + - + diff --git a/OmiseSDK/Resources/en.lproj/OmiseSDK.strings b/OmiseSDK/Resources/en.lproj/OmiseSDK.strings index 77c6a796..1da28158 100644 --- a/OmiseSDK/Resources/en.lproj/OmiseSDK.strings +++ b/OmiseSDK/Resources/en.lproj/OmiseSDK.strings @@ -122,6 +122,9 @@ /* Class = "UILabel"; text = "TrueMoney Wallet"; ObjectID = "ewt-LA-vRb"; */ "ewt-LA-vRb.text" = "TrueMoney Wallet"; +/* Class = "UILabel"; text = "TrueMoney"; ObjectID = "ext-Bd-tya"; */ +"ext-Bd-tya.text" = "TrueMoney"; + /* Class = "UILabel"; text = "Label"; ObjectID = "hNq-jM-xs4"; */ "hNq-jM-xs4.text" = "Label"; diff --git a/OmiseSDK/Resources/ja.lproj/OmiseSDK.strings b/OmiseSDK/Resources/ja.lproj/OmiseSDK.strings index 5472eac0..6df289dd 100644 --- a/OmiseSDK/Resources/ja.lproj/OmiseSDK.strings +++ b/OmiseSDK/Resources/ja.lproj/OmiseSDK.strings @@ -151,6 +151,9 @@ /* Class = "UILabel"; text = "TrueMoney Wallet"; ObjectID = "ewt-LA-vRb"; */ "ewt-LA-vRb.text" = "TrueMoneyウォレット"; +/* Class = "UILabel"; text = "TrueMoney"; ObjectID = "ext-Bd-tya"; */ +"ext-Bd-tya.text" = "TrueMoney"; + /* Class = "UILabel"; text = "Pay with Citi Rewards Points"; ObjectID = "zmw-2Y-WAX"; */ "zmw-2Y-WAX.text" = "Citi Rewardsポイント"; diff --git a/OmiseSDK/Resources/th.lproj/OmiseSDK.strings b/OmiseSDK/Resources/th.lproj/OmiseSDK.strings index d864d212..94793186 100644 --- a/OmiseSDK/Resources/th.lproj/OmiseSDK.strings +++ b/OmiseSDK/Resources/th.lproj/OmiseSDK.strings @@ -172,6 +172,9 @@ /* Class = "UILabel"; text = "TrueMoney Wallet"; ObjectID = "ewt-LA-vRb"; */ "ewt-LA-vRb.text" = "ทรูมันนี่วอลเล็ท"; +/* Class = "UILabel"; text = "TrueMoney"; ObjectID = "ext-Bd-tya"; */ +"ext-Bd-tya.text" = "ทรูมันนี่"; + /* Class = "UILabel"; text = "Pay with Citi Rewards Points"; ObjectID = "zmw-2Y-WAX"; */ "zmw-2Y-WAX.text" = "ชำระด้วยคะแนนซิตี้รีวอร์ด"; diff --git a/OmiseSDKTests/Views/PaymentChooserViewControllerTests.swift b/OmiseSDKTests/Views/PaymentChooserViewControllerTests.swift new file mode 100644 index 00000000..96c09646 --- /dev/null +++ b/OmiseSDKTests/Views/PaymentChooserViewControllerTests.swift @@ -0,0 +1,90 @@ +// +// PaymentChooserViewControllerTests.swift +// OmiseSDKTests +// +// Created by Andrei Solovev on 5/12/23. +// Copyright © 2023 Omise. All rights reserved. +// + +import XCTest +@testable import OmiseSDK + +class PaymentChooserViewControllerTests: XCTestCase { + let allSourceTypes: [OMSSourceTypeValue] = [ + .internetBankingBAY, + .internetBankingBBL, + .mobileBankingSCB, + .mobileBankingOCBCPAO, + .mobileBankingOCBC, + .mobileBankingBAY, + .mobileBankingBBL, + .mobileBankingKTB, + .alipay, + .alipayCN, + .alipayHK, + .billPaymentTescoLotus, + .barcodeAlipay, + .dana, + .gcash, + .installmentBAY, + .installmentFirstChoice, + .installmentBBL, + .installmentMBB, + .installmentKTC, + .installmentKBank, + .installmentSCB, + .installmentCiti, + .installmentTTB, + .installmentUOB, + .kakaoPay, + .eContext, + .promptPay, + .payNow, + .touchNGo, + .touchNGoAlipayPlus, + .trueMoney, + .trueMoneyJumpApp, + .pointsCiti, + .fpx, + .mobileBankingKBank, + .rabbitLinepay, + .grabPay, + .grabPayRms, + .boost, + .shopeePay, + .shopeePayJumpApp, + .maybankQRPay, + .duitNowQR, + .duitNowOBW, + .atome, + .payPay + ] + + func testTruemoveFiltering() { + let trueMoneyWalletOnly = allSourceTypes.filter { $0 != .trueMoneyJumpApp } + let trueMoneyJumpAppOnly = allSourceTypes.filter { $0 != .trueMoney } + let trueMoneyAndJumpApp = allSourceTypes + let noTrueMoneyAndJumpApp = allSourceTypes.filter { + ($0 != .trueMoney) && ($0 != .trueMoneyJumpApp) + } + + let vc = PaymentChooserViewController() + vc.loadView() + + vc.allowedPaymentMethods = trueMoneyWalletOnly + XCTAssertTrue(vc.showingValues.contains(.truemoney)) + XCTAssertFalse(vc.showingValues.contains(.truemoneyJumpApp)) + + vc.allowedPaymentMethods = trueMoneyJumpAppOnly + XCTAssertTrue(vc.showingValues.contains(.truemoneyJumpApp)) + XCTAssertFalse(vc.showingValues.contains(.truemoney)) + + vc.allowedPaymentMethods = trueMoneyAndJumpApp + XCTAssertTrue(vc.showingValues.contains(.truemoneyJumpApp)) + XCTAssertFalse(vc.showingValues.contains(.truemoney)) + + vc.allowedPaymentMethods = noTrueMoneyAndJumpApp + XCTAssertFalse(vc.showingValues.contains(.truemoneyJumpApp)) + XCTAssertFalse(vc.showingValues.contains(.truemoney)) + } +}