Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Tobster_
Posts: 262
Registered: ‎07-20-2012
My Device: Blackberry Z10 (White), BlackBerry Dev Alpha C
My Carrier: O2 UK
Accepted Solution

In-app purchases to remove advertisements

Hello, 

 

I am currently looking into implementing the BlackBerry ad service into the next update of my Cascades application and I was wondering if it's possible to have an in-app purchase that allows the user to remove the ads say to download a separate bar file which wouldn't have the ads in - is this doable? 

 

Also, do you know how to implement the in-app purchase as a button in the application (top swipe-down) menu?

 

Thanks in advance :smileyhappy:

Please use plain text.
Developer
slashkyle
Posts: 820
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Telus

Re: In-app purchases to remove advertisements

[ Edited ]

This is possible, see my application Sideload Companion.

 

I didn't use blackberry ad service, I just created adds for my own apps but this is essentially the same as what you're looking to do

 

To remove the adds once the upgrade has been purchased just make a call to the payment service, get the reciept string and check to see if they purchased the content and then set a variable to reflect their purchase.  

 

Use QSettings to persist the 'paid' variable and always check for payments on application launch, it's also a good practice to have a restore purchases button.

 

You can find documentation on how to establish the payment service here

https://developer.blackberry.com/native/documentation/cascades/device_platform/paymentservice/index....

 

Sample freemium app

https://developer.blackberry.com/native/documentation/cascades/device_platform/paymentservice/explor...

 

If you follow through the documentation it will guide you through integrating the c++ payment manager and then exposing it to QML so you can use it there, then its as simple as calling the payment manger when you click the action item from the menu

Please use plain text.
Developer
Tobster_
Posts: 262
Registered: ‎07-20-2012
My Device: Blackberry Z10 (White), BlackBerry Dev Alpha C
My Carrier: O2 UK

Re: In-app purchases to remove advertisements

Thanks :smileyhappy:

 

I have everything sorted for the UI and I have played around with the Freemium sample app too. 

 

One question though, I'd like to be able to add a button in the application (swipe-down) menu to remove the ads. I already have the actionitem set up ready in application menu:

 

TabbedPane {
    Menu.definition: MenuDefinition {
        actions: [
            ActionItem {
                title: "About"
                imageSource: "asset:///IMG/ic_info.png"

                onTriggered: {
                    aboutSheet.open()
                }
            },
            ActionItem {
                title: "Contact Us"
                imageSource: "asset:///IMG/ic_email.png"

                onTriggered: {
                    emailInvocation.query.uri = "mailto:support@tundracorestudios.co.uk?subject=Contact"
                    emailInvocation.query.updateQuery();
                }

            },
            ActionItem {
              title: "Remove Ads"
              imageSource: "asset:///IMG/ic_clear_list.png"  
            },
            ActionItem {
                title: "Share App"
                imageSource: "asset:///IMG/ic_share.png"
                
                onTriggered: {
                    invokeShare.trigger("bb.action.SHARE")
                }
            },
            ActionItem {
                title: "More Apps"
                imageSource: "asset:///IMG/ic_buy.png"

                onTriggered: {
                    invokebb.trigger("bb.action.OPEN")
                }
            }
        ]

 What do I need to add to the ActionItem for the payment window to appear, without going to separate screen?

 

Thanks again

Please use plain text.
Developer
slashkyle
Posts: 820
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Telus

Re: In-app purchases to remove advertisements

in the onTriggered of your action item just make a call to the payment service with the info related to the feature you want to purchase.  The info can be found in the vendor portal where you setup the add-on.

 

onTriggered: {
     //Go Pro!
     paymentControl.pid = "PID" //Found in vendor Portal
     paymentControl.sku = "SKU" //Found in vendor Portal
     paymentControl.name = "Name of content" //Found in vendor Portal
     paymentControl.metadata = "MetaData" //Found in vendor Portal
     paymentControl.getPrice(paymentControl.pid, paymentControl.sku);
     paymentControl.purchase(paymentControl.pid, paymentControl.sku, paymentControl.name, paymentControl.metadata)
   }

 

Please use plain text.
Developer
Tobster_
Posts: 262
Registered: ‎07-20-2012
My Device: Blackberry Z10 (White), BlackBerry Dev Alpha C
My Carrier: O2 UK

Re: In-app purchases to remove advertisements

Thank you! I've got it working in test mode now.

 

Finally, I have gone into BlackBerry World Vendor Portal to add the digital good and I can add descriptions, SKU etc. but don't I need to actually upload a file or a new bar file so that when the user purchases the in-app consumable to remove the ads the adverts actually disappear? 

 

Thanks again

Please use plain text.
Developer
slashkyle
Posts: 820
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Telus

Re: In-app purchases to remove advertisements

[ Edited ]

they wont just disappear by clicking the button :smileywink:... you need to have code attached to the onpurchaseresponsesuccess signal, there you should save a variable to qsettings indicating that they paid to remove adds. then execute code based on that change to remove the adds.

 

Also be sure to check for existing payments and update the variable if they have paid so if they erase the app they don't have to re-buy (like on kiwi-wonder :smileysad:

Please use plain text.
Developer
Tobster_
Posts: 262
Registered: ‎07-20-2012
My Device: Blackberry Z10 (White), BlackBerry Dev Alpha C
My Carrier: O2 UK

Re: In-app purchases to remove advertisements

Haha - I knew it wasn't as simple as that :smileywink: - I was purely just trying to ask how easy it would be. 

 

So, what you're saying is I need to add some code to onpurchaseresponsesuccess (I'm guessing this should be placed in the main.qml file too?) and then add a variable in applicationui.cpp which will check to see if they have purchased the in-app purchase and if they have the ads will be removed?

 

Also, I know about Kiki-wonder :smileysad: - has it been fixed now?

Please use plain text.
Developer
slashkyle
Posts: 820
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Telus

Re: In-app purchases to remove advertisements

[ Edited ]

they claim it will be fixed in the next update whenever that is... but they also said that about the update before :smileysad: 

 

If you've never used QSettings before I made a sample on how to do this

https://github.com/slashkyle/Cascades-Samples/tree/master/RememberThis

 

once you have QSettings, it's as simple as

 

Container {
   id: root

property int removeAdds

onRemoveAddsChanged: {
   if (removeAdds == 100){
      //Hide advertisements
   }
}

attachedObjects: [
PaymentServiceControl {
id: paymentControl onPurchaseResponseSuccess: { cpp.saveValueFor("removeAdds","100"); root.removeAdds = 100; } } ] onCreationCompleted: { paymentControl.getExisting (true); root.removeAdds = parseInt(cpp.getValueFor("removeAdds","")); } }

 cpp. is a contextProperty

Please use plain text.
Developer
slashkyle
Posts: 820
Registered: ‎10-16-2012
My Device: Red Z10
My Carrier: Telus

Re: In-app purchases to remove advertisements

also just an FYI, test mode and production mode are 2 completely different things, just because test mode is working does not mean production mode is.  Before releasing this i strongly reccomend to upload it to BlackBerry world and  test it from your sandbox, ensure you can remove the adds and payment is coming back a success, if you don't have success in the sandbox neither will your customers when its released :smileywink:

 

Please use plain text.
Developer
Tobster_
Posts: 262
Registered: ‎07-20-2012
My Device: Blackberry Z10 (White), BlackBerry Dev Alpha C
My Carrier: O2 UK

Re: In-app purchases to remove advertisements

Ah right, so probably not coming any time soon then :smileywink:

 

Yeah, you're right - I've never used QSettings before :smileyhappy: So, should I copy the src files from your Github project and then important them into mine or do I need to edit the applicationui files?

 

Also, thanks for reminding me about checking it in my sandbox as it would have been a nightmare if it didn't work for customers - so thanks :smileyvery-happy:

Please use plain text.