| 1 | import 'package:cake_wallet/core/selectable_option.dart'; |
| 2 | |
| 3 | enum PaymentType { |
| 4 | all, |
| 5 | bankTransfer, |
| 6 | creditCard, |
| 7 | debitCard, |
| 8 | applePay, |
| 9 | googlePay, |
| 10 | revolutPay, |
| 11 | neteller, |
| 12 | skrill, |
| 13 | sepa, |
| 14 | sepaInstant, |
| 15 | ach, |
| 16 | achInstant, |
| 17 | Khipu, |
| 18 | palomaBanktTansfer, |
| 19 | ovo, |
| 20 | zaloPay, |
| 21 | zaloBankTransfer, |
| 22 | gcash, |
| 23 | imps, |
| 24 | dana, |
| 25 | ideal, |
| 26 | paypal, |
| 27 | sepaOpenBankingPayment, |
| 28 | gbpOpenBankingPayment, |
| 29 | lowCostAch, |
| 30 | mobileWallet, |
| 31 | pixInstantPayment, |
| 32 | yellowCardBankTransfer, |
| 33 | fiatBalance, |
| 34 | bancontact, |
| 35 | pixPay, |
| 36 | unknown, |
| 37 | } |
| 38 | |
| 39 | extension PaymentTypeTitle on PaymentType { |
| 40 | String? get title { |
| 41 | switch (this) { |
| 42 | case PaymentType.all: |
| 43 | return 'All Payment Methods'; |
| 44 | case PaymentType.bankTransfer: |
| 45 | return 'Bank Transfer'; |
| 46 | case PaymentType.creditCard: |
| 47 | return 'Credit Card'; |
| 48 | case PaymentType.debitCard: |
| 49 | return 'Debit Card'; |
| 50 | case PaymentType.applePay: |
| 51 | return 'Apple Pay'; |
| 52 | case PaymentType.googlePay: |
| 53 | return 'Google Pay'; |
| 54 | case PaymentType.revolutPay: |
| 55 | return 'Revolut Pay'; |
| 56 | case PaymentType.neteller: |
| 57 | return 'Neteller'; |
| 58 | case PaymentType.skrill: |
| 59 | return 'Skrill'; |
| 60 | case PaymentType.sepa: |
| 61 | return 'SEPA'; |
| 62 | case PaymentType.sepaInstant: |
| 63 | return 'SEPA Instant'; |
| 64 | case PaymentType.ach: |
| 65 | return 'ACH'; |
| 66 | case PaymentType.achInstant: |
| 67 | return 'ACH Instant'; |
| 68 | case PaymentType.Khipu: |
| 69 | return 'Khipu'; |
| 70 | case PaymentType.palomaBanktTansfer: |
| 71 | return 'Paloma Bank Transfer'; |
| 72 | case PaymentType.ovo: |
| 73 | return 'OVO'; |
| 74 | case PaymentType.zaloPay: |
| 75 | return 'Zalo Pay'; |
| 76 | case PaymentType.zaloBankTransfer: |
| 77 | return 'Zalo Bank Transfer'; |
| 78 | case PaymentType.gcash: |
| 79 | return 'GCash'; |
| 80 | case PaymentType.imps: |
| 81 | return 'IMPS'; |
| 82 | case PaymentType.dana: |
| 83 | return 'DANA'; |
| 84 | case PaymentType.ideal: |
| 85 | return 'iDEAL'; |
| 86 | case PaymentType.paypal: |
| 87 | return 'PayPal'; |
| 88 | case PaymentType.sepaOpenBankingPayment: |
| 89 | return 'SEPA Open Banking Payment'; |
| 90 | case PaymentType.gbpOpenBankingPayment: |
| 91 | return 'GBP Open Banking Payment'; |
| 92 | case PaymentType.lowCostAch: |
| 93 | return 'Low Cost ACH'; |
| 94 | case PaymentType.mobileWallet: |
| 95 | return 'Mobile Wallet'; |
| 96 | case PaymentType.pixInstantPayment: |
| 97 | return 'PIX Instant Payment'; |
| 98 | case PaymentType.yellowCardBankTransfer: |
| 99 | return 'Yellow Card Bank Transfer'; |
| 100 | case PaymentType.fiatBalance: |
| 101 | return 'Fiat Balance'; |
| 102 | case PaymentType.bancontact: |
| 103 | return 'Bancontact'; |
| 104 | case PaymentType.pixPay: |
| 105 | return 'PIX Pay'; |
| 106 | default: |
| 107 | return null; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | String? get lightIconPath { |
| 112 | switch (this) { |
| 113 | case PaymentType.all: |
| 114 | return 'assets/images/usd_round_light.svg'; |
| 115 | case PaymentType.creditCard: |
| 116 | case PaymentType.debitCard: |
| 117 | case PaymentType.yellowCardBankTransfer: |
| 118 | return 'assets/images/card.svg'; |
| 119 | case PaymentType.bankTransfer: |
| 120 | return 'assets/images/bank_light.svg'; |
| 121 | case PaymentType.skrill: |
| 122 | return 'assets/images/skrill.svg'; |
| 123 | case PaymentType.applePay: |
| 124 | return 'assets/images/apple_pay_round_light.svg'; |
| 125 | case PaymentType.revolutPay: |
| 126 | return 'assets/images/revolut_light.svg'; |
| 127 | default: |
| 128 | return null; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | String? get darkIconPath { |
| 133 | switch (this) { |
| 134 | case PaymentType.all: |
| 135 | return 'assets/images/usd_round_dark.svg'; |
| 136 | case PaymentType.creditCard: |
| 137 | case PaymentType.debitCard: |
| 138 | case PaymentType.yellowCardBankTransfer: |
| 139 | return 'assets/images/card_dark.svg'; |
| 140 | case PaymentType.bankTransfer: |
| 141 | return 'assets/images/bank_dark.svg'; |
| 142 | case PaymentType.skrill: |
| 143 | return 'assets/images/skrill.svg'; |
| 144 | case PaymentType.applePay: |
| 145 | return 'assets/images/apple_pay_round_dark.svg'; |
| 146 | case PaymentType.revolutPay: |
| 147 | return 'assets/images/revolut_dark.svg'; |
| 148 | default: |
| 149 | return null; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | String? get description { |
| 154 | switch (this) { |
| 155 | default: |
| 156 | return null; |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | class PaymentMethod extends SelectableOption { |
| 162 | PaymentMethod({ |
| 163 | required this.paymentMethodType, |
| 164 | required this.customTitle, |
| 165 | required this.customIconPath, |
| 166 | this.customDescription, |
| 167 | this.customPaymentMethodType, |
| 168 | }) : super(title: paymentMethodType.title ?? customTitle); |
| 169 | |
| 170 | final PaymentType paymentMethodType; |
| 171 | final String customTitle; |
| 172 | final String customIconPath; |
| 173 | final String? customDescription; |
| 174 | final String? customPaymentMethodType; |
| 175 | bool isSelected = false; |
| 176 | |
| 177 | @override |
| 178 | String? get description => paymentMethodType.description ?? customDescription; |
| 179 | |
| 180 | @override |
| 181 | String get lightIconPath => paymentMethodType.lightIconPath ?? customIconPath; |
| 182 | |
| 183 | @override |
| 184 | String get darkIconPath => paymentMethodType.darkIconPath ?? customIconPath; |
| 185 | |
| 186 | @override |
| 187 | bool get isOptionSelected => isSelected; |
| 188 | |
| 189 | factory PaymentMethod.all() { |
| 190 | return PaymentMethod( |
| 191 | paymentMethodType: PaymentType.all, |
| 192 | customTitle: 'All Payment Methods', |
| 193 | customIconPath: 'assets/images/dollar_coin.svg'); |
| 194 | } |
| 195 | |
| 196 | factory PaymentMethod.fromOnramperJson(Map<String, dynamic> json) { |
| 197 | final type = PaymentMethod.getPaymentTypeId(json['paymentTypeId'] as String?); |
| 198 | return PaymentMethod( |
| 199 | paymentMethodType: type ?? PaymentType.unknown, |
| 200 | customPaymentMethodType: json['paymentTypeId'] as String?, |
| 201 | customTitle: json['name'] as String? ?? 'Unknown', |
| 202 | customIconPath: json['icon'] as String? ?? 'assets/images/card.png', |
| 203 | customDescription: json['description'] as String?); |
| 204 | } |
| 205 | |
| 206 | factory PaymentMethod.fromDFX(String paymentMethod, PaymentType paymentType) { |
| 207 | return PaymentMethod( |
| 208 | paymentMethodType: paymentType, |
| 209 | customTitle: paymentMethod, |
| 210 | customIconPath: 'assets/images/card.png'); |
| 211 | } |
| 212 | |
| 213 | factory PaymentMethod.fromMoonPayJson(Map<String, dynamic> json, PaymentType paymentType) { |
| 214 | return PaymentMethod( |
| 215 | paymentMethodType: paymentType, |
| 216 | customTitle: json['paymentMethod'] as String, |
| 217 | customIconPath: 'assets/images/card.png'); |
| 218 | } |
| 219 | |
| 220 | factory PaymentMethod.fromMeldJson(Map<String, dynamic> json) { |
| 221 | final type = PaymentMethod.getPaymentTypeId(json['paymentMethod'] as String?); |
| 222 | final logos = json['logos'] as Map<String, dynamic>; |
| 223 | return PaymentMethod( |
| 224 | paymentMethodType: type ?? PaymentType.unknown, |
| 225 | customTitle: json['name'] as String? ?? 'Unknown', |
| 226 | customIconPath: logos['dark'] as String? ?? 'assets/images/card.png', |
| 227 | customDescription: json['description'] as String?); |
| 228 | } |
| 229 | |
| 230 | factory PaymentMethod.fromKryptonimJson(Map<String, dynamic> json) { |
| 231 | final type = PaymentMethod.getPaymentTypeId(json['payment_method'] as String?); |
| 232 | return PaymentMethod( |
| 233 | paymentMethodType: type ?? PaymentType.unknown, |
| 234 | customTitle: json['payment_method'] as String? ?? 'Unknown', |
| 235 | customIconPath: 'assets/images/card.png', |
| 236 | ); |
| 237 | } |
| 238 | |
| 239 | static PaymentType? getPaymentTypeId(String? type) { |
| 240 | switch (type?.toLowerCase()) { |
| 241 | case 'banktransfer': |
| 242 | case 'bank': |
| 243 | case 'yellow_card_bank_transfer': |
| 244 | return PaymentType.bankTransfer; |
| 245 | case 'creditcard': |
| 246 | case 'card': |
| 247 | case 'credit_debit_card': |
| 248 | return PaymentType.creditCard; |
| 249 | case 'debitcard': |
| 250 | return PaymentType.debitCard; |
| 251 | case 'applepay': |
| 252 | case 'apple_pay': |
| 253 | return PaymentType.applePay; |
| 254 | case 'googlepay': |
| 255 | case 'google_pay': |
| 256 | return PaymentType.googlePay; |
| 257 | case 'revolutpay': |
| 258 | return PaymentType.revolutPay; |
| 259 | case 'neteller': |
| 260 | return PaymentType.neteller; |
| 261 | case 'skrill': |
| 262 | return PaymentType.skrill; |
| 263 | case 'sepabanktransfer': |
| 264 | case 'sepa': |
| 265 | case 'sepa_bank_transfer': |
| 266 | return PaymentType.sepa; |
| 267 | case 'sepainstant': |
| 268 | case 'sepa_instant': |
| 269 | return PaymentType.sepaInstant; |
| 270 | case 'ach': |
| 271 | case 'ach_bank_transfer': |
| 272 | return PaymentType.ach; |
| 273 | case 'iach': |
| 274 | case 'instant_ach': |
| 275 | return PaymentType.achInstant; |
| 276 | case 'khipu': |
| 277 | return PaymentType.Khipu; |
| 278 | case 'palomabanktransfer': |
| 279 | return PaymentType.palomaBanktTansfer; |
| 280 | case 'ovo': |
| 281 | return PaymentType.ovo; |
| 282 | case 'zalopay': |
| 283 | return PaymentType.zaloPay; |
| 284 | case 'zalobanktransfer': |
| 285 | case 'za_bank_transfer': |
| 286 | return PaymentType.zaloBankTransfer; |
| 287 | case 'gcash': |
| 288 | return PaymentType.gcash; |
| 289 | case 'imps': |
| 290 | return PaymentType.imps; |
| 291 | case 'dana': |
| 292 | return PaymentType.dana; |
| 293 | case 'ideal': |
| 294 | return PaymentType.ideal; |
| 295 | case 'paypal': |
| 296 | return PaymentType.paypal; |
| 297 | case 'sepa_open_banking_payment': |
| 298 | return PaymentType.sepaOpenBankingPayment; |
| 299 | case 'bancontact': |
| 300 | return PaymentType.bancontact; |
| 301 | case 'pix': |
| 302 | return PaymentType.pixPay; |
| 303 | default: |
| 304 | return null; |
| 305 | } |
| 306 | } |
| 307 | } |