Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[Solved] IAP for windows phone 8.1

Discussion in 'Unity IAP' started by euro008, Sep 28, 2017.

Thread Status:
Not open for further replies.
  1. euro008

    euro008

    Joined:
    Sep 28, 2017
    Posts:
    6
    I've added IAP in my application, but it doesn't work correctly. Simulating of purchaising in the Unity is pass. After publishing application in the Microsoft Store I can buy the add-on. But after application reinstall\update add-on lost. And I have to purchase add-on again. How correctly create purchase validateion.

    And question else. Money was not charged from the card after purchasing add-on. since the purchase it has been several days.

    Somebody came across similar problems?

    check:

    Code (CSharp):
    1.     public void button_left()
    2.     {
    3.         for (int j = 0; j <= array.Length - 1; j++)
    4.         {
    5.             array[j].SetActive(false);
    6.         }
    7.         i--; if (i <= 0) i = 0;
    8.         newcamposition = new Vector3(ps[i].transform.position.x, ps[i].transform.position.y, ps[i].transform.position.z - dist_p[i]);
    9.         sh_name[i].SetActive(true);
    10.         sh_number = i;
    11.  
    12.         if (Purchaser.CheckBuyState("buy_ms_id")) { hawk.SetActive(true);  }
    13.        
    14.     }

    purcaser:

    Code (CSharp):
    1. using System;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Purchasing;
    5.  
    6.  
    7.     // Deriving the Purchaser class from IStoreListener enables it to receive messages from Unity Purchasing.
    8.     public class Purchaser : MonoBehaviour, IStoreListener
    9.     {
    10.         private static IStoreController m_StoreController;          // The Unity Purchasing system.
    11.         private static IExtensionProvider m_StoreExtensionProvider; // The store-specific Purchasing subsystems.
    12.  
    13.         public static string kProductIDNonConsumable = "buy_ms_id";
    14.  
    15.         void Start()
    16.         {
    17.             // If we haven't set up the Unity Purchasing reference
    18.             if (m_StoreController == null)
    19.             {
    20.                 // Begin to configure our connection to Purchasing
    21.                 InitializePurchasing();
    22.             }
    23.         }
    24.  
    25.     public static bool CheckBuyState(string id)
    26.     {
    27.         Product product = m_StoreController.products.WithID(id);
    28.         if (product.hasReceipt) { return true; }
    29.         else { return false; }
    30.     }
    31.  
    32.     public void InitializePurchasing()
    33.         {
    34.             // If we have already connected to Purchasing ...
    35.             if (IsInitialized())
    36.             {
    37.                 // ... we are done here.
    38.                 return;
    39.             }
    40.  
    41.             // Create a builder, first passing in a suite of Unity provided stores.
    42.             var builder = ConfigurationBuilder.Instance(StandardPurchasingModule.Instance());
    43.  
    44.  
    45.             // Continue adding the non-consumable product.
    46.             builder.AddProduct(kProductIDNonConsumable, ProductType.NonConsumable);
    47.  
    48.             // Kick off the remainder of the set-up with an asynchrounous call, passing the configuration
    49.             // and this class' instance. Expect a response either in OnInitialized or OnInitializeFailed.
    50.             UnityPurchasing.Initialize(this, builder);
    51.         }
    52.  
    53.         private bool IsInitialized()
    54.         {
    55.             // Only say we are initialized if both the Purchasing references are set.
    56.             return m_StoreController != null && m_StoreExtensionProvider != null;
    57.         }
    58.  
    59.         public void BuyNonConsumable()
    60.         {
    61.             // Buy the non-consumable product using its general identifier. Expect a response either
    62.             // through ProcessPurchase or OnPurchaseFailed asynchronously.
    63.             BuyProductID(kProductIDNonConsumable);
    64.         }
    65.  
    66.         void BuyProductID(string productId)
    67.         {
    68.             // If Purchasing has been initialized ...
    69.             if (IsInitialized())
    70.             {
    71.                 // ... look up the Product reference with the general product identifier and the Purchasing
    72.                 // system's products collection.
    73.                 Product product = m_StoreController.products.WithID(productId);
    74.  
    75.                 // If the look up found a product for this device's store and that product is ready to be sold ...
    76.                 if (product != null && product.availableToPurchase)
    77.                 {
    78.                     Debug.Log(string.Format("Purchasing product asychronously: '{0}'", product.definition.id));
    79.                     // ... buy the product. Expect a response either through ProcessPurchase or OnPurchaseFailed
    80.                     // asynchronously.
    81.                     m_StoreController.InitiatePurchase(product);
    82.                 }
    83.                 // Otherwise ...
    84.                 else
    85.                 {
    86.                     // ... report the product look-up failure situation
    87.                     Debug.Log("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase");
    88.                 }
    89.             }
    90.             // Otherwise ...
    91.             else
    92.             {
    93.                 // ... report the fact Purchasing has not succeeded initializing yet. Consider waiting longer or
    94.                 // retrying initiailization.
    95.                 Debug.Log("BuyProductID FAIL. Not initialized.");
    96.             }
    97.         }
    98.  
    99.         // Restore purchases previously made by this customer. Some platforms automatically restore purchases, like Google.
    100.         // Apple currently requires explicit purchase restoration for IAP, conditionally displaying a password prompt.
    101.         public void RestorePurchases()
    102.         {
    103.             // If Purchasing has not yet been set up ...
    104.             if (!IsInitialized())
    105.             {
    106.                 // ... report the situation and stop restoring. Consider either waiting longer, or retrying initialization.
    107.                 Debug.Log("RestorePurchases FAIL. Not initialized.");
    108.                 return;
    109.             }
    110.  
    111.             // If we are running on an Apple device ...
    112.             if (Application.platform == RuntimePlatform.IPhonePlayer ||
    113.                 Application.platform == RuntimePlatform.OSXPlayer)
    114.             {
    115.                 // ... begin restoring purchases
    116.                 Debug.Log("RestorePurchases started ...");
    117.  
    118.                 // Fetch the Apple store-specific subsystem.
    119.                 var apple = m_StoreExtensionProvider.GetExtension<IAppleExtensions>();
    120.                 // Begin the asynchronous process of restoring purchases. Expect a confirmation response in
    121.                 // the Action<bool> below, and ProcessPurchase if there are previously purchased products to restore.
    122.                 apple.RestoreTransactions((result) => {
    123.                     // The first phase of restoration. If no more responses are received on ProcessPurchase then
    124.                     // no purchases are available to be restored.
    125.                     Debug.Log("RestorePurchases continuing: " + result + ". If no further messages, no purchases available to restore.");
    126.                 });
    127.             }
    128.             // Otherwise ...
    129.             else
    130.             {
    131.                 // We are not running on an Apple device. No work is necessary to restore purchases.
    132.                 Debug.Log("RestorePurchases FAIL. Not supported on this platform. Current = " + Application.platform);
    133.             }
    134.         }
    135.  
    136.         //
    137.         // --- IStoreListener
    138.         //
    139.  
    140.         public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
    141.         {
    142.             // Purchasing has succeeded initializing. Collect our Purchasing references.
    143.             Debug.Log("OnInitialized: PASS");
    144.  
    145.             // Overall Purchasing system, configured with products for this application.
    146.             m_StoreController = controller;
    147.             // Store specific subsystem, for accessing device-specific store features.
    148.             m_StoreExtensionProvider = extensions;
    149.         }
    150.  
    151.         public void OnInitializeFailed(InitializationFailureReason error)
    152.         {
    153.             // Purchasing set-up has not succeeded. Check error for reason. Consider sharing this reason with the user.
    154.             Debug.Log("OnInitializeFailed InitializationFailureReason:" + error);
    155.         }
    156.  
    157.         public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs args)
    158.         {
    159.             if (String.Equals(args.purchasedProduct.definition.id, kProductIDNonConsumable, StringComparison.Ordinal))
    160.             {
    161.                 Debug.Log(string.Format("ProcessPurchase: PASS. Product: '{0}'", args.purchasedProduct.definition.id));
    162.    
    163.             GetComponent<check>().hawk.SetActive(true);
    164.             // TODO: The non-consumable item has been successfully purchased, grant this item to the player.
    165.         }
    166.          
    167.             // Or ... an unknown product has been purchased by this user. Fill in additional products here....
    168.             else
    169.             {
    170.                 Debug.Log(string.Format("ProcessPurchase: FAIL. Unrecognized product: '{0}'", args.purchasedProduct.definition.id));
    171.             }
    172.  
    173.             // Return a flag indicating whether this product has completely been received, or if the application needs
    174.             // to be reminded of this purchase at next app launch. Use PurchaseProcessingResult.Pending when still
    175.             // saving purchased products to the cloud, and when that save is delayed.
    176.             return PurchaseProcessingResult.Complete;
    177.         }
    178.  
    179.     public void OnPurchaseFailed(Product product, PurchaseFailureReason failureReason)
    180.         {
    181.             // A product purchase attempt did not succeed. Check failureReason for more detail. Consider sharing
    182.             // this reason with the user to guide their troubleshooting actions.
    183.             Debug.Log(string.Format("OnPurchaseFailed: FAIL. Product: '{0}', PurchaseFailureReason: {1}", product.definition.storeSpecificId, failureReason));
    184.         }
    185.     }
    186.  
     
  2. ap-unity

    ap-unity

    Unity Technologies

    Joined:
    Aug 3, 2016
    Posts:
    1,519
    @euro008

    Would you be able to provide the device log when you are making the purchase?

    Also, which version of Unity Editor and which version of IAP were you using?
     
  3. euro008

    euro008

    Joined:
    Sep 28, 2017
    Posts:
    6
    Unity 5.6.3 personal - because the version supports windows phone 8.1
    IAP 1.14 - After last updates I can't publish my application. It doesn't pass sertification in MS Store.
    Unfortunately I can't provide logs, because I do not know where they are.
    Does Unity IAP support windows phone 8.1?
    I checked it in windows 10 and problem doesn't persist. But I need implement IAP in Windows Phone 8.1.
     
  4. JeffDUnity3D

    JeffDUnity3D

    Unity Technologies

    Joined:
    May 2, 2017
    Posts:
    14,446
Thread Status:
Not open for further replies.