跳转到主要内容
POST
此请求用于创建支付。当工作流为 SDK_CHECKOUT(默认值)时,需要结账会话,因此请先创建结账会话。DIRECT 或 REDIRECT 工作流则不需要结账会话。
重要尽管创建支付时某些对象不是必需的,但如果您提供这些信息,可以提升用户的支付体验。
3DS 支付请查看 3D Secure 页面,了解如何在 Yuno 上使用 3DS 创建支付。
促销要按促销价格收费,请发送原始 amount,并在 additional_data.order.discounts 中添加一条折扣行,其中包含 type: YUNO_PROMOTION 和促销报价的 quote_id。Yuno 会按折扣后的价格收费,保持您发送的 amount 不变,并返回 discount_amount。如果要兑换促销码而不是报价,请在折扣行上发送 { "code": "<code>" }。试运行不接受促销码(请参阅试运行)。请参阅促销码和促销。促销报价示例需要为您的组织启用 Promotions:在 Yuno 启用之前,创建促销报价会返回 204,且不会有 quote_id。
要授权支付但不立即捕获(不向客户扣款),请在支付方式详情中,在与支付方式类型匹配的对象下发送 capture: false:卡使用 payment_method.detail.card.capture,支持授权的钱包使用 payment_method.detail.wallet.capture(例如使用已保存账单协议的 PayPal)。Yuno 只读取与支付方式类型匹配的对象下的该标志,因此在钱包支付中,card 下的 capture: false 会被忽略,支付会被立即捕获。 如果您希望以单步方式处理支付(同时完成授权和捕获),请在同一对象下将 capture 设为 true。
部分批准要在卡支付中接受低于 amount.value 的批准金额,请发送 payment_method.detail.card.partial_approval: true。该字段适用于购买(capture: true)和授权(capture: false),在验证时会被忽略。服务提供商批准的金额通过 amount.authorized 返回,支付会保持与全额批准相同的状态,因此当 amount.authorized 低于 amount.value 减去 discount_amount(没有促销时,低于 amount.value)时,即为部分批准。如果未发送该字段,或服务提供商不支持部分批准,支付将按常规卡支付处理。
要在 Sandbox 中测试 Yuno 内所有可能的交易结果,请参阅测试数据文档。
元数据与路由逻辑路由规则读取支付上的元数据,并与其客户上的元数据合并。如果您使用元数据驱动路由逻辑,请在支付或客户上设置元数据。仅在结账会话上设置的元数据不会影响支付路由。当路由规则带有元数据条件时,结账会话的元数据只决定该会话列出哪些支付方式和分期付款选项,因此如果两者都需要,请在两处设置相同的元数据。
vaulted_token 会覆盖设备 fingerprint如果同时提供 payment_method.vaulted_token 和 payment_method.token,vaulted_token 会替换所有支付数据,包括设备 fingerprint(third_party_session_id)。如果您需要使用设备 fingerprint 进行欺诈筛查,请勿同时发送这两个字段。
对于两步支付(先授权再捕获),请按上述方式将 capture 设为 false,然后使用捕获授权 endpoint。 此请求需要 X-Idempotency-Key。详情请参阅身份验证。

促销码

Promotions 按组织启用只有在 Yuno 为您的组织启用 Promotions 之后,携带促销码的支付才能生效。在此之前,此类支付会被拒绝,返回 422 PROMOTION_NOT_APPLICABLE 和原因 PROMOTIONS_NOT_ENABLED,且不会创建支付。请参阅促销。
要按促销码的价格收费,请将促销码放在 additional_data.order.discounts 的折扣行上,而不是放入 quote_id。请发送原始 amount,切勿发送折扣后的金额。
Request
这里只展示了请求中与此相关的部分,其余部分是您已经在发送的请求体。Yuno 会在创建支付之前将促销码兑换为报价,之后该支付将按带报价的支付继续处理。响应内容请参阅支付携带的内容。使用创建促销创建促销。促销码介绍了完整流程。 折扣行遵循以下规则。违反任一规则的折扣行会在执行任何其他操作之前被拒绝,返回 400 INVALID_PARAMETERS,且不会创建支付。 **MERCHANT 行上的促销码会被忽略。**当一行的 type 为 MERCHANT,或该行没有 type 但带有 id 或 name 时,Yuno 会将其视为 MERCHANT 行。Yuno 会丢弃此类行的 code,且不报错:不会应用任何促销,支付会在没有该折扣的情况下继续处理。要兑换促销码,请将其发送到没有 id、name 或 unit_amount,且 type 未填写或设为 YUNO_PROMOTION 的行上。 任何响应都不会重复您的促销码。当促销服务在消息中引用该促销码时,Yuno 会将其替换为 ***。 使用促销码时不需要 payment_method.type。促销码适用于整笔支付,与支付方式无关。仅当您的支付包含该类型时,Yuno 才会将其发送给促销服务。

幂等性键与使用次数

  • **X-Idempotency-Key 为必填项。**创建支付要求每笔支付都提供该标头:缺少该标头时,响应为 400 INVALID_PARAMETERS,消息为 The header 'x-idempotency-key' is required.。Yuno 还会在计入使用次数之前去除键前后的空格,去除空格后为空的键会被拒绝,返回 400 INVALID_PARAMETERS:The header 'x-idempotency-key' is required to apply a promotion code.
  • **当 Yuno 接受某个促销码用于支付时,计为一次使用。**计数发生在支付尝试时,即支付到达服务提供商之前,并以该支付的 X-Idempotency-Key 作为键。
  • **再次使用相同的键不会计入第二次使用。**使用相同的键和相同的促销码重试支付时,将按第一次使用的结果计价。
  • **一个键只属于一个促销码。**将同一个键用于另一个促销码会被拒绝,返回 422 PROMOTION_NOT_APPLICABLE 和原因 IDEMPOTENCY_KEY_REUSED。
  • **已拒绝的支付仍会占用其使用次数。**Yuno 不会退回使用次数。支付被拒绝后的新尝试需要新的 X-Idempotency-Key,并会计入一次新的使用。

试运行

试运行不接受促销码。带有标头 X-Dry-Run: true 且在 YUNO_PROMOTION 行上携带 code 的支付会被拒绝,返回 400 INVALID_PARAMETERS,且不会创建支付:
Dry run with a code (400)
Yuno 会在请求报价、对卡进行令牌化或到达服务提供商之前拒绝该支付,因此不会计入使用次数。消息中永远不会重复您的促销码。只有值 true(不区分大小写)才会触发试运行。不带促销码的试运行,或带有 quote_id 行的试运行,不受影响。要试用促销码,请使用 sandbox 环境。

携带促销码的支付的响应

当促销码未能转换为报价时,不会创建支付,响应会说明原因。 **ENGINE_UNAVAILABLE 涵盖两种原因,且响应不会说明是哪一种。**两者返回的 reason 和消息都相同。
  • **暂时性原因:稍后重试。**促销服务未及时响应、返回了错误,或 Yuno 暂时停用了 Promotions。请稍后重试同一笔支付。
  • 非暂时性原因:重试会得到相同的响应。某个自动促销在此支付的选择中胜出,并且会使扣款金额为零。请不带促销码发送该支付。不带促销码的支付会按全额扣款,促销检查不会拒绝它。
对于这两种原因,消息都显示 Try again.,因此无法据此判断应重试哪一种。如果稍后重试后同一笔支付仍返回 ENGINE_UNAVAILABLE,请不带促销码发送该支付。此时客户将支付全价,并失去该促销码对这笔支付的折扣。
Code that leaves a charge of zero (422)
ZERO_CHARGE 属于胜出的促销码。当某个自动促销在选择中胜出且其报价会导致扣款金额为零时,支付不会因 ZERO_CHARGE 被拒绝:Yuno 会以 422 PROMOTION_NOT_APPLICABLE 和原因 ENGINE_UNAVAILABLE 拒绝该支付,且不会创建支付。这就是上文所述 ENGINE_UNAVAILABLE 的非暂时性原因:请不带促销码发送该支付。 对于以下支付,促销码同样会被拒绝,且不会创建支付: 促销错误码列出了所有响应以及每条消息的文本。

授权

public-api-key
string
header
默认值:<Your public-api-key>
必填
private-secret-key
string
header
默认值:<Your private-secret-key>
必填

请求头

X-Idempotency-Key
string
必填

Unique identifier used in HTTP headers to ensure that a request is processed only once, even if it is retried due to network issues or timeouts.

请求体

application/json
account_id
string
默认值:{{account_id}}
必填

The unique identifier of the account. You find this information on the Yuno dashboard (UUID, 36 chars).

merchant_order_id
string
默认值:""
必填

The unique identifier of the customer's order (MAX 255; MIN 3).

description
string
必填

The description of the payment (MAX 255; MIN 3).

amount
object
必填

Specifies the payment amount object, with the value and currency.

country
enum<string>
必填

Country where the transaction must be processed (MAX 2; MIN 2; ISO 3166-1).

可用选项:
AR,
BO,
BR,
CL,
CO,
CR,
EC,
SV,
GT,
HN,
MX,
NI,
PA,
PY,
PE,
US,
UY
payment_method
object
必填

The payment method object.

taxes
object

Specifies the order's tax object.

checkout
object

Specifies the checkout object. This object is not mandatory for back to back payments. Required when workflow is defined as SDK_CHECKOUT or is not sent. not required for DIRECT or REDIRECT payments.

additional_data
object

Specifies the additional_data object. This object is not mandatory. However, if you send this information, the payment experience will be enhanced for your user.

merchant_reference
string

Identification of the payment transaction defined by the merchant (MAX 255; MIN 3). Optional to complement the merchant_order_id.

response_additional_data
object

Controls additional data returned in the payment response and in the payment webhooks.

customer_payer
object

Specifies customer object for payments.

workflow
enum<string>
默认值:SDK_CHECKOUT

The payment workflow. Indicates whether the integration will use Yuno´s SDK or will be a back to back connection. Guides

  • SDK_CHECKOUT: [Recommended] - Use Yuno's SDK.
  • DIRECT: Back to back integration with provider info for custom payment experience.
  • REDIRECT: Back to back integration with provider redirection.

可用选项:
SDK_CHECKOUT,
CHECKOUT,
REDIRECT,
DIRECT,
SDK_SEAMLESS
external_subscription
object

Links this payment to a subscription managed in an external billing platform. When present on an approved payment with a vaulted card, Yuno takes over the subscription's recurring charges. Cannot be sent together with the subscription object (returns INVALID_REQUEST). The object is returned in the payment response, in Retrieve Payment and in payment webhooks.

external_invoice
object

Links this payment to an invoice of an external billing platform, so that a payment you collect with Yuno pays that invoice (for example a balance top-up). Yuno checks the invoice before it charges. When the payment is approved, Yuno reports it to the invoice; when it is declined, Yuno records a failed attempt and the invoice stays open. A smaller amount than the amount remaining is accepted on one-off invoices; invoices of subscriptions that Stripe charges automatically need the exact amount. Cannot be sent together with external_subscription or subscription (returns INVALID_REQUEST). The object is returned in the payment response, in Retrieve Payment and in payment webhooks. See Pay a Stripe invoice (top-ups) for the amount rules and the error codes.

subscription
object

Specifies the subscription object. Send exactly one of three shapes: inline terms (frequency, availability and amount) to create a subscription, plan_id to create one from a plan, or id to charge an existing subscription. See Start a subscription with the first payment.

callback_url
string

The URL where to redirect the customer after the payment. Only required for DIRECT integrations that have a redirection (MAX 526; MIN 3).

fraud_screening
object

Fraud screening object.

split_marketplace
object[]

Split marketplace array of objects

metadata
object[]

Custom key–value tags to track this payment or add context (e.g., order_id, invoice, campaign). Up to 120 items.

响应

201

id
string
示例:

"6c44ed29-cc51-4479-a5eb-108afdaadd50"

account_id
string
示例:

"493e9374-510a-4201-9e09-de669d75f256"

description
string
示例:

"Test Payment"

country
string
示例:

"US"

status
string
示例:

"SUCCEEDED"

sub_status
string
示例:

"APPROVED"

merchant_order_id
string
示例:

"1744403449"

created_at
string
示例:

"2025-04-11T20:30:49.825637Z"

updated_at
string
示例:

"2025-04-11T20:30:51.953868Z"

amount
object
discount_amount
object

The total discount of the Yuno promotion applied to the payment: the sum of the YUNO_PROMOTION lines of additional_data.order.discounts. Absent when no promotion applied. The amount charged is amount.value minus this value, and it is on transactions.amount. See Promotions.

checkout
object
payment_method
object
customer_payer
object
additional_data
object
transactions
object
transactions_history
object[]
callback_url
string
示例:

"http://www.google.com/?checkoutSession=7fb7093e-dc67-4c7a-80c5-d25cf5e6ff27"

workflow
string
示例:

"SDK_CHECKOUT"

metadata
object[]
fraud_screening
any
示例:

""

subscription_code
string<uuid> | null

Identifier of the subscription created or charged by this payment. Null when the payment carries no subscription.

plan_id
string

The subscription's plan when this payment was created. Present only on payments created with subscription.plan_id and on their renewals; absent otherwise.

plan_assigned_at
string<date-time>

When the plan was assigned to the subscription (UTC, ISO 8601). Present only on payments that carry plan_id.

routing_rules
object
simplified_mode
boolean
默认值:true
示例:

false

external_subscription
object

The subscription in an external billing platform that this payment belongs to, as it was sent when the payment was created. The key is in the response only when the payment carried external_subscription.

external_invoice
object

The invoice in an external billing platform that this payment pays (a top-up), as it was sent when the payment was created. The key is in the response only when the payment carried external_invoice. See Pay a Stripe invoice (top-ups).

shipping
any | null

Shipping.