question

StephenPS avatar image
StephenPS asked

Implementing PurchasingListener for Adobe Air

I am seeking to implement AmazonIapV2 IAPs for my project. I have made the changes to the manifest as set out in the documentation and added the ANE to the project fine. AmazonIapV2.isSupported() comes back as true. However the ANE does not appear to include the PurchasingListener referred to in the documentation so I can't register it as referred to in the documentation here https://developer.amazon.com/public/apis/earn/in-app-purchasing/docs-v2/implementing-iap. The methods are present but there does not seem to be the ability to register and create an instance.

Note that documentation appears to relate to a Java version rather than as3 but, apart from some syntax I was expecting it to be similar.

A worked example of how to implement IAPs in AS3 would be great.

Thanks

iappurchasingadobe air
10 |5000

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

WangChao@Amazon avatar image
WangChao@Amazon answered

Within the App Tester, from the main menu, please tap the 2. API Response Settings option to see if all of them are set to be default. And are you using the latest Amazon-AIR-SDK?

To make it easier for you to debug, I have uploaded my working sample here. After changing the SKUs in GetProductData(), you can try to run it on your side. If you still could not get it work, please share some screenshots of your app, your JSON file and Amazon App Tester so that we could take a closer look. Thanks.

sample.zip


sample.zip (8.2 KiB)
10 |5000

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

WangChao@Amazon avatar image
WangChao@Amazon answered

Hello,

Please check IAP Plugin Methods and Events for Adobe AIR and Knowledge base article In-App Purchasing v2 for Adobe Air.

10 |5000

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

StephenPS avatar image
StephenPS answered

Thanks for the response. I have been through both those reference documents in detail but still can’t get the event listeners to work. I am making the user and product data requests, and I am getting back the request IDs but the listeners are not being heard by the app (I have tried a trace at the start of each, which simply is not firing. Any further help you can give would be gratefully appreciated. I have copied below the manifest and relevant code extracts.

Thanks for the help.

The manifest first:

 <android>  <manifestAdditions><![CDATA[  <manifest
android:installLocation="auto">  <uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="19"/>  <uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>  <uses-permission
android:name="android.permission.INTERNET"/>  <uses-permission
android:name="com.android.vending.BILLING" />  <uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE" />  <application>  <activity
android:launchMode="standard">  <intent-filter>    <action
android:name="android.intent.action.MAIN"/>    <category
android:name="android.intent.category.LAUNCHER"/>  </intent-filter>  <intent-filter>  <action
android:name="android.intent.action.VIEW" />  <category
android:name="android.intent.category.DEFAULT" />  <category
android:name="android.intent.category.BROWSABLE" />  </intent-filter>  </activity><receiver
android:name="com.amazon.device.iap.ResponseReceiver">    <intent-filter>      <action
android:name="com.amazon.inapp.purchasing.NOTIFY"
android:permission="com.amazon.inapp.purchasing.Permission.NOTIFY">      </action></intent-filter>    </receiver>  <activity
android:name="com.applovin.adview.AppLovinInterstitialActivity" />  <activity
android:name="com.applovin.adview.AppLovinConfirmationActivity" />  <meta-data
android:name="com.facebook.sdk.ApplicationId" android:value="fbXXXXXXXXXXXXXXXX"/>  <meta-data
android:name="com.facebook.sdk.ApplicationName"
android:value="XXXXXXXXXX"/>  <meta-data
android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"
/>  <activity
android:name="com.facebook.FacebookActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:label="XXXXXXXX" />  <provider
android:authorities="com.facebook.app.FacebookContentProviderXXXXXXXXXXXXXX"
android:name="com.facebook.FacebookContentProvider"
android:exported="true" />  </application>  </manifest>  ]]></manifestAdditions>  </android>

I have then added the listeners and made the data requests as follows:

if(AmazonIapV2.isSupported()){AmazonIapV2.addEventListener(AmazonIapV2Event.GET_USER_DATA_RESPONSE,
getUserDataResponseEventHandler);AmazonIapV2.addEventListener(AmazonIapV2Event.GET_PRODUCT_DATA_RESPONSE,
getProductDataResponseEventHandler);var vProducts:SkusInput = new SkusInput();  var list:Vector.<String>
= new Vector.<String>();  list.push("XXXXXXXXXXXXXXXXX");  list.push("VVVVVVVVVVVVVVV");  list.push("YYYYYYYYYYYYYYYYY");  vProducts.skus = list;var requestOutput:RequestOutput =
AmazonIapV2.getUserData();  var requestId:String =
requestOutput.requestId;  var
requestOutputData:RequestOutput = AmazonIapV2.getProductData(vProducts);  var requestIdData:String =
requestOutputData.requestId;}

I can trace those variables and can confirm I do get the appropriate requestIDs. The response handlers are as follows:

public
static function getUserDataResponseEventHandler(event:AmazonIapV2Event):void
{
var response:GetUserDataResponse =
event.getUserDataResponse;
  var requestId:String =
response.requestId;
  var userId:String =
response.amazonUserData.userId;
  var marketplace:String =
response.amazonUserData.marketplace;
  var status:String =
response.status;
}
public
static function getProductDataResponseEventHandler(event:AmazonIapV2Event):void
{
  var
response:GetProductDataResponse = event.getProductDataResponse;
  var requestId:String =
response.requestId;
  var productDataMap:Object =
response.productDataMap;
  var unavailableSkus:Vector.<String>
= response.unavailableSkus;
  var status:String =
response.status;
}

Placing traces in those responses shows that the responses are not being fired.

10 |5000

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

WangChao@Amazon avatar image
WangChao@Amazon answered

Do you have Amazon App Tester installed on your testing device? Please check https://developer.amazon.com/public/apis/earn/in-app-purchasing/docs-v2/installing-and-configuring-app-tester.

10 |5000

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

StephenPS avatar image
StephenPS answered

Hi thanks for your reply.

I have installed the App Tester but not yet been able to add the JSON file to mnt/sdcard (no sd card installed - so I have ordered one - is there another way to add the JSON?).

That said I am not clear how this will help. The problem is not that I am getting back failed IAPs but that the listeners themselves don't seem to work at all. I should get a response even if it is that it failed to find the IAPs.

For me there seems like two likely culprits:

1. Most other ANEs I install (including Google Play and iOS IAPs) I have had to initialise the ANE in some way but that does not seem required or possible here. Have I missed this stage and if so where/ how do I initialise the ANE?

2. There is some error in my code, either in the manifest or the code itself (see code extracts in my earlier reply).

When I do get the sd card and can add the JSON what result/info are you looking to get?

Of course it could be something else so I remain open minded.

Thanks

Stephen

10 |5000

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

WangChao@Amazon avatar image
WangChao@Amazon answered

Hi Stephen,

Could you please elaborate "initialise the ANE"? You did include the ANE lib in your apk, right?

Your code seems OK to me. I am guessing that you are not getting the callbacks because App Tester are not firing any as it is not correctly configured. Could you please put the JSON file in the root directory of your device, then within the App Tester, from the main menu, please tap the IAP Items in JSON File option to see if you can get the human-readable list of the item data in your JSON file? Thanks.

10 |5000

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

StephenPS avatar image
StephenPS answered

Hi,

To clarify yes I have the ANE lib in my apk. By initialise the ANE most ANE's I have included in my project require some form of initialisation to create a singleton instance. This normally takes the form of something like calling a .create() method being called once before it can be used and often passing in an account key so that my app is identified. I know this is not always required but wanted to check if it was something missing. It appears not to be needed here.

I now have the app tester working and yes the IAP Items in JSON File returns a human readable list of the item data I was expecting and I do now get a successful response to the call. So far so good. Does that mean that the JSON file is standing in for the actual App Store? If so how can I check that the actual App Store will work when the game goes live? Or am I still not understanding correctly what the app tester does?

In any case although I now get a successful response and can trace out the request ID etc. the returned productDataMap object that is returned appears to be empty so I am unable to access the price, title etc. from within the app. What should I be expecting here?

Thanks.

10 |5000

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

WangChao@Amazon avatar image
WangChao@Amazon answered

Hi Stephen,

Glad to know to know that you get App Tester working now. If you want to check how the actual Amazon Appstore works, please use Live App Testing. Thanks.

For the getting empty productDataMap object issue, please double check if you are using the correct SKUs in your App. Could you please also check what is in response.unavailableSkus?

10 |5000

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

StephenPS avatar image
StephenPS answered

Hi,

Yes I had checked those skus carefully and have done so again and again - happy to share them if I can send them to you privately. The response.unavailableSkus also came back empty. I did deliberately try an incorrect sku at one point and that did not come up in unavailableSkus as I would have expected.

To me that suggests that the Skus.Input is not carrying in the list of Skus correctly but is sending in an empty request (or the unavailable list would include any errors right?). I have included again my code for this area below as it seems the right area to focus on.

Note, I do get back the requestIdData and response.status comes back as SUCCESSFULL

I do get back a GetProductDataResponse object.

and var productDataMap:Object = response.productDataMap gives me an Object but so far as I an tell that Object is empty.

Help please!

Code snippets:

AmazonIapV2.addEventListener(AmazonIapV2Event.GET_PRODUCT_DATA_RESPONSE, getProductDataResponseEventHandler); 
var vProducts:SkusInput = new SkusInput();
var list:Vector.<String> = new Vector.<String>(); 
list.push("xxxxxxxxxx"); 
list.push("yyyyyyyyyy"); 
list.push("zzzzzzzzzz"); 
vProducts.skus = list;
var requestOutputData:RequestOutput = AmazonIapV2.getProductData(vProducts);
var requestIdData:String = requestOutputData.requestId;

All of which seems to follow your example code exactly as far as I can tell.

10 |5000

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

StephenPS avatar image
StephenPS answered

Hi, so it seems that I had the GetProductData API set to SUCCESSFUL rather than default (I don't think it's anything I ever changed but that's where it was). Anyway changing that has given me the correct info that I was expecting to get back (price etc.). Thanks for helping me to get through that and I have downloaded your zip for future reference.

Best Regards

Stephen

1 comment
10 |5000

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

Glad to know you have figured this out. Enjoy:)

0 Likes 0 ·