> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Economy v2 中的真钱价格跟踪

> 在 PlayFab Economy v2 捆绑包上设置 RealMoneyPriceDetails，并通过 marketplace_transaction_redeemed 事件跟踪收入以进行分析报告。

<Info>
  Economy v2 现已正式发布。如需支持和反馈，请访问 [PlayFab 论坛](https://community.playfab.com)。
</Info>

当玩家通过外部市场（Apple App Store、Google Play、Steam、Microsoft Store、Nintendo eShop、PlayStation Store）购买物品时，交易涉及真实世界的资金。通过在你的目录捆绑包上配置 `RealMoneyPriceDetails`，PlayFab 会在 [marketplace\_transaction\_redeemed](/services/playfab/api-references/events/Inventory/marketplace-transaction-redeemed) 事件中记录收入金额，使你能够构建收入分析和报告。

本教程将引导你完成端到端的流程：在捆绑包上设置真钱价格、兑换购买，并在事件中查看收入数据。

## 先决条件

* 一个 [PlayFab 开发者账户](https://developer.playfab.com/en-us/sign-up)。
* 在 [Game Manager](https://developer.playfab.com/) 中创建的 title。
* 已配置的市场集成（例如 [Google](/services/playfab/economy-monetization/economy-v2/marketplace/marketplace-integrations/google)、[Apple](/services/playfab/economy-monetization/economy-v2/marketplace/marketplace-integrations/apple) 或 [Microsoft Store](/services/playfab/economy-monetization/economy-v2/marketplace/marketplace-integrations/microsoft)）。
* 一个已发布的捆绑包，其[市场映射](/services/playfab/economy-monetization/economy-v2/catalog/bundles) 将其链接到市场产品。

## 步骤 1：在你的捆绑包上设置真钱价格

将 `RealMoneyPriceDetails` 添加到链接到你的市场产品的捆绑包。以每个市场的**最小货币单位**（例如 USD 的美分）指定价格。

### API

使用 [UpdateDraftItem](https://learn.microsoft.com/en-us/rest/api/playfab/economy/catalog/update-draft-item) 向现有捆绑包添加价格，然后发布它：

```json theme={null}
{
  "Item": {
    "Id": "{{StarterPackBundleID}}",
    "Type": "bundle",
    "Title": {
      "NEUTRAL": "Starter Pack"
    },
    "ItemReferences": [
      {
        "Id": "{{LaserSwordID}}",
        "Amount": 1
      },
      {
        "Id": "{{GoldCurrencyID}}",
        "Amount": 500
      }
    ],
    "RealMoneyPriceDetails": {
      "GooglePlayPrices": {
        "USD": 499
      },
      "AppleAppStorePrices": {
        "USD": 499
      },
      "MicrosoftStorePrices": {
        "USD": 499
      }
    },
    "AlternateIds": [
      {
        "Type": "GooglePlay",
        "Value": "com.mygame.starterpack"
      },
      {
        "Type": "AppleAppStore",
        "Value": "com.mygame.starterpack"
      },
      {
        "Type": "MicrosoftStore",
        "Value": "9NBLGGH42CFD"
      }
    ]
  },
  "Publish": true
}
```

### Game Manager

1. 转到 **Economy** > **Catalog (V2)** > **Bundles**。
2. 选择要编辑的捆绑包。
3. 在 **Prices** 部分，为捆绑包出现的每个市场设置真钱价格。
4. 确保 **Marketplace Mapping** 部分具有每个市场的正确 AlternateIds。
5. 选择 **Save and publish**。

***

### 价格格式参考

价格使用最小货币单位。目前仅支持 **USD**。

| 真实世界价格  | 字典值             |
| ------- | --------------- |
| \$0.99  | `{"USD": 99}`   |
| \$1.39  | `{"USD": 139}`  |
| \$4.99  | `{"USD": 499}`  |
| \$9.99  | `{"USD": 999}`  |
| \$19.99 | `{"USD": 1999}` |

仅为你的 title 使用的市场设置价格。支持的市场属性为：

* `AppleAppStorePrices`
* `GooglePlayPrices`
* `MicrosoftStorePrices`
* `NintendoEShopPrices`
* `PlayStationStorePrices`
* `SteamPrices`

### 每个市场的不同价格

如果你的游戏在各商店中定价不同，请单独设置每个市场属性：

```json theme={null}
"RealMoneyPriceDetails": {
  "GooglePlayPrices": {
    "USD": 499
  },
  "AppleAppStorePrices": {
    "USD": 529
  },
  "SteamPrices": {
    "USD": 449
  }
}
```

## 步骤 2：玩家进行购买并兑换

在玩家从外部市场购买物品后，你的游戏调用适当的兑换 API：

| 市场                | 兑换 API                                                                                                                                                 |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Google Play       | [RedeemGooglePlayInventoryItems](https://learn.microsoft.com/en-us/rest/api/playfab/economy/inventory/redeem-google-play-inventory-items)              |
| Apple App Store   | [RedeemAppleAppStoreInventoryItems](https://learn.microsoft.com/en-us/rest/api/playfab/economy/inventory/redeem-apple-app-store-inventory-items)       |
| Microsoft Store   | [RedeemMicrosoftStoreInventoryItems](https://learn.microsoft.com/en-us/rest/api/playfab/economy/inventory/redeem-microsoft-store-inventory-items)      |
| Steam             | [RedeemSteamInventoryItems](https://learn.microsoft.com/en-us/rest/api/playfab/economy/inventory/redeem-steam-inventory-items)                         |
| Nintendo eShop    | [RedeemNintendoEShopInventoryItems](https://learn.microsoft.com/en-us/rest/api/playfab/economy/inventory/redeem-nintendo-e-shop-inventory-items)       |
| PlayStation Store | [RedeemPlayStationStoreInventoryItems](https://learn.microsoft.com/en-us/rest/api/playfab/economy/inventory/redeem-play-station-store-inventory-items) |

当 PlayFab 处理兑换时，它：

1. 将市场收据与捆绑包的 `AlternateId` 匹配。
2. 将捆绑包的内容授予玩家的库存。
3. 发出一个 `marketplace_transaction_redeemed` 事件，其中包含来自匹配捆绑包的 `RealMoneyPrices`。

## 步骤 3：在事件中查看收入

成功兑换后，会发出 `marketplace_transaction_redeemed` 事件，其中包括真钱价格数据。你可以在 Game Manager 中找到此事件或通过数据管道查询它。

### 在 Game Manager 中查看

1. 转到 **Data** > **Event History**（在 **Analyze** 部分下）。
2. 搜索 `marketplace_transaction_redeemed` 事件名。
3. 选择一个事件以查看其详细信息，包括 `RealMoneyPrices` 字段。

### 示例事件负载

Starter Pack (\$4.99 USD) 的 Google Play 兑换产生如下事件：

```json theme={null}
{
  "EventName": "marketplace_transaction_redeemed",
  "Marketplace": "GooglePlay",
  "MarketplaceTransctionId": "GPA.1234-5678-9012-34567",
  "MarketplaceAlternateId": "com.mygame.starterpack",
  "Amount": 1,
  "ItemId": "{{StarterPackBundleID}}",
  "ItemType": "bundle",
  "RealMoneyPrices": {
    "USD": 499
  }
}
```

同一捆绑包从 Apple App Store（定价 \$5.29 USD）兑换产生：

```json theme={null}
{
  "RealMoneyPrices": {
    "USD": 529
  }
}
```

PlayFab 使用发生兑换的特定市场的价格。

### 查询收入数据

你可以将事件数据用于自定义分析。例如，要计算一段时间内的总收入，查询所有 `marketplace_transaction_redeemed` 事件并对 `RealMoneyPrices.USD` 值求和：

```text theme={null}
Total revenue = Sum of (RealMoneyPrices.USD × Amount) across all events
```

<Note>
  `RealMoneyPrices` 反映了你在 `RealMoneyPriceDetails` 中配置的内容，而不是市场实际收取的金额。保持你的价格与你的市场列表同步，以获得准确的报告。
</Note>

## 最佳做法

* **始终在市场捆绑包上设置 `RealMoneyPriceDetails`。** 没有它，兑换事件中的 `RealMoneyPrices` 字段将为空，你将失去收入可见性。
* **使用最小货币单位。** 对于 USD，请提供以美分为单位的价格（例如，`499` 表示 \$4.99）。
* **仅填充你使用的市场。** 你不需要为每个市场设置价格——仅为你的 title 发布所在的市场设置。
* **保持价格与你的市场列表同步。** 当你在外部市场中更新价格时，请更新 `RealMoneyPriceDetails` 中相应的属性以保持准确的报告。
* **当价格不同时，按市场设置价格。** 如果你的游戏在各商店中定价不同，请使用按市场的属性来反映每个平台上的实际价格。

## 另请参阅

* [真钱价格参考](/services/playfab/economy-monetization/economy-v2/catalog/real-money-prices)
* [Economy v2 捆绑包](/services/playfab/economy-monetization/economy-v2/catalog/bundles)
* [欺诈防范快速入门](/services/playfab/economy-monetization/economy-v2/fraud-prevention/quickstart)
* [市场集成](/services/playfab/economy-monetization/economy-v2/marketplace/marketplace-integrations/overview)
* [marketplace\_transaction\_redeemed 事件](/services/playfab/api-references/events/Inventory/marketplace-transaction-redeemed)
