

#import "Debit_closeTransaction.h"

@interface Debit_closeTransaction()
FREObject ANE4MBG_bank_Debit_closeTransaction(FREContext cxt,
                                              void* functionData,
                                              uint32_t argc,
                                              FREObject argv[]);
@end

@implementation Debit_closeTransaction
+ (void)ContextInitializer:(FunctionSets *)funcSets {
    LOG_METHOD;
    [funcSets addFuncSet:@"ANE4MBG_bank_Debit_closeTransaction"
                 pointer:&ANE4MBG_bank_Debit_closeTransaction];
    
}

FREObject ANE4MBG_bank_Debit_closeTransaction(FREContext cxt,
                                              void* functionData,
                                              uint32_t argc,
                                              FREObject argv[]) {
    LOG_METHOD;
    ArgsParser *parser = [ArgsParser sharedParser];
    [parser setArgc:argc argv:argv];
    NSString *transactionId = [parser nextString];
    NSString *onSuccess  = [parser nextString];
    NSString *onError = [parser nextString];
    
    FREContext context = [ContextOwner sharedContext];
    
    [MBGBankDebit
     closeTransaction:transactionId
     onSuccess:^(MBGTransaction *transaction) {
         FREResult result = TCDispatch(context,
                                     onSuccess,
                                     [ArgsParser transactionToJSON:transaction]);
         if(result != FRE_OK) [ArgsParser reportResult:result];
     }
     onError:^(MBGError *error) {
         FREResult result = TCDispatch(context,
                                     onError,
                                     error);
         if(result != FRE_OK) [ArgsParser reportResult:result];
     }];
    
    return NULL;
}

@end
