|
| 1 | +// |
| 2 | +// PaymentSheetFormFactory+BankDebits.swift |
| 3 | +// StripePaymentSheet |
| 4 | +// |
| 5 | +// Created by Nick Porter on 8/3/26. |
| 6 | +// |
| 7 | +// Copyright © 2026 Stripe, Inc. All rights reserved. |
| 8 | +// |
| 9 | + |
| 10 | +@_spi(STP) import StripeCore |
| 11 | +@_spi(STP) import StripePayments |
| 12 | +@_spi(STP) import StripeUICore |
| 13 | + |
| 14 | +extension PaymentSheetFormFactory { |
| 15 | + func makeEPS() -> PaymentMethodElement { |
| 16 | + let name = configuration.billingDetailsCollectionConfiguration.name != .never |
| 17 | + ? makeName(apiPath: "billing_details[name]") : nil |
| 18 | + let email = configuration.billingDetailsCollectionConfiguration.email == .always ? makeEmail() : nil |
| 19 | + let phone = configuration.billingDetailsCollectionConfiguration.phone == .always ? makePhone() : nil |
| 20 | + let bank = makeBankDropdown( |
| 21 | + label: STPLocalizedString("EPS Bank", "Label title for EPS Bank"), |
| 22 | + apiPath: "eps[bank]", |
| 23 | + banks: BankDropdown.eps |
| 24 | + ) |
| 25 | + let address = makeBillingAddressSectionIfNecessary(requiredByPaymentMethod: false) |
| 26 | + as? PaymentMethodElementWrapper<AddressSectionElement> |
| 27 | + connectBillingDetailsFields(addressElement: address, phoneElement: phone) |
| 28 | + let elements: [Element?] = [name, email, phone, bank, address] |
| 29 | + |
| 30 | + return makeDefaultsApplierWrapper( |
| 31 | + for: FormElement( |
| 32 | + autoSectioningElements: elements.compactMap { $0 }, |
| 33 | + theme: theme |
| 34 | + ) |
| 35 | + ) |
| 36 | + } |
| 37 | + |
| 38 | + func makePrzelewy24() -> PaymentMethodElement { |
| 39 | + let name = configuration.billingDetailsCollectionConfiguration.name != .never |
| 40 | + ? makeName(apiPath: "billing_details[name]") : nil |
| 41 | + let email = configuration.billingDetailsCollectionConfiguration.email != .never |
| 42 | + ? makeEmail(apiPath: "billing_details[email]") : nil |
| 43 | + let phone = configuration.billingDetailsCollectionConfiguration.phone == .always ? makePhone() : nil |
| 44 | + let bank = makeBankDropdown( |
| 45 | + label: STPLocalizedString("Przelewy24 Bank", "Label title for Przelewy24 Bank"), |
| 46 | + apiPath: "p24[bank]", |
| 47 | + banks: BankDropdown.przelewy24 |
| 48 | + ) |
| 49 | + let address = makeBillingAddressSectionIfNecessary(requiredByPaymentMethod: false) |
| 50 | + as? PaymentMethodElementWrapper<AddressSectionElement> |
| 51 | + connectBillingDetailsFields(addressElement: address, phoneElement: phone) |
| 52 | + let elements: [Element?] = [name, email, phone, bank, address] |
| 53 | + |
| 54 | + return makeDefaultsApplierWrapper( |
| 55 | + for: FormElement( |
| 56 | + autoSectioningElements: elements.compactMap { $0 }, |
| 57 | + theme: theme |
| 58 | + ) |
| 59 | + ) |
| 60 | + } |
| 61 | + |
| 62 | + func makeAUBECSDebit() -> PaymentMethodElement { |
| 63 | + let name = configuration.billingDetailsCollectionConfiguration.name != .never |
| 64 | + ? makeName(label: String.Localized.nameOnAccount, apiPath: "billing_details[name]") : nil |
| 65 | + let email = configuration.billingDetailsCollectionConfiguration.email != .never |
| 66 | + ? makeEmail(apiPath: "billing_details[email]") : nil |
| 67 | + let phone = configuration.billingDetailsCollectionConfiguration.phone == .always ? makePhone() : nil |
| 68 | + let bsb = makeBSB(apiPath: "au_becs_debit[bsb_number]") |
| 69 | + let accountNumber = makeAUBECSAccountNumber(apiPath: "au_becs_debit[account_number]") |
| 70 | + let address = makeBillingAddressSectionIfNecessary(requiredByPaymentMethod: false) |
| 71 | + as? PaymentMethodElementWrapper<AddressSectionElement> |
| 72 | + connectBillingDetailsFields(addressElement: address, phoneElement: phone) |
| 73 | + let elements: [Element?] = [ |
| 74 | + name, |
| 75 | + email, |
| 76 | + phone, |
| 77 | + bsb, |
| 78 | + accountNumber, |
| 79 | + address, |
| 80 | + makeAUBECSMandate(), |
| 81 | + ] |
| 82 | + |
| 83 | + return makeDefaultsApplierWrapper( |
| 84 | + for: FormElement( |
| 85 | + autoSectioningElements: elements.compactMap { $0 }, |
| 86 | + theme: theme |
| 87 | + ) |
| 88 | + ) |
| 89 | + } |
| 90 | + |
| 91 | + func makeFPX() -> PaymentMethodElement { |
| 92 | + let bank = makeBankDropdown( |
| 93 | + label: STPLocalizedString("FPX Bank", "Select a bank dropdown for FPX"), |
| 94 | + apiPath: "fpx[bank]", |
| 95 | + banks: BankDropdown.fpx |
| 96 | + ) |
| 97 | + let address = makeBillingAddressSectionIfNecessary(requiredByPaymentMethod: false) |
| 98 | + as? PaymentMethodElementWrapper<AddressSectionElement> |
| 99 | + let name = configuration.billingDetailsCollectionConfiguration.name == .always ? makeName() : nil |
| 100 | + let email = configuration.billingDetailsCollectionConfiguration.email == .always ? makeEmail() : nil |
| 101 | + let phone = configuration.billingDetailsCollectionConfiguration.phone == .always ? makePhone() : nil |
| 102 | + connectBillingDetailsFields(addressElement: address, phoneElement: phone) |
| 103 | + let elements: [Element?] = [bank, address, name, email, phone] |
| 104 | + |
| 105 | + return makeDefaultsApplierWrapper( |
| 106 | + for: FormElement( |
| 107 | + autoSectioningElements: elements.compactMap { $0 }, |
| 108 | + theme: theme |
| 109 | + ) |
| 110 | + ) |
| 111 | + } |
| 112 | + |
| 113 | + private func makeBankDropdown( |
| 114 | + label: String, |
| 115 | + apiPath: String, |
| 116 | + banks: [(name: String, value: String)] |
| 117 | + ) -> PaymentMethodElementWrapper<DropdownFieldElement> { |
| 118 | + let items = banks.map { |
| 119 | + DropdownFieldElement.DropdownItem( |
| 120 | + pickerDisplayName: $0.name, |
| 121 | + labelDisplayName: $0.name, |
| 122 | + accessibilityValue: $0.name, |
| 123 | + rawData: $0.value |
| 124 | + ) |
| 125 | + } |
| 126 | + let defaultIndex = items.firstIndex { |
| 127 | + $0.rawData == getPreviousCustomerInput(for: apiPath) |
| 128 | + } ?? 0 |
| 129 | + let dropdown = DropdownFieldElement( |
| 130 | + items: items, |
| 131 | + defaultIndex: defaultIndex, |
| 132 | + label: label, |
| 133 | + theme: theme |
| 134 | + ) |
| 135 | + return PaymentMethodElementWrapper(dropdown) { dropdown, params in |
| 136 | + params.paymentMethodParams.additionalAPIParameters[apiPath] = dropdown.selectedItem.rawData |
| 137 | + return params |
| 138 | + } |
| 139 | + } |
| 140 | +} |
| 141 | + |
| 142 | +private enum BankDropdown { |
| 143 | + static let eps: [(name: String, value: String)] = [ |
| 144 | + ("Ärzte- und Apothekerbank", "arzte_und_apotheker_bank"), |
| 145 | + ("Austrian Anadi Bank AG", "austrian_anadi_bank_ag"), |
| 146 | + ("Bank Austria", "bank_austria"), |
| 147 | + ("bank99 AG", "brull_kallmus_bank_ag"), |
| 148 | + ("Bankhaus Carl Spängler & Co.AG", "bankhaus_carl_spangler"), |
| 149 | + ("Bankhaus Schelhammer & Schattera AG", "bankhaus_schelhammer_und_schattera_ag"), |
| 150 | + ("BAWAG P.S.K. AG", "bawag_psk_ag"), |
| 151 | + ("BKS Bank AG", "bks_bank_ag"), |
| 152 | + ("BTV VIER LÄNDER BANK", "btv_vier_lander_bank"), |
| 153 | + ("Capital Bank Grawe Gruppe AG", "capital_bank_grawe_gruppe_ag"), |
| 154 | + ("Dolomitenbank", "dolomitenbank"), |
| 155 | + ("Easybank AG", "easybank_ag"), |
| 156 | + ("Erste Bank und Sparkassen", "erste_bank_und_sparkassen"), |
| 157 | + ("Hypo Alpe-Adria-Bank International AG", "hypo_alpeadriabank_international_ag"), |
| 158 | + ("HYPO NOE LB für Niederösterreich u. Wien", "hypo_noe_lb_fur_niederosterreich_u_wien"), |
| 159 | + ("HYPO Oberösterreich,Salzburg,Steiermark", "hypo_oberosterreich_salzburg_steiermark"), |
| 160 | + ("Hypo Tirol Bank AG", "hypo_tirol_bank_ag"), |
| 161 | + ("Hypo Vorarlberg Bank AG", "hypo_vorarlberg_bank_ag"), |
| 162 | + ("HYPO-BANK BURGENLAND Aktiengesellschaft", "hypo_bank_burgenland_aktiengesellschaft"), |
| 163 | + ("Marchfelder Bank", "marchfelder_bank"), |
| 164 | + ("Oberbank AG", "oberbank_ag"), |
| 165 | + ("Raiffeisen Bankengruppe Österreich", "raiffeisen_bankengruppe_osterreich"), |
| 166 | + ("Schoellerbank AG", "schoellerbank_ag"), |
| 167 | + ("Sparda-Bank Wien", "sparda_bank_wien"), |
| 168 | + ("Volksbank Gruppe", "volksbank_gruppe"), |
| 169 | + ("Volkskreditbank AG", "volkskreditbank_ag"), |
| 170 | + ("VR-Bank Braunau", "vr_bank_braunau"), |
| 171 | + ] |
| 172 | + |
| 173 | + static let przelewy24: [(name: String, value: String)] = [ |
| 174 | + ("Alior Bank", "alior_bank"), |
| 175 | + ("Bank Millenium", "bank_millennium"), |
| 176 | + ("Bank Nowy BFG S.A.", "bank_nowy_bfg_sa"), |
| 177 | + ("Bank PEKAO S.A", "bank_pekao_sa"), |
| 178 | + ("Bank spółdzielczy", "banki_spbdzielcze"), |
| 179 | + ("BLIK", "blik"), |
| 180 | + ("BNP Paribas", "bnp_paribas"), |
| 181 | + ("BOZ", "boz"), |
| 182 | + ("CitiHandlowy", "citi_handlowy"), |
| 183 | + ("Credit Agricole", "credit_agricole"), |
| 184 | + ("e-Transfer Pocztowy24", "etransfer_pocztowy24"), |
| 185 | + ("Getin Bank", "getin_bank"), |
| 186 | + ("IdeaBank", "ideabank"), |
| 187 | + ("ING", "ing"), |
| 188 | + ("inteligo", "inteligo"), |
| 189 | + ("mBank", "mbank_mtransfer"), |
| 190 | + ("Nest Przelew", "nest_przelew"), |
| 191 | + ("Noble Pay", "noble_pay"), |
| 192 | + ("Płać z iPKO (PKO BP)", "pbac_z_ipko"), |
| 193 | + ("Plus Bank", "plus_bank"), |
| 194 | + ("Santander", "santander_przelew24"), |
| 195 | + ("Toyota Bank", "toyota_bank"), |
| 196 | + ("VeloBank", "velobank"), |
| 197 | + ("Volkswagen Bank", "volkswagen_bank"), |
| 198 | + ] |
| 199 | + |
| 200 | + static let fpx: [(name: String, value: String)] = STPFPXBankBrand.allCases |
| 201 | + .compactMap { brand in |
| 202 | + guard brand != .unknown, |
| 203 | + let name = STPFPXBank.stringFrom(brand), |
| 204 | + let value = STPFPXBank.identifierFrom(brand) |
| 205 | + else { |
| 206 | + return nil |
| 207 | + } |
| 208 | + return (name, value) |
| 209 | + } |
| 210 | + .sorted { $0.value < $1.value } |
| 211 | +} |
0 commit comments