Search Unity

Question IAP Script work only with google play but not IAP

Discussion in 'Unity Distribution Portal (UDP)' started by Karrix, Nov 25, 2020.

  1. Karrix

    Karrix

    Joined:
    Feb 10, 2019
    Posts:
    10
    Hello, I took a script from internet for IAP, it work well with Google Play but not in UDP.

    Code
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using System;
    4. using UnityEngine;
    5. using UnityEngine.Purchasing;
    6.  
    7. public class IAPManager : MonoBehaviour, IStoreListener
    8. {
    9.    // --------------- HIDED CODE --------------------
    10.  
    11.     public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    12.     {
    13.         float price = (float)args.purchasedProduct.metadata.localizedPrice;
    14.         string currency = args.purchasedProduct.metadata.isoCurrencyCode;
    15.         string purchaseId = args.purchasedProduct.definition.id;
    16.  
    17.         if (String.Equals(purchaseId, removeAds, StringComparison.Ordinal))
    18.             BuyRemoveAds(price, currency, purchaseId);
    19.         else if (String.Equals(purchaseId, freeRewardAds, StringComparison.Ordinal))
    20.             BuyFreeRewardAds(price, currency, purchaseId);
    21.         else if (String.Equals(purchaseId, koin10k, StringComparison.Ordinal))
    22.             BuyKoin10k(price, currency, purchaseId);
    23.         else if (String.Equals(purchaseId, koin50k, StringComparison.Ordinal))
    24.             BuyKoin50k(price, currency, purchaseId);
    25.         else if (String.Equals(purchaseId, koin200k, StringComparison.Ordinal))
    26.             BuyKoin200k(price, currency, purchaseId);
    27.         else
    28.             Debug.Log("Purchase Failed");
    29.         return PurchaseProcessingResult.Complete;
    30.     }
    31.  
    32.      //**************************** Dont worry about these methods ***********************************
    33.     private void Awake()
    34.     {
    35.         TestSingleton();
    36.     }
    37.  
    38.     void Start()
    39.     {
    40.         fncDict = new Dictionary<string, Action<float, string, string>>(){
    41.             {"remove_ads", BuyRemoveAds},
    42.             {"free_reward_ads", BuyFreeRewardAds},
    43.             {"koin_10k", BuyKoin10k},
    44.             {"koin_50k", BuyKoin50k},
    45.             {"koin_200k", BuyKoin200k}
    46.         };
    47.         if (m_StoreController == null) { InitializePurchasing(); }
    48.     }
    49.  
    50.     private void TestSingleton()
    51.     {
    52.         if (instance != null) { Destroy(gameObject); return; }
    53.         instance = this;
    54.         DontDestroyOnLoad(gameObject);
    55.     }
    56.  
    57.     void BuyProductID(string productId)
    58.     {
    59.         if (IsInitialized())
    60.         {
    61.             Product product = m_StoreController.products.WithID(productId);
    62.             if (product != null && product.availableToPurchase)
    63.             {
    64.                 Debug.Log(string.Format("Purchasing product asychronously: '{0}'", product.definition.id));
    65.                 m_StoreController.InitiatePurchase(product);
    66.             }
    67.             else
    68.             {
    69.                 Debug.Log("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase");
    70.             }
    71.         }
    72.         else
    73.         {
    74.             Debug.Log("BuyProductID FAIL. Not initialized.");
    75.         }
    76.     }
    77.  
    78.     public void RestorePurchases()
    79.     {
    80.         if (!IsInitialized())
    81.         {
    82.             Debug.Log("RestorePurchases FAIL. Not initialized.");
    83.             return;
    84.         }
    85.  
    86.         if (Application.platform == RuntimePlatform.IPhonePlayer ||
    87.             Application.platform == RuntimePlatform.OSXPlayer)
    88.         {
    89.             Debug.Log("RestorePurchases started ...");
    90.  
    91.             var apple = m_StoreExtensionProvider.GetExtension<IAppleExtensions>();
    92.             apple.RestoreTransactions((result) => {
    93.                 Debug.Log("RestorePurchases continuing: " + result + ". If no further messages, no purchases available to restore.");
    94.             });
    95.         }
    96.         else
    97.         {
    98.             Debug.Log("RestorePurchases FAIL. Not supported on this platform. Current = " + Application.platform);
    99.         }
    100.     }
    101.  
    102.     public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    103.     {
    104.         Debug.Log("OnInitialized: PASS");
    105.         m_StoreController = controller;
    106.         m_StoreExtensionProvider = extensions;
    107.     }
    108.  
    109.  
    110.     public void OnInitializeFailed(InitializationFailureReason error)
    111.     {
    112.         Debug.Log("OnInitializeFailed InitializationFailureReason:" + error);
    113.     }
    114.  
    115.     public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
    116.     {
    117.         Debug.Log(string.Format("OnPurchaseFailed: FAIL. Product: '{0}', PurchaseFailureReason: {1}", product.definition.storeSpecificId, failureReason));
    118.     }
    119. }
    Error from android:
    11-25 17:44:37.448 32636 32636 I Unity : Purchased Finished. ResultCode: -300, message: The given parameter is missing or invalid: invalid price:1,99 with currency:USD at iap:HIDE, purchaseInfoString: {"developerPayload":"","gameOrderId":"HIDE","itemType":"inapp","orderQueryToken":"HIDE","productId":"remove_ads","store":"UDP","storePurchaseJsonString":"{\"cpOrderId\":\"HIDE\",\"developerPayload\":\"\",\"productId\":\"remove_ads\",\"totalAmount\":0}"}
    11-25 17:44:37.448 32636 32636 I Unity : UnityEngine.UDP.PurchaseForwardCallback:eek:nPurchaseFinished(Int32, String, String)
    11-25 17:44:37.448 32636 32636 I Unity : System.Reflection.MonoMethod:Invoke(Object, BindingFlags, Binder, Object[], CultureInfo)
    11-25 17:44:37.448 32636 32636 I Unity : UnityEngine.AndroidJavaProxy:Invoke(String, Object[])
    11-25 17:44:37.448 32636 32636 I Unity : UnityEngine._AndroidJNIHelper:InvokeJavaProxyMethod(AndroidJavaProxy, IntPtr, IntPtr)
    11-25 17:44:37.448 32636 32636 I Unity :
    11-25 17:44:37.453 32636 32677 I Unity : onPurchaseFailedEvent({0}): productId:remove_ads message:{"error":"The given parameter is missing or invalid: invalid price:1,99 with currency:USD at iap:HIDE","purchaseInfo":{"ItemType":"inapp","ProductId":"remove_ads","GameOrderId":"HIDE","OrderQueryToken":"HIDE","StorePurchaseJsonString":"{\"cpOrderId\":\"HIDE\",\"developerPayload\":\"\",\"productId\":\"remove_ads\",\"totalAmount\":0}"}}
    11-25 17:44:37.453 32636 32677 I Unity : UnityEngine.Purchasing.PurchasingManager:OnPurchaseFailed(PurchaseFailureDescription)
    11-25 17:44:37.453 32636 32677 I Unity : UnityEngine.Purchasing.<>c__DisplayClass8_0:<Purchase>b__0(Boolean, String)
    11-25 17:44:37.453 32636 32677 I Unity : System.Action`2:Invoke(T1, T2)
    11-25 17:44:37.453 32636 32677 I Unity : UnityEngine.UDP.UdpIapBridge:OnPurchaseFailed(String, PurchaseInfo)
    11-25 17:44:37.453 32636 32677 I Unity : System.Action:Invoke()
    11-25 17:44:37.453 32636 32677 I Unity : UnityEngine.UDP.MainThreadDispatcher:Update()
    11-25 17:44:37.453 32636 32677 I Unity :
    11-25 17:44:37.453 32636 32677 I Unity : (
    11-25 17:44:37.455 32636 32677 I Unity : OnPurchaseFailed: FAIL. Product: 'remove_ads', PurchaseFailureReason: Unknown11-25 17:44:37.455 32636 32677 I Unity : IAPManager:OnPurchaseFailed(Product, PurchaseFailureReason)
    11-25 17:44:37.455 32636 32677 I Unity : UnityEngine.Purchasing.<>c__DisplayClass8_0:<Purchase>b__0(Boolean, String)
    11-25 17:44:37.455 32636 32677 I Unity : System.Action`2:Invoke(T1, T2)
    11-25 17:44:37.455 32636 32677 I Unity : UnityEngine.UDP.UdpIapBridge:OnPurchaseFailed(String, PurchaseInfo)
    11-25 17:44:37.455 32636 32677 I Unity : System.Action:Invoke()
    11-25 17:44:37.455 32636 32677 I Unity : UnityEngine.UDP.MainThreadDispatcher:Update()
    11-25 17:44:37.455 32636 32677 I Unity :
    11-25 17:44:37.455 32636 32677 I Unity : (Filename: ./Runtime/Export/Debug/Debug.bindings.h Line: 35)
     
    vuthanhcong1102 likes this.