Dynamic In-App Purchases
Asked Answered
W

2

9

This question (Android In-App Billing Dynamic Product List) was asked over 3 years ago. Are dynamic in-app purchase items still unavailable to Android?

The reason I’m looking to implement this sort of functionality is because my app features a way for certain users to create their own in-app purchases for others to buy.

It seems like an alternative solution would be to use consumable in-app currency but I’d much rather have a purchase option directly through the Play Store (especially since I’ve seen methods for hacking in-game currency everywhere).

Regardless of the option, I do want to use server-side verification. Might there be a way to add in-app purchases through a server?

Weil answered 15/12, 2014 at 21:21 Comment(0)
D
6

I'm not sure if this will suffice, but you can use the Google Play API and insert new in app billing products that way. All in app billing products for Android still need to be specified in the Google Play Developer Console, but at least with the Play API, you can do it programatically.

Drawer answered 16/12, 2014 at 23:7 Comment(10)
This definitely looks promising! I'll update the question as soon as it's implemented. Thank youWeil
hi @Drawer can you give me the detail of how to use this insert product using API . I can't understand in this doc that how I can insert my item dynamically.Quintessence
I'm going through with same problem, can you help me or do you have any example for this. @Quintessence c0debloodedMinaminabe
@Weil did you implement this feature?:)Nina
@Nina Nope, I didn't end up adding this logic to my app since I pivoted the design not long after. Definitely seems doable if needed in the future though.Weil
I will implement it and post the answer. :).Nina
Hi, I've used this API to insert products to Play Store successfully(its active and visible) BUT only the products that I add via this API doesn't load in the client app when I use the Google Play billing library. Do you happen to know why? Did you also face a similar issue?Clifton
Can you maybe share your experciences with this? @CliftonLimousine
@Limousine Hi, yes. I've posted a question regarding this issue.Clifton
Beware there are limits to this approach. Google has 1k limit and Apple 10k limit on items created. Src: #11391973Curagh
B
6

I managed to implement this using a Google Play Api and uploading the products to the playstore dynamically/programmatically.

First I used PHP since I am using Laravel for my backend REST API. It is up to you to choose you own. I will installed the google/apiclient library using composer using composer require google/apiclient

https://developers.google.com/android-publisher/api-ref/inappproducts

https://developers.google.com/android-publisher/api-ref/inappproducts/insert

A sample product could be uploaded as such:

Step1: You will need to authenticate to the service. By using a service json file or Auth oath if you prefer. In my case I used the service json file and enabled the Google Play API in my GCP console.

Step2: You need an sku(unique) refer to the docs and see the required format

Step3: You need to set a Price(micros) you can use https://github.com/Torann/laravel-currency to convert from one currency to another which I used in this case to obtain my currency based on the default currency of the Store(In app products) NB: The currencies must match else you will get an error.

Step4: You need to set Listings which are basically the title/descriptions under that your app needs for translations purposes


$client = new Google_Client();
$client->setAuthConfig(storage_path('service_account.json'));

// You have to add this scope so it knows it is in app billing store
$client->addScope('https://www.googleapis.com/auth/androidpublisher');
$service = new Google_Service_AndroidPublisher($client);

$body = new \Google_Service_AndroidPublisher_InAppProduct();
$body->setSku("unique_sku_here");
$body->setPackageName('android_app_package_name'); // e.g com.example.in_app_test

//1.00 USD = 1,000,000 Microns.

// Create a new price object 
$price = new \Google_Service_AndroidPublisher_Price();
$price->setCurrency('USD');

//Using **torann/currency** library to convert from one currency to another

$new_price = intval(currency("1000", $from = "EUR", $to = "USD", false));
$price->priceMicros = $new_price * 1000000;
$body->setDefaultPrice($price);

// Setting the default language

$body->defaultLanguage = "en_US";
$body->setListings([
                    'en_US' => [
                        'title' => 'Product Title',
                        'description' => "Product Description here"
                    ]
                ]);    

$purchase = $service->inappproducts->insert(
                     'android_app_package_name',
                     $body,
                    [
                      'autoConvertMissingPrices' => true,
                    ]);

$purchase->setStatus(true); // Always set this to mark the product active on the GPlay console.

With this you will have a return of a successful product upload.

Cheers. Feel free to comment should you have any blockers, I would be happy to clarify.

Bibbie answered 24/2, 2020 at 18:25 Comment(4)
Hi, I've used this API in my Java backend to insert products to Play Store successfully(its active and visible) but only the products that I add via this API doesn't load in the client app when I try to query my products using the Google Play billing library. The products that I add manually via the console are only visible which is strange. Do you happen to know why? Did you also face a similar issue?Clifton
Can i see how you are getting the products?Bibbie
Hi, here's a reference with more details.Clifton
Beware there are limits to this approach. Google has 1k limit and Apple 10k limit on items created. Src: #11391973Curagh

© 2022 - 2024 — McMap. All rights reserved.