POST /api/v2/server-side-api/purchase/set/transaction/

设置交易

在 Adapty 中为您应用的最终用户创建新交易并提供访问等级。通过此方法创建的交易将出现在您的分析报告和事件动态中,并将发送至所有集成渠道。

更新现有订阅: 若要在不生成新的 subscription_renewed 事件的情况下更新 billing_issue_detected_atrenew_status_changed_at,请在相同的 store_original_transaction_id 下重用现有的 store_transaction_id。提交任何新的 store_transaction_id 将被视为新交易并触发 subscription_renewed 事件。

Header parameters

adapty-customer-user-idstring

您系统中客户的唯一 ID。adapty-customer-user-idadapty-profile-id 二者必填其一。

adapty-profile-idstring

您系统中用户画像的唯一 ID。如果您使用匿名用户画像,此为最佳选择。adapty-customer-user-idadapty-profile-id 二者必填其一。

Request body

Option 1 — object

一次性购买的交易数据

purchase_typestringrequired

购买类型

One of: "one_time_purchase"

storestringrequired

发生购买的商店。常见值包括 app_storeplay_storestripepaddle 或任意自定义商店标识符

environmentstring

发生购买的环境

One of: "Production", "Sandbox"

store_product_idstringrequired

商店中的产品 ID

store_transaction_idstringrequired

商店中的交易 ID。最多 50 个字符。PayPal 及某些自定义商店的交易 ID 可能超过此限制——请在提交前对值进行截断或哈希处理,否则请求将失败。

store_original_transaction_idstringrequired

商店中的原始交易 ID

is_family_sharedboolean

该购买是否为家庭共享

priceobjectrequired
countrystringrequired

ISO 3166-1 alpha-2 格式的国家代码,例如 US

currencystringrequired

ISO 4217 格式的货币代码,例如 USD

valuenumberrequired

价格值

purchased_atstringrequired

购买发生的时间

variation_idstring

用于 A/B 测试的实验变体 ID

offerobject
categorystringrequired

优惠类别

One of: "introductory", "promotional", "offer_code", "win_back"

typestringrequired

优惠类型

One of: "free_trial", "pay_as_you_go", "pay_up_front"

idstring

优惠 ID

refunded_atstring

退款发生的时间

cancellation_reasonstring

取消原因

One of: "billing_error", "cancelled_by_developer", "new_subscription_replace", "price_increase", "product_was_not_available", "refund", "unknown", "upgraded", "voluntarily_cancelled", "adapty_revoked"

Option 2 — object

订阅购买的交易数据

purchase_typestringrequired

购买类型

One of: "subscription"

storestringrequired

发生购买的商店。常见值包括 app_storeplay_storestripepaddle 或任意自定义商店标识符

environmentstring

发生购买的环境

One of: "Production", "Sandbox"

store_product_idstringrequired

商店中的产品 ID

store_transaction_idstringrequired

商店中的交易 ID。最多 50 个字符。PayPal 及部分自定义商店的交易 ID 可能超出此限制——提交前请对值进行截断或哈希处理,否则请求将失败。

store_original_transaction_idstringrequired

商店中的原始交易 ID

is_family_sharedboolean

该购买是否为家庭共享

priceobjectrequired
countrystringrequired

ISO 3166-1 alpha-2 格式的国家代码,例如 US

currencystringrequired

ISO 4217 格式的货币代码,例如 USD

valuenumberrequired

价格值

purchased_atstringrequired

购买发生的时间

variation_idstring

A/B 测试的实验变体 ID

offerobject
categorystringrequired

优惠类别

One of: "introductory", "promotional", "offer_code", "win_back"

typestringrequired

优惠类型

One of: "free_trial", "pay_as_you_go", "pay_up_front"

idstring

优惠 ID

refunded_atstring

购买退款的时间

cancellation_reasonstring

取消原因

One of: "billing_error", "cancelled_by_developer", "new_subscription_replace", "price_increase", "product_was_not_available", "refund", "unknown", "upgraded", "voluntarily_cancelled", "adapty_revoked"

originally_purchased_atstringrequired

订阅最初购买的时间

expires_atstringrequired

订阅到期的时间

renew_statusbooleanrequired

订阅是否将自动续期

renew_status_changed_atstring

续期状态变更的时间

billing_issue_detected_atstring

检测到账单问题的时间

grace_period_expires_atstring

宽限期到期的时间

Responses

交易记录成功

Schema
dataobjectrequired
app_idstringrequired

您的应用程序的内部 ID

profile_idstringrequired

Adapty 用户画像 ID

customer_user_idstringrequired

您的系统中该用户的 ID

total_revenue_usdnumberrequired

一个浮点数值,表示该用户画像所产生的以美元计算的总收入

segment_hashstringrequired

内部参数

timestampintegerrequired

响应时间(毫秒),用于解决竞态条件

custom_attributesarray of objectrequired

每个用户画像最多允许设置 30 个自定义属性

keystringrequired

键必须是不超过 30 个字符的字符串。只允许使用字母、数字、破折号、点和下划线

valuestring | numberrequired

属性值不得超过 50 个字符。值只允许使用字符串和浮点数

access_levelsarray of objectrequired

访问等级对象数组。如果用户没有任何访问等级,则为空数组

access_level_idstring

访问等级标识符

storestring

购买该访问等级的商店

store_product_idstring

商店中的产品 ID

store_base_plan_idstring

商店中的基础方案 ID

store_transaction_idstring

商店中的交易 ID

store_original_transaction_idstring

商店中的原始交易 ID

offerallOf

优惠详情(若应用了促销活动或新用户优惠)

categorystring

优惠类别

One of: "introductory", "promotional", "offer_code", "win_back"

typestring

优惠类型

One of: "free_trial", "pay_as_you_go", "pay_up_front"

idstring

优惠 ID

starts_atstring

访问等级的生效时间

purchased_atstring

访问等级的购买时间

originally_purchased_atstring

访问等级的最初购买时间

expires_atstring

访问等级的到期时间

renewal_cancelled_atstring

续订取消的时间

billing_issue_detected_atstring

检测到计费问题的时间

is_in_grace_periodboolean

该访问等级是否处于宽限期

cancellation_reasonstring

取消原因

subscriptionsarray of objectrequired

订阅对象数组。如果用户没有任何订阅,则为空数组

storestring

购买订阅的商店

store_product_idstring

商店中的产品 ID

store_base_plan_idstring

商店中的基础方案 ID

store_transaction_idstring

商店中的交易 ID

store_original_transaction_idstring

商店中的原始交易 ID

offerallOf

优惠详情(若已应用促销活动或新用户优惠)

categorystring

优惠类别

One of: "introductory", "promotional", "offer_code", "win_back"

typestring

优惠类型

One of: "free_trial", "pay_as_you_go", "pay_up_front"

idstring

优惠 ID

environmentstring

环境(沙盒、生产)

purchased_atstring

订阅的购买时间

originally_purchased_atstring

订阅的首次购买时间

expires_atstring

订阅的到期时间

renewal_cancelled_atstring

取消续订的时间

billing_issue_detected_atstring

检测到计费问题的时间

is_in_grace_periodboolean

订阅是否处于宽限期

cancellation_reasonstring

取消原因

non_subscriptionsarray of objectrequired

一次性购买对象数组。如果用户没有任何购买记录,则为空数组

purchase_idstring

唯一购买标识符

storestring

购买所在的商店

store_product_idstring

商店中的产品 ID

store_base_plan_idstring

商店中的基础方案 ID

store_transaction_idstring

商店中的交易 ID

store_original_transaction_idstring

商店中的原始交易 ID

purchased_atstring

购买时间

environmentstring

环境(沙盒、生产)

is_refundboolean

是否为退款

is_consumableboolean

是否为消耗型商品

请求无效

Schema
errorsarray of objectrequired
sourcestring

错误来源

errorsarray of string

错误消息数组

error_codestringrequired

简短错误名称

status_codeintegerrequired

HTTP 状态码

未授权

Schema
errorsarray of objectrequired
sourcestring

错误来源

errorsarray of string

错误消息数组

error_codestringrequired

简短错误名称

status_codeintegerrequired

HTTP 状态码

未找到用户画像

Schema
errorsarray of objectrequired
sourcestring

错误来源

errorsarray of string

错误消息数组

error_codestringrequired

简短错误名称

status_codeintegerrequired

HTTP 状态码

服务器内部错误