PaymentResponse.fromApiResponse constructor

PaymentResponse.fromApiResponse(
  1. Map<String, dynamic> response
)

Factory method to create response from API data.

Creates a PaymentResponse instance from raw Paystack API response data. This method handles parsing and type conversion of API response fields.

Parameters

  • response: Raw response map from Paystack API

Returns

A new PaymentResponse instance with parsed data.

Implementation

factory PaymentResponse.fromApiResponse(Map<String, dynamic> response) {
  return PaymentResponse(
    reference: response['reference'] as String? ?? '',
    status: _parseStatus(response['status'] as String?),
    amount: response['amount'] as int? ?? 0,
    currency: _parseCurrency(response['currency'] as String?),
    paymentMethod: _parsePaymentMethod(response['payment_method'] as String?),
    gatewayResponse: response['gateway_response'] as String?,
    rawResponse: response,
    createdAt: response['created_at'] != null
        ? DateTime.parse(response['created_at'] as String)
        : null,
  );
}