midtransCharge method

Future<Response> midtransCharge(
  1. String tokenId,
  2. String orderId,
  3. String grossAmount,
  4. List<Map> itemDetails,
  5. Map customerDetails
)

Do charge on your transaction

how to call midtransCharge:

List

Map customer_details = { 'first_name': customerFirstName, 'last_name': customerLastName, 'email': customerEmail, 'phone': customerPhone }

midtransCharge(yourTokenId, yourOrderId, yourGrossAmount, item_details, customer_details);

Implementation

Future<http.Response> midtransCharge(String tokenId, String orderId,
    String grossAmount, List<Map> itemDetails, Map customerDetails) async {
  String baseUrl =
      isProduction == true ? midtransProductionUrl : midtransStagingUrl;

  String url = baseUrl + 'v2/charge';
  var encodingBody = json.encode({
    'payment_type': 'credit_card',
    'transaction_details': {'order_id': orderId, 'gross_amount': grossAmount},
    'credit_card': {"token_id": tokenId, "authentication": true},
    'item_details': itemDetails,
    'customer_details': customerDetails
  });

  final response = await http.post(url, body: encodingBody, headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
    'Authorization': base64.encode(utf8.encode(serverKey + ':'))
  });

  return response;
}