Posted: 17th Jan 2023 15:52
Hello everyone,It's been a while since I've been here.
I'm working on a card project with AGK.
The development is going well, but I can't finalize the purchase system. (In App Purchase).

The app is crashing, and I don't know if I'm doing things correctly and in the right way.

Can anyone confirm that the process is correct?

Thank you for your answers


On the start of the game :
+ Code Snippet
	inAppPurchaseSetTitle(getAppName())
	InAppPurchaseSetKeys ( "******", "" )
	InAppPurchaseAddProductID( "token_0", 0 )
	InAppPurchaseSetup()



When the button ?buy? is clicked, it run this function :
+ Code Snippet
	filename$ = "tokens.datas"
	do
		if GetFileExists( filename$ )
			if GetInAppPurchaseAvailable2(0) = 0
				InAppPurchaseActivate(0)	
				PurchaseStat = GetInAppPurchaseAvailable2(0)
				if PurchaseStat = 4
					file = OpenToRead(filename$)
					TOKENS=val(Readline(file))
					TOKENS = TOKENS+10
					CloseFile(file)
					file = OpenTowrite( filename$, 0 )
					WriteString(file,str(TOKENS))
					CloseFile(file)
				endif
			endif	
		endif
		Sync()
	loop




On the Google Dev Console :



Thanks
Posted: 18th Jan 2023 9:31
Update :

+ Code Snippet
	filename$ = "tokens.datas"

		if GetFileExists( filename$ )
			if GetInAppPurchaseAvailable2(0) = 0
				InAppPurchaseActivate(0)	
				PurchaseStat = GetInAppPurchaseAvailable2(0)
				while (PurchaseStat < 2)
					sync()
                endwhile
				if PurchaseStat = 4
					file = OpenToRead(filename$)
					TOKENS=val(Readline(file))
					TOKENS = TOKENS+10
					CloseFile(file)
					file = OpenTowrite( filename$, 0 )
					WriteString(file,str(TOKENS))
					CloseFile(file)
				endif
			endif	
		endif


Now i get a Error message : "Product not recognised by Google Billing Library" when i cast the app via AppGameKit :



And the error when i publish a release on Google Play Console :
"cannot start purchase as IAP setup failed"
Posted: 18th Jan 2023 16:46
Couple of suggestions. I would recommend you use this routine after the 'InAppPurchaseActivate(0)' command:

+ Code Snippet
while GetInAppPurchaseState()=0
    sync()
endwhile


This will wait until the user completes the IAP process, if available. Then checking the availability again should be done after. The first error you observed is expected. Casting the app to the player through broadcast will not work with IAP's since the product name, keys, and ID will not match (your app will carry different values compared to the AppGameKit player). So the IAP option will only work once you've uploaded the bundle to Google Play.

Then if you are receiving the message about the IAP setup failing, something may not be matching. Verify the following:

- The title you are specifying in 'InAppPurchaseSetTitle()' matches the GooglePlay value exactly (compare your 'getAppName()' result with the app name as it appears in Google Play).
- The 'InAppPurchaseSetKeys()' value matches the string as displayed in GooglePlay exactly.

If those check out, perhaps there is a lingering issue with the IAP list index (or you may be using an older version with the issue). Try adding this line after your first 'InAppPurchaseAddProduct()' line, so it would look like this:

+ Code Snippet
InAppPurchaseAddProductID("token_0",0)
InAppPurchaseAddProductID("null",2) // Add a second redundant value as type 2


Then upload to Google Play and test again.
Posted: 24th Jan 2023 9:38
Thank you for your quick response,

I took the time to test your suggestions, thank you, I even created a second app on GooglePlay to retest the entire process. But nothing, I still have the same error "Cannot start purchase as IAP setup failed".

So the IAP option will only work once you've uploaded the bundle to Google Play

Thank you, I wasn't sure, so I put it in case it helps to pinpoint the problem...

The title you are specifying in 'InAppPurchaseSetTitle()' matches the GooglePlay value exactly (compare your 'getAppName()' result with the app name as it appears in Google Play).

I double-checked the name, now it corresponds exactly, but no improvement in the problem.

The 'InAppPurchaseSetKeys()' value matches the string as displayed in GooglePlay exactly.

Double-checked this too. it seems ok

Normally I have the latest version, but I still tried this solution, but nothing.


+ Code Snippet
message(getAppName())

//In App Purchass Setup

	inAppPurchaseSetTitle(getAppName())
	InAppPurchaseSetKeys ("******", "" )
	InAppPurchaseAddProductID("token0",0)
	InAppPurchaseAddProductID("null",2) // Add a second redundant value as type 2
	InAppPurchaseSetup()
	
//--

filename$ = "tokens.datas"

		if GetFileExists( filename$ )
			if GetInAppPurchaseAvailable2(0) = 0
				InAppPurchaseActivate(0)
				while GetInAppPurchaseState()=0
					sync()
				endwhile
				PurchaseStat = GetInAppPurchaseAvailable2(0)
				while (PurchaseStat < 2)
					sync()
                endwhile
				if PurchaseStat = 4
					file = OpenToRead(filename$)
					TOKENS=val(Readline(file))
					TOKENS = TOKENS+10
					CloseFile(file)
					file = OpenTowrite( filename$, 0 )
					WriteString(file,str(TOKENS))
					CloseFile(file)
				endif
			endif	
		endif
Posted: 24th Jan 2023 15:24
In this line:

InAppPurchaseAddProductID("token0",0)

Try using:

InAppPurchaseAddProductID("token_0",0)

Your initial ID call is lacking the underscore contained in the Google Play listing. That will need to match exactly. You included it in your first example, but it's lacking in the last one above.
Posted: 24th Jan 2023 15:37
Thank you, yes indeed, I also tested without underscore by creating a new product on GooglePlay, I thought that maybe the problem comes from there, but it is not that... I should have said so in my last answer.

Thanks for your time, and your help.
Posted: 24th Jan 2023 15:51
Ok, then only other thing I can think of would be the key value not matching. Sometimes it's easy to accidently copy a space character at the end of it or missing a character. It can help to break down the key into smaller line sections in variables:

keyA$="12345678901234567890"
keyB$+"12345678901234567890"
keyC$="12345678901234567890"

And so on until the key is completed, then analyze each character set. Then run the InAppPurchaseSetKeys(keyA$+keyB$+keyC$,"") command. The error message is likely correctly pointing to the problem. Odds are, there is just something that isn't matching and the setup is failing. I'm guessing your test device has an active internet connection and you are signed into your Google account on the device? Another consideration, give the process some time before checking it's status in the game/app, just 5-10 seconds, but enough that the data exchange can take place between the device and Google even if the connection is really slow.
Posted: 24th Jan 2023 20:38
Ok, it work !

A big thanks to you SFSW ! You help me a lot, to do the right thinks and to undestand how all this work, so thanks !

I was downloading the apk from another link and installing it on my mobile. There is also a share link once the app is published, but it was not working either. It is necessary to use the link provided in the "Testers" tab and not the link provided inthe tabs of the release version of the app.



Now... iOS..
Posted: 24th Jan 2023 22:02
Ah yes, good catch! Glad you got it working now.