LokotroPayOnError.fromJson constructor

LokotroPayOnError.fromJson(
  1. Map<String, dynamic> json
)

Factory constructor to create from raw API JSON response

Implementation

factory LokotroPayOnError.fromJson(Map<String, dynamic> json) {
  return LokotroPayOnError(
    message: json['message'] ?? 'An error occurred',
    title: json['title'] ?? 'Error',
    errorCode: json['error_code'] != null
        ? parseApiResponseCode(json['error_code'])
        : null,
    identifier: json['identifier'],
    customerReference: json['customer_reference'],
    systemReference: json['system_reference'] ?? json['payment_id'],
    amount: double.tryParse(json['amount']?.toString() ?? '0'),
    currency: json['currency'] ?? json['currency_str'],
    successRedirectUrl: json['success_redirect_url'],
    failRedirectUrl: json['fail_redirect_url'],
    timestamp: json['timestamp'] != null
        ? DateTime.tryParse(json['timestamp'])
        : DateTime.now(),
  );
}