verifyOtp method
Verify OTP for e-wallet payment
Implementation
Future<LokotroEWalletVerifyResponse> verifyOtp({
required String transactionId,
required String otpCode,
}) async {
try {
final requestData = {
'payment_id': transactionId,
'otp_code': otpCode,
};
final response = await _httpClient.post<Map<String, dynamic>>(
'/payments/verify-otp',
data: requestData,
parser: (data) => data as Map<String, dynamic>,
);
if (response.isSuccess && response.data != null) {
final responseData = response.data!['data'] as Map<String, dynamic>;
final paymentInfo = responseData['payment_info'] as Map<String, dynamic>?;
return LokotroEWalletVerifyResponse(
success: responseData['success'] as bool,
status: responseData['status'] as String,
// Support both old field names and new standardized format with payment_info
transactionReference: responseData['transaction_reference'] as String?
?? paymentInfo?['reference'] as String?
?? paymentInfo?['identifier'] as String?,
debitAmount: (responseData['debit_amount'] as num?)?.toDouble()
?? (paymentInfo?['transactional_amount'] as num?)?.toDouble(),
walletBalance: (responseData['wallet_balance'] as num?)?.toDouble(),
emailsSent: (responseData['emails_sent'] as List?)?.cast<String>(),
completedAt: responseData['completed_at'] as String?
?? paymentInfo?['completed_at'] as String?
?? responseData['verified_at'] as String?,
message: response.data!['message'] as String? ?? responseData['message'] as String? ?? '',
paymentId: responseData['payment_id'] as String?,
paymentInfo: paymentInfo,
);
} else {
throw LokotroPayException(
message: response.message,
code: 'OTP_VERIFICATION_FAILED',
);
}
} catch (e) {
LokotroPayLog.m('ewallet.verify_otp.err', 'verify OTP failed (type=${e.runtimeType})');
rethrow;
}
}