创建支付
使用 Yuno 创建支付。支持多种支付方式、卡 vault 存储和 3DS 配置。
SDK_CHECKOUT(默认值)时,需要结账会话,因此请先创建结账会话。DIRECT 或 REDIRECT 工作流则不需要结账会话。
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)时,即为部分批准。如果未发送该字段,或服务提供商不支持部分批准,支付将按常规卡支付处理。capture 设为 false,然后使用捕获授权 endpoint。
此请求需要 X-Idempotency-Key。详情请参阅身份验证。
促销码
422 PROMOTION_NOT_APPLICABLE 和原因 PROMOTIONS_NOT_ENABLED,且不会创建支付。请参阅促销。additional_data.order.discounts 的折扣行上,而不是放入 quote_id。请发送原始 amount,切勿发送折扣后的金额。
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,且不会创建支付:
true(不区分大小写)才会触发试运行。不带促销码的试运行,或带有 quote_id 行的试运行,不受影响。要试用促销码,请使用 sandbox 环境。
携带促销码的支付的响应
当促销码未能转换为报价时,不会创建支付,响应会说明原因。ENGINE_UNAVAILABLE 涵盖两种原因,且响应不会说明是哪一种。**两者返回的 reason 和消息都相同。
- **暂时性原因:稍后重试。**促销服务未及时响应、返回了错误,或 Yuno 暂时停用了 Promotions。请稍后重试同一笔支付。
- 非暂时性原因:重试会得到相同的响应。某个自动促销在此支付的选择中胜出,并且会使扣款金额为零。请不带促销码发送该支付。不带促销码的支付会按全额扣款,促销检查不会拒绝它。
Try again.,因此无法据此判断应重试哪一种。如果稍后重试后同一笔支付仍返回 ENGINE_UNAVAILABLE,请不带促销码发送该支付。此时客户将支付全价,并失去该促销码对这笔支付的折扣。
ZERO_CHARGE 属于胜出的促销码。当某个自动促销在选择中胜出且其报价会导致扣款金额为零时,支付不会因 ZERO_CHARGE 被拒绝:Yuno 会以 422 PROMOTION_NOT_APPLICABLE 和原因 ENGINE_UNAVAILABLE 拒绝该支付,且不会创建支付。这就是上文所述 ENGINE_UNAVAILABLE 的非暂时性原因:请不带促销码发送该支付。
对于以下支付,促销码同样会被拒绝,且不会创建支付:
授权
请求头
请求体
The unique identifier of the account. You find this information on the Yuno dashboard (UUID, 36 chars).
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 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 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.
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.
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.
响应
201
- Payment
- Card - With card details
- Card - With airline data
- Card - With customer, billing, and shipping details
- Card - With customer, billing, shipping and order items
- Card - With installments
- Card - With authorization
- Card - With merchant advice code (MAC)
- Card - With device fingerprint
- Card - With vault on success
- Card - With vaulted token
- Alternative payment method
- Card - With shipping, fee and tip amount
- Card - With NT
- Wallet - Direct
- Split Marketplace
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.
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).