initializeTransaction method
Initializes a Paystack transaction.
Implementation
Future<PaystackResponse> initializeTransaction({
required String email,
required int amount,
required String callbackUrl,
String? reference,
List<String>? channels,
String currency = 'NGN',
}) async {
Logger.logInfo('Initializing transaction for $email with amount $amount');
_validateAmount(amount);
_validateEmail(email);
_validateCallbackUrl(callbackUrl);
final url = Uri.parse('$_baseUrl/transaction/initialize');
final body = jsonEncode({
'email': email,
'amount': amount * 100,
'callback_url': callbackUrl,
'reference': reference ?? _generateReference(),
'currency': currency,
if (channels != null && channels.isNotEmpty) 'channels': channels,
});
return _retryRequest(() => _postRequest(url, body));
}