-
Notifications
You must be signed in to change notification settings - Fork 1
feat(#281): currency-aware payment method suggestions in create-order form #297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Catrya
merged 2 commits into
MostroP2P:main
from
codaMW:feat/281-currency-aware-payment-methods
Aug 11, 2026
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| { | ||
| "ARS": ["Mercado Pago", "MODO", "CVU", "Belo", "Lemon", "CBU", "Efectivo"], | ||
| "AUD": ["PayID", "Alipay", "Cash deposit", "Revolut", "Cash"], | ||
| "BOB": ["QR", "Transferencia Bancaria", "Efectivo"], | ||
| "BRL": ["PIX", "TED", "PicPay", "Depósito", "Cash"], | ||
| "CAD": ["Interac e-Transfer", "Any national bank", "Wise", "Revolut", "Cash"], | ||
| "CHF": ["TWINT", "Cash"], | ||
| "CLP": ["MACH", "Cuenta RUT", "Mercado Pago", "Transferencia bancaria", "Efectivo"], | ||
| "CRC": ["Bank transfer (IBAN)", "SINPE Móvil", "Cash"], | ||
| "COP": ["Nequi", "Daviplata", "PSE", "Llaves BRE-B", "Transferencia bancaria", "Efectivo"], | ||
| "CUP": ["Transfermovil", "EnZona", "Tarjeta Clásica", "Saldo móvil", "MiTransfer", "Efectivo"], | ||
| "EUR": ["Revolut", "HalCash", "Bank Transfer", "Wise", "SEPA instant", "Bizum", "Payoneer", "Cash"], | ||
| "GBP": ["Revolut", "Monzo", "Wise", "Any national bank", "Bank Transfer", "Cash"], | ||
| "JPY": ["PayPay", "Bank Transfer", "Cash"], | ||
| "KES": ["M-PESA", "Equity Bank", "NCBA Bank", "Airtel Money", "Co-operative Bank", "Standard Chartered", "Ecobank", "GTBank", "Pochi la Biashara", "Cash"], | ||
| "MLC": ["Transfermovil", "EnZona"], | ||
| "MWK": ["Airtel Money", "TNM Mpamba", "Bank Transfer", "Cash"], | ||
| "MXN": ["SPEI", "CoDi", "Retiro Cajero BBVA", "Efectivo"], | ||
| "MZN": ["M-Pesa", "e-Mola", "Millennium bim", "BCI", "Cash"], | ||
| "NGN": ["OPay", "PalmPay", "Moniepoint", "GTBank", "Access Bank", "UBA", "Zenith Bank", "Bank Transfer", "Cash"], | ||
| "PEN": ["Yape", "Plin", "QR Yape", "Transferencia bancaria", "Cash"], | ||
| "PHP": ["Any national bank", "GCash", "Cash"], | ||
| "PYG": ["SIPAP", "Transferencia bancaria", "Efectivo"], | ||
| "TZS": ["M-Pesa", "Mixx by Yas (Tigo Pesa)", "Airtel Money", "Halopesa", "CRDB Bank", "Cash"], | ||
| "UGX": ["MTN MoMo", "Airtel Money", "Chipper Cash", "Cash"], | ||
| "USD": ["Cash App", "Venmo", "Zelle", "PayPal", "Wise", "Payoneer", "Strike", "Revolut", "N1CO", "Transfer365", "Cash"], | ||
| "VES": ["Pago Móvil", "Binance P2P", "Transferencia bancaria", "Efectivo"], | ||
| "ZAR": ["Capitec", "FNB", "Absa", "Nedbank", "Standard Bank", "FNB eWallet", "MTN MoMo", "Cash"], | ||
| "ZMW": ["Airtel Money", "MTN MoMo", "Zamtel Kwacha", "FNB eWallet", "Stanbic Bank", "SPENN", "Cash"], | ||
| "default": ["Bank Transfer", "Cash in person"] | ||
| } | ||
36 changes: 36 additions & 0 deletions
36
lib/features/order/providers/payment_methods_provider.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import 'dart:convert'; | ||
|
|
||
| import 'package:flutter/services.dart'; | ||
| import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
|
||
| /// The default payment methods used when a currency has no specific list. | ||
| const _fallbackMethods = <String>['Bank Transfer', 'Cash in person']; | ||
|
|
||
| /// Loads the currency → payment-methods map from the bundled asset once. | ||
| final paymentMethodsDataProvider = | ||
| FutureProvider<Map<String, List<String>>>((ref) async { | ||
| final raw = | ||
| await rootBundle.loadString('assets/data/payment_methods.json'); | ||
| final decoded = jsonDecode(raw) as Map<String, dynamic>; | ||
| return decoded.map( | ||
| (code, methods) => MapEntry( | ||
| code, | ||
| (methods as List<dynamic>).cast<String>(), | ||
| ), | ||
| ); | ||
| }); | ||
|
|
||
| /// The suggested payment methods for [currencyCode], falling back to the | ||
| /// `default` list (and then a hardcoded fallback) for unknown currencies. | ||
| /// | ||
| /// Returns an empty list while the asset is still loading so the section can | ||
| /// render its custom field without flashing placeholder chips. | ||
| final paymentMethodsForCurrencyProvider = | ||
| Provider.family<List<String>, String>((ref, currencyCode) { | ||
| final data = ref.watch(paymentMethodsDataProvider); | ||
| return data.maybeWhen( | ||
| data: (map) => | ||
| map[currencyCode] ?? map['default'] ?? _fallbackMethods, | ||
| orElse: () => const <String>[], | ||
| ); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -101,4 +101,5 @@ flutter: | |
|
|
||
| assets: | ||
| - assets/data/fiat.json | ||
| - assets/data/payment_methods.json | ||
| - assets/images/ | ||
42 changes: 42 additions & 0 deletions
42
test/features/order/providers/payment_methods_provider_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import 'dart:convert'; | ||
| import 'dart:io'; | ||
|
|
||
| import 'package:flutter_test/flutter_test.dart'; | ||
|
|
||
| Map<String, List<String>> _loadShipped() { | ||
| final raw = File('assets/data/payment_methods.json').readAsStringSync(); | ||
| final decoded = jsonDecode(raw) as Map<String, dynamic>; | ||
| return decoded.map( | ||
| (k, v) => MapEntry(k, (v as List<dynamic>).cast<String>()), | ||
| ); | ||
| } | ||
|
|
||
| List<String> _forCurrency(Map<String, List<String>> data, String code) => | ||
| data[code] ?? data['default'] ?? const ['Bank Transfer', 'Cash in person']; | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
|
|
||
| void main() { | ||
| late Map<String, List<String>> data; | ||
| setUpAll(() => data = _loadShipped()); | ||
|
|
||
| group('payment_methods.json currency contract', () { | ||
| test('ships a default fallback plus many currencies', () { | ||
| expect(data.containsKey('default'), isTrue); | ||
| expect(data.length, greaterThan(20)); | ||
| }); | ||
| test('known currency resolves to its list', () { | ||
| final ars = _forCurrency(data, 'ARS'); | ||
| expect(ars, contains('Mercado Pago')); | ||
| expect(ars, contains('CVU')); | ||
| expect(ars, isNot(contains('Zelle'))); | ||
| }); | ||
| test('African currencies present', () { | ||
| expect(_forCurrency(data, 'MWK'), contains('Airtel Money')); | ||
| expect(_forCurrency(data, 'KES'), contains('M-PESA')); | ||
| }); | ||
| test('unknown currency falls back to default', () { | ||
| final unknown = _forCurrency(data, 'XXX'); | ||
| expect(unknown, contains('Bank Transfer')); | ||
| expect(unknown, contains('Cash in person')); | ||
| }); | ||
| }); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.