Skip to content

Commit

Permalink
Merge pull request #246 from omise/feature/MIT-2092
Browse files Browse the repository at this point in the history
Filter Truemoney Wallet / TrueMoney payment methods
  • Loading branch information
Andrei Solovev authored Dec 6, 2023
2 parents 501b7ee + b1283f8 commit 2d740b3
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 20 deletions.
4 changes: 4 additions & 0 deletions OmiseSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -316,6 +317,7 @@
75F2A0B32A1A5EAD0038FA54 /* AtomeFormViewModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AtomeFormViewModelProtocol.swift; sourceTree = "<group>"; };
75F2A0B52A1A5F020038FA54 /* AtomeFormViewContext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AtomeFormViewContext.swift; sourceTree = "<group>"; };
75F2A0C02A1A84900038FA54 /* UIColor+Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Helpers.swift"; sourceTree = "<group>"; };
75F8C0B62B1F78E300AE78D9 /* PaymentChooserViewControllerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentChooserViewControllerTests.swift; sourceTree = "<group>"; };
8A00FEC21F1DE88600246078 /* README.md */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; tabWidth = 2; };
8A01E48C21059EFF00D73FE6 /* PaymentInformation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaymentInformation.swift; sourceTree = "<group>"; };
8A01F78A20D90EC5003FC11E /* Client+ObjC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Client+ObjC.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -882,6 +884,7 @@
isa = PBXGroup;
children = (
F615CBF7261565D600E1A2D9 /* CardExpiryDatePickerTests.swift */,
75F8C0B62B1F78E300AE78D9 /* PaymentChooserViewControllerTests.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
);
Expand Down
42 changes: 31 additions & 11 deletions OmiseSDK/PaymentChooserViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -577,17 +577,9 @@ class PaymentChooserViewController: AdaptableStaticTableViewController<PaymentCh
}

private func updateShowingValues() {
var paymentMethodsToShow: [PaymentChooserOption] = allowedPaymentMethods.reduce(into: []) { (result, sourceType) in
let paymentOptions = PaymentChooserOption.paymentOptions(for: sourceType)
for paymentOption in paymentOptions where !result.contains(paymentOption) {
result.append(paymentOption)
}
}

if showsCreditCardPayment {
paymentMethodsToShow.insert(.creditCard, at: 0)
}

var paymentMethodsToShow = paymentOptions(from: allowedPaymentMethods)
paymentMethodsToShow = appendCreditCardPayment(paymentOptions: paymentMethodsToShow)
paymentMethodsToShow = filterTrueMoney(paymentOptions: paymentMethodsToShow)
showingValues = paymentMethodsToShow

os_log("Payment Chooser: Showing options - %{private}@",
Expand All @@ -600,3 +592,31 @@ class PaymentChooserViewController: AdaptableStaticTableViewController<PaymentCh
flowSession?.requestToCancel()
}
}

private extension PaymentChooserViewController {
func paymentOptions(from sourceTypes: [OMSSourceTypeValue]) -> [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
}
}
18 changes: 9 additions & 9 deletions OmiseSDK/Resources/Base.lproj/OmiseSDK.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@
<edgeInsets key="layoutMargins" top="0.0" left="16" bottom="0.0" right="16"/>
</view>
<view key="tableFooterView" contentMode="scaleToFill" id="g6L-kx-hv0">
<rect key="frame" x="0.0" y="2234" width="375" height="0.0"/>
<rect key="frame" x="0.0" y="2254" width="375" height="0.0"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
Expand Down Expand Up @@ -1549,14 +1549,14 @@
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" ambiguous="YES" insetsLayoutMarginsFromSafeArea="NO" text="TrueMoney" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="ext-Bd-tya">
<rect key="frame" x="55" y="0.0" width="312" height="64"/>
<rect key="frame" x="67" y="0.0" width="288" height="64"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="14"/>
<color key="textColor" red="0.23999999999999999" green="0.25" blue="0.29999999999999999" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<imageView opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" ambiguous="YES" insetsLayoutMarginsFromSafeArea="NO" image="TrueMoney" adjustsImageSizeForAccessibilityContentSizeCategory="YES" id="DqM-AD-5EN">
<rect key="frame" x="8" y="16" width="32" height="32"/>
<rect key="frame" x="20" y="16" width="32" height="32"/>
<autoresizingMask key="autoresizingMask"/>
</imageView>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" image="Redirect" translatesAutoresizingMaskIntoConstraints="NO" id="XXk-p5-owH">
Expand Down Expand Up @@ -3128,7 +3128,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<view key="tableFooterView" contentMode="scaleToFill" id="rLy-XG-aKO">
<rect key="frame" x="0.0" y="1090" width="375" height="0.0"/>
<rect key="frame" x="0.0" y="1230" width="375" height="0.0"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
Expand Down Expand Up @@ -3695,22 +3695,22 @@
</scenes>
<designables>
<designable name="1JF-Jq-C50">
<size key="intrinsicContentSize" width="5" height="22"/>
<size key="intrinsicContentSize" width="23" height="48"/>
</designable>
<designable name="1dv-2d-6Zi">
<size key="intrinsicContentSize" width="38" height="33"/>
</designable>
<designable name="AJd-kX-GAq">
<size key="intrinsicContentSize" width="5" height="22"/>
<size key="intrinsicContentSize" width="23" height="48"/>
</designable>
<designable name="PBr-uW-pM8">
<size key="intrinsicContentSize" width="5" height="22"/>
<size key="intrinsicContentSize" width="23" height="48"/>
</designable>
<designable name="Par-EA-T3D">
<size key="intrinsicContentSize" width="55.333333333333336" height="22"/>
<size key="intrinsicContentSize" width="73.666666666666671" height="48"/>
</designable>
<designable name="Y1l-QK-aPc">
<size key="intrinsicContentSize" width="5" height="22"/>
<size key="intrinsicContentSize" width="23" height="48"/>
</designable>
<designable name="ZPa-NN-y1M">
<size key="intrinsicContentSize" width="30" height="33"/>
Expand Down
3 changes: 3 additions & 0 deletions OmiseSDK/Resources/en.lproj/OmiseSDK.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
3 changes: 3 additions & 0 deletions OmiseSDK/Resources/ja.lproj/OmiseSDK.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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ポイント";

Expand Down
3 changes: 3 additions & 0 deletions OmiseSDK/Resources/th.lproj/OmiseSDK.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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" = "ชำระด้วยคะแนนซิตี้รีวอร์ด";

Expand Down
90 changes: 90 additions & 0 deletions OmiseSDKTests/Views/PaymentChooserViewControllerTests.swift
Original file line number Diff line number Diff line change
@@ -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))
}
}

0 comments on commit 2d740b3

Please sign in to comment.