Andrew avatar image
Andrew asked

Unity - Need to listen/respond to all IAP 2.0 events?

I create a GameObject (AmazonIAPManager) that initializes IAB and is not destroyed on scene load. On Start I call void Start () { DontDestroyOnLoad(this); // Obtain object used to interact with plugin IAmazonIapV2 iapService = AmazonIapV2Impl.Instance; iapService.AddPurchaseResponseListener(EventHandler); } When I want to purchase, I do this: IAmazonIapV2 iapService = AmazonIapV2Impl.Instance; // Construct object passed to operation as input SkuInput request = new SkuInput(); // Set input value switch (hintType) { case 0: request.Sku = AmazonIAPManager.BUY_HINT; break; case 1: request.Sku = AmazonIAPManager.BUY_HINT1; break; case 2: request.Sku = AmazonIAPManager.BUY_HINT2; break; case 3: request.Sku = AmazonIAPManager.BUY_HINT3; break; case 4: request.Sku = AmazonIAPManager.BUY_HINT4; break; } // Call synchronous operation with input object RequestOutput response = iapService.Purchase(request); // Get return value string requestIdString = response.RequestId; Debug.Log("request ID string: " + requestIdString); AmazonIAPManager.BUY_HINT3 are constants defined in AmazonIAPManager. All purchases are consumables. Is this correct? I am unclear what to do (if anything) with AmazonUserData. I also do not know if it is required to respond to other event listeners as described here ( iapService.AddGetUserDataResponseListener(GetUserDataResponseHandler); iapService.AddGetProductDataResponseListener(ProductDataResponseHandler); iapService.AddGetPurchaseUpdatesResponseListener(PurchaseUpdatesResponseHandler); An example project would be extremely helpful if anyone can point us in the right direction.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

justin avatar image
justin answered
Hi Andrew, It looks like you're instantiating a new instance of your iapService each time you are trying to perform a purchase. The AmazonIapV2Impl.Instance should only be called once and treated as a singleton, or the callbacks may not fire on the right instance.
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.