本指南将向您介绍如何从 Adjust 收入验证 SDK 迁移至 SDK v5 的内置收入验证功能。SDK v5 收入验证流程是一种更简化的收入验证方法。
使用收入验证 SDK 时,验证分为三个步骤:
-
初始化收入验证 SDK。
var adjustPVConfig = new ADJPConfig(adjustAppToken,ADJPEnvironment.Production);adjustPVConfig.SetLogLevel(ADJPLogLevel.Info);new GameObject("AdjustPurchase").AddComponent<adjustpurchase>();AdjustPurchase.Init(adjustPVConfig); -
验证您的购买。
// purchase verification request on iOSAdjustPurchase.VerifyPurchaseiOS("{Receipt}", "{TransactionID}", "{ProductId}", VerificationInfoDelegate);// purchase verification request on AndroidAdjustPurchase.VerifyPurchaseAndroid("{ItemSKU}", "{ItemToken}", "{DeveloperPayload}", VerificationInfoDelegate);// ...private void VerificationInfoDelegate(ADJPVerificationInfo verificationInfo){Debug.Log("Verification info callback!");Debug.Log("Message: " + verificationInfo.Message);Debug.Log("Status code: " + verificationInfo.StatusCode);Debug.Log("Verification state: " + verificationInfo.VerificationState);} -
根据验证结果配置
AdjustEvent
对象并将其发送至 Adjust。AdjustEvent adjustEvent = new AdjustEvent("abc123");adjustEvent.setRevenue(6.0, "EUR");adjustEvent.setProductId("product-id");adjustEvent.setTransactionId("transaction-id");adjustEvent.setPurchaseToken("purchase-token"); // Android onlyadjustEvent.setReceipt("receipt"); // iOS onlyAdjust.trackEvent(adjustEvent);
在 SDK v5 中,此工作流程得到了简化。Adjust.verifyAndTrackAppStorePurchase()
和Adjust.verifyAndTrackPlayStorePurchase()
方法允许您向 Adjust 服务器发送事件并以回传的形式接收验证状态。Adjust 会自动记录事件和验证状态。
指南
按照本指南中的步骤从收入验证 SDK 迁移至 SDK v5 内置收入验证功能。
1. 卸载收入验证 SDK
要开始迁移,请卸载 Adjust 收入验证 SDK 。
2. 移除收入验证 SDK 代码
卸载 Adjust 收入验证 SDK 后,您必须从项目中移除所有收入验证代码。
3. 迁移至 SDK v5 收入验证功能
移除现有收入验证代码后,您就转而使用 SDK v5 的内置收入验证方法了。通过 Adjust SDK 验证购买的方法有两种:
- 创建代表购买的
AdjustEvent
对象并为目标商店配置购买属性。 - 创建代表购买的
AdjustAppStorePurchase
(Apple App Store) 或AdjustPlayStorePurchase
(Google Play 商店) 对象。
记录事件并验证购买
如需发送收入事件进行验证并监听收入验证状态,请按照下列步骤操作:
-
使用您的事件识别码实例化
AdjustEvent
对象并设置以下参数:ProductId
(string
):已被成功售出货品的产品识别码。TransactionId
(string
):要验证的交易 ID。
-
请使用下列参数调用
Adjust.VerifyAndTrackPlayStorePurchase
方法:event
(AdjustEvent
): 您的实例化事件对象。callback
(Action
):接收AdjustPurchaseVerificationResult
对象作为参数的委托回传函数。
在此示例中,收入验证响应被输出至日志后台进程。
AdjustEvent adjustEvent = new AdjustEvent("abc123");adjustEvent.SetRevenue(6.66, "CAD");adjustEvent.TransactionId = "transaction-id";adjustEvent.ProductId = "product-id";Adjust.VerifyAndTrackPlayStorePurchase(adjustEvent, verificationResult =>{ Debug.Log("Verification status: " + verificationResult.VerificationStatus); Debug.Log("Code: " + verificationResult.Code); Debug.Log("Message: " + verificationResult.Message);});
如需发送收入事件进行验证并监听收入验证状态,请按照下列步骤操作:
-
使用您的事件识别码实例化
AdjustEvent
对象并设置以下参数:ProductId
(String
):已购买产品的 ID。PurchaseToken
(String
): 与购买关联的购买识别码。
-
请使用下列参数调用
Adjust.VerifyAndTrackPlayStorePurchase
方法:ajustEvent
(AdjustEvent
): 您的实例化事件对象。callback
(Action
):接收AdjustPurchaseVerificationResult
对象作为参数的委托回传函数。
在此示例中,收入验证响应被输出至日志后台进程。
AdjustEvent adjustEvent = new AdjustEvent("abc123");adjustEvent.SetRevenue(6.66, "CAD");adjustEvent.ProductId = "product-id";adjustEvent.PurchaseToken = "purchase-token";Adjust.VerifyAndTrackPlayStorePurchase(adjustEvent, verificationResult =>{ Debug.Log("Verification status: " + verificationResult.VerificationStatus); Debug.Log("Code: " + verificationResult.Code); Debug.Log("Message: " + verificationResult.Message);});
仅验证购买
如需发送独立的 App Store 购买并监听收入验证状态,请按照下列步骤操作:
-
使用以下参数实例化
AdjustAppStorePurchase
对象:ProductId
(string
):已被成功售出货品的产品识别码。TransactionId
(string
):要验证的交易 ID。
-
请使用下列参数调用
Adjust.VerifyAppStorePurchase
方法:purchase
(AdjustAppStorePurchase
): 您的实例化事件对象。callback
(Action
):接收AdjustPurchaseVerificationResult
对象作为参数的委托回传函数。
在此示例中,收入验证响应被输出至日志后台进程。
AdjustAppStorePurchase purchase = new AdjustAppStorePurchase("product-id", "transaction-id");Adjust.VerifyAppStorePurchase(purchase, verificationResult =>{ Debug.Log("Verification status: " + verificationResult.VerificationStatus); Debug.Log("Code: " + verificationResult.Code); Debug.Log("Message: " + verificationResult.Message);});
如需发送独立的 Play 商店购买并监听收入验证状态,请按照下列步骤操作:
-
使用以下参数实例化
AdjustPlayStorePurchase
:ProductId
(string
):已购买产品的 ID。PurchaseToken
(string
): 与购买关联的购买识别码。
-
请使用下列参数调用
Adjust.VerifyPlayStorePurchase
方法:purchase
(AdjustPlayStorePurchase
): 实例化的购买对象。verificationResultCallback
(Action
):接收AdjustPurchaseVerificationResult
对象作为参数的委托回传函数。
在此示例中,收入验证响应被输出至日志后台进程。
AdjustPlayStorePurchase purchase = new AdjustPlayStorePurchase("product-id", "purchase-token");Adjust.VerifyPlayStorePurchase(purchase, verificationResult =>{ Debug.Log("Verification status: " + verificationResult.VerificationStatus); Debug.Log("Code: " + verificationResult.Code); Debug.Log("Message: " + verificationResult.Message);});