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

Payment Service

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

In-App Purchase Issue

[ Edited ]

Whilst investigating the issue of the images not swiping/scrolling in a Webview (http://supportforums.blackberry.com/t5/Native-Development/Issue-With-Scrolling-Images-In-Webview/m-p...) I came across the issue that if a user purchases my in-app purchase and then deletes the application and reinstalls the in-app purchase hasn't worked. 

 

Firstly, the in-app purchase is to remove the advertisements - it does that very well but when the application gets deleted and reinstalled the adverts appear once again and I do not want to force consumers to pay twice so I really need to get this issue fixed as it is currently preventing me from releasing an update to my application. 

 

I am working off of this sample: http://supportforums.blackberry.com/t5/Native-Development/Sample-Removing-In-App-Ads/m-p/2783323/hig... and have used it to create the in-app purchase for my application. 

 

Here is my source code, from my main.qml file of my application:

 

import bb.cascades 1.0
import bb.platform 1.0
import com.sample.payment 1.0

TabbedPane {
    id: tabbedPane
    property variant payment

    Menu.definition: MenuDefinition {
        id: appMenu
        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=Shopping For eBay App: Contact"
                    emailInvocation.query.updateQuery();
                }

            },
            ActionItem {
                id: upgradeAction
                title: "Remove Ads"
                imageSource: "asset:///IMG/ic_clear_list.png"

                onTriggered: {
                    if (tabbedPane.payment) {
                        /* replace the values in quotes "" below with the values from
                         * your vendor account for this application's add-on. */
                        payment.mPaymentControl.pid = "{REMOVED}"
                        payment.mPaymentControl.sku = "{REMOVED}"
                        payment.mPaymentControl.name = "Remove Ads"
                        payment.mPaymentControl.metadata = "Purchasing this will remove the adverts!"
                        payment.mPaymentControl.getPrice(payment.mPaymentControl.pid, payment.mPaymentControl.sku);
                        payment.mPaymentControl.purchase(payment.mPaymentControl.pid, payment.mPaymentControl.sku, payment.mPaymentControl.name, payment.mPaymentControl.metadata)
                    }
                }
                attachedObjects: [
                    // Definition to hold the PaymentControl so it is only created when neccesary
                    ComponentDefinition {
                        id: paymentdef
                        Container {
                            id: payContainer
                            onCreationCompleted: {
                                console.log("Payment Definition Created - Checking for Existing Purchases")
                                paymentControl.getExisting(true);
                            }

                            property alias mPaymentControl: paymentControl

                            attachedObjects: [
                                PaymentServiceControl {
                                    id: paymentControl
                                    property string pid
                                    property string sku
                                    property string name
                                    property string metadata

                                    // Play receipt animation on purchase response

                                    onPurchaseResponseSuccess: {
                                        cpp.saveValueFor("removedAds", "23");
                                        root.removedAds = 23;
                                        console.log("purchaseResponse - " + receiptString)
                                    }
                                    onInfoResponseError: {
                                        console.log("Purchase Error - " + errorCode + " - " + errorText)
                                    }

                                    onExistingPurchasesResponseSuccess: {
                                        if (receiptsString == "(No purchases)") {
                                            console.log("existing unable to find receipt")
                                        } else {
                                            console.log("existing receiptString - " + receiptsString)
                                            cpp.saveValueFor("removedAds", "23");
                                            root.removedAds = 23;
                                        }
                                        console.log("existingPurchaseResponse Success - " + receiptsString)
                                    }
                                }
                            ]
                        }
                    }
                ]
            },
            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")
                }
            }
        ]
        attachedObjects: [
            Sheet {
                id: aboutSheet
                About {
                }
            },
            Invocation {
                id: invokeShare
                query {
                    mimeType: "text/plain"
                    data: qsTr("Get your shopping done easily on your #BlackBerry10 with 'Shopping For eBay'; check it out in @BlackBerry World: http://appworld.blackberry.com/webstore/content/35964888/")
                    invokeActionId: "bb.action.SHARE"
                }
            },
            Invocation {
                id: invokebb
                query {
                    mimeType: "text/html"
                    uri: "appworld://vendor/64825/"
                    invokeActionId: "bb.action.OPEN"
                }
            },
            Invocation {
                id: emailInvocation
                query.mimeType: "text/plain"
                query.invokeTargetId: "sys.pim.uib.email.hybridcomposer"
                query.invokeActionId: "bb.action.SENDEMAIL"
                onArmed: {
                    emailInvocation.trigger(emailInvocation.query.invokeActionId);
                }
            }
        ]
    }
    showTabsOnActionBar: false
    Tab {
        title: qsTr("Home") + Retranslate.onLocaleOrLanguageChanged
        imageSource: "IMG/101.Home.png"
        NavigationPane {
            id: navigationPane0
            Page {
                onCreationCompleted: {
                    root.removedAds = parseInt(cpp.getValueFor("removedAds", ""))
                    if (root.removedAds != 23) {
                        tabbedPane.payment = paymentdef.createObject(navigationPane0);
                    } else {
                        console.log("Not Creating Payment Definition, User has Already Paid To Remove Ads")
                    }

                }
                id: page1
                //actionBar actions

                //Title bar

                Container {
                    id: root
                    property int removedAds

                    onRemovedAdsChanged: {
                        if (removedAds == 23) {
                            myAds.visible = false
                            myAds2.visible = false
                            appMenu.removeAction(upgradeAction)
                        }
                    }
                    Container {
                        id: myAds
                        horizontalAlignment: HorizontalAlignment.Center
                        layout: StackLayout {

                        }
                        MyAds {
                            horizontalAlignment: HorizontalAlignment.Center
                            topPadding: 15.0
                        }
                    }
                    Container {

                        layout: DockLayout {

                        }
                        // To enable scrolling in the WebView, it is put inside a ScrollView.
                        ScrollView {
                            id: scrollView

                            scrollViewProperties.overScrollEffectMode: OverScrollEffectMode.None
                            // We let the scroll view scroll in both x and y and enable zooming,
                            // max and min content zoom property is set in the WebViews onMinContentScaleChanged
                            // and onMaxContentScaleChanged signal handlers.
                            scrollViewProperties {
                                scrollMode: ScrollMode.Vertical
                                pinchToZoomEnabled: true
                            }

                            //Webview

                        } // ScrollView// A progress indicator that is used to show the loading status
                        Container {
                            bottomPadding: 25
                            horizontalAlignment: HorizontalAlignment.Center
                            verticalAlignment: VerticalAlignment.Bottom

                            ProgressIndicator {
                                id: progressIndicator
                                opacity: 0.0
                            }
                        }
                    }
                } // End of container
            }
        }
    } //End of first tab
} //End of tabbedPane

 Any help and guidance towards this issue would be greatly appricated. 

 

Thanks in advance! Smiley Very Happy

Developer
Posts: 136
Registered: ‎01-25-2010
My Device: Z30, Z10, Q10, Dev Alpha B & Bold 9900
My Carrier: Bell

Re: In-App Purchase Issue

Hi,

 

I was running into the same issue... our code base is different but in the end it does apply the same concept.

http://supportforums.blackberry.com/t5/Native-Development/Payment-Service-Not-fetching-past-purchase...

 

After a few hours of digging arround, I did noticed that the sample code had bogus code which threw my logic out. Anyhow... To test I used the following approached :

 

1. Purchased the goods from my device.

2. Deleted the app.

3. Pushed new app release on BB World.

4. Turned on the Sandboxing feature in BlackBerry World and pulled new rev.

 

From my app, I displayed a few dialog box which allowed me to view the data returned back and quickly identify the bogus issue.

 

 

Retired
Posts: 2,559
Registered: ‎10-16-2009
My Device: BlackBerry Z10
My Carrier: Bell

Re: In-App Purchase Issue

If you are testing using a sandbox account then past purchases cannot be restored. Purchases made with a sandbox account do not get logged to the server, so if you try to restore (ex after deleting then re-installing the same app) then no purchases will be returned.

 

You can test your restore logic using purchases made within the same app session: open the app, make a purchase, attempt a restore, all without closing the app.

 

The only other option would be to remove your account from the sandbox and attempt the purchase using real $$

Garett
@garettBeuk
--
Goodbye everybody!
Developer
Posts: 385
Registered: ‎07-20-2012
My Device: Blackberry Z10 (White), BlackBerry Dev Alpha C
My Carrier: O2 UK

Re: In-App Purchase Issue

Hi Garett, 

 

I was using my Sandbox to test this but I just got a few users, who have already downloaded and remove the ads - directly from BlackBerry World, to test it and they reported back saying that after uninstalling the application and re-installing the adverts didn't appear - which is great to hear as it demonstrates that my code is operating correctly. 

 

I was only concerned about this because if I was to release an update, with currently 3,000 downloads and 100 in-app purchases (added the in-app purchase in the latest release), I wouldn't want to have the users that have already paid to have to pay again; so, thank you for your assistance Smiley Very Happy