parsePaymentResponse method
Parse provider-specific response into standardized PaymentResponse
Implementation
@override
PaymentResponse parsePaymentResponse(Map<String, dynamic> response) {
final status = response['status']?.toString().toLowerCase();
final transactionId =
response['transaction_id'] ?? response['reference'] ?? response['id'];
final orderId =
response['reference'] ?? response['order_id'] ?? response['orderId'];
switch (status) {
case 'success':
case 'successful':
case 'completed':
return PaymentResponse.success(
transactionId: transactionId,
message: 'Payment completed successfully',
orderId: orderId,
provider: PaymentProvider.paystack,
amount: response['amount']?.toDouble(),
currency: response['currency'],
rawResponse: response,
);
case 'pending':
case 'ongoing':
return PaymentResponse.pending(
transactionId: transactionId,
message: 'Payment is being processed',
orderId: orderId,
provider: PaymentProvider.paystack,
rawResponse: response,
);
case 'cancelled':
case 'canceled':
return PaymentResponse.cancelled(
message: 'Payment was cancelled',
orderId: orderId,
provider: PaymentProvider.paystack,
rawResponse: response,
);
case 'failed':
case 'abandoned':
default:
return PaymentResponse.failure(
message: response['gateway_response'] ??
response['message'] ??
'Payment failed',
errorCode: response['error_code'],
orderId: orderId,
provider: PaymentProvider.paystack,
rawResponse: response,
);
}
}