есть пост запрос пример:
POST /api HTTP/1.1
Host: checkout.test.paycom.com
X-Auth: 100fe486b33784292111b7dc
Cache-Control: no-cache
{
"id": 123,
"method": "cards.create",
"params": {
"card": { "number": "4444444444444444", "expire": "0420"},
"amount": 350000,
"save": true
}
}
функция:
class Service {
static String url = 'checkout.test.paycom.com';
static Map<String, dynamic> headers = {
'Host': 'checkout.test.paycom.com',
'X-Auth': '3423343243434',
'Cache-Control': 'no-cache'
};
Future createCard(
String id, String cardNumber, String expire, int amount) async {
try {
Map<String, dynamic> body = {
'id': id,
'method': 'cards.create',
'params': {
'card': {
'number': cardNumber,
'expire': expire,
},
'amount': amount,
},
};
final response = await http.post(url, body: body, headers: headers);
if (response.statusCode == 200) {
final result = jsonDecode(response.body);
List<CardModel> data = result['params']['card'];
print(data);
}
} catch (e) {
print(e.toString());
}
return null;
}
}
factory CardModel.fromJson(Map<String, dynamic> json) {
return CardModel(
id: json['id'],
cardNumber: json['number'],
expire: json['expire'],
amount: int.parse(json['amount']),
);
}
выдает ошибку type '_InternalLinkedHashMap<String, Object>' is not a subtype of type 'String' in type cast. Что делаю не так?