I am using google play subscription services for my app.But when any use or customer tries to pay for my subscription with any given payment method.It shows -
Unavailable for this purchase.
Only I can pay with Google play account money.
I tried all method on different mobiles. But problem is same.
I am using standard code given on google developers site.
private BillingClient billingClient=BillingClient.newBuilder(activity)
.setListener(this).build();
billingClient.startConnection(new BillingClientStateListener() {
#Override
public void onBillingSetupFinished(BillingResult billingResult) {
if (billingResult.getResponseCode() == BillingResponse.OK) {
}
}
#Override
public void onBillingServiceDisconnected() {
}
});
I want to enable all payment methods for my app.
Try to add enablePendingPurchases(), so
private BillingClient billing_client = BillingClient.newBuilder( this ).enablePendingPurchases().setListener(...
Related
I am trying to implement Subscriptions for the first time. I am using BillingClient v3.0.1. It is contract so I am not the owner of the Google Play account. The account owner has set up financials for the account and has configured the API. I have created the subscription products in the Google Play console, added the billing library through Gradle and com.android.vending.BILLING in the manifest, and published a build on the Closed Alpha track for internal testing.
I initialize the billing client successfully
billingClient = BillingClient.newBuilder(mContext)
.enablePendingPurchases()
.setListener(this)
.build();
billingClient.startConnection(new BillingClientStateListener() {
#Override public void onBillingSetupFinished(#NonNull BillingResult billingResult) {
...
}
#Override public void onBillingServiceDisconnected() {
...
}
});
and everything works, I retrieve the list of products
SkuDetailsParams params = SkuDetailsParams.newBuilder()
.setSkusList(skuList)
.setType(BillingClient.SkuType.SUBS)
.build();
billingClient.querySkuDetailsAsync(params, new SkuDetailsResponseListener() {
#Override public void onSkuDetailsResponse(#NonNull BillingResult billingResult, #Nullable List<SkuDetails> list) {
...
});
and that too is successful, but when I try to purchase the product on a real device with a build running the same version code as the Alpha testing track version using:
BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder()
.setSkuDetails(product)
.build();
BillingResult billingResult = billingClient.launchBillingFlow(mContext, billingFlowParams);
The pop-up shows an Error in the pop-up "The item you were attempting to purchase could not be found".
I have been going through everything I can find (short of receipt validation, which will be next up after I can actually complete a purchase), but am stuck.
Any advice / thoughts?
Thanks
Stephen
In 'desperation' -> Well actually because I had nothing better to try, I updated the build on GooglePlay alpha test track and ran the exact same build on my test device and now it is working, no other changes, but progress.
After correctly configuring the BillingClient as in the documentation onBillingSetupFinished is not called.
//...
billingClient = BillingClient.newBuilder(this)
.setListener(purchaseUpdateListener)
.enablePendingPurchases()
.build();
//billingClient != null
billingClient.startConnection(new BillingClientStateListener() {
#Override
public void onBillingSetupFinished(BillingResult billingResult) {
//This is not called
}
#Override
public void onBillingServiceDisconnected() {
//This is not called
}
});
//...
It only happens on some devices.
Some Chinese devices, like the one I have (BV9900). They have a clean button when you press and hold home that not only closes all apps, but also completely closes all apps and services, including Google's.
By preventing any app from running in the background, this disables in-app purchases. The solution in this case is to open the Play Store in Intent to start the services again.
I was wondering could you help. I followed the instructions at https://developer.android.com/google/play/billing/integrate, but I cannot seem to get the purchase flow working. The billing seems to setup ok, but when I try to query for my in-app products, the list is always returning empty. Can someone please help?
In my app level build.gradle file, I have included the Google Billing SDK:
implementation 'com.android.billingclient:billing:3.0.0'
Then I have created an activity to test out the code. It first initialises the BillingClient and starts the connection. The connection seems to finish the setup correctly. Once setup correctly, I then try to query the products that I have available in my Google Play Console under 'Store presence' > 'In-app products' > 'Manage products'
The following is then the code in the Activity that should kick off the process and return the SkuDetails list, but unfortunately it is returning back empty.
private BillingClient billingClient;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_billing);
this.billingClient = BillingClient.newBuilder(this)
.enablePendingPurchases()
.setListener(this.purchaseUpdateListener)
.build();
this.billingClient.startConnection(billingClientStateListener);
}
private PurchasesUpdatedListener purchaseUpdateListener = new PurchasesUpdatedListener() {
#Override
public void onPurchasesUpdated(#NonNull BillingResult billingResult, #Nullable List<Purchase> list) {
Log.d("Billing", "onPurchasesUpdated - List Size: " + list.size());
}
};
private BillingClientStateListener billingClientStateListener = new BillingClientStateListener() {
#Override
public void onBillingSetupFinished(#NonNull BillingResult billingResult) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
Log.d("Billing", "onBillingSetupFinished - OK");
queryProducts();
} else {
Log.d("Billing", "onBillingSetupFinished - Something wrong response Code: " + billingResult.getResponseCode());
}
}
#Override
public void onBillingServiceDisconnected() {
Log.d("Billing", "Service disconnected");
}
};
private void queryProducts() {
List<String> productIdsList = new ArrayList<>();
productIdsList.add("test.billing.001");
SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
params.setSkusList(productIdsList).setType(BillingClient.SkuType.INAPP);
this.billingClient.querySkuDetailsAsync(params.build(), new SkuDetailsResponseListener() {
#Override
public void onSkuDetailsResponse(#NonNull BillingResult billingResult, #Nullable List< SkuDetails > list) {
Log.d("Billing", "onSkuDetailsResponse - List Size: " + list.size());
}
});
}
So for anyone who is having similar issues, it seems that (well in my case anyways) that my app needed to be successfully published before I could retrieve the in-app products from the app. Once my app was published, I was then able to query and use the in-app products.
According to Maxim Alov comment for Billing 5.0.0, the problem is in invitations for testers.
My steps to fix this problem:
Open tester's invitation link and accept
Open app via link from previous step
After two these steps (in my case second helped) all products started to come
I'm using billing-lib-5.0.0 and also had the same issue -
queryProductDetails() was always empty on my release builds, let alone
debug builds. I'd actually added all my test gmail emails to list of
testers for Closed Testing, and also LICENSED all of them. No effect.
Eventually, I recognized that the link to my test app is not generated
on Play Console Closed Testing track page. I recreated the track, this
time for Internal Testing, and the link has appeared. Then I logged in
to each of my gmails and accepted to be a tester from that link. After
doing that, products started to come, in IDE
I am executing the code described by the google billing library, but my device always connects to the billing client, also if I m in flight mode.
//Initiate billing client
bc = BillingClient.newBuilder(getApplicationContext()).setListener(this).
enablePendingPurchases().build();
bc.startConnection(new BillingClientStateListener() {
#Override
public void onBillingSetupFinished(BillingResult billingResult) {
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
// The BillingClient is ready. You can query purchases here.
Toast.makeText(getApplicationContext(), "Connected", Toast.LENGTH_SHORT).show();
}
}
#Override
public void onBillingServiceDisconnected() {
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
Toast.makeText(getApplicationContext(), "Failure", Toast.LENGTH_SHORT).show();
}
});
Google Play services cache purchases, so it is available offline
I am developing an application which will allow user to purchase using In App Purchase and I want to remove ads after purchase. I can purchase succesfully with code below
BillingFlowParams flowParams = BillingFlowParams.newBuilder()
.setSku("android.test.purchased")
.setType(BillingClient.SkuType.INAPP)
.build();
mBillingClient.launchBillingFlow(getActivity(), flowParams);
But I cannot see the result from queryPurchaseHistoryAsync when I open app again and call this method below.
mBillingClient.queryPurchaseHistoryAsync(BillingClient.SkuType.INAPP, new PurchaseHistoryResponseListener() {
#Override
public void onPurchaseHistoryResponse(int responseCode, List<Purchase> purchasesList) {
purchasesList.size();
}
});
purchasesList.size() == 0
Is "queryPurchaseHistoryAsync" method cannot show test purchase or Am I doing something wrong?
Edit: Is queryPurchaseHistoryAsync method check purchase after delete and install app again.
Yes queryPurchaseHistoryAsync method check purchase after deleting and installing the app again against particular user
mBillingClient.queryPurchaseHistoryAsync(BillingClient.SkuType.INAPP, new PurchaseHistoryResponseListener() {
#Override
public void onPurchaseHistoryResponse(#NonNull BillingResult billingResult, #Nullable List<PurchaseHistoryRecord> list) {
}
});
Try this it will give all purchase items.
mBillingClient.querySkuDetailsAsync(params.build(),
new SkuDetailsResponseListener() {
#Override
public void onSkuDetailsResponse(int responseCode, List<SkuDetails> skuDetailsList) {
listener.onSkuDetailsResponse(responseCode, skuDetailsList);
}
});
mBillingClient.queryPurchases() is all you need. Call it at every app start and, for example, every time your main activity resumes. This way your (reinstalled) app will eventually detect all user's purchases.