diff --git a/lib/cake_pay/cake_pay_api.dart b/lib/cake_pay/cake_pay_api.dart index 68aba3f3e..5f1a350c0 100644 --- a/lib/cake_pay/cake_pay_api.dart +++ b/lib/cake_pay/cake_pay_api.dart @@ -230,6 +230,7 @@ class CakePayApi { var headers = { 'accept': 'application/json; charset=UTF-8', + 'Content-Type': 'application/json; charset=UTF-8', 'Authorization': 'Api-Key $apiKey', }; @@ -240,7 +241,7 @@ class CakePayApi { 'Failed to fetch vendors: statusCode - ${response.statusCode}, queryParams -$queryParams, response - ${response.body}'); } - final bodyJson = json.decode(response.body); + final bodyJson = json.decode(utf8.decode(response.bodyBytes)); if (bodyJson is List && bodyJson.isEmpty) { return []; diff --git a/lib/cake_pay/cake_pay_card.dart b/lib/cake_pay/cake_pay_card.dart index d3f07e409..82ba179e6 100644 --- a/lib/cake_pay/cake_pay_card.dart +++ b/lib/cake_pay/cake_pay_card.dart @@ -1,5 +1,3 @@ -import 'dart:convert'; - import 'package:cake_wallet/entities/fiat_currency.dart'; class CakePayCard { @@ -38,17 +36,11 @@ class CakePayCard { }); factory CakePayCard.fromJson(Map json) { + final name = stripHtmlIfNeeded(json['name'] as String? ?? ''); - final decodedName = fixEncoding(name); - final description = stripHtmlIfNeeded(json['description'] as String? ?? ''); - final decodedDescription = fixEncoding(description); - final termsAndConditions = stripHtmlIfNeeded(json['terms_and_conditions'] as String? ?? ''); - final decodedTermsAndConditions = fixEncoding(termsAndConditions); - final howToUse = stripHtmlIfNeeded(json['how_to_use'] as String? ?? ''); - final decodedHowToUse = fixEncoding(howToUse); final fiatCurrency = FiatCurrency.deserialize(raw: json['currency_code'] as String? ?? ''); @@ -59,10 +51,10 @@ class CakePayCard { return CakePayCard( id: json['id'] as int? ?? 0, - name: decodedName, - description: decodedDescription, - termsAndConditions: decodedTermsAndConditions, - howToUse: decodedHowToUse, + name: name, + description: description, + termsAndConditions: termsAndConditions, + howToUse: howToUse, expiryAndValidity: json['expiry_and_validity'] as String?, cardImageUrl: json['card_image_url'] as String?, country: json['country'] as String?, @@ -79,13 +71,4 @@ class CakePayCard { static String stripHtmlIfNeeded(String text) { return text.replaceAll(RegExp(r'<[^>]*>|&[^;]+;'), ' '); } - - static String fixEncoding(String text) { - try { - final bytes = latin1.encode(text); - return utf8.decode(bytes, allowMalformed: true); - } catch (_) { - return text; - } - } } diff --git a/lib/cake_pay/cake_pay_vendor.dart b/lib/cake_pay/cake_pay_vendor.dart index 564896654..8ad305da0 100644 --- a/lib/cake_pay/cake_pay_vendor.dart +++ b/lib/cake_pay/cake_pay_vendor.dart @@ -1,5 +1,3 @@ -import 'dart:convert'; - import 'cake_pay_card.dart'; class CakePayVendor { @@ -21,7 +19,6 @@ class CakePayVendor { factory CakePayVendor.fromJson(Map json, String country) { final name = stripHtmlIfNeeded(json['name'] as String); - final decodedName = fixEncoding(name); var cardsJson = json['cards'] as List?; CakePayCard? cardForVendor; @@ -36,7 +33,7 @@ class CakePayVendor { return CakePayVendor( id: json['id'] as int, - name: decodedName, + name: name, unavailable: json['unavailable'] as bool? ?? false, cakeWarnings: json['cake_warnings'] as String?, country: country, @@ -47,9 +44,4 @@ class CakePayVendor { static String stripHtmlIfNeeded(String text) { return text.replaceAll(RegExp(r'<[^>]*>|&[^;]+;'), ' '); } - - static String fixEncoding(String text) { - final bytes = latin1.encode(text); - return utf8.decode(bytes, allowMalformed: true); - } }