initiateLink method

  1. @override
Future<String?> initiateLink({
  1. required bool isTestMode,
  2. required String hash,
  3. required EasebuzzPaymentModel paymentModel,
})
override

Implementation

@override
Future<String?> initiateLink({
  required bool isTestMode,
  required String hash,
  required EasebuzzPaymentModel paymentModel,
}) async {
  final url = isTestMode
      ? 'https://testpay.easebuzz.in/payment/initiateLink'
      : 'https://pay.easebuzz.in/payment/initiateLink';

  // Set the hash in the payment model
  paymentModel.hash = hash;
  final dio = Dio();
  try {
    // Make the POST request
    final response = await dio.post(
      url,
      data: paymentModel.toJson(),
      options: Options(
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded',
        },
      ),
    );

    // Check if the response is successful
    if (response.statusCode == 200) {
      // Return the 'data' field from the response
      return response.data['data'];
    } else {
      // Handle error response
      debugPrint('Error: ${response.statusCode} - ${response.data}');
      return null;
    }
  } catch (e) {
    debugPrint('Error initiating link: $e');
    return null;
  }
}