how can i use consumePurchase method in in-app billing v3 - java

I am using in-app billing from this link: https://github.com/anjlab/android-inapp-billing-v3
it allows me to purchase the item one time only. so I googled how to be able to purchase it more than one time all results lead that I need to consume the old purchase. I cannot find how and were to call the consuming function
here is the consuming function:
billingProcess.consumePurchase(n_Selected)
I tried to call it in the onCreate method: it did not do anything
I tried to call it in onProductPurchased method: it did not do anything

You should consider Google Play's official Billing Library. Add
com.android.billingclient:billing:2.0
to your build.gradle.
https://github.com/googlesamples/android-play-billing/tree/master/TrivialDrive_v2
is Google's best practice.
You should always call queryPurchases and call consumeAsyc for outstanding purchases in the callback. Also, call consumeAsyc in onPurchasesUpdate method, which is triggered after a successful purchase.

Related

How do I use the amadeus-java SDK to test pricing and booking flights?

I understand that the amadeus-java SDK offers methods that simplify GET and POST calls to the Amadeus Self-Service API endpoint Flight Offers Search.
Is there a way to make POST calls to Flight Offers Price and Flight Create Orders within the SDK?
If the SDK does not have methods for this, how would I retrieve the access token I fetched via SDK to make those calls explicitly?
Thanks in advance!
Flight Offers Price and Flight Create Orders are about to be integrated into the Java SDK (PRs opened, a bit more work to do and you will be able to use them).
The other solution will be to use the methods post and get directly from our client like in the example below (that you can find the README description of the Java SDK):
You can make any arbitrary API call as well directly with the .get
method. Keep in mind, this returns a raw Resource
Response response = amadeus.get("/v2/reference-data/urls/checkin-links", Params.with("airlineCode", "BA"));
response.getResult();

queryPurchases() vs queryPurchaseHistoryAsync() in order to 'restore' functionality?

I'm using the Play Billing Library in order to trigger and manage purchases which in turn unlocked extra functionality within an app. This part is working.
However, what is the best way to 'restore' purchases. Say for example someone who has bought the app buys a new phone. Logs in to the Play Store, downloads my app and then finds that the payment screen to 'upgrade' is being displayed. iOS has a specific method for this but I'm not aware of one for Android.
My thoughts are to query the Play Store and confirm whether the account has previously SUCCESSFULLY purchased the item, if so then I will call the local upgrade function within the app.
It appears there are two similar methods. But which one should I used in this scenario? Where a user has either wiped their phone or bought a new one?
queryPurchases()? Or queryPurchaseHistoryAsync()?
You should use queryPurchases. That gives you all the current active (non-consumed, non-cancelled, non-expired) purchases for each SKU.
queryPurchaseHistoryAsync won't do what you need because it will only give you a list of the most recent purchases for each SKU. They may have expired, been cancelled or been consumed, and there's no way to tell. Therefore this response can't be used to tell what purchases to apply in your app.
So far as I can see, the only valid use for queryPurchaseHistoryAsync is to provide a user with a list of their purchase history. It's a bit of an oddball.
Note also: queryPurchases is synchronous so in most cases it needs to be run in some kind of background worker thread. I run mine in an AsyncTask.
Per documentation queryPurchases uses the Play Store app cache to get the results while queryPurchaseHistoryAsyncactually checks the Purchase AP for the most recent purchases. So, in your case you should check the Asyncmethod.
queryPurchases
Get purchases details for all the items bought within your app. This method uses a cache of Google Play Store app without initiating a network request.
queryPurchaseHistoryAsync
Returns the most recent purchase made by the user for each SKU, even if that purchase is expired, canceled, or consumed.
Also, make sure to check the documentation. It recommends to Cache purchase details on your servers.
https://developer.android.com/google/play/developer-api.html#practices
I know it's a bit late, but I just discovered this myself. Sharing my answer for others to benefit.
So I learned that queryPurchases() is cached locally on your device, but is updated when you call queryPurchaseHistoryAsync()
I discovered from this Stackoverflow answer here
So my solution, is when wanting to restore a purchase on a new device, or a fresh install of my app. Call queryPurchaseHistoryAsync() Then in the callback onPurchaseHistoryResponse() call queryPurchases() and look within the List<Purchase> from the PurchasesResult for the purchase status of any of the user's past purchases.
If there's an expected purchase your app can grant the entitlements of their past purchase.
The documentation has been updated for the latest versions of BillingClient. queryPurchases() is deprecated. Also note that queryPurchases() only ever returned purchases made by the current device, so that method will not inform your scenario of a new wiped phone. To get accurate information use the async calls.
queryPurchasesAsync() will return all active subscription and unconsumed one-time Purchase objects for the sku type provided. It gets the purchases from the local Play Services cache, so there are no guarantees the cache will contain purchases from another device in your "new phone" scenario, and no guarantees the cache will yet be current in your "wiped phone" scenario.
queryPurchaseHistoryAsync() will make a network request and return the most recent PurchaseHistory object for each sku matching the provided sku type, even if cancelled or consumed.
Also, to perform the upgrade call launchBillingFlow() with the appropriate BillingFlowParams and BillingFlowParams.SubscriptionUpdateParams for the sku you now know to be purchased.

Android app, Google maps api location validation for java

I'm using Android Studio to create an app that utilizes google maps api. I am having trouble validating if the user input is an actual location.
i.e if the user enters "fdfdfaef", program crashes.
i have the following code to store the user "location" input:
address = geocoder.getFromLocationName(location, 1)
Any help on how to check if the input is valid or not or at least to prevent a crash. Thanks and appreciate it.
Since you haven't posted any code, I will go out on a limb and suggest that you might be doing this on your main UI thread.
From the doc,
The query will block and returned values will be obtained by means of
a network lookup. The results are a best guess and are not guaranteed
to be meaningful or correct. It may be useful to call this method from
a thread separate from your primary UI thread.
Try doing a async task that requests information using the Geocoding API. On getting a result, update the UI. Offloading to an AsyncTask will prevent the crash, at the very least.
Does that help you?

how to get the Fee Amount for paypal

I am currently looking at a system that implements the PayPal api. As a part of this I need to get the feeAmt() which is the fee that is paid to paypal for processing the payment.
From the documentation that I have looked at it appears that I have to implement the getExpressCheckoutDetailsReq() method in order to get the information that I want however no matter what I have tried I am struggling to do this. I should also let you know that I am currently developing my application using Java so using this is going to be best.
If any more explanation is needed please don't hesitate to ask and I will do my best to amend the post :)
GetExpressCheckoutDetails does not include the fee because at that point no payment has been made yet. That's the 2nd of 3 calls for Express Checkout, and until the final call is made there is no fee.
The fee amount would actually come in that final call's response: DoExpressCheckoutPayment. It will come in the PAYMENTINFO_n_FEEAMT parameter, where n is the number of the payment (0,1,2,etc.) Most likely it'll be 0 unless you're working with parallel payments.
Alternatively, you can use Instant Payment Notification (IPN) to get details about transactions, including the fee, in real-time when transactions are completed on your PayPal account.
Yet another option would be to use the GetTransactionDetails API to pull data for an individual transaction which would include the fee in a FEEAMT parameter. Maybe that's the one you were initially thinking of..??

Use Call Activity without logging in recent calls

I have an application that uses call activity to call people. However, when the call is made, the number will be logged to recent call list, and I don't want this to happen.
What would be the best way for the phone to not to log the calls made?
I am not sure if the recent call list uses the same database as the call log, however if it does you can just delete the call from that content provider after it is made.
Take a look at this: http://www.mobisoftinfotech.com/blog/android/androidcalllogdeletion/

Categories