Items in OpeanIAB

35 views
Skip to first unread message

Boris Minaev

unread,
Apr 19, 2013, 3:01:36 PM4/19/13
to opf_o...@googlegroups.com
I have a question about items in OpenIab. Item has different "id's" in different stores. So, we need to create a class OpenItem, which contains something like hashmap "store -> item_name_in_store" and whenever developer use OpenIabHelper he needs to use OpenItem instead of google_sku. 

And all functions in OpenIabHelper will use OpenItem instead of google_sku's. E. g.:   public void launchPurchaseFlow(Activity act, OpenItem sku, int requestCode, IabHelper.OnIabPurchaseFinishedListener listener) 
instead of
  public void launchPurchaseFlow(Activity act, String sku, int requestCode, IabHelper.OnIabPurchaseFinishedListener listener) So developer needs to create OpenItems each time he uses lunchPurchaseFlow function (or create all OpenItem objects in init part of program). 

Another solution of this problem, which I see, looks like this. When developer creates OpenIabHelper, he transmit all he knows about items (array of OpenItems) to OpenIabHelper class. And he can now use all functions like in IabHelper (by Google). He send google_sku and OpenIabHelper class if needed converts it to another store sku.

But I still don't understand how to handle such situation. There is an app, which sells books, and developer doesn't know all skus. He wants to get skus from our API. But we can't return OpenItem objects, because we know only right sku for store which is now main.

So question is "What is the best way to store and transmit items?"

--
Best regards, Boris Minaev

Ruslan Sayfutdinov

unread,
Apr 19, 2013, 5:39:07 PM4/19/13
to opf_o...@googlegroups.com
I think that creating abstraction for skus like OpenItem is much better.
If there isn't matching sku for current appstore in OpenItem launchPurchaseFlow and other functions which use sku must throw an exception. 
OpenItem is base class and it may be singleton to avoid creating redundant objects.
So developer call method
void add(Market market, string sku)
from static initialization block for example.

пятница, 19 апреля 2013 г., 23:01:36 UTC+4 пользователь Борис Минаев написал:

Vassili Philippov

unread,
Apr 20, 2013, 8:03:16 AM4/20/13
to Boris Minaev, opf_o...@googlegroups.com

OpenItem is a right approach. The only my concern is that it could make library usage more difficult (you will need to write more code).

There are few options:

1. Use JSON string instead of OpenItem. Something like

String sku = "{\"google\" : \"xxx\", \"amazon\" : \"yyy\"};

public void launchPurchaseFlow(Activity act, String sku, int requestCode, IabHelper.OnIabPurchaseFinishedListener listener);

But I am concern about readability of this syntax. Too many \ symbols. We can ignore official JSON specification and allow single quotes, it will make syntax more readable:

 

String sku = "{'google' : 'xxx', 'amazon' : 'yyy'};

 

2. Use OpenItem class but make a constructor that takes JSON string like

 

OpenItem sku = new OpenItem("{'google' : 'xxx', 'amazon' : 'yyy'});

 

I would vote for #1 but both ways are OK.

Best regards,
Vassili

Reply all
Reply to author
Forward
0 new messages