From 76fc1055b6d725a4e4072226fc5ef9ae6635619d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=A6=8C=EA=A6=AB=EA=A6=B6=EA=A6=8F=EA=A7=80=EA=A6=A6?= =?UTF-8?q?=EA=A6=BF=EA=A6=A7=EA=A6=AE=EA=A6=91=EA=A6=A9=EA=A6=AD=EA=A7=80?= Date: Thu, 3 Nov 2022 17:31:27 +0800 Subject: Conform to updated C API --- midtrans.dart | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) (limited to 'midtrans.dart') diff --git a/midtrans.dart b/midtrans.dart index 4476477..2746042 100644 --- a/midtrans.dart +++ b/midtrans.dart @@ -17,10 +17,9 @@ class MidtransBanktransfer extends Struct { } typedef MidtransStatus = Pointer Function(Pointer); - +typedef MidtransBanktransferNew = MidtransBanktransfer Function(Pointer); typedef MidtransChargeBanktransfer -= Pointer Function(MidtransBanktransfer, MidtransTransaction, - Array>); += Pointer Function(MidtransBanktransfer, MidtransTransaction); class Midtrans { final dylib = Platform.isAndroid ? DynamicLibrary.open('libmidtrans.so') @@ -47,31 +46,27 @@ class Midtrans { return status; } - String chargeBanktransfer(MidtransBanktransfer payment, - MidtransTransaction transaction, - Array> customFields) { + String chargeBanktransfer(String bank, String orderID, + int grossAmount) { + final midtrans_banktransfer_new = dylib.lookupFunction + + ('midtrans_banktransfer_new'); + final midtrans_transaction_new = dylib.lookupFunction + , Long), + MidtransTransaction Function(Pointer, int)> + ('midtrans_transaction_new'); final midtrans_charge = dylib.lookupFunction ('midtrans_charge_banktransfer'); - final va_number = midtrans_charge(payment, transaction, - customFields).toDartString(); - 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]); - } - } - return va_number; + final bankUtf8 = bank.toNativeUtf8(); + final order_id = orderID.toNativeUtf8(); + final vaNumber = midtrans_charge( + midtrans_banktransfer_new(bankUtf8), + midtrans_transaction_new(order_id, grossAmount)) + .toDartString(); + calloc.free(bankUtf8); + calloc.free(order_id); + return vaNumber; } void cleanup() { -- cgit v1.2.3