[Solved] Unity's IAP code explained

Hello, I am porting my android game to iOS, all works but I have a little problem with IAPs (i am using official unitys IAP plugin)

When testing on my iPhone, iap works, but apples confirm purchase window appears little bit delayed after the click (like 1-2 seconds, unlike on android where it pop ups straight away) so sometimes user can click it multiple times which leads to opening confirm popup multiple times.

I check some other top apps on ios, and what they does is displaying some sort of popup like “waiting for transaction” before apples confirm transaction window appears, i want to to the same, just not sure if I understand unitys iap code properly,

i have added capital letters comment in the code below to show how i think i would do it, would be grateful if someone can look and confirm if it is correct:

void BuyProductID(string productId)
     {
         // If Purchasing has been initialized ...
         if (IsInitialized())
         {
           
             // -<<<<<<<<<< DISPLAY MY POPUP "WAITING FOR TRANSACTION" >>>>>>>>>>>>>>>>>>>>>
           
             // ... look up the Product reference with the general product identifier and the Purchasing
             // system's products collection.
             Product product = m_StoreController.products.WithID(productId);
             // If the look up found a product for this device's store and that product is ready to be sold ...
             if (product != null && product.availableToPurchase)
             {
                 Debug.Log(string.Format("Purchasing product asychronously: '{0}'", product.definition.id));
                 // ... buy the product. Expect a response either through ProcessPurchase or OnPurchaseFailed
                 // asynchronously.
                 m_StoreController.InitiatePurchase(product);
               
               
                 // CLOSE MY POPUP BECAUSE APPLES CONFIRM POPUP IS NOW VISIBLE!!
               
               
             }
             // Otherwise ...
             else
             {
                 // ... report the product look-up failure situation
                 Debug.Log("BuyProductID: FAIL. Not purchasing product, either is not found or is not available for purchase");
               
                 // CLOSE MY POPUP BECAUSE OF ERROR
             }
         }
         // Otherwise ...
         else
         {
             // ... report the fact Purchasing has not succeeded initializing yet. Consider waiting longer or
             // retrying initiailization.
             Debug.Log("BuyProductID FAIL. Not initialized.");
         }
     }

Also my last question would be, should i enable IN APP PURCHASE capability in XCODE capabilities?

Regards.

I don’t believe you need to enable IN APP PURCHASE in XCode. Your popup suggestion might work, but you would need an async co-routine.

i have imported IAP plugin… i dont kno how to add code to purchase accessories using real money and how can i confirm that real money is used for purchasing please help me to do

Once you publish your app, users will be prompted to purchase and will be charged real money. You can set up test users too, so real money is not charged. Have you set up your products on iTunes Connect yet? Unity - Manual: Configuring for Apple App Store and Mac App Store

3276079--253306--screenshot.PNG
am using for ANDROID google play i dont understand this part. i have to write this code??

Yes, but you can name the product whatever you want. It doesn’t have to contain the periods, and can be like “gold50” or “myproduct01” . Also, you don’t need to add the popup code in your original post.

ok thank you