# iOS SDK\_支付功能

可使用应用内购买所需的支付功能。支付结果值以Delegate形式实现。

&#x20;

## **AppDelegate设置** <a href="#appdelegate-she-zhi" id="appdelegate-she-zhi"></a>

***

为使用支付功能设置AppDelegate时，请使用下列代码。

```
#import <GamePot/GamePot.h>

@interface ViewController () <GamePotPurchaseDelegate>
@end
@implementation ViewController

- (void)viewDidLoad
{
    ...
    [[GamePot getInstance] setPurchaseDelegate:self];
    ...
}

- (void)GamePotPurchaseSuccess:(GamePotPurchaseInfo *)_info
{
    // 付款成功
}

- (void)GamePotPurchaseFail:(NSError *)_error
{
    // 支付错误。请在游戏弹窗显示失败原因相关消息。
    // 消息语句请使用[error localizedDescription]。
}

- (void)GamePotPurchaseCancel
{
    // 启动付款过程中取消
    // 在游戏弹窗显示“已取消支付。”消息。
}
@end
```

## **支付尝试功能** <a href="#zhi-fu-chang-shi-gong-neng" id="zhi-fu-chang-shi-gong-neng"></a>

***

如要使用支付尝试功能，请使用下列代码。

* 尝试一般支付

  ```
  #import <GamePot/GamePot.h>

  // productid：输入商店中注册的商品ID
  [[GamePot getInstance] purchase:productid];
  ```
* 单独管理支付尝试及发票号

  ```
  #import <GamePot/GamePot.h>

  // productId：输入商店中注册的商品ID
  // uniqueId：输入单独管理的发票号
  [[GamePot getInstance] purchase:productid uniqueId:uniqueid];
  ```
* 单独管理支付尝试、发票号，将角色信息传递到Webhook

  ```
  #import <GamePot/GamePot.h>

  // productId：商店中添加的商品ID
  // uniqueId：单独管理的发票号
  // serverId：付费角色的服务器ID
  // playerId：付费角色的角色ID
  // etc      ： 付费角色的其他信息
  [[GamePot getInstance] purchase:productid uniqueId:uniqueid serverId:serverid playerId:playerid etc:etc]];
  ```

## **获取付费道具列表功能** <a href="#huo-qu-fu-fei-dao-ju-lie-biao-gong-neng" id="huo-qu-fu-fei-dao-ju-lie-biao-gong-neng"></a>

***

如要使用获取由商店传递的应用内付费道具列表功能，请使用下列代码。

```
[case1]
NSArray<SKProduct*>* itemList = [[GamePot getInstance] getDetails];

// 读取根据设备的货币设置标注的价格时
[[GamePot getInstance] getLocalizePrice:[product productIdentifier]];

[case2]

[[GamePot getInstance] getPurchaseItemsJsonString];


[case3]

@try{
    [[GamePot getInstance] getPurchaseDetailListAsyncToJSON:^(BOOL _success, NSString *_items, NSError *_error)
    {
        if(_success)
        {
            if(_items)
            {
                // In-app information
            }
        }else
        {
            if(_error){
                // NSLog(@"Error = %@", [_error localizedDescription]);
            }
        }
    }];
}
@catch(NSException* ex){
    NSLog(@"Error : %@", ex);
}

```

## **发放付费道具的功能** <a href="#fa-fang-fu-fei-dao-ju-de-gong-neng" id="fa-fang-fu-fei-dao-ju-de-gong-neng"></a>

***

可设置为与支付商店的发票明细进行对照并完成所有验证后向开发商服务器传递发放请求。

详细说明请参考[道具发放请求](https://nbase.atlassian.net/wiki/spaces/gamepotGuide/pages/44499433)。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.gamepot.io/basics/gamepot-2.0/zhong-wen/ios-sdk/ios-sdk-zhi-fu-gong-neng.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
