Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Shmulzious · Feb 10, 2019 at 01:45 PM · iosiap

Recipets not created on iOS before restoring purchases

Hello,

I am using the latest IAP package for 2017.2.1p4 (1.20.1). To make I am not doing something incorrectly, I used the IAP Demo scene, and only changed the products that are added. This is the scenario -

  1. Purchase a non-consumable product on the app, and completely close it. (just closing, nothing more)

  2. Run app again, initialising Unity IAP.

  3. Look for the receipt of the product you've previously purchased.

Expected : receipt member of Product should not be null or empty Actual : it is. Only after successfully restoring purchases the receipt is populated.

This happens only with non-consumables. With subscription I do get the receipt right after OnInitialised.

This issue is relevant to me only on iOS (on Android it automatically calls restore purchases so no problems there), also should be mentioned I am working in a sandbox environment (i.e. testing iap environment).

I need this receipt before RestorePurchase because I need to detect refunds and potentially re-add monetisation.

Thanks, Shmulik.

The code I'm using -

 #if UNITY_PURCHASING
 using UnityEngine.Events;
 using UnityEngine.UI;
 using System.IO;
 using System.Collections.Generic;
 
 namespace UnityEngine.Purchasing
 {
     [RequireComponent(typeof(Button))]
     [AddComponentMenu("Unity IAP/IAP Button")]
     [HelpURL("https://docs.unity3d.com/Manual/UnityIAP.html")]
     public class IAPButton : MonoBehaviour
     {
         public enum ButtonType
         {
             Purchase,
             Restore
         }
 
         [System.Serializable]
         public class OnPurchaseCompletedEvent : UnityEvent<Product>
         {
         };
 
         [System.Serializable]
         public class OnPurchaseFailedEvent : UnityEvent<Product, PurchaseFailureReason>
         {
         };
 
         [HideInInspector]
         public string productId;
 
         [Tooltip("The type of this button, can be either a purchase or a restore button")]
         public ButtonType buttonType = ButtonType.Purchase;
 
         [Tooltip("Consume the product immediately after a successful purchase")]
         public bool consumePurchase = true;
 
         [Tooltip("Event fired after a successful purchase of this product")]
         public OnPurchaseCompletedEvent onPurchaseComplete;
 
         [Tooltip("Event fired after a failed purchase of this product")]
         public OnPurchaseFailedEvent onPurchaseFailed;
 
         [Tooltip("[Optional] Displays the localized title from the app store")]
         public Text titleText;
 
         [Tooltip("[Optional] Displays the localized description from the app store")]
         public Text descriptionText;
 
         [Tooltip("[Optional] Displays the localized price from the app store")]
         public Text priceText;
 
         void Start()
         {
             Button button = GetComponent<Button>();
 
             if (buttonType == ButtonType.Purchase)
             {
                 if (button)
                 {
                     button.onClick.AddListener(PurchaseProduct);
                 }
 
                 if (string.IsNullOrEmpty(productId))
                 {
                     Debug.LogError("IAPButton productId is empty");
                 }
 
                 if (!CodelessIAPStoreListener.Instance.HasProductInCatalog(productId))
                 {
                     Debug.LogWarning("The product catalog has no product with the ID \"" + productId + "\"");
                 }
             }
             else if (buttonType == ButtonType.Restore)
             {
                 if (button)
                 {
                     button.onClick.AddListener(Restore);
                 }
             }
         }
 
         void OnEnable()
         {
             if (buttonType == ButtonType.Purchase)
             {
                 CodelessIAPStoreListener.Instance.AddButton(this);
                 if (CodelessIAPStoreListener.initializationComplete) {
                     UpdateText();
                 }
             }
         }
 
         void OnDisable()
         {
             if (buttonType == ButtonType.Purchase)
             {
                 CodelessIAPStoreListener.Instance.RemoveButton(this);
             }
         }
 
         void PurchaseProduct()
         {
             if (buttonType == ButtonType.Purchase)
             {
                 Debug.Log("IAPButton.PurchaseProduct() with product ID: " + productId);
 
                 CodelessIAPStoreListener.Instance.InitiatePurchase(productId);
             }
         }
 
         void Restore()
         {
             if (buttonType == ButtonType.Restore)
             {
                 if (Application.platform == RuntimePlatform.WSAPlayerX86 ||
                     Application.platform == RuntimePlatform.WSAPlayerX64 ||
                     Application.platform == RuntimePlatform.WSAPlayerARM)
                 {
                     CodelessIAPStoreListener.Instance.ExtensionProvider.GetExtension<IMicrosoftExtensions>()
                         .RestoreTransactions();
                 }
                 else if (Application.platform == RuntimePlatform.IPhonePlayer ||
                          Application.platform == RuntimePlatform.OSXPlayer ||
                          Application.platform == RuntimePlatform.tvOS)
                 {
                     CodelessIAPStoreListener.Instance.ExtensionProvider.GetExtension<IAppleExtensions>()
                         .RestoreTransactions(OnTransactionsRestored);
                 }
                 else if (Application.platform == RuntimePlatform.Android &&
                          StandardPurchasingModule.Instance().appStore == AppStore.SamsungApps)
                 {
                     CodelessIAPStoreListener.Instance.ExtensionProvider.GetExtension<ISamsungAppsExtensions>()
                         .RestoreTransactions(OnTransactionsRestored);
                 }
                 else if (Application.platform == RuntimePlatform.Android &&
                          StandardPurchasingModule.Instance().appStore == AppStore.CloudMoolah)
                 {
                     CodelessIAPStoreListener.Instance.ExtensionProvider.GetExtension<IMoolahExtension>()
                         .RestoreTransactionID((restoreTransactionIDState) =>
                         {
                             OnTransactionsRestored(
                                 restoreTransactionIDState != RestoreTransactionIDState.RestoreFailed &&
                                 restoreTransactionIDState != RestoreTransactionIDState.NotKnown);
                         });
                 }
                 else
                 {
                     Debug.LogWarning(Application.platform.ToString() +
                                      " is not a supported platform for the Codeless IAP restore button");
                 }
             }
         }
 
         void OnTransactionsRestored(bool success)
         {
             Debug.Log("Transactions restored: " + success);
         }
 
         /**
          *  Invoked to process a purchase of the product associated with this button
          */
         public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)
         {
             Debug.Log(string.Format("IAPButton.ProcessPurchase(PurchaseEventArgs {0} - {1})", e,
                 e.purchasedProduct.definition.id));
 
             onPurchaseComplete.Invoke(e.purchasedProduct);
 
             return (consumePurchase) ? PurchaseProcessingResult.Complete : PurchaseProcessingResult.Pending;
         }
 
         /**
          *  Invoked on a failed purchase of the product associated with this button
          */
         public void OnPurchaseFailed(Product product, PurchaseFailureReason reason)
         {
             Debug.Log(string.Format("IAPButton.OnPurchaseFailed(Product {0}, PurchaseFailureReason {1})", product,
                 reason));
 
             onPurchaseFailed.Invoke(product, reason);
         }
 
         internal void UpdateText()
         {
             var product = CodelessIAPStoreListener.Instance.GetProduct(productId);
             if (product != null)
             {
                 if (titleText != null)
                 {
                     titleText.text = product.metadata.localizedTitle;
                 }
 
                 if (descriptionText != null)
                 {
                     descriptionText.text = product.metadata.localizedDescription;
                 }
 
                 if (priceText != null)
                 {
                     priceText.text = product.metadata.localizedPriceString;
                 }
             }
         }
     }
 }
 #endif
 

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

132 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Restore IAP in IOS unity 5.3 1 Answer

Does receipt verification require an internet connection? 0 Answers

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Hi I get a crash using iAP in iOS8 0 Answers

Update/Refresh screen before IAP InitiatePurchase 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges