//
//  GodelTracker.m
//  GodelCordovaDemo
//
//  Created by Balaganesh S on 24/05/18.
//

#import "GodelTracker.h"
#import <JuspaySafeBrowser/JuspaySafeBrowser.h>

@implementation GodelTracker

- (void)JuspayTrackStatus:(CDVInvokedUrlCommand*)command {
    
    NSDictionary *arguments = [[command arguments] objectAtIndex:0];
    
    NSString *status = [arguments valueForKey:@"status"];
    NSString *transactionId = [arguments valueForKey:@"txnId"];
    
    JPTransactionStatus *transactionStatus = [[JPTransactionStatus alloc] init];

    transactionStatus.paymentID = transactionId;
    if ([status isEqualToString:@"SUCCESS"]) {
        transactionStatus.paymentStatus = JPSUCCESS;
    } else if ([status isEqualToString:@"CANCELLED"]) {
        transactionStatus.paymentStatus = JPCANCELLED;
    } else if ([status isEqualToString:@"FAILURE"]) {
        transactionStatus.paymentStatus = JPFAILURE;
    } else {
        transactionStatus.paymentStatus = JPUNKNOWNSTATUS;
    }
    
    [Logger logPaymentStatus:transactionStatus];
    
    CDVPluginResult *result = [CDVPluginResult
                               resultWithStatus:CDVCommandStatus_OK
                               messageAsDictionary:@{}];
    [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
    
}

@end
