3.计费能力

3.1 设置支付回调

Android

PayNative.setPayResultCallback(new PayManager.PayCallback() {

    @Override
    public void onPayFinish(PayParams params) {
        // TODO Auto-generated method stub
        switch (params.getPayResult()){
            //支付成功
            case PayDef.PAY_RESULT_SUCCESS:
                break;
            //支付失败
            case PayDef.PAY_RESULT_FAIL:
                break;
            //取消支付
            case PayDef.PAY_RESULT_CANCEL:
                break;
        }
    }

    @Override
    public void onInitPayAgentFinish(BasePayAgent arg0) {
        // TODO Auto-generated method stub

    }
});

回调方法说明:

onPayFinish:支付结果回调

  • payParams:支付相关参数(可通过该参数获取支付结果、计费ID等信息)

onInitPayAgentFinish:支付方式初始化成功

iOS

[IOSLoader setPayResultCallback:^(NSDictionary *dic) {
        if ([[dic objectForKey:@"reasonCode"] integerValue] == 1) {
            //支付成功
        }
    }];

3.2 该市场是否支持退出(仅限Android)

Android(必接)

PayNative.isExitGame();

Unity

Wb.PayManager.Instance.IsSupportExit();

3.3 获取支付按钮类型

Android

PayNative.getButtonType(payID);

iOS

[IOSLoader getButtonType];

Unity

Wb.PayManager.Instance.GetButtonType(int payID);

3.4 获取所在的市场类型

Android

PayNative.getMarketType();

iOS

[IOSLoader getMarketType];

Unity

Wb.PayManager.Instance.GetMarketType();

3.5 获取礼包控制信息

Android

PayNative.getGiftCtrlFlagUse(int ctrl);

iOS

[IOSLoader getGiftSwitch:ctrl];

Unity

Wb.PayManager.Instance.GetGiftCtrlFlagUse(int ctrl)

参数:

  • ctrl:控制参数

返回值:

控制参数

控制参数说明:

数值

礼包名称

弹出规则

1

新手礼包

进入游戏首页时如果没购买过新手礼包则弹出

2

快冲

用户虚拟货币不足时弹出

3

限时礼包

进入游戏首页时如果已经买过新手礼包则弹出

4

过关奖励

过关时弹出

5

vip礼包

进入关卡选择页时弹出

6

今日特价

按钮触发

7

实惠大礼包

按钮触发

8

商城

按钮触发

3.6 调用支付

Android

PayNative.orderPay(id);
orderPay(int id,String userdata);
orderPay(int id,int price,String userdata);
orderPay(int id, int price, int payType,String userdata);

如需使用微信支付,需要在assets目录放入feedata_wx.xml;如需支付宝,需要放入feedata_alipay.xml

iOS

[IOSLoader orderPay:id];
[IOSLoader orderPay:id userData:@"userData"];
[IOSLoader orderPay:id price:price userData:@"userData"];
[IOSLoader orderPay:id price:price type:payType userData:@"userData"];
//可直接调用此方法,默认已设置支付回调
[IOSLoader textPayWithProductId:payId userInfo:userInfo tradeIdCallBack:^(NSDictionary * _Nullable object) {
    // 订单id回调
    NSString *tramsactionId = [object valueForKey:@"transactionId"];

} callBack:^(NSDictionary * _Nullable object) {
     if ([object[@"reasonCode"] integerValue] == 0) {
         // 购买成功
     }
     if ([object[@"reasonCode"] integerValue] == 1) {
         // 购买失败
     }
}];

Unity

Wb.PayManager.Instance.OrderPay(int id, Action<string, int> callFun);
Wb.PayManager.Instance.OrderPay(int id, string userData, Action<string, int> callFun);
Wb.PayManager.Instance.OrderPay(int id, int price, string userData, Action<string, int> callFun);
Wb.PayManager.Instance.OrderPayWithType(int id, int price, int payType,string userData, Action<string, int> callFun)

示例:

Wb.PayManager.Instance.OrderPay(1, (result, id) =>
{

    if (result.Equals("Paysuccess"))
    {
        ShowToast("支付成功", false);
    }
    else if (result.Equals("Payfail"))
    {
        ShowToast("支付失败", true);
    }
    else if (result.Equals("Paycancel"))
    {
        ShowToast("支付取消", false);
    }

});

参数:

  • id:游戏中定义的计费点id

  • price:计费点的价格,单位为分。

  • payType:指定的支付类型。eg:PayDef.PAY_TYPE_MM

  • userdata:用户自定义数据

  • callFun:支付回调(仅Unity)

3.7 订单恢复(补发道具)

iOS

+ (void)payConsumableGoodsRecoveryCallBack:(void (^)(NSDictionary *))callback;
+ (void)payConsumableGoodsRecoveryFinish:(NSString *)transactionId;

说明:用户上一次订单未成功发放道具或钻石,SDK会在下一次进入游戏时,主动回调订单信息 可以在这一步为用户恢复订单

方法需要在- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions方法中调用

使用:

// 消耗型商品恢复
[IOSLoader payConsumableGoodsRecoveryCallBack:^(NSDictionary *dic) {

    int coin = [[NSUserDefaults standardUserDefaults] integerForKey:@"coinKey"];
    [[NSUserDefaults standardUserDefaults] setInteger:(coin + 60) forKey:@"coinKey"];

    [IOSLoader payConsumableGoodsRecoveryFinish:dic[@"tradeId"]];

    int payPrice = [[dic valueForKey:@"payPrice"]intValue];
    int payType = [[dic valueForKey:@"payType"] intValue];
    [IOSLoader tj_payWithMoney:payPrice coin:60 source:payType];

    NSString *message = [NSString stringWithFormat:@"%@ ",dic];
    UIAlertController* successAlert = [UIAlertController alertControllerWithTitle:@"内购恢复成功 " message:message preferredStyle: UIAlertControllerStyleAlert];
    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:NULL];
    [successAlert addAction:okAction];

    [self.window.rootViewController presentViewController:successAlert animated:YES completion:^{

    }];
}];

3.8 是否需要有更多游戏按钮

Android

PayNative.isMoreGame();

Unity

Wb.PayManager.Instance.IsMoreGameBtn();

3.9 打开更多游戏

Android

PayNative.openMoreGame();

Unity

Wb.PayManager.Instance.OpenMoreGame();

3.10 跳转应用商店的某个应用详情页

Android

PayNative.openMarket(String package);

iOS

[IOSLoader jumpSomeApp:appid];

参数:

  • appid:跳转应用的id

Unity

Wb.PayManager.Instance.OpenMarket(string package);

参数:

  • package:在Android平台为应用包名,在ios平台为应用id

3.10 跳转当前应用的商店详情页

Android

PayNative.openAppraise();

iOS

[IOSLoader openAppDetail];

Unity

Wb.PayManager.Instance.OpenAppraise();

最后更新于