# 发起分账或分账回退

> 对已完成的支付发起分账，或对一笔已有分账发起回退。

```yaml
openapi: 3.1.0
info:
  title: 发起分账或分账回退
  version: 1.0.0
  description: 对已完成的支付发起分账，或对一笔已有分账发起回退。
paths:
  /profit/share:
    post:
      summary: 发起分账或分账回退
      description: 对已完成的支付发起分账，或对一笔已有分账发起回退。
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                currency:
                  type: string
                  description: 分账或分账回退币种，使用 [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217)
                    三位字母货币代码。
                gatewayReference:
                  type: string
                  description: 要分账的 Onerway 支付交易，取创建支付时返回的 `transactionId`。
                  x-onerway-required: conditional
                  x-onerway-condition:
                    - "`profitType` 为 `share` 时必填。"
                  x-onerway-constraints:
                    - kind: rule
                      text: 创建支付时必须设置 `paymentMethodOptions.share.profitShare=true`，否则该笔支付不具备分账资格。
                    - kind: rule
                      text: "`profitType` 为 `return` 时不要传入；回退通过 `profitParentReference` 与
                        `profitGatewayReference` 定位原分账单。"
                merchantNo:
                  type: string
                  description: 发起本次分账或分账回退的商户号。
                  x-onerway-constraints:
                    - kind: rule
                      text: 平台模式下传收款的子商户号，与创建该笔支付时使用的 `merchantNo` 保持一致。
                profitCompleted:
                  type: boolean
                  description: 本次请求是否已结束该笔支付的分账；后续还会继续分账时传 `false`。
                  x-onerway-required: conditional
                  x-onerway-condition:
                    - "`profitType` 为 `share` 时必填。"
                  x-onerway-constraints:
                    - kind: rule
                      text: 一旦传入 `true`，该笔支付后续再发起分账会被拒绝。
                profitGatewayReference:
                  type: string
                  description: 被回退的原分账单号，由 Onerway 在发起分账时返回。
                  x-onerway-required: conditional
                  x-onerway-condition:
                    - "`profitType` 为 `return` 时必填。"
                profitParentReference:
                  type: string
                  description: 被回退的原分账请求号。自动分账的请求号由 Onerway 生成。
                  x-onerway-required: conditional
                  x-onerway-condition:
                    - "`profitType` 为 `return` 时必填。"
                profitReference:
                  type: string
                  description: 本次分账或分账回退的商户侧请求号。
                  x-onerway-constraints:
                    - kind: rule
                      text: 该字段作为幂等键使用；分账与分账回退的请求号需全局唯一。
                profitType:
                  type: string
                  description: 要执行的操作类型；该值决定哪些关联单号字段必填。
                  enum:
                    - share
                    - return
                  x-enum-descriptions:
                    share: 对已完成的支付发起分账。
                    return: 对一笔已有分账发起回退。
                receivers:
                  type: string
                  description: 分账或分账回退的接收方列表；每条明细传入一个对象。
                  contentMediaType: application/json
                  contentSchema:
                    type: array
                    items:
                      type: object
                      properties:
                        profitDetailReference:
                          type: string
                          description: 商户侧分账或分账回退明细请求号；同一 `profitReference` 下需保持唯一。
                        profitDetailParentReference:
                          type: string
                          description: 被回退的原分账明细请求号。
                          x-onerway-required: conditional
                          x-onerway-condition:
                            - "`profitType` 为 `return` 时必填。"
                        profitDetailGatewayReference:
                          type: string
                          description: Onerway 返回的原分账明细单号。
                          x-onerway-required: conditional
                          x-onerway-condition:
                            - "`profitType` 为 `return` 时必填。"
                        type:
                          type: string
                          description: 该明细对应的资金用途；该字段不表示接收方账号类型。
                          enum:
                            - "1"
                            - "2"
                            - "3"
                            - "4"
                            - "5"
                            - "6"
                            - "7"
                            - "99"
                          x-enum-descriptions:
                            "1": 商户结算款：分给实际卖家、子商户或服务提供方的订单结算金额。
                            "2": 平台服务费：归属平台的佣金、技术服务费与软件服务费。
                            "3": 合作方佣金：支付给渠道、代理或分销合作方的佣金。
                            "4": 支付处理费：收单处理费、交易处理费与支付通道相关费用。
                            "5": 税费：VAT、GST 或其他需要单独归集的税项。
                            "6": 物流履约费：物流、配送、仓储与履约相关费用。
                            "7": 营销补贴：优惠、补贴、活动成本或由某一方承担的营销费用。
                            "99": 其他：由 Onerway 与商户约定的其他分账用途。
                        account:
                          type: string
                          description: 分账接收方商户号；回退分账时填写原分账明细对应的接收方商户号。
                        amount:
                          type: string
                          description: 该明细的分账或分账回退金额。
                          x-onerway-constraints:
                            - kind: rule
                              text: 金额使用 decimal string；商户系统应避免用二进制浮点数直接计算金额。
                        description:
                          type: string
                          description: 商户自定义的明细描述，便于对账和问题排查。
                      required:
                        - profitDetailReference
                        - type
                        - account
                        - amount
                  x-onerway-format: json_string
                sign:
                  type: string
                  description: 请求签名字符串；生成方式详见[请求签名](/zh/payments/get-started/request-signing)。
                urlCallback:
                  type: string
                  description: 接收本次 API 分账或分账回退结果通知的地址。原支付已配置
                    `paymentMethodOptions.share.profitShareNotifyUrl` 时，无需再传本字段。
                  x-onerway-required: conditional
                  x-onerway-condition:
                    - 原支付未配置 `paymentMethodOptions.share.profitShareNotifyUrl`
                      时必填。
              required:
                - currency
                - merchantNo
                - profitReference
                - profitType
                - receivers
                - sign
            examples:
              create-profit-share:
                summary: 发起分账
                value:
                  currency: USD
                  gatewayReference: replace_with_transaction_id
                  merchantNo: replace_with_merchant_no
                  profitCompleted: false
                  profitReference: example_profit_share_reference
                  profitType: share
                  receivers: '[{"profitDetailReference":"example_profit_share_detail_reference","type":"1","account":"replace_with_receiver_merchant_no","amount":"80.00","description":"Seller
                    settlement"}]'
                  sign: replace_with_calculated_signature
                  urlCallback: https://developers.onerway.com/example-profit-callback
              reverse-profit-share:
                summary: 发起分账回退
                value:
                  currency: USD
                  merchantNo: replace_with_merchant_no
                  profitGatewayReference: replace_with_original_profit_gateway_reference
                  profitParentReference: replace_with_original_profit_reference
                  profitReference: example_profit_reversal_reference
                  profitType: return
                  receivers: '[{"profitDetailReference":"example_profit_reversal_detail_reference","profitDetailParentReference":"replace_with_original_profit_detail_reference","profitDetailGatewayReference":"replace_with_original_profit_detail_gateway_reference","type":"1","account":"replace_with_receiver_merchant_no","amount":"80.00","description":"Reverse
                    seller settlement"}]'
                  sign: replace_with_calculated_signature
                  urlCallback: https://developers.onerway.com/example-profit-callback
      responses:
        "200":
          description: 分账已受理
          content:
            application/json:
              schema:
                type: object
                properties:
                  respCode:
                    type: string
                    description: 响应码；`20000`
                      表示请求受理成功，最终结果以异步通知或[查询分账结果](/zh/payments/api-reference/endpoints/query-profit-share)为准；其余为错误码。完整码表见[响应码](/zh/payments/api-reference/response-codes)。
                  respMsg:
                    type: string
                    description: 响应码对应的可读说明。
                  data:
                    type: object
                    properties:
                      profitType:
                        type: string
                        description: 本次执行的操作类型。
                        enum:
                          - share
                          - return
                        x-enum-descriptions:
                          share: 对已完成的支付发起分账。
                          return: 对一笔已有分账发起回退。
                      profitReference:
                        type: string
                        description: 请求中提交的商户侧请求号。
                      profitGatewayReference:
                        type: string
                        description: Onerway 为本次分账或分账回退生成的单号；请保存此单号，用于后续查询和分账回退。
                      state:
                        type: string
                        description: 分账单整体处理状态。`completed` 不代表每条明细都成功，需逐条检查 `receivers[].result`。
                        enum:
                          - processing
                          - completed
                        x-enum-descriptions:
                          processing: 分账单处理中。
                          completed: 分账单处理结束；单条明细结果需逐条检查。
                      currency:
                        type: string
                        description: 分账或分账回退结算币种。
                      receivers:
                        type: string
                        description: 各接收方的处理结果列表。
                        contentMediaType: application/json
                        contentSchema:
                          type: array
                          items:
                            type: object
                            properties:
                              profitDetailReference:
                                type: string
                                description: 商户侧提交的明细请求号。
                              profitDetailGatewayReference:
                                type: string
                                description: Onerway 返回的明细单号。
                              type:
                                type:
                                  - string
                                  - "null"
                                description: 该明细对应的资金用途。
                                enum:
                                  - "1"
                                  - "2"
                                  - "3"
                                  - "4"
                                  - "5"
                                  - "6"
                                  - "7"
                                  - "99"
                                  - null
                                x-enum-descriptions:
                                  "1": 商户结算款：分给实际卖家、子商户或服务提供方的订单结算金额。
                                  "2": 平台服务费：归属平台的佣金、技术服务费与软件服务费。
                                  "3": 合作方佣金：支付给渠道、代理或分销合作方的佣金。
                                  "4": 支付处理费：收单处理费、交易处理费与支付通道相关费用。
                                  "5": 税费：VAT、GST 或其他需要单独归集的税项。
                                  "6": 物流履约费：物流、配送、仓储与履约相关费用。
                                  "7": 营销补贴：优惠、补贴、活动成本或由某一方承担的营销费用。
                                  "99": 其他：由 Onerway 与商户约定的其他分账用途。
                                x-onerway-value:
                                  nullable: true
                                  when:
                                    en: Returns `null` when the fund purpose is not recorded.
                                    zh: 未记录资金用途时返回 `null`。
                              amount:
                                type: string
                                description: 实际分账或分账回退金额。
                                x-onerway-constraints:
                                  - kind: rule
                                    text: 金额使用 decimal string；商户系统应避免用二进制浮点数直接计算金额。
                              result:
                                type: string
                                description: 该明细的处理结果。
                                enum:
                                  - pending
                                  - success
                                  - failed
                                x-enum-descriptions:
                                  pending: 该明细处理中。
                                  success: 该明细处理成功。
                                  failed: 该明细处理失败；失败原因见 `failReason`。
                              failReason:
                                type:
                                  - string
                                  - "null"
                                description: 该明细的失败原因。
                                x-onerway-constraints:
                                  - kind: rule
                                    text: 面向排查的可读文本，取值不固定；程序分支应依据 `result`，不要匹配该字符串。
                                x-onerway-value:
                                  nullable: true
                                  when:
                                    en: Returned only when `result` is `failed`; otherwise `null`.
                                    zh: 仅当 `result` 为 `failed` 时返回；其余情况为 `null`。
                              createdAt:
                                type: string
                                description: 明细创建时间。
                                x-onerway-constraints:
                                  - kind: rule
                                    text: 格式为 `yyyy-MM-dd HH:mm:ss`；不要按 Unix 时间戳解析。
                              finishedAt:
                                type:
                                  - string
                                  - "null"
                                description: 明细完成时间。
                                x-onerway-constraints:
                                  - kind: rule
                                    text: 格式为 `yyyy-MM-dd HH:mm:ss`；不要按 Unix 时间戳解析。
                                x-onerway-value:
                                  nullable: true
                                  when:
                                    en: Returns `null` while `result` is `pending`.
                                    zh: "`result` 为 `pending` 时返回 `null`。"
                        x-onerway-format: json_string
                      sign:
                        type: string
                        description: 响应签名字符串；Onerway 不要求商户对同步响应验签。
                    description: 分账或分账回退结果。
              examples:
                create-profit-share:
                  summary: 分账已受理
                  value:
                    respCode: "20000"
                    respMsg: Success
                    data:
                      profitType: share
                      profitReference: example_profit_share_reference
                      profitGatewayReference: replace_with_profit_gateway_reference
                      state: processing
                      currency: USD
                      receivers: '[{"profitDetailReference":"example_profit_share_detail_reference","profitDetailGatewayReference":"replace_with_profit_detail_gateway_reference","type":"1","amount":"80.00","result":"pending","failReason":null,"createdAt":"2026-06-22
                        10:00:00","finishedAt":null}]'
                      sign: replace_with_sha256_signature
                reverse-profit-share:
                  summary: 分账回退已受理
                  value:
                    respCode: "20000"
                    respMsg: Success
                    data:
                      profitType: return
                      profitReference: example_profit_reversal_reference
                      profitGatewayReference: replace_with_profit_reversal_gateway_reference
                      state: completed
                      currency: USD
                      receivers: '[{"profitDetailReference":"example_profit_reversal_detail_reference","profitDetailGatewayReference":"replace_with_profit_reversal_detail_gateway_reference","type":"1","amount":"80.00","result":"success","failReason":null,"createdAt":"2026-06-22
                        11:00:00","finishedAt":"2026-06-22 11:00:08"}]'
                      sign: replace_with_sha256_signature
```
