diff options
author | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2022-11-03 17:31:27 +0800 |
---|---|---|
committer | ꦌꦫꦶꦏ꧀ꦦꦿꦧꦮꦑꦩꦭ꧀ <erik@darapsa.co.id> | 2022-11-03 17:31:27 +0800 |
commit | 76fc1055b6d725a4e4072226fc5ef9ae6635619d (patch) | |
tree | 6a065bc52eef46050d2ca99898aac37361a8b8e4 /midtrans.dart | |
parent | 644d7860b962e1e272ef4e5682d1cc68fa0609ad (diff) |
Conform to updated C API
Diffstat (limited to 'midtrans.dart')
-rw-r--r-- | midtrans.dart | 45 |
1 files changed, 20 insertions, 25 deletions
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<Utf8> Function(Pointer<Utf8>); - +typedef MidtransBanktransferNew = MidtransBanktransfer Function(Pointer<Utf8>); typedef MidtransChargeBanktransfer -= Pointer<Utf8> Function(MidtransBanktransfer, MidtransTransaction, - Array<Pointer<Utf8>>); += Pointer<Utf8> 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<Pointer<Utf8>> customFields) { + String chargeBanktransfer(String bank, String orderID, + int grossAmount) { + final midtrans_banktransfer_new = dylib.lookupFunction + <MidtransBanktransferNew, MidtransBanktransferNew> + ('midtrans_banktransfer_new'); + final midtrans_transaction_new = dylib.lookupFunction + <MidtransTransaction Function(Pointer<Utf8>, Long), + MidtransTransaction Function(Pointer<Utf8>, int)> + ('midtrans_transaction_new'); final midtrans_charge = dylib.lookupFunction <MidtransChargeBanktransfer, MidtransChargeBanktransfer> ('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() { |