createPaymentIntent method

Future<Map<String, dynamic>> createPaymentIntent(
  1. String amount,
  2. String currency,
  3. String secretKey
)

Implementation

Future<Map<String, dynamic>> createPaymentIntent(
    String amount,
    String currency,
    String secretKey,
    ) async {
  try {
    final Map<String, dynamic> body = {
      'amount': amount,
      'currency': currency,
      'payment_method_types[]': 'card',
    };
    final response = await http.post(
      Uri.parse('https://api.stripe.com/v1/payment_intents'),
      body: body,
      headers: {
        'Authorization': 'Bearer $secretKey',
        'Content-Type': 'application/x-www-form-urlencoded',
      },
    );
    return jsonDecode(response.body);
  } catch (err) {
    return {};
  }
}