如何区分Unity购买和Restore购买?

问题描述 投票:0回答:1

我正在尝试实现统一 iap,我需要将 PaymentSucceed 事件发送到我的分析以便跟踪购买!

我在我的

中调用 PaymentSucceed 事件
 public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)

功能,但问题是,当用户重新安装应用程序时,在 Android 上再次调用 ProcessPurchase 事件来恢复购买,并发送事件进行我的分析,但这不是收入事件,因此将其计为付款是不正确的,您能否分享一些想法,我如何理解它是否以正确的方式恢复或实际付款?

这是我的 ProcessPurchase 脚本

public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    {
        // A consumable product has been purchased by this user.
     
        if (String.Equals(args.purchasedProduct.definition.id, kProductIDNoAds, StringComparison.Ordinal))
        {
            Debug.Log(string.Format("ProcessPurchase: PASS. Product: '{0}'", args.purchasedProduct.definition.id));
            PlayerPrefs.SetInt("noads",1);
            BannerAdManager.Instance.HideBanner();
            CheckNoAds();
           
        var prodID = args.purchasedProduct.definition.id;
        var price = ReplaceCommas(args.purchasedProduct.metadata.localizedPrice.ToString());
        var currency = args.purchasedProduct.metadata.isoCurrencyCode;
        var receipt = args.purchasedProduct.receipt;
   
        var param = new Dictionary<string, string>();
        param["af_quantity"] = "1";
        param["af_content_type"] = "general";
           
        var recptToJSON = (Dictionary<string, object>)AFMiniJSON.Json.Deserialize(receipt);
        var receiptPayload = (Dictionary<string, object>)AFMiniJSON.Json.Deserialize((string)recptToJSON["Payload"]);
           
        var purchaseData = (string)receiptPayload["json"];
        var signature = (string)receiptPayload["signature"];

        Debug.LogError("Purchase Event Sent Start");
       
        AppsFlyerAndroid appsFlyerAndroid = new AppsFlyerAndroid();
        appsFlyerAndroid.validateAndSendInAppPurchase(
            "111",
            signature,
            purchaseData,
            price,
            currency,
            param,
            this);
       
        Debug.LogError("Purchase Event Sent Finish");
 
       PaymentSucceed(args.purchasedProduct.definition.id,args.purchasedProduct.metadata.isoCurrencyCode,(float)args.purchasedProduct.metadata.localizedPrice,"noads");
 
        }
        // Or ... an unknown product has been purchased by this user. Fill in additional products here....
        else
        {
            Debug.Log(string.Format("ProcessPurchase: FAIL. Unrecognized product: '{0}'", args.purchasedProduct.definition.id));
        }

        // Return a flag indicating whether this product has completely been received, or if the application needs
        // to be reminded of this purchase at next app launch. Use PurchaseProcessingResult.Pending when still
        // saving purchased products to the cloud, and when that save is delayed.
        return PurchaseProcessingResult.Complete;
    }
unity-game-engine in-app-purchase appsflyer
1个回答
0
投票

这个问题的答案(我刚才正在寻找这个)位于 Product 类(来自文档):

有收据

自有非消耗品和订阅应始终有收据。消费品的收据在应用程序重新启动之间不会保留,除非它有待处理的事务。一旦消耗品被确认(ConfirmPendingPurchase),收据将被删除。

收据

该产品的购买收据(如果拥有)。对于消耗品购买,这将是最近的购买收据。除非有待处理的交易,否则在应用程序重新启动之间不会设置消费品的收据。一旦消耗品被确认(ConfirmPendingPurchase),收据就会被删除。收据为 JSON 格式。

如果您在恢复阶段收到带有收据的消耗品,则它是待处理产品。如果没有收据,只是恢复之前购买的。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.