Sign In Register

How can we help you today?

Start a new topic
Answered

BuyVirtualGoodResponse Errors

Hi,


I've just upgraded to the latest ActionScript SDK, and I've had to rework all our code (we were using a year old version).


I'm currently unable to work out how to retrieve errors on BuyVirtualGoodResponse.


Here is the code:


public function handleInAppPurchaseResponse(response:BuyVirtualGoodResponse ):void

{

      if (response.HasErrors)

      {

               var errors:Object = response.getScriptData();

      }

}


In this case, errors = null. I've looked at the contents of response, and it does contain the error information I need, but I'm not sure how to get it.


Thanks,

Graeme.


Best Answer

Thanks, I have it working with getAttribute method.


I was using the latest SDK from the page which does not have the getErrors method. I downloaded the SWC from Bitbucket, however it does not appear to be in a working state, as I received lots of what looked like socket errors. I have gone back to the older SWC and it's working fine now.


Thanks,

Graeme.


Hi Graeme,

The errors in the response are in JSON format. You need to parse the error from the response as a string.  In C# for instance I would do the following: Debug.Log("error buying virtual good"+ response.Errors.JSON.ToString());

This gets the error JSON  from the response and parses it as a string into my console in Unity. 

Does this help point you in the right direction? Do you think you can apply this in terms of ActionScript? 

If not I'm happy to help you further. 

Regards Patrick. 

Hi Graeme


In the ActionScript sdk, you should use the getErrors() method instead of the getScriptData() method


public function handleInAppPurchaseResponse(response:BuyVirtualGoodResponse ):void

{

      if (response.HasErrors)

      {

               var errors:Object = response.getErrors();

      }

}


Hope that help !


Gabriel

Hi,


Beware that 'HasErrors' is NOT defined as a getter (as is the practice in ActionScript for 'get' methods), thus you need to use the parentheses to get the return value. If you do not type the parentheses then the if statement will always be evaluated as true. I know that for example IntelliJ IDEA does not add the parentheses when I use a code hint and confirm my selection with ENTER or TAB key so you need to be extra cautious here.


To access the error in the response, I use the following code:

if( response.HasErrors() ) {
	var error:Object = response.getAttribute( "error" );
	// further query the error object
}

The error object is already parsed JSON - its properties match the properties you see in TestHarness.


Marcel 


Hi Gabriel,


The response does not have getErrors() method, really the only way I found to get the error data is using the approach I mentioned above.


Marcel

Oh, I see there is the getErrors() method now (I was using a slightly outdated SDK) - just a note that the precompiled SWC linked on this page is not necessarily the latest one - it has to be taken from the Bitbucket repository.


Marcel

Answer

Thanks, I have it working with getAttribute method.


I was using the latest SDK from the page which does not have the getErrors method. I downloaded the SWC from Bitbucket, however it does not appear to be in a working state, as I received lots of what looked like socket errors. I have gone back to the older SWC and it's working fine now.


Thanks,

Graeme.

Login to post a comment