- Home /
Prime31 Android in app billing fires purchaseSucceededEvent when I canceled the purchase from Google Checkout
Hi there, maybe the title itself is self explanatory. I'll just explained it even further.
I am currently modifying and testing IABTestScene from Prime31's Android in app billing package. This is my modifications:
In the IABUIManager
public class IABUIManager : MonoBehaviour
{
static bool[] testProducts = new bool[5]; //5 test products
static public List<string> lastEventList = new List<string>(); //Last event fired from the IAB
void OnGUI()
{
....
if( GUI.Button( new Rect( xPos, yPos, width, height ), "Purchase Real Product" ) )
{
IABAndroid.purchaseProduct( "test.product1", "1" ); // Dev payload = the index of the product in the product list
}
....
float widthTxt = Screen.width - 100.0f;
float heightTxt = 20.0f;
xPos = (Screen.width / 2) - (widthTxt / 2) - 5.0f;
yPos = lastYPos;
string lastEventTxt = "";
int lastEventTextFieldHeightMod = 0;
//Events text field
foreach (string str in lastEventList)
{
lastEventTxt += "Event: " + str + "\r\n";
lastEventTextFieldHeightMod++;
}
GUI.TextField(new Rect( xPos, yPos += heightPlus, widthTxt, 1+( heightTxt * lastEventTextFieldHeightMod) ), lastEventTxt);
}
...
}
In the IABAndroidEventListener
public class IABAndroidEventListener : MonoBehaviour
{
...
void billingSupportedEvent( bool isSupported )
{
string lastEventStr = "billingSupportedEvent: " + isSupported;
Debug.Log( "billingSupportedEvent: " + isSupported );
IABUIManager.lastEventList.Add(lastEventStr);
if (isSupported)
IABUIManager.isSupported = true;
}
void purchaseSignatureVerifiedEvent( Hashtable payload )
{
var signedData = payload["signedData"].ToString();
var signature = payload["signature"].ToString();
Debug.Log( "purchaseSignatureVerifiedEvent. signedData: " + signedData + ", signature: " + signature );
string lastEventStr = "purchaseSignatureVerifiedEvent. signedData: " + signedData + ", signature: " + signature ;
IABUIManager.lastEventList.Add(lastEventStr);
}
void purchaseSucceededEvent( string productId, string developerPayload )
{
Debug.Log( "purchaseSucceededEvent: " + productId + ", payload: " + developerPayload );
string lastEventStr = "purchaseSucceededEvent: " + productId + ", payload: " + developerPayload;
IABUIManager.lastEventList.Add(lastEventStr);
IABUIManager.testProducts[int.Parse(developerPayload)] = true;
}
void purchaseCancelledEvent( string productId, string developerPayload )
{
Debug.Log( "purchaseCancelledEvent: " + productId + ", payload: " + developerPayload );
string lastEventStr = "purchaseCancelledEvent: " + productId + ", payload: " + developerPayload;
IABUIManager.lastEventList.Add(lastEventStr);
IABUIManager.testProducts[int.Parse(developerPayload)] = false;
}
void confirmationFailedEvent( string productId, string developerPayload )
{
Debug.Log( "confirmationFailedEvent: " + productId + ", payload: " + developerPayload );
string lastEventStr = "confirmationFailedEvent: " + productId + ", payload: " + developerPayload;
IABUIManager.lastEventList.Add(lastEventStr);
IABUIManager.testProducts[int.Parse(developerPayload)] = false;
}
void purchaseRefundedEvent( string productId, string developerPayload )
{
Debug.Log( "purchaseRefundedEvent: " + productId + ", payload: " + developerPayload );
string lastEventStr = "purchaseRefundedEvent: " + productId + ", payload: " + developerPayload;
IABUIManager.lastEventList.Add(lastEventStr);
IABUIManager.testProducts[int.Parse(developerPayload)] = false;
}
void purchaseFailedEvent( string productId, string developerPayload )
{
Debug.Log( "purchaseFailedEvent: " + productId + ", payload: " + developerPayload );
string lastEventStr = "purchaseFailedEvent: " + productId + ", payload: " + developerPayload;
IABUIManager.lastEventList.Add(lastEventStr);
IABUIManager.testProducts[int.Parse(developerPayload)] = false;
}
void transactionsRestoredEvent()
{
string lastEventStr = "transactionsRestoredEvent";
Debug.Log( "transactionsRestoredEvent" );
IABUIManager.lastEventList.Add(lastEventStr);
}
void transactionRestoreFailedEvent( string error )
{
string lastEventStr = "transactionRestoreFailedEvent: " + error;
Debug.Log( "transactionRestoreFailedEvent: " + error );
IABUIManager.lastEventList.Add(lastEventStr);
}
...
}
Now this is what I did:
Clicked the "Initialize IAB" button.
Waited a while and then clicked the "Purchase Real Product" button.
Finished all the needed purchase confirmation
Waited a while and then the purchaseSucceededEvent was fired and the events text field showed the log from purchaseSucceededEvent delegate.
Went to the Publisher's Google Checkout and clicked the cancel entire order.
Waited a while and saw that the events text field showed that the purchaseSucceededEvent was fired again. Just like what happened when I clicked the "Purchase Real Product" button.
So is this how things normally behave with in app billing? This is my first time trying to integrate the in app billing in general (and Prime's In App Billing in particular). So CMIIW but shouldn't the event purchaseCancelledEvent fired instead of purchaseSucceededEvent? If it is a normal thing, how do I know whether a purchase is canceled, failed or refunded?
Thanks in advance.