import 'dart:ffi'; import 'dart:io'; import 'package:ffi/ffi.dart'; import 'package:path/path.dart' as path; class MidtransTransaction extends Struct { Pointer order_id; @Long() int gross_amount; } class MidtransBanktransfer extends Struct { Pointer bank; Pointer va_number; Pointer bca; Pointer permata; } class Midtrans { DynamicLibrary dylib; Midtrans(String apiKey, String caInfo) { dylib = Platform.isAndroid ? DynamicLibrary.open('libmidtrans.so') : DynamicLibrary.process(); final apiKeyUtf8 = apiKey.toNativeUtf8(); final caInfoUtf8 = caInfo.toNativeUtf8(); final midtrans_init = dylib.lookupFunction , Pointer), void Function(Pointer, Pointer)> ('midtrans_init'); midtrans_init(apiKeyUtf8, caInfoUtf8); calloc.free(apiKeyUtf8); calloc.free(caInfoUtf8); } void chargeBanktransfer(MidtransBanktransfer payment, MidtransTransaction transaction, Array> customFields) { final midtrans_charge = dylib.lookupFunction >), void Function(MidtransBanktransfer, MidtransTransaction, Array>)> ('midtrans_charge_banktransfer'); midtrans_charge(payment, transaction, customFields); calloc.free(payment.bank); if (payment.va_number != null) { calloc.free(payment.va_number); } if (payment.bca != null) { calloc.free(payment.bca); } if (payment.permata != null) { calloc.free(payment.permata); } calloc.free(transaction.order_id); for (var i = 0; i < 6; i++) { if (customFields[i] != null) { calloc.free(customFields[i]); } } } void cleanup() { final midtrans_cleanup = dylib.lookupFunction('midtrans_cleanup'); midtrans_cleanup(); } }