Skip to content

Commit

Permalink
Merge pull request #93 from payjp/kitagawa/fix-brand-validation
Browse files Browse the repository at this point in the history
カードフォーム画面で利用可能ブランドによるカード番号バリデーションが実施されないのを修正
  • Loading branch information
yatatsu authored Dec 18, 2024
2 parents df0b81e + 8f14067 commit 939b152
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Sources/Views/CardFormView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ public class CardFormView: UIView {
inputPhoneNumberComplete()
}

func setAcceptedBrands(_ brands: [CardBrand]) {
viewModel.setAcceptedCardBrands(brands)
}

func inputCardNumberSuccess(value: CardNumber) {
cardFormProperties.cardNumberErrorLabel.text = nil
}
Expand Down
1 change: 1 addition & 0 deletions Sources/Views/CardFormViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ extension CardFormViewController: CardFormScreenDelegate {

func reloadBrands(brands: [CardBrand]) {
accptedBrands = brands
cardFormView.setAcceptedBrands(brands)
brandsView.reloadData()
}

Expand Down
10 changes: 9 additions & 1 deletion Sources/Views/CardFormViewViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ protocol CardFormViewViewModelType {
/// - completion: 取得結果
func fetchAcceptedBrands(with tenantId: String?, completion: CardBrandsResult?)

/// 利用可能ブランドをセットする
/// - Parameter brands: 利用可能ブランド
func setAcceptedCardBrands(_ brands: [CardBrand])

/// フォームの入力値を取得する
/// - Parameter completion: 取得結果
func cardFormInput(completion: (Result<CardFormInput, Error>) -> Void)
Expand Down Expand Up @@ -184,7 +188,7 @@ class CardFormViewViewModel: CardFormViewViewModelType {
// 利用可能ブランドのチェック
if let acceptedCardBrands = self.acceptedCardBrands {
if cardNumberInput.brand != .unknown && !acceptedCardBrands.contains(cardNumberInput.brand) {
return .failure(.cardNumberInvalidError(value: cardNumberInput, isInstant: false))
return .failure(.cardNumberInvalidBrandError(value: cardNumberInput, isInstant: true))
}
}
// 桁数チェック
Expand Down Expand Up @@ -342,6 +346,10 @@ class CardFormViewViewModel: CardFormViewViewModelType {
}
}

func setAcceptedCardBrands(_ brands: [CardBrand]) {
self.acceptedCardBrands = brands
}

func cardFormInput(completion: (Result<CardFormInput, Error>) -> Void) {
if let cardNumberString = cardNumber?.value, let month = monthYear?.month,
let year = monthYear?.year, let cvc = cvc {
Expand Down

0 comments on commit 939b152

Please sign in to comment.