I have been trying for days to get Google IAP working, to no avail.
Can someone please help me out, this is beyond despressing now lol.
In adb log I only get this:
Please call init before trying to purchase products.
Google Play is all set up nicely as per the guides and I am currently testing from an internal testing track from within Google Play.
I have also tried all the help in Solar2d forums website etc…
I have seriously no clue as what to do next.
Thanking you in anticipation.
Code below:
Main.lua
–in app purchases--------------------------------------------------------------------------
local store=require(“plugin.google.iap.billing”);
local function transactionListener(e)
if(e.name==“init”)then
print(“e.name INIT -------- WE ARE INSIDE INAPP IAPLISTENER - INIT”);
local function openStore()
print(“After 8 seconds the state of store is:”,store.isActive);
end
timer.performWithDelay(8000,openStore,1);
elseif(e.name==“storeTransaction”)then
if not(e.transaction.isError)then
print(“e.name inside storeTransaction”);
–e.transaction,state will return ‘purchased’ / ‘restored’ / ‘cancelled’ / ‘failed’
–google iap also has consumed and refunded.
–consumed is for allowing players to buy consumables again
if(e.transaction.state==“purchased”)then
print(“Store Purchase”,e.transaction.productIdentifier);
if(e.transaction.productIdentifier==“com.xxx.1”)then
–do whatever
elseif(e.transaction.productIdentifier==“com.xxx.2”)then
–do whatever
elseif(e.transaction.productIdentifier==“com.xxx.3”)then
–do whatever
end
elseif(e.transaction.state==“consumed”)then
end
else
print("There was an error in storeTransaction",e.transaction.errorType,e.transaction.errorString);
end
--store.finishTransaction(e.transaction);
end
end
local function productListener(e)
print(“WE ARE INSIDE IAP ITEMSLISTENER”);
for li=1,#e.products do
print(e.products[li].title);
print(e.products[li].price);
print(e.products[li].description);
print(e.products[li].productIdentifier);
print(e.products[li].price);
print(e.products[li].localizedPrice);
if(e.products[li].productIdentifier==“com.xxx.1”)then
shop1Txt.text=e.products[li].localizedPrice;
end
if(e.products[li].productIdentifier==“com.xxx.2”)then
shop2Txt.text=e.products[li].localizedPrice;
end
if(e.products[li].productIdentifier==“com.xxx.”)then
shop3Txt.text=e.products[li].localizedPrice;
end
end
end
local productIdentifiers={“com.xxx.1”,“com.xxx.2”,“com.xxx.3”};
local function loadItems()
if(store.canLoadProducts)then
store.loadProducts(productIdentifiers,productListener);
end
end
purchaseJokerCoins1=function()
if(store.canMakePurchases)then
audio.play(sound.coin);
store.purchase(“com.xxx.1”);
else
native.showAlert(“Purchase”,“In-app purchases are not allowed.”,{“OK”});
end
end
purchaseJokerCoins2=function()
if(store.canMakePurchases)then
audio.play(sound.coin);
store.purchase(“com.xxx.2”);
else
native.showAlert(“Purchase”,“In-app purchases are not allowed.”,{“OK”});
end
end
purchaseJokerCoins3=function()
if(store.canMakePurchases)then
audio.play(sound.coin);
store.purchase(“com.xxx.3”);
else
native.showAlert(“Purchase”,“In-app purchases are not allowed.”,{“OK”});
end
end
timer.performWithDelay(5000,store.init(transactionListener),1);
Build.settings - the relevant bits
settings =
{
orientation =
{
– Supported values for orientation:
– portrait, portraitUpsideDown, landscapeLeft, landscapeRight
default = “landscapeRight”,
supported = {“landscapeLeft”,“landscapeRight”},
},
--
-- Android section
--
android =
{
usesPermissions =
{
"android.permission.INTERNET",
"android.permission.ACCESS_NETWORK_STATE",
"android.permission.WRITE_EXTERNAL_STORAGE",
"com.android.vending.BILLING",
--"android.permission.GET_ACCOUNTS",
"android.permission.ACCESS_COARSE_LOCATION",
"android.permission.ACCESS_FINE_LOCATION",
--"android.permission.RECORD_AUDIO",
},
minSdkVersion = "21", --version 5+
applicationChildElements =
{
[[
<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"/> -- replace with your app id. See: https://goo.gl/fQ2neu
]],
},
},
Config.lua - in full
application =
{
content =
{
width = 1536,
height = 2048,
scale = “letterbox”,
fps = 60,
--[[
imageSuffix =
{
["@2x"] = 2,
["@4x"] = 4,
},
--]]
},
license =
{
google =
{
key = "MIIBIxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
},
},
}