Jump to content

In App Purchase - Mission accomplished !


valueerror
 Share

Recommended Posts

I still didn't find any tutorial out there on how to properly implement  in app purchases (in my case with android && crosswalk) so this is some sort of tutorial for in app purchases

(but it isn't finished yet - that's why i need your help  ;) )

 

  • i'm using this plugin http://plugins.cordo...ordova.purchase (it seems to be the right choice for this since it's the most used plugin in the database)
  • i added the permissions "com.android.vending.BILLING" to my project settings (this is needed for the google developer console to recognize the apk as "billing enabled" and allow adding an "in-app product")
  • added the plugin "cc.fovea.cordova.purchase" to my game using intel xdk crosswalk > 3rd party plugins > get plugin from the web (plugin is located in the apache cordova plugin registry)  

          ATTENTION:  this doesn't work due to a bug in the current version  3.10.1 where $BILLING_KEY is not properly set

          you have to download the plugin from the git repo : https://github.com/j3k0/cordova-plugin-purchase   and install it manually (see next step - adding local plugin over the UI will not work!)

  • i created a file called "intelxdk.config.additions.xml" in the same directory as the other xdk files (this file will be included in the actual build files - it's a way to include additional parameters for plugins like "billing_key)
  • i added the following xml code to the xml file:   (MIIB... is the Licence Key!  you'll find it in the developer console under Services & APIs) 

<intelxdk:plugin intelxdk:name="cc.fovea.cordova.purchase" intelxdk:value="cc.fovea.cordova.purchase" intelxdk:type="local">

    <intelxdk:param intelxdk:name="BILLING_KEY" intelxdk:value="MIIB........DAQAB" />
</intelxdk:plugin>

 

  • now you need to edit one file in the plugin to make up for the BUG !  edit the file plugin.xml   and find the section that says <string name="billing_key_param"> and add your Licence Key instead of the variable $BILLING_KEY so it looks like this:

<config-file target="res/values/billing_key_param.xml" parent="/*">

            <string name="billing_key_param">MIIBIj..................DAQAB</string>
 </config-file>
  • i was then able to build the project and upload the apk with the right permissions and the plugin (and the additional parameter) as "alpha" release to the playstore and also add my first "in-app product"  (id:  "noads") https://play.google.com/apps/publish/
  • i defined a price and activated it..  
  • i published my app as alpha release !!!
  • i added the example code from the github plugin website to my code so the "device ready" signal should do some sort of "appstore" setup
document.addEventListener('deviceready', initializeStore, false);
         function initializeStore() {                // Let's set a pretty high verbosity level, so that we see a lot of stuff                // in the console (reassuring us that something is happening).                store.verbosity = store.WARNING;                // We register a dummy product. It's ok, it shouldn't                // prevent the store "ready" event from firing.  "noads"  is the current id                 store.register({                    id:    "noads",                    alias: "no ads",                    type:  store.NON_CONSUMABLE                });                // When everything goes as expected, it's time to celebrate!                store.ready(function() {                    console.log("STORE READY");                });                                // When purchase is approved show some logs and finish the transaction.                store.when("noads").approved(function(order) {                    console.log("PURCHASE APPROVED");                    order.finish();                });                               store.when("noads").owned(function() {                   console.log("PRODUCT PURCHASED");                   alert('You purchased the ad-free version! Please restart the application to finish.');                   disableADS(); // custom function triggered              });                                // After we've done our setup, we tell the store to do                // it's first refresh. Nothing will happen if we do not call store.refresh()                store.refresh();            }
 
  • it seems that i need to setup a testing google account because i'm not allowed to use my google dev account for testpurchases ?! so i added another account as "Gmail accounts with testing access" in the settings section of the developer console AND i had to create a google group and invite those testers AND add the group as allowed apha testers in the apk section !!  (make sure the app version code is the same otherwise the purchase will not work !)
  • i now have my button in place that should trigger the purchase by calling the following function:
function buyADS(){   store.order('noads');}
  • i installed an apk file i built in intel xdk (not the one i uploaded to the store because i made some changes to the store script) with a user thats in the "alpha test group" (developer is not allowed to purchase) !!
  • then i started the game and clicked on my "buy-button" 
  • it actually loads the store inside my app and let me complete a test-purchase (add creditcardnumber and so on...)

 

Yeeehaaa !!   :ph34r:

Link to comment
Share on other sites

So there are a few questions left.

 

  1. for now i store the succesfull purchase in the local storage so the next time the app is loaded it first checks the local storage and disables the ads.   seems a little bit unprofessional to me.. how would you do it ??
  2. i want to provide additional assets like skins or levels via inapp purchases..  how do i upload them to the store (i don't see any option for that)  and how do i make sure those assets are then downloaded and stored into the right folder or that current local assets are replaced by the new ones?

 

:huh:  :huh:

 

hopefully there is someone in this forum with a little bit more insight..   thx in advance !!

Link to comment
Share on other sites

so it looks like i'm going to stick with the method i used for #1  i thought about always checking the store for the purchased item to prevent tempering with the local storage to circumvent the purchase but i guess that's not really necessary..

 

as for the 2nd problem..   i guess i will include those assets (extra levels, skins, etc) in the original package and de/activate them with another variable stored in the local storage.. so i'm basically doing it exactly like #1

i was hoping to find a way to NOT have to include everything to keep the filesize small but i didn't find anything on how to do this..  it seems like i have to create a second app that shares the same developer key because if it does those two apps can share resources .. and then find a way to access those resources from the original app ..  but this is a bit complicated for me to find out by trial and error and i still couldn't find any tutorials on this...

Link to comment
Share on other sites

  • 2 weeks later...

Do I need to wrap my app in cordova/crosswalk to test? 

I would hate to make small changes and keep wrapping my app and reinstalling it just to test

Anyway to use intel xdm live preview to test? also can I test ads without wrapping? 

Link to comment
Share on other sites

you definitely can not use the internal emulator and as far as i know ads are not working in the app preview either..

i think i read something about this and they said it will definitely come but is not finished yet.. therefore you need to build and install your app everytime you want to test something related to thirdparty plugins 

Link to comment
Share on other sites

  • 1 month later...

Hi, I'm using the same plugin to build my app with phonegap, but I have problem to retrieve product from the store.

I have followed your guide step by step but its doesn't work and I don't understand why.

Have I to build or compile the project? because if I build it, the project is reseated

 

thanks

Link to comment
Share on other sites

Hi,

 

thanks for your tutorial. But unfortunatly It's does't work for me..

 

So I'm pretty sure I followed correctly your tutorial (after reading over and over).

This is what i did :

 

1. Downloaded the plugin https://github.com/j3k0/cordova-plugin-purchase

2. Put in the my www xdk app folder

3. Add it as a third party plugin from local folder

 

Capture1.jpg

 

4. Add permissions : com.android.vending.BILLING

Capture2.jpg

5. Add/modify intelxdk.config.additions.xml

Capture3.jpg

6. Modify plugin.xml in the plugin folder (in my www app) to add my billing key..

 

But this is what happen :

Capture46080f.jpg

 

 

Don't really know what I did wrong or what's happening..

Thanks in advance, any help or advice is welcome.

 

 

ps: I use the Intel XDK 1826

ps2: I would like to thanks you again for taking time to write your tutoriel!

Link to comment
Share on other sites

well.. you obviously missed that part of the tutorial ;-)

 

 ATTENTION:  this doesn't work due to a bug in the current version  3.10.1 where $BILLING_KEY is not properly set

 you have to download the plugin from the git repo : https://github.com/j...plugin-purchase   and install it manually (see next step - adding local plugin over the UI will not work!)

 

 

that means..  do not add it as 3rd party plugin.. it will not complile..  

so instead of step 3 - you do 4 and 5  -- the lines you added to config.additions are enough :)

Link to comment
Share on other sites

Omg, I lost my after noon for that...and I had the solution under my eyes..

 

you should add a line-through "i added the plugin "cc.fovea.cordova.purchase" to my game using intel xdk crosswalk > 3rd party plugins > get plugin from the web (plugin is located in the apache cordova plugin registry) ".

:D

 

Thanks!

Link to comment
Share on other sites

Still have a problem with the permission.

How do you add "com.android.vending.BILLIN" ?

When I add it like this :

Capture2.jpg

 

I have this :

  • Added permission "android.permission.com.android.vending.BILLING"

When I add Billing I got "android.permission.BILLING". <_<

Trying to add it by intelxdk.config.additions.xml but still not successful.

Link to comment
Share on other sites

thx for the suggestion..  i edited the line :)

 

android.permission.com.android.vending.BILLING

 

looks quite right to me.. is there a problem with it.. does it work??

i think i read the same thing somewhere..

 

 

what if you add  android.permission.com.android.vending.BILLING instead of com.android.vending.BILLING

is it rewritten to android.permission.android.permission.com.android.vending.BILLING then ??

 

this is how it looks like on my screen..  

post-6912-0-04479200-1429003167.png

Link to comment
Share on other sites

Can't test android.permission.com.android.vending.BILLING right now but I think it will rewrite it like you said.

 

 

In my developer console I have the BILLING permissions ;

 

Capture2.jpg

 

But I can't add in-app product..

 

Capture.jpg

 

So I don"t think I have the good permissions.

Link to comment
Share on other sites

currently using 1878  (i'm always using the newest one i can get .. i don't think this is related to the version i am using because it worked with every version in the last months)

 

i definetly only added "com.android.vending.BILLING"  in intel xdk gui..

 

in the automatically created intelxdk.config.crosswalk.xml it says :

<preference name="android-permission" value="com.android.vending.BILLING"/>

 

what happens when i build for crosswalk and upload the apk to the playstore is unclear..  i don't know why there is 

  • android.permission.com.android.vending.BILLING

AND

  • com.android.vending.BILLING

and if its even needed to add an inapp product :(

Link to comment
Share on other sites

Yeah I edited the plugin.xml to add the key like you said :

<config-file target="res/values/billing_key_param.xml" parent="/*">

            <string name="billing_key_param">MIIBIj..................DAQAB</string>
 </config-file>
 
Do you put the plugin in the www folder ? And what's the plugin folder name ?  "cc.fovea.cordova.purchase" ?
Link to comment
Share on other sites

  • 3 months later...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...