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
bmorr
Posts: 225
Registered: ‎04-13-2013
My Device: Z10
My Carrier: Telus
Accepted Solution

In-app purchase responseError

I have an in-app purchase, and while it works well, I forgot to take into account what would happen if the user purchases the app, deletes the app, then re-installes.  

 

Basically in this scenario the user cannot unlock the features because they get an error (AW30222i) which is the "You have purchased this item already, and won't be charged to download it again." error.

 

Issue is I want to enable the features when this error comes up.

 

Can anybody tell me if this code will work?  I've put it up on my vendor account as a draft, but it's been a few hours and it's not showing up, so I was hoping just based on looking at the code it may be a glaring YES or NO.

 

PaymentServiceControl {
                        id: paymentControl
                        property string id
                        property string sku
                        property string name
                        property string metadata
                        onPriceResponseSuccess: {
                        	
                        }
                        onPurchaseResponseSuccess: {
                            purchaseMenu.purchaseValue = false
                            _app.saveValueFor("purchaseButtonInfo", purchaseMenu.purchaseValue)
                            purchaseToast.show()
                        }
                        onExistingPurchasesResponseSuccess: {
                            
                        }
                        onSubscriptionTermsResponseSuccess: {
                        
                        }
                        onCancelSubscriptionResponseSuccess: {
                        
                        }
                        onCheckStatusResponseSuccess: {
                        
                        }
                        onInfoResponseError: {
                            if(errorCode == "AW30222i")
                            purchaseMenu.purchaseValue = false
                            _app.saveValueFor("purchaseButtonInfo", purchaseMenu.purchaseValue)
                            purchaseToast.show()
                        }
                    }

Thanks in advance. 

Please use plain text.
Developer
slashkyle
Posts: 798
Registered: ‎10-16-2012
My Device: Red Z10, Dev Alpha C
My Carrier: Telus

Re: In-app purchase responseError

[ Edited ]

You can have your app check every time the app is opened if there is existing purcahses in onCreationCompleted

 

onCreationCompleted: {
    paymentControl.getExisting (true);
}

 then in your payment control listen for existingPurchasesResponseSuccess

 

onExistingPurchasesResponseSuccess: { 
if (receiptsString == "(No purchases)"){ console.log("existing unable to find receipt") } else { console.log("existing receiptString - " + receiptsString) //already purchased enable content } console.log("existingPurchaseResponseSuccess - " + receiptsString) }

 if you have multiple avaliable items you'll need to analyze the recieptString in your console.log and use that information to adjust this method to check for what content was purchased and only enable that

Please use plain text.
Developer
bmorr
Posts: 225
Registered: ‎04-13-2013
My Device: Z10
My Carrier: Telus

Re: In-app purchase responseError

Thanks this will work much better! Will accept as solution if it works.
Please use plain text.
Developer
slashkyle
Posts: 798
Registered: ‎10-16-2012
My Device: Red Z10, Dev Alpha C
My Carrier: Telus

Re: In-app purchase responseError

[ Edited ]

you may also want to have a button somewhere that calls the getexisting function in case they have no internet connection at the launch of the app, and this makes it so customers are able to manually check themselves

Please use plain text.
Developer
bmorr
Posts: 225
Registered: ‎04-13-2013
My Device: Z10
My Carrier: Telus

Re: In-app purchase responseError

Thanks so much, this worked like a charm!

Please use plain text.
Developer
bmorr
Posts: 225
Registered: ‎04-13-2013
My Device: Z10
My Carrier: Telus

Re: In-app purchase responseError

[ Edited ]

BTW with regards to my original code the error code I had was wrong, instead of that convoluted AW03... all I needed was this:

 

                        onInfoResponseError: {
                            if(errorCode == 2)
                            purchaseMenu.purchaseValue = false
                            _app.saveValueFor("purchaseButtonInfo", purchaseMenu.purchaseValue)
                            purchaseToast.show()
                        }

 This worked for running the fucntion if the already purchased error came up.  Error code 2 is the right code for this.  I couldn't find documentation on the various payment error codes but I ran a consol.log(errorCode) to figure it out.

 

cheers,

Please use plain text.