> For the complete documentation index, see [llms.txt](https://tyson.gitbook.io/vigamedoc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tyson.gitbook.io/vigamedoc/en/ke-hu-duan-jie-ru/ye-wu-jie-kou-1/3.-ji-fei-neng-li.md).

# 3.Payment

## 3.1 Set payment callback

### Android

```
PayNative.setPayResultCallback(new PayManager.PayCallback() {

    @Override
    public void onPayFinish(PayParams params) {
        // TODO Auto-generated method stub
        switch (params.getPayResult()){
            //pay success
            case PayDef.PAY_RESULT_SUCCESS:
                break;
            //pay fail
            case PayDef.PAY_RESULT_FAIL:
                break;
            //cancel pay
            case PayDef.PAY_RESULT_CANCEL:
                break;
        }
    }

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

    }
});
```

Callback Method Description：

onPayFinish：Payment Result Callback

* payParams：Payment related parameters (payment result, billing ID and other information can be obtained through this parameter)

onInitPayAgentFinish：Payment method initialized success

### iOS

```
[IOSLoader setPayResultCallback:^(NSDictionary *dic) {
        if ([[dic objectForKey:@"reasonCode"] integerValue] == 1) {
            //pay success
        }
    }];
```

## 3.2 Does the market support exit?（only Android）

### Android（Necessary）

```
PayNative.isExitGame();
```

### Unity

```
Wb.PayManager.Instance.IsSupportExit();
```

## 3.3 Get payment button type

### Android

```
PayNative.getButtonType(payID);
```

### iOS

```
[IOSLoader getButtonType];
```

### Unity

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

## 3.4 Get the market type

### Android

```
PayNative.getMarketType();
```

### iOS

```
[IOSLoader getMarketType];
```

### Unity

```
Wb.PayManager.Instance.GetMarketType();
```

## 3.5 Get package control information

### Android

```
PayNative.getGiftCtrlFlagUse(int ctrl);
```

### iOS

```
[IOSLoader getGiftSwitch:ctrl];
```

### Unity

```
Wb.PayManager.Instance.GetGiftCtrlFlagUse(int ctrl)
```

parameter：

* ctrl：Control parameter

Return value：

Control parameter

Description of control parameters：

| number | package name              | Pop-up rules                                                                          |
| ------ | ------------------------- | ------------------------------------------------------------------------------------- |
| 1      | Beginner's gift package   | Pop up if you haven't bought a novice gift bag when entering the game Homepage        |
| 2      | Quick rush                | Pop up when user virtual currency is insufficient                                     |
| 3      | Limited time gift package | When entering the game homepage, if you have bought a novice gift bag, it will pop up |
| 4      | Clearance Award           | Pop up when passing the Checkpoint                                                    |
| 5      | VIP gift package          | Pop up when entering the level selection page                                         |
| 6      | Today's deal              | Button trigger                                                                        |
| 7      | Affordable package        | Button trigger                                                                        |
| 8      | Shopping Mall             | Button trigger                                                                        |

## 3.6 Call payment

### 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);
```

> If you want to use WeChat payment, you need to put feedata\_wx.xml in the assets directory. If you want Alipay, you need to put 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"];
```

```
//This method can be called directly. Payment callback is set by default.
[IOSLoader textPayWithProductId:id callBack:^(NSDictionary *dic) {
        if ([dic[@"reasonCode"] integerValue] == 0) {
            //pay success
        }
    }];
```

### 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)
```

example：

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

    if (result.Equals("Paysuccess"))
    {
        ShowToast("pay success", false);
    }
    else if (result.Equals("Payfail"))
    {
        ShowToast("pay fail", true);
    }
    else if (result.Equals("Paycancel"))
    {
        ShowToast("cancel pay", false);
    }

});
```

parameter：

* id:Billing points defined in the gameid
* price:The price of the billing point, in minutes.  &#x20;
* payType:Payment type specified。eg:PayDef.PAY\_TYPE\_MM  &#x20;
* userdata:User defined data
* callFun:Payment callback（only  Unity）

## 3.7 Repay props

#### iOS

```
[IOSLoader payConsumableGoodsRecoveryCallBack:^(NSDictionary * dic) {
        //Repay props

        //call finish method
        [IOSLoader payConsumableGoodsRecoveryFinish];
}];
```

## 3.7 Need more game buttons

### Android

```
PayNative.isMoreGame();
```

### Unity

```
Wb.PayManager.Instance.IsMoreGameBtn();
```

## 3.8 Open more games

### Android

```
PayNative.openMoreGame();
```

### Unity

```
Wb.PayManager.Instance.OpenMoreGame();
```

## 3.9 Jump to an app details page in the store

### Android

```
PayNative.openMarket(String package);
```

### iOS

```
[IOSLoader jumpSomeApp:appid];
```

parameter：

* appid：Appid of jump APP

### Unity

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

parameter：

* package：The name of APP package in Android platform and app ID in IOS platform

## 3.10 Jump to the store details page of the current app

### Android

```
PayNative.openAppraise();
```

### iOS

```
[IOSLoader openAppDetail];
```

### Unity

```
Wb.PayManager.Instance.OpenAppraise();
```
