- Home /
How to set codeless IAPButton OnPurchaseComplete callback through code
I have all of my in-app purchases working fine using codeless IAP through the inspector. Now I've decided to set the purchase callbacks manually for OnPurchaseComplete and OnPurchaseFailed through code instead of through the inspector and I receive a compile error.
Error: error CS0428: Cannot convert method group 'OnPurchaseComplete_ListenerUnlockChat' to non-delegate type `UnityEngine.Purchasing.IAPButton.OnPurchaseCompletedEvent'. Consider using parentheses to invoke the method
Here is my function definition (works through inspector):
public void OnPurchaseComplete_ListenerUnlockChat(UnityEngine.Purchasing.Product product)
{
if(product.definition.id == "unlock_chat")
{
... code
}
}
The variable:
public IAPButton button_IAPUnlockChat;
And here is how I am trying to set it (error is on this line):
button_IAPUnlockChat.onPurchaseComplete = globalManager.purchaserManager.OnPurchaseComplete_ListenerUnlockChat;
Any help would be appreciated!
Answer by breban1 · May 20, 2019 at 08:26 PM
I figured out that I needed to call AddListener instead of setting the event like I was. Here is the code I used to fix it.
button_IAPUnlockChat.onPurchaseComplete.AddListener(globalManager.purchaserManager.OnPurchaseComplete_ListenerUnlockChat);
Your answer
Follow this Question
Related Questions
Bizarre Missing Assembly 'Common' Error 0 Answers
Unity IAP using unity servers? 0 Answers
IAPUnity - Processing Purchases Crash! 0 Answers
In App plugins free 1 Answer
InApp Purchases for Android AND iOs 0 Answers