# Pay Station API

# 概览 {% #overview %}

* **版本：**2.0.0
* **服务器**：
  * `https://api.xsolla.com/api`

支付中心通过向用户提供在游戏商店中进行游戏内购买支付时的便捷UI，让合作伙伴实现其游戏变现。要设置支付UI的打开，请参阅这些[说明](/zh/doc/pay-station/how-to/how-to-open-payment-ui/)。

Pay Station API提供以下调用组：
- 令牌 — 包含使用任意用户参数生成令牌以便通过支付UI进行后续支付处理的API调用。
- [令牌化](/zh/doc/pay-station/features/tokenization/) — 
  包含用于在不打开支付UI或无需用户介入的情况下安全处理支付的API调用。
- 报告— 包含返回用户交易数据、生成报告及获取按货币分类的提现细目。
- 退款 — 包含请求完全或部分退款的API调用。
- 测试 — 包含测试拒付过程的API调用。

关于配置支付UI的详细信息，请参阅[付款解决方案集成指南](/zh/solutions/payments/integration-guide/integration-flow/)。

<div class="note">
<p><strong>注：</strong></p><p>还可参阅<a href="https://github.com/xsolla/xsolla-postman">Postman合集</a>下的<b>Xsolla Base API</b>部分来测试用于集成的API调用。</p>
</div>

# Xsolla Business Accounts {% #business-accounts %}

Business Account is the primary tool for configuring Xsolla features, as well 
as for working with analytics and transactions.

Xsolla develops tools for different business categories. To simplify 
navigation, these tools are grouped into separate accounts by target audience:

* [mobile games](https://xsolla.com/for/mobile-games/account/)

* [free-to-play PC games](https://xsolla.com/for/free-to-play-pc/account/)

* [premium PC games](https://xsolla.com/for/premium-pc-games/account/)

* [web games](https://xsolla.com/for/web-games/account/)

<div class="note">
<p><strong>注：</strong></p><p><a href="https://publisher.xsolla.com/">Publisher Account</a> is a legacy tool.</p>
</div>


Version: 2.0

## Servers

```
https://api.xsolla.com/merchant/v2
```

## Security

### basicAuth

Xsolla API uses basic access authentication. All requests to the API must 
contain the `Authorization: Basic <your_authorization_basic_key>` header, where 
`<your_authorization_basic_key>` is the `merchant_id:api_key` or 
`project_id:api_key` pair encoded according to the Base64 standard.

Go to your [account](/zh/api/pay-station/business-accounts/) to find these 
parameters:

- `project_id` is shown:
  - Next to the project name when you click it in the account header.
  - In the URL of any account page. The URL has the following format: 
    `https://xsolla.com/for/<business-account-
    type>/account/<merchant_id>/projects/<project_id>/`.
- `merchant_id`可在以下地方找到：
  - In the **Company settings > General info** section.
  - In the URL of any account page. The URL has the following format: 
    `https://xsolla.com/for/<business-account-type>/account/<merchant_id>/`.
- `api_key` is shown in your account only once when it is created and must be 
  stored on your side. You can create a new key in the following sections:
  - **Settings > API keys** (in this section, you can create an API key only for a 
    particular project).
  - **Company settings > API keys** (in this section, you can create an API key 
    that will be applied to all projects in a particular company).

For more information about working with API keys, see the [API reference](/zh/api/getting-started/#api_keys_overview).


Type: http
Scheme: basic

## Download OpenAPI description

[Pay Station API](https://xsolla.redocly.app/_bundle/@l10n/zh/api/pay-station/index.yaml)

## 令牌

### 创建令牌

 - [POST /merchants/{merchant_id}/token](https://xsolla.redocly.app/zh/api/pay-station/token/create-token.md): 您可以通过任意用户参数创建令牌。您在获取令牌时发送这些参数并在成功支付后会收到发回的参数。令牌只能包含本文档中描述的参数或您预定义的参数。

如果任何参数以不正确的格式或类型发送，将不会获得令牌。作为响应，您将收到422 
HTTP代码，JSON正文中有相应的错误描述。在extended_message中，您将收到具体错误参数的相关信息。

By default, the token lifetime is 24 hours. If you want to change this value, 
contact your Customer Success Manager or send an email to csm@xsolla.com. The new value will be enabled 
for all your company’s projects created in the account.


注意调用此API方法后获得的令牌只能用于授权其他请求。只有在集成了订阅产品的情况下才能使用此令牌打开支付UI。要在新窗口中打开支付UI，请使用以下链接：https://secure.xsolla.com/paystation4/?token={token} ，其中{token}是收到的令牌。如要进行测试，请使用以下URL： https://sandbox-secure.xsolla.com/paystation4/?token={token}。





注意此API调用不包含project_id路径参数，因此您需要使用在您公司的所有项目中都有效的API密钥来设置授权。

### 使令牌失效

 - [POST /projects/{project_id}/token/{token}/expire](https://xsolla.redocly.app/zh/api/pay-station/token/invalidate-token.md): 使现有支付令牌失效，防止其继续用于打开支付UI。它可用于避免单实例商品在并行会话中发生重复支付。调用成功后，所有使用该支付令牌打开的其他用户会话都会过期。


注：此API调用具有幂等性，可多次调用。

## 令牌化

### 列示已保存的支付帐户

 - [GET /projects/{project_id}/users/{user_id}/payment_accounts](https://xsolla.redocly.app/zh/api/pay-station/tokenization/get-saved-accounts.md): 列示已保存的用户支付帐户。


注：在沙盒模式下，此API调用只适用于没有3-D Secure功能的测试银行卡。

### 删除已保存的支付帐户

 - [DELETE /projects/{project_id}/users/{user_id}/payment_accounts/{type}/{account_id}](https://xsolla.redocly.app/zh/api/pay-station/tokenization/delete-saved-account.md): 删除已保存的支付帐户。


注：在沙盒模式下，此API调用只适用于没有3-D Secure功能的测试银行卡。





注：您可以在沙盒模式下调用此API方法，方法是在请求中传入测试支付帐户的数据。关于沙盒模式访问和测试场景的详细信息，请参阅说明。

### 通过已保存的帐户收费

 - [POST /projects/{project_id}/users/{user_id}/payments/{type}/{account_id}](https://xsolla.redocly.app/zh/api/pay-station/tokenization/charge-with-saved-account.md): 使用已保存的支付帐户收费。


注：在沙盒模式下，此API调用只适用于没有3-D Secure功能的测试银行卡。





注意为使API调用正常工作，请配置一个2分钟的超时时间。

## 报告

### 列示所有报告

 - [GET /merchants/{merchant_id}/reports](https://xsolla.redocly.app/zh/api/pay-station/reports/get-reports.md): 获取指定数据范围的财务报告列表。


注意此API调用不包含project_id路径参数，因此您需要使用在您公司的所有项目中都有效的API密钥来设置授权。

### 列示所有操作

 - [GET /merchants/{merchant_id}/reports/transactions/registry.{format}](https://xsolla.redocly.app/zh/api/pay-station/reports/get-transactions.md): 返回指定时间段内成功和取消的交易的详细信息列表。您可以在响应中获得付款信息，包括费用、税以及订单和用户的数据。您可以获得JSON或CSV格式的列表。您可以使用此
API调用进行财务对账。


注意此API调用不包含project_id路径参数，因此您需要使用在您公司的所有项目中都有效的API密钥来设置授权。

### 查找交易

 - [GET /merchants/{merchant_id}/reports/transactions/search.{format}](https://xsolla.redocly.app/zh/api/pay-station/reports/find-transactions.md): 根据具体搜索参数返回交易列表。您将在响应中获得游戏中所有付款的数据，包括未成功完成的付款。您不仅可以指定交易时间段，还可以指定其他参数，例如搜索某个用户进行的交
易或处于某个付款状态下的交易。您可以获取JSON或CSV格式的列表。


注意此API调用不包含project_id路径参数，因此您需要使用在您公司的所有项目中都有效的API密钥来设置授权。

### 查找交易（快速搜索）

 - [GET /merchants/{merchant_id}/reports/transactions/simple_search](https://xsolla.redocly.app/zh/api/pay-station/reports/find-transactions-fast.md): 在几秒钟内基于特定搜索参数获取交易列表。此为以JSON、CSV或XLS格式返回该数据的查找交易API调用的另一选择。


注意此API调用不包含project_id路径参数，因此您需要使用在您公司的所有项目中都有效的API密钥来设置授权。

### 按货币获取出款细目

 - [GET /merchants/{merchant_id}/reports/transactions/summary/transfer](https://xsolla.redocly.app/zh/api/pay-station/reports/get-payouts-breakdown.md): 按货币获取出款细目。


注意此API调用不包含project_id路径参数，因此您需要使用在您公司的所有项目中都有效的API密钥来设置授权。

### 获取交易

 - [GET /merchants/{merchant_id}/reports/transactions/{transaction_id}/details](https://xsolla.redocly.app/zh/api/pay-station/reports/get-transaction.md): 按ID获取完整交易信息。


注意此API调用不包含project_id路径参数，因此您需要使用在您公司的所有项目中都有效的API密钥来设置授权。

### 列示所有汇款

 - [GET /merchants/{merchant_id}/reports/transfers](https://xsolla.redocly.app/zh/api/pay-station/reports/get-payouts.md): 列示某个时间段内的所有出款。


注意此API调用不包含project_id路径参数，因此您需要使用在您公司的所有项目中都有效的API密钥来设置授权。

## 退款

### 请求部分退款

 - [PUT /merchants/{merchant_id}/reports/transactions/{transaction_id}/partial_refund](https://xsolla.redocly.app/zh/api/pay-station/refund/request-partial-refund.md): 向用户发送部分退款请求。关于退款流程和支持部分退款的支付方式的详细信息，请参阅我们的文档。


注：您可以在沙盒模式下调用此API方法，方法是在请求中传入测试支付的数据。关于沙盒模式访问和测试场景的详细信息，请参阅说明。





注意此API调用不包含project_id路径参数，因此您需要使用在您公司的所有项目中都有效的API密钥来设置授权。

### 请求退款

 - [PUT /merchants/{merchant_id}/reports/transactions/{transaction_id}/refund](https://xsolla.redocly.app/zh/api/pay-station/refund/request-refund.md): 发送退款请求以向用户退款。详细过程请参阅退款功能。


注：您可以在沙盒模式下调用此API方法，方法是在请求中传入测试支付的数据。关于沙盒模式访问和测试场景的详细信息，请参阅说明。





注意此API调用不包含project_id路径参数，因此您需要使用在您公司的所有项目中都有效的API密钥来设置授权。

## 测试

### 请求拒付

 - [POST /merchants/{merchant_id}/projects/{project_id}/payments/{transaction_id}/chargeback](https://xsolla.redocly.app/zh/api/pay-station/testing/request-chargeback.md): 在沙盒模式下请求拒付：

- To access the sandbox mode, pass "mode":"sandbox" when you [get the 
  token](/zh/api/pay-station/operation/create-token/).

- 需在用于测试的同一个项目中以沙盒模式进行测试支付。

- 交易状态必须不能为refunded、cancelled。

- Your role in the account has to be at least Financial manager. (You can 
  find it in the Settings > Members section.)

- Refer to the instructions for more information 
  about this testing scenario.


注：Refer to the documentation for more information about other testing scenarios.

