mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-07 03:19:31 +00:00
fix: wrong card for vendor country (#1905)
* fix: wrong card for vendor country * Update lib/cake_pay/cake_pay_vendor.dart --------- Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
parent
542920a512
commit
b1c9be637f
4 changed files with 20 additions and 12 deletions
|
@ -204,8 +204,8 @@ class CakePayApi {
|
||||||
/// Get Vendors
|
/// Get Vendors
|
||||||
Future<List<CakePayVendor>> getVendors({
|
Future<List<CakePayVendor>> getVendors({
|
||||||
required String apiKey,
|
required String apiKey,
|
||||||
|
required String country,
|
||||||
int? page,
|
int? page,
|
||||||
String? country,
|
|
||||||
String? countryCode,
|
String? countryCode,
|
||||||
String? search,
|
String? search,
|
||||||
List<String>? vendorIds,
|
List<String>? vendorIds,
|
||||||
|
@ -247,7 +247,7 @@ class CakePayApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
return (bodyJson['results'] as List)
|
return (bodyJson['results'] as List)
|
||||||
.map((e) => CakePayVendor.fromJson(e as Map<String, dynamic>))
|
.map((e) => CakePayVendor.fromJson(e as Map<String, dynamic>, country))
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,11 @@ class CakePayCard {
|
||||||
}
|
}
|
||||||
|
|
||||||
static String fixEncoding(String text) {
|
static String fixEncoding(String text) {
|
||||||
|
try {
|
||||||
final bytes = latin1.encode(text);
|
final bytes = latin1.encode(text);
|
||||||
return utf8.decode(bytes, allowMalformed: true);
|
return utf8.decode(bytes, allowMalformed: true);
|
||||||
|
} catch (_) {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,8 +29,8 @@ class CakePayService {
|
||||||
|
|
||||||
/// Get Vendors
|
/// Get Vendors
|
||||||
Future<List<CakePayVendor>> getVendors({
|
Future<List<CakePayVendor>> getVendors({
|
||||||
|
required String country,
|
||||||
int? page,
|
int? page,
|
||||||
String? country,
|
|
||||||
String? countryCode,
|
String? countryCode,
|
||||||
String? search,
|
String? search,
|
||||||
List<String>? vendorIds,
|
List<String>? vendorIds,
|
||||||
|
|
|
@ -7,7 +7,7 @@ class CakePayVendor {
|
||||||
final String name;
|
final String name;
|
||||||
final bool unavailable;
|
final bool unavailable;
|
||||||
final String? cakeWarnings;
|
final String? cakeWarnings;
|
||||||
final List<String> countries;
|
final String country;
|
||||||
final CakePayCard? card;
|
final CakePayCard? card;
|
||||||
|
|
||||||
CakePayVendor({
|
CakePayVendor({
|
||||||
|
@ -15,19 +15,23 @@ class CakePayVendor {
|
||||||
required this.name,
|
required this.name,
|
||||||
required this.unavailable,
|
required this.unavailable,
|
||||||
this.cakeWarnings,
|
this.cakeWarnings,
|
||||||
required this.countries,
|
required this.country,
|
||||||
this.card,
|
this.card,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory CakePayVendor.fromJson(Map<String, dynamic> json) {
|
factory CakePayVendor.fromJson(Map<String, dynamic> json, String country) {
|
||||||
final name = stripHtmlIfNeeded(json['name'] as String);
|
final name = stripHtmlIfNeeded(json['name'] as String);
|
||||||
final decodedName = fixEncoding(name);
|
final decodedName = fixEncoding(name);
|
||||||
|
|
||||||
var cardsJson = json['cards'] as List?;
|
var cardsJson = json['cards'] as List?;
|
||||||
CakePayCard? firstCard;
|
CakePayCard? cardForVendor;
|
||||||
|
|
||||||
if (cardsJson != null && cardsJson.isNotEmpty) {
|
if (cardsJson != null && cardsJson.isNotEmpty) {
|
||||||
firstCard = CakePayCard.fromJson(cardsJson.first as Map<String, dynamic>);
|
try {
|
||||||
|
cardForVendor = CakePayCard.fromJson(cardsJson
|
||||||
|
.where((element) => element['country'] == country)
|
||||||
|
.first as Map<String, dynamic>);
|
||||||
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
return CakePayVendor(
|
return CakePayVendor(
|
||||||
|
@ -35,8 +39,8 @@ class CakePayVendor {
|
||||||
name: decodedName,
|
name: decodedName,
|
||||||
unavailable: json['unavailable'] as bool? ?? false,
|
unavailable: json['unavailable'] as bool? ?? false,
|
||||||
cakeWarnings: json['cake_warnings'] as String?,
|
cakeWarnings: json['cake_warnings'] as String?,
|
||||||
countries: List<String>.from(json['countries'] as List? ?? []),
|
country: country,
|
||||||
card: firstCard,
|
card: cardForVendor,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue