//
//

#import "HeroUSDK_ios.h"
#import "HeroUSDKInterfaceUnity.h"


#if defined(__cplusplus)
extern "C"{
#endif
    extern void UnitySendMessage(const char *, const char *, const char *);
#if defined(__cplusplus)
}
#endif

@implementation HeroUSDK_ios

static HeroUSDK_ios * __singleton__;
+ (HeroUSDK_ios *)shareInstance {
    static dispatch_once_t predicate;
    dispatch_once( &predicate, ^{ __singleton__ = [[[self class] alloc] init]; } );
    return __singleton__;
}

- (instancetype)init {
    self = [super init];
    if (self) {
        [self addNotifications];
        bU3dInited = NO;
    }
    return self;
}

-(void)addNotifications
{
    static BOOL isAdded = NO;
    if (isAdded) { return ; }
    isAdded = YES;
    //添加通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(initNotification:) name:GAME_PUBLIC_NOTIFICATION_NAME_INIT object:nil];
    //监听用户登陆成功的通知 单机版游戏不用监听
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginNotification:) name:GAME_PUBLIC_NOTIFICATION_NAME_LOGIN object:nil];
    //监听点击切换账号
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeAccountNotification:) name:GAME_PUBLIC_NOTIFICATION_NAME_CHANGE_ACCOUNT  object:nil];
    //内购通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(iapNotification:) name:GAME_PUBLIC_NOTIFICATION_NAME_IAPPURCHASE_FINISH object:nil];
    //踢下线
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginValidNotification:) name:GAME_PUBLIC_NOTIFICATION_NAME_LOGONINVALID object:nil];
    //同意协议通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(clickProtocol) name:GAME_PUBLIC_NOTIFICATION_NAME_PROTOCOL object:nil];
    //注销成功通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onAccountCancellationNotification) name:GAME_PUBLIC_NOTIFICATION_NAME_EXIT_LOGIN object:nil];
    //截屏通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onScreenShotNotiry) name:GAME_PUBLIC_NOTIFICATION_NAME_SCREEN_SHOT object:nil];
}
//初始化通知
-(void)initNotification:(NSNotification *)notification
{
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [self sendU3dMessage:@"onInitSuccess" params:params];
}
//截屏通知
-(void)onScreenShotNotiry
{
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [self sendU3dMessage:@"onScreenShotCallbackAction" params:params];
}
//注销成功
-(void)onAccountCancellationNotification
{
    //注销成功回调
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    params[@"msg"] = @"注销账号成功";
    [self sendU3dMessage:@"onAccountDeleteCallBackSuccess" params:params];
}
//登录通知
-(void)loginNotification:(NSNotification *)notification
{
    BOOL isLoginSuccess = [notification.object[GAME_PUBLIC_TAG_LOGIN_IS_SUCCESS] boolValue];
    if (isLoginSuccess) {
        NSString * accessCode = notification.object[GAME_PUBLIC_TAG_ACCESS_CODE];
        NSString * accessToken = notification.object[GAME_PUBLIC_TAG_HEROU_ACCESS_TOKEN];
        NSString * sdkuserid = [[HeroUPlatform sharedInstance] getUserId] ;
        NSString * username = [[HeroUPlatform sharedInstance] getUserName] ;
        NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
        if (accessCode != nil ) {
            params[@"accessCode"] = accessCode ;
        }
        if (accessToken != nil ) {
            params[@"accessToken"] = accessToken ;
        }
        if (sdkuserid != nil ) {
            params[@"sdkuserid"] = sdkuserid ;
        }
        if (username != nil ) {
            params[@"username"] = username ;
        }
        [self sendU3dMessage:@"onLoginSuccess" params:params];
        
        NSLog(@"用户登陆成功!");
        NSLog(@"==> AccessCode: %@", accessCode);
        NSLog(@"==> AccessToken: %@", accessToken);
        NSLog(@"==> sdkuserid: %@", sdkuserid);
        NSLog(@"==> username: %@", username);
        NSLog(@"==> params: %@", params);
    } else {
        NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
        params[@"msg"] = @"用户登陆失败!" ;
        [self sendU3dMessage:@"onLoginFailed" params:params];
        
        NSLog(@"用户登陆失败!");
    }
}
//切换账号通知
-(void)changeAccountNotification:(NSNotification *)notification
{
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init] ;
    params[@"msg"] = @"切换账号成功!" ;
    
    [self sendU3dMessage:@"onSwitchAccountSuccess" params:params];
}
//内购通知
-(void)iapNotification:(NSNotification *)notification
{
    BOOL isIapPurchaseSucess = [notification.object[GAME_PUBLIC_TAG_IAPPURCHASE_IS_SUCCESS] boolValue];
    if (isIapPurchaseSucess) {
        GamePaymentOrder * paymentOrder = notification.object[GAME_PUBLIC_TAG_PAYMENT_ORDER];
        NSMutableDictionary  *params = [[NSMutableDictionary alloc] init];
        if (paymentOrder.orderId != nil) {
            params[@"orderId"] = paymentOrder.orderId ;
        }
        if (paymentOrder.orderAmount != nil) {
            params[@"orderAmount"] = paymentOrder.orderAmount ;
        }
        if (paymentOrder.currency != nil) {
            params[@"currency"] = paymentOrder.currency ;
        }
        [self sendU3dMessage:@"onPaySuccess" params:params];
        
        NSLog(@"iap购买成功");
        NSLog(@"支付成功订单:iap订单id: %@",paymentOrder.orderId);
        
    } else {
        GamePaymentOrder * paymentOrder = notification.object[GAME_PUBLIC_TAG_PAYMENT_ORDER];
        NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
        params[@"code"] = [NSString stringWithFormat:@"%ld",(long)paymentOrder.errorCode] ;
        if (paymentOrder.errorDescription != nil) {
            params[@"msg"] = paymentOrder.errorDescription ;
        }
        [self sendU3dMessage:@"onPayFailed" params:params];
        
        NSLog(@"iap购买失败");
    }
}
//登录失效、踢下线通知
-(void)loginValidNotification:(NSNotification *)notification
{
    NSString *reason = notification.userInfo[GAME_PUBLIC_CP_KICKOFF_REASON] ;
    if (reason != nil) {
        //被踢下线
        NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
        params[@"msg"] = reason ;
        
        [self sendU3dMessage:@"onLogonInvalid" params:params];
        
    } else {
        //登录失效
        NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
        params[@"msg"] = @"登录失效,请尝试重新登录" ;
        
        [self sendU3dMessage:@"onReLoginFromInvalid" params:params];
    }
}
//这里处理同意协议后的逻辑
-(void)clickProtocol
{
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [self sendU3dMessage:@"onClickProtocol" params:params];
}
- (NSString *)jsonStrFromDictionary:(NSDictionary *)dic {
    NSError *error = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:0 error:&error];
    if ([error code]) {
        return @"";
    }
    return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}

-(void)sendU3dMessage:(NSString *)messageName params:(NSDictionary *)dict
{
    if (dict != nil)
    {
        NSString *jsonString = [self jsonStrFromDictionary:dict];
        UnitySendMessage([_gameObjectName UTF8String], [messageName UTF8String], [jsonString UTF8String]);
    } else {
        UnitySendMessage([_gameObjectName UTF8String], [messageName UTF8String], "");
    }
}

- (void)setListener:(NSString *)gameObjectName
{
    _gameObjectName = gameObjectName;
    bU3dInited = YES ;
}
- (void)initWithUSDKKey:(NSString *)productKey
              productID:(NSString *)productID
{
    HeroUProject *uProject = [[HeroUProject alloc] init];
    //原usdkProductId
    uProject.usdkProductId = productID;
    //原usdkProductKey
    uProject.usdkProductKey = productKey ;
    //市场插件需要参数
    if (self.application != nil) {
        uProject.application = self.application ;
    }
    if (self.launchOptions != nil) {
        uProject.launchOptions = self.launchOptions ;
    }
    [[HeroUPlatform sharedInstance] initWithProject:uProject];
}
//登录
- (void)enterLoginView
{
    [[HeroUPlatform sharedInstance] enterLoginView] ;
}
//退出登录
- (void)logout
{
    [[HeroUPlatform sharedInstance] logout] ;
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    params[@"msg"] = @"退出登录成功";
    [self sendU3dMessage:@"onLogoutSuccess" params:params];
}
//退出登录并显示账号历史界面
- (void)logoutAndSowLoginView
{
    [[HeroUPlatform sharedInstance] logoutAndSowLoginView] ;
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    params[@"msg"] = @"退出登录成功";
    [self sendU3dMessage:@"onLogoutSuccess" params:params];
}
//用户中心
- (void)showUserCenter
{
    [[HeroUPlatform sharedInstance] showUserCenter] ;
}
//清除本地账号
- (void)cleanUserEntities
{
    [[HeroUPlatform sharedInstance] cleanUserEntities] ;
}
//用户名
- (NSString *)getUserName
{
    return [[HeroUPlatform sharedInstance] getUserName] ;
}
//用户ID
- (NSString *)getUserId
{
    return [[HeroUPlatform sharedInstance] getUserId] ;
}
//SDKID
- (NSString *)getSdkId
{
    return [[HeroUPlatform sharedInstance] getSdkId] ;
}
//获取设备号
- (NSString *)getDeviceNum
{
    return [[HeroUPlatform sharedInstance] getDeviceNum] ;
}
//渠道ID
- (NSString *)getChannelId
{
    return [[HeroUPlatform sharedInstance] getChannelId];
}
//渠道名称
- (NSString *)getChannelName
{
    return [[HeroUPlatform sharedInstance] getChannelName];
}
//getProjectId
- (NSString *)getChannelSdkVersionName
{
    return [[HeroUPlatform sharedInstance] getChannelSdkVersionName];
}
//获取英雄官网渠道的ProjectId
- (NSString *)getProjectId
{
    return [[HeroUPlatform sharedInstance] getProjectId];
}
//内购
- (void)iapPurchaseWithData:(GamePaymentParameters *)parameters
{
    [[HeroUPlatform sharedInstance] iapPurchaseWithData:parameters] ;
}
//设置基础参数
- (void)setBaseRoleInfoWithData:(HeroHDCBaseGameRoleInfo *)baseInfo
{
    [[HeroUPlatform sharedInstance] setBaseRoleInfoWithData:baseInfo] ;
}
//角色登录
- (void)roleLoginWithGameRoleInfo:(HeroHDCGameRoleInfo *)roleInfo
{
    [[HeroUPlatform sharedInstance] roleLoginWithGameRoleInfo:roleInfo] ;
}
//角色注册
- (void)roleRegisterWithGameRoleInfo:(HeroHDCGameRoleInfo *)roleInfo
{
    [[HeroUPlatform sharedInstance] roleRegisterWithGameRoleInfo:roleInfo] ;
}
//角色升级
- (void)roleLevelUpWithGameRoleInfo:(HeroHDCGameRoleInfo *)roleInfo
{
    [[HeroUPlatform sharedInstance] roleLevelUpWithGameRoleInfo:roleInfo] ;
}
//分享
- (void)share:(NSString *)shareJSON
{
    NSData *jsonData = [shareJSON dataUsingEncoding:NSUTF8StringEncoding];
    NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:nil];
    HeroUShareModel *shareModel = [[HeroUShareModel alloc] init];
    NSInteger sharePlatform = [dictionary[@"sharePlatform"] integerValue];
    NSInteger shareType = [dictionary[@"shareType"] integerValue];
    if (sharePlatform == 20001) {
        //QQ分享
        shareModel.sharePlatform = HeroU_Share_Platform_QQ ;
    }
    if (sharePlatform == 20002) {
        //QQ空间分享
        shareModel.sharePlatform = HeroU_Share_Platform_QQ_Space;
    }
    if (sharePlatform == 20003) {
        //微信分享
        shareModel.sharePlatform = HeroU_Share_Platform_WeChat ;
    }
    if (sharePlatform == 20004) {
        //微信朋友圈分享
        shareModel.sharePlatform = HeroU_Share_Platform_WXTimeLine ;
    }
    if (sharePlatform == 20005) {
        //新浪分享
        shareModel.sharePlatform = HeroU_Share_Platform_Weibo ;
    }
    if (sharePlatform == 20000) {
        //有界面分享
        shareModel.sharePlatform = HeroU_Share_Platform_All ;
    }
    if (sharePlatform == 30001) {
        //twitter无界面分享
        shareModel.sharePlatform = HeroU_Share_Platform_Twitter ;
    }
    if (sharePlatform == 30002) {
        //facebook无界面分享
        shareModel.sharePlatform = HeroU_Share_Platform_Facebbok ;
    }
    if (shareType == 1) {
        //分享链接
        shareModel.shareType = HeroUShareType_link ;
        shareModel.shareLinkTitle = dictionary[@"title"];
        shareModel.shareLinkDescription = dictionary[@"text"] ;
        shareModel.shareLink = dictionary[@"url"] ;
    }
    if (shareType == 2) {
        //分享图片
        shareModel.shareType = HeroUShareType_image ;
        NSString *imagePath = dictionary[@"imagePath"] ;
        shareModel.shareImage = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:imagePath]];
    }
    if (shareType == 3) {
        //分享文本
        shareModel.shareType = HeroUShareType_text ;
        shareModel.shareText = dictionary[@"text"] ;
    }
    [[HeroUPlatform sharedInstance] heroUShareWithShareModel:shareModel success:^(NSString *successMessage, HeroUShareStatus status, HeroUShareTaget target) {
            NSInteger targetType = 20001 ;
            if (target == HeroUShareTaget_QQ) {
                targetType = 20001 ;
            }
            if (target == HeroUShareTaget_QQSpace) {
                targetType = 20002 ;
            }
            if (target == HeroUShareTaget_wechat) {
                targetType = 20003 ;
            }
            if (target == HeroUShareTaget_wechatLine) {
                targetType = 20004 ;
            }
            if (target == HeroUShareTaget_Weibo) {
                targetType = 20005 ;
            }
            if (target == HeroUShareTaget_Twitter) {
                targetType = 30001 ;
            }
            if (target == HeroUShareTaget_Facebbok) {
                targetType = 30002 ;
            }
         [self sendU3dMessage:@"onShareSuccessdAction" params:@{@"shareType":@(target)}];
    } failure:^(NSString *failureMessage, HeroUShareStatus status, HeroUShareTaget target) {
            NSInteger targetType = 20001 ;
            if (target == HeroUShareTaget_QQ) {
                targetType = 20001 ;
            }
            if (target == HeroUShareTaget_QQSpace) {
                targetType = 20002 ;
            }
            if (target == HeroUShareTaget_wechat) {
                targetType = 20003 ;
            }
            if (target == HeroUShareTaget_wechatLine) {
                targetType = 20004 ;
            }
            if (target == HeroUShareTaget_Weibo) {
                targetType = 20005 ;
            }
            if (target == HeroUShareTaget_Twitter) {
                targetType = 30001 ;
            }
            if (target == HeroUShareTaget_Facebbok) {
                targetType = 30002 ;
            }
         [self sendU3dMessage:@"onShareFailedAction" params:@{@"shareType":@(target),@"msg":failureMessage}];
    }];
}
//保存图片到相册
- (void)addPicToAlbum:(NSString *)imagePath albumName:(NSString *)albumName
{
    [[HeroUPlatform sharedInstance] addPicToAlbumWithImageObj:imagePath albumName:albumName success:^(NSDictionary * _Nonnull result) {
        NSLog(@"=======> 保存图片成功 : %@ <=======",result) ;
    } failure:^(NSString * _Nonnull error) {
        NSLog(@"=======> 保存图片失败 : %@ <=======",error) ;
    }];
}
//上报闪屏
- (void)postSplashScreenEndSuccess
{
    [[HeroUPlatform sharedInstance] postSplashScreenEndSuccess:^(id obj) {
        NSLog(@"--------------> iOS闪屏上报成功 <-------------") ;
    } faild:^(id obj) {
        NSLog(@"--------------> iOS闪屏上报失败 <------------") ;
    }] ;
}
//扫码登录
- (void)showScanViewWithExt:(NSString *)exit
{
    [[HeroUPlatform sharedInstance] showScanViewWithExt:exit] ;
}
//收到踢下线结果回调SDK
- (void)cpKickOffCallBackWithResult:(NSString *)result
{
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    if (result.length > 0) {
        params[GAME_PUBLIC_CP_KICKOFF_RESULT] = result ;
    }
    [[HeroUPlatform sharedInstance] cpKickOffCallBackWithResult:params];
}
//打开内置浏览器
- (void)openBrowser:(NSString *)openID
{
    [[HeroUPlatform sharedInstance] heroUOpenBrowserByWebId:openID success:^(NSDictionary * _Nonnull dic) {
           NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
           params[@"msg"] = @"通过webId获取信息成功" ;
           [self sendU3dMessage:@"onOpenBrowserSucccess" params:params];
     } failure:^(NSString * _Nonnull error) {
           NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
           params[@"msg"] = error ;
           [self sendU3dMessage:@"onOpenBrowserFailed" params:params];
     }];
}
//打开用户中心
- (void)showAccountCenter
{
    [[HeroUPlatform sharedInstance] showUserCenter];
}
//注销账号
- (void)accountCancellation
{
    [[HeroUPlatform sharedInstance] accountCancellation];
}
//撤回注销 账号
- (void)accountUnCancellation
{
    [[HeroUPlatform sharedInstance] accountUnCancellationWithSuccess:^(id  _Nonnull obj) {
        NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
        params[@"msg"] = @"Success" ;
        [self sendU3dMessage:@"onAccountUnCancellationSuccess" params:params];
    } failure:^(id  _Nonnull obj) {
        NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
        params[@"msg"] = obj ;
        [self sendU3dMessage:@"onAccountUnCancellationFail" params:params];
    }];
}
//日志上报
- (void)uploadIssue
{
    [[HeroUPlatform sharedInstance] uploadIssue] ;
}
//切换账号，无界面
- (void)switchAccount
{
    [[HeroUPlatform sharedInstance] logoutAndSowLoginView];
}
//USDK埋点
- (void)track:(NSString *) eventName WithProperties:(NSString *)paramters
{
     NSData *data = [paramters dataUsingEncoding:NSUTF8StringEncoding];
     if (data != NULL) {
        NSDictionary *info = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        if (info != NULL) {
          [[HeroUPlatform sharedInstance] track:eventName withProperties:info];
        }
     }
}
//USDK埋点回调
- (void)trackEventDataCallback
{
    [[HeroUPlatform sharedInstance] trackEventDataCallback:^(NSDictionary * _Nonnull data) {
        NSMutableDictionary *dataDic = [[NSMutableDictionary alloc] init];
        dataDic[@"data"] = [data hb_JSONString] ;
        [self sendU3dMessage:@"onTrackDataCallBackAction" params:dataDic];
    }];
}
//XsollaPay商城
- (void)startXsollaPayWithXsollaProperties:(NSString *)paramter 
{
    NSData *data = [paramter dataUsingEncoding:NSUTF8StringEncoding];
        if (data != NULL) {
            NSDictionary *info = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            if (info != NULL) {
                HeroUXsollaModel *model = [[HeroUXsollaModel alloc] init] ;
                if ( info[@"serverId"] != NULL) {
                    model.serverId = info[@"serverId"] ;
                }
                if ( info[@"roleName"] != NULL) {
                    model.roleName = info[@"roleName"] ;
                }
                if ( info[@"roleId"] != NULL) {
                    model.roleId = info[@"roleId"] ;
                }
                if ( info[@"cpUid"] != NULL) {
                    model.cpUid = info[@"cpUid"] ;
                }
                model.isJumpOutBrowser = [info[@"isJumpOutBrowser"] boolValue];
                [[HeroUPlatform sharedInstance] startXsollaPayWithXsollaModel:model];
            }
        }
}
//获取全球账号绑定状态
- (void)getGlobalBindState
{
     [[HeroUPlatform sharedInstance] getBindStateWithSuccess:^(NSDictionary * _Nonnull result) {
             NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
             data[@"data"] = [result hb_JSONString] ;
             data[@"status"] = @"1" ;
             [self sendU3dMessage:@"onGetGlobalBindStateAction" params:data];
         } failure:^(NSString * _Nonnull error) {
             NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
             data[@"msg"] = @"获取绑定信息失败" ;
             data[@"status"] = @"0" ;
             [self sendU3dMessage:@"onGetGlobalBindStateAction" params:data];
         }];
}
//全球绑定账号
- (void)bindAccountWithType:(int )type 
{
    [[HeroUPlatform sharedInstance] bindAccountWithType:type success:^(NSDictionary * _Nonnull result) {
            NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
            data[@"data"] = [result hb_JSONString] ;
            data[@"status"] = @"1" ;
            [self sendU3dMessage:@"onBindAccountWithTypeAction" params:data];
        } failure:^(NSString * _Nonnull error) {
            NSMutableDictionary *data = [[NSMutableDictionary alloc] init];
            data[@"msg"] = @"绑定账号失败" ;
            data[@"status"] = @"0" ;
            [self sendU3dMessage:@"onBindAccountWithTypeAction" params:data];
        }];
}

//打开客服
- (void)openServiceView
{
    [[HeroUPlatform sharedInstance] openServiceView] ;
}

//获取协议内容
- (NSString *)getProtocolResult
{
    NSDictionary* resultDic = [[HeroUPlatform sharedInstance] getProtocolResult];
    if (resultDic.allValues.count > 0) {
        NSData *josnData = [NSJSONSerialization dataWithJSONObject:resultDic options:NSJSONWritingPrettyPrinted error:nil] ;
        if (josnData != nil) {
            NSString *jsonString = [[NSString alloc] initWithData:josnData encoding:NSUTF8StringEncoding] ;
            return jsonString ;
        }
    }
    return nil ;
}
//点击同意通知
- (void)setAgreeProtocol
{
    [[HeroUPlatform sharedInstance] setAgreeProtocol] ;
}

//市场插件日志上报
- (void)logEvent:(NSString *)eventName paramter:(NSString *)paramter
{
    NSData *data = [paramter dataUsingEncoding:NSUTF8StringEncoding];
    if (data != NULL) {
       NSDictionary *info = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
       if (info != NULL) {
           [[HeroUPlatform sharedInstance] logEvent:eventName parameters:info];
       }
    }
}

//市场插件支付日志上报
- (void)logPurchaseWithOrderId:(NSString *)orderId amount:(double)amount currency:(NSString *)currency paramter:(NSString *)paramter
{
    NSData *data = [paramter dataUsingEncoding:NSUTF8StringEncoding];
    if (data != NULL) {
        NSDictionary *info = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        if (info != NULL) {
            [[HeroUPlatform sharedInstance] logPurchaseWithOrderId:orderId amount:amount currency:currency parameters:info];
        }
    }
}

@end
