ChargeResponse.fromJson constructor

ChargeResponse.fromJson(
  1. Map<String, dynamic> json,
  2. Version version
)

Implementation

factory ChargeResponse.fromJson(Map<String, dynamic> json, Version version) {
  Map<String, dynamic> data = json['data'] ?? {};
  var isV2 = version == Version.v2;

  return ChargeResponse(
      status: json['status'],
      message: json['message'],
      hasData: data.isNotEmpty,
      id: data['id'] ?? 0,
      authModel: isV2 ? data['authModelUsed'] : data['auth_model'],
      chargeResponseStatus: data['status'],
      flwRef: isV2 ? data['flwRef'] : data['flw_ref'],
      txRef: isV2 ? data['txRef'] : data['tx_ref'],
      orderRef: isV2 ? data['orderRef'] : data['order_ref'],
      chargeResponseMessage:
          isV2 ? data['chargeResponseMessage'] : data['processor_response'],
      chargeResponseCode: data['chargeResponseCode'],
      suggestedAuth: data['suggested_auth'],
      authUrl: isV2 ? data['authurl'] : data['auth_url'],
      appFee: isV2 ? data['appfee'].toString() : data['app_fee'].toString(),
      currency: data['currency'],
      chargedAmount: data['charged_amount'].toString(),
      meta: json['meta'] != null ? Meta.fromMap(json['meta']) : Meta(),
      card: data['card'] != null
          ? BankCard.fromMap(data['card'], version == Version.v2)
          : null,
      validateInstruction: data['validateInstructions']?['instruction'],
      rawResponse: json);
}