# 创建购买支付令牌

生成订单及其支付令牌。订单根据请求正文中传递的商品生成。

如需在新窗口中打开支付UI，请使用以下链接：https://secure.xsolla.com/paystation4/?token={token}，其中{token}是收到的令牌。

如要进行测试，请使用以下URL：https://sandbox-secure.xsolla.com/paystation4/?token={token}`。

注意
   
   为确保该方法正常工作，请传入user.country.value参数（国家/地区代码）或X-User-Ip标头（如果国家/地区未知，则传入用户的IPv4地址）。传入的数据将用于确定支付货币。
不支持IPv6地址。所选货币将用于艾克索拉支付UI中的支付方式。

Endpoint: POST /v3/project/{project_id}/admin/payment/token
Version: 2.0.0
Security: basicAuth

## Path parameters:

  - `project_id` (integer, required)
    项目ID。您可以在发布商帐户的项目名称旁找到此参数；使用项目时，也可以在浏览器地址栏中找到此参数。URL格式如下：https://publisher.xsolla.com//projects/。
    Example: 44056

## Request fields (application/json):

  - `sandbox` (boolean)
    设置为true以测试付款流程。在这种情况下，请使用https://sandbox-secure.xsolla.com访问测试支付UI。

  - `user` (object, required)

  - `user.id` (object, required)

  - `user.id.value` (string)
    用户ID。测试时可传入任意值。如需接受真实付款，您需要使用自己系统中的用户ID值。此ID会在[用户验证](https://developers.xsolla.com/zh/webhooks/operation/user-validation/)Webhook中传递。

  - `user.name` (object)

  - `user.name.value` (string)
    用户显示名称。

  - `user.email` (object)

  - `user.email.value` (string)
    用户邮箱。必须符合RFC 822协议。

  - `user.country` (object)

  - `user.country.value` (string)
    符合[ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)标准的两位大写国家/地区代码。如果未在X-User-Ip请求头中传入IP地址，则此参数为必填。关于[艾克索拉支持的国家/地区](https://developers.xsolla.com/zh/doc/shop-builder/references/supported-countries/)的详细信息，请参阅文档。示例：country=US
    Example: "US"

  - `user.country.allow_modify` (boolean)
    用户是否可以在支付UI中更改国家/地区。

  - `user.age` (integer)
    用户年龄。

  - `user.phone` (object)

  - `user.phone.value` (string, required)
    用户手机号码。

  - `user.phone.allow_modify` (boolean)
    用户是否可以在支付UI中更改手机号。如果令牌中传入了phone.value值，则值默认为false。

  - `user.phone.hidden` (boolean)

  - `user.tracking_id` (object)

  - `user.tracking_id.value` (string, required)
    唯一跟踪ID（用于营销活动）。

  - `user.steam_id` (object)

  - `user.steam_id.value` (string, required)
    Steam ID。

  - `user.is_legal` (boolean)
    用户是否为法人实体。

  - `user.legal` (object)
    包含法人实体详情的对象。如果user.is_legal为true，则此对象及其所有参数均为必填。

  - `user.legal.name` (string)
    完整法定名称。

  - `user.legal.address` (string)
    完整法定地址。

  - `user.legal.vat_id` (string)
    个人纳税人识别号。

  - `user.legal.country` (string)
    注册成立国家/地区。使用符合[ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2)标准的两字母大写国家/地区代码。

  - `purchase` (object, required)

  - `purchase.items` (array, required)

  - `purchase.items.sku` (string, required)
    唯一商品ID。SKU只能包含大小写英文字母、数字、句点、短横线和下划线。

注意如需多次销售同一SKU，请在purchase.items[].quantity参数中指定所需数量。数组中不支持重复SKU⸺创建令牌时仅使用第一次出现的SKU。在这种情况下不会返回错误。
    Example: "t-shirt"

  - `purchase.items.quantity` (number, required)
    商品的数量。
    Example: 2

  - `promo_code` (string)
    区分大小写的唯一兑换码。包含字母和数字。

  - `settings` (object)
    用于为用户配置支付流程和支付UI的设置。

  - `settings.ui` (object)
    界面设置。

  - `settings.ui.theme` (string)
    支付UI主题。可以是63295a9a2e47fab76f7708e1（浅色主题（默认）），或63295aab2e47fab76f7708e3（深色主题）。您也可以[创建自定义主题](https://developers.xsolla.com/zh/doc/pay-station/features/ui-theme-customization/#pay_station_ui_theme_customization_in_token)，然后在此参数中传入其ID。
    Enum: "63295a9a2e47fab76f7708e1", "63295aab2e47fab76f7708e3"

  - `settings.ui.desktop` (object)
    桌面版的界面设置。

  - `settings.ui.desktop.header` (object)
    页眉设置。

  - `settings.ui.desktop.header.is_visible` (boolean)
    是否在支付UI中显示页眉。

  - `settings.ui.desktop.header.visible_logo` (boolean)
    如果为true，则在页眉中显示Logo。如需上传图片，请在[发布商帐户](https://publisher.xsolla.com/)中打开项目，并前往支付收银台>设置部分。

  - `settings.ui.desktop.header.visible_name` (boolean)
    是否在页眉中显示项目名称。

  - `settings.ui.desktop.header.visible_purchase` (boolean)
    是否在页眉中显示购买描述（purchase.description.value）。默认为true。

  - `settings.ui.desktop.header.type` (string)
    页眉的显示方式。可为compact（隐藏项目名称和用户ID）或normal（默认）。
    Enum: "compact", "normal"

  - `settings.ui.desktop.header.close_button` (boolean)
    是否在桌面端支付UI中显示关闭按钮。该按钮将关闭支付UI并将用户重定向到settings.return_url参数中指定的URL。默认为false。

  - `settings.ui.mode` (string)
    支付UI的界面模式。只能是user_account。请注意，页眉仅包含用户帐户的导航菜单，而没有用于选择产品或进行付款的任何选项。此模式仅适用于桌面端。
    Enum: "user_account"

  - `settings.ui.user_account` (object)
    用户帐户详细信息。

  - `settings.ui.user_account.payment_accounts` (object)
    我的支付帐户子菜单。

  - `settings.ui.user_account.payment_accounts.enable` (boolean, required)
    是否显示子菜单。默认为false。

  - `settings.ui.user_account.info` (object)
    我的帐户页面。

  - `settings.ui.user_account.info.enable` (boolean, required)
    是否显示子菜单。默认为false。

  - `settings.ui.user_account.info.order` (integer, required)
    子菜单在菜单中的位置。

  - `settings.ui.user_account.subscriptions` (object)
    管理订阅子菜单。

  - `settings.ui.user_account.subscriptions.enable` (boolean, required)
    是否显示子菜单。默认为false。

  - `settings.ui.user_account.subscriptions.order` (integer, required)
    子菜单在菜单中的位置。

  - `settings.ui.header` (object)

  - `settings.ui.header.visible_virtual_currency_balance` (boolean)
    此元素是否可在支付UI中隐藏。

  - `settings.ui.mobile` (object)

  - `settings.ui.mobile.header` (object)

  - `settings.ui.mobile.header.close_button` (boolean)
    是否在移动端支付UI中显示关闭按钮。该按钮将关闭支付UI并将用户重定向到settings.return_url参数中指定的URL。

  - `settings.ui.is_prevent_external_link_open` (boolean)
    是否禁用指向外部资源的重定向链接。点击外部链接时，会通过postMessage机制发送external-link-open事件。重定向链接地址通过url参数传递。

  - `settings.ui.is_payment_methods_list_mode` (boolean)
    打开支付UI时，是否显示用户所在国家/地区可用的支付方式列表。如果为false（默认），则显示settings.payment_method参数中传入的支付方式，或由[PayRank算法](https://developers.xsolla.com/zh/solutions/payments/payment-ui-management/top-payment-methods-management/)选择的支付方式。

  - `settings.ui.is_independent_windows` (boolean)
    是否将用户从嵌入式启动器浏览器(WebView)跳转到其默认浏览器进行购买。

  - `settings.ui.currency_format` (string)
    设置为code时，将在支付UI中显示三字母[ISO 4217](https://developers.xsolla.com/zh/doc/pay-station/references/supported-currencies/)币种代码。默认显示币种符号，而不是三字母币种代码。

  - `settings.ui.is_show_close_widget_warning` (boolean)
    关闭支付页面前，将鼠标悬停在×图标上时，是否显示关于交易处理中的警告。如果传入false或未传入该参数，则不显示警告。

  - `settings.ui.layout` (string)
    支付UI主要元素的位置。您可以在游戏内打开支付UI和/或交换订单信息和支付方式信息列的位置。详细信息请参阅[自定义说明](https://developers.xsolla.com/zh/doc/pay-station/features/ui-theme-customization/#pay_station_ui_theme_customization_layout)。
    Enum: "embed", "column_reverse", "embed_column_reverse"

  - `settings.ui.is_three_ds_independent_windows` (boolean)
    是否在新浏览器窗口中打开3-D Secure检查。如果您的配置强制执行内容安全政策(CSP)，请设置为true。

  - `settings.ui.is_cart_open_by_default` (boolean)
    打开移动版支付UI时购物车中商品列表的显示方式。如果为true，列表将以展开视图显示。如果为false（默认）或未传入该参数，列表将以折叠视图显示。

  - `settings.currency` (string)
    首选支付币种。符合[ISO 4217](https://en.wikipedia.org/wiki/ISO_4217)标准的三字母币种代码。关于[艾克索拉支持的币种](https://developers.xsolla.com/zh/doc/pay-station/references/supported-currencies/)的详细信息，请参阅文档。

  - `settings.language` (string)
    界面语言。两字母小写[语言代码](https://developers.xsolla.com/zh/doc/pay-station/features/localization/)。

  - `settings.external_id` (string)
    交易外部ID。

  - `settings.payment_method` (integer)
    支付方式ID。它决定收银台页面中的币种显示方式，因为某些支付方式可能仅支持特定币种。

  - `settings.return_url` (string)
    付款后将用户重定向到的页面。系统会自动将user_id、foreigninvoice、invoice_id和status参数添加到链接中。

  - `settings.redirect_policy` (object)

  - `settings.redirect_policy.redirect_conditions` (string)
    触发用户跳转到返回URL的支付状态。
    Enum: "none", "successful", "successful_or_canceled", "any"

  - `settings.redirect_policy.delay` (integer)
    用户自动跳转到返回URL前的延迟时间。

  - `settings.redirect_policy.status_for_manual_redirection` (string)
    触发显示跳转按钮的支付状态，点击该按钮会将用户重定向到返回URL。
    Enum: "none", "successful", "successful_or_canceled", "any"

  - `settings.redirect_policy.redirect_button_caption` (string)
    本地化的重定向按钮文字。
    Example: "Text button"

  - `custom_parameters` (object,null)
    以有效JSON键值对集合表示的自定义参数。
您可以通过此字段传递其他参数，以配置反欺诈过滤器。具体请[参阅支付收银台文档](https://developers.xsolla.com/zh/doc/pay-station/features/antifraud/)。

## Response 201 fields (application/json):

  - `token` (string)
    支付令牌。

  - `order_id` (integer)
    订单ID。
    Example: 1

## Response 401 fields (application/json):

  - `statusCode` (integer)
    Example: 401

  - `errorCode` (integer)
    Example: 1020

  - `errorMessage` (string)
    Example: "[0401-1020]: Error in Authentication method occurred"

## Response 422 fields (application/json):

  - `statusCode` (number)
    响应状态代码。
    Example: 422

  - `errorCode` (number)
    错误代码。
    Example: 1102

  - `errorMessage` (string)
    可读的错误消息。
    Example: "[0401-1102]: Unprocessable Entity. The property `external_id` is required"

  - `transactionId` (string)
    请求的唯一ID。
    Example: "da145238620011eb8e24fe6913ff226a"


