How to implement in-app purchases?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Message
Author
User avatar
storykween
Regular
Posts: 154
Joined: Mon Sep 30, 2013 1:17 pm
Completed: Serafina's Saga, Quantum Conscience, Echoes of the Fey, miraclr - Divine Dating Sim
Organization: Woodsy Studio
Location: St Louis
Contact:

How to implement in-app purchases?

#1 Post by storykween »

Greetings,
I have been trying to add in-app purchase items to my games for months, but I have not yet figured out how to do so through Ren'Py (I can do a little programming, but I'm not an expert). I was very happy about the inclusion of in-app purchasing billing permissions in the 6.17 release of Ren'Py, but I still don't know how to actually *USE* it, for instance with the Google Play store.

How do I actually declare part of the build as an in-app purchase? How do I implement code into the Ren'Py script--for instance if I have a bonus scene I want to include as an in-app purchase? I have searched and searched but I can't find any tutorials about how to do this through Ren'Py tools; all the instructions on Google Play (for instance, these here about in-app billing: http://developer.android.com/google/pla ... grate.html) don't make sense to me because they have nothing to do with the process of configuring and creating a build through Ren'Py.

If anyone can give me any advice on this subject, or point me to a good tutorial on how to actually implement in-app purchases through Ren'Py, I would be so very grateful!
Image
My website: woodsy-studio.com

User avatar
dyrarendy
Regular
Posts: 59
Joined: Wed Apr 02, 2014 12:26 pm
Projects: Visual Novel Dating Sims Masa SMA
Location: Indonesia, Cimahi
Contact:

Re: How to implement in-app purchases?

#2 Post by dyrarendy »

I think u should make 2 version apk.

1. Free version, or Demo. Without Manifest In-App Purchase. Without bonus scene.
2. Buy Version, With Manifest In-App Purchase. Full version.
My Project :
Image

User avatar
storykween
Regular
Posts: 154
Joined: Mon Sep 30, 2013 1:17 pm
Completed: Serafina's Saga, Quantum Conscience, Echoes of the Fey, miraclr - Divine Dating Sim
Organization: Woodsy Studio
Location: St Louis
Contact:

Re: How to implement in-app purchases?

#3 Post by storykween »

I realize that's a possible workaround, but far from optimal. I'd really like to figure out how to actually implement in-app purchases!
Image
My website: woodsy-studio.com

User avatar
storykween
Regular
Posts: 154
Joined: Mon Sep 30, 2013 1:17 pm
Completed: Serafina's Saga, Quantum Conscience, Echoes of the Fey, miraclr - Divine Dating Sim
Organization: Woodsy Studio
Location: St Louis
Contact:

Re: How to implement in-app purchases?

#4 Post by storykween »

I now see online documentation that explains how to set up in-app purchasing:

http://www.renpy.org/doc/html/iap.html

I haven't finished setting it up yet but I think I'm on my way now!
Image
My website: woodsy-studio.com

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: How to implement in-app purchases?

#5 Post by PyTom »

If you hit any problems, please let me know and I'll fix the docs, now that they exist.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
jack_norton
Lemma-Class Veteran
Posts: 4084
Joined: Mon Jul 21, 2008 5:41 pm
Completed: Too many! See my homepage
Projects: A lot! See www.winterwolves.com
Tumblr: winterwolvesgames
Contact:

Re: How to implement in-app purchases?

#6 Post by jack_norton »

I think the best for the docs would be some simple code examples, in particular how to use restore purchases on splash (and add restore purchases buttons in main menu) to avoid lots of people complaints. If I had time would post them myself, but... too many real life stuff going on :(
follow me on Image Image Image
computer games

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: How to implement in-app purchases?

#7 Post by PyTom »

Actually, it does restore purchases automatically on startup, so it should be less necessary.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
jack_norton
Lemma-Class Veteran
Posts: 4084
Joined: Mon Jul 21, 2008 5:41 pm
Completed: Too many! See my homepage
Projects: A lot! See www.winterwolves.com
Tumblr: winterwolvesgames
Contact:

Re: How to implement in-app purchases?

#8 Post by jack_norton »

Ah OK good, I didn't read the docs yet so assumed worked like in my games. Better then :)
follow me on Image Image Image
computer games

User avatar
storykween
Regular
Posts: 154
Joined: Mon Sep 30, 2013 1:17 pm
Completed: Serafina's Saga, Quantum Conscience, Echoes of the Fey, miraclr - Divine Dating Sim
Organization: Woodsy Studio
Location: St Louis
Contact:

Re: How to implement in-app purchases?

#9 Post by storykween »

(Accidentally posted this reply to the wrong page first, sorry about that)

Well, I am mostly getting the IAP system to work so far! There still seem to be a few issues, though. Most importantly, even though a player can successfully choose to buy an in-app purchase to keep playing the game, the game crashes after pulling up the Google Play store. Mind you, the purchase DOES go through, but you have to force-quit the game and bring it up again to resume the app.

Here's my code as it stands right now.

Code: Select all

init:
    define samplename = iap.register(
        product = "samplename",
        identifier = "com.ws.qc.productname",
        google = "productname",
    ) 
Later in the game, the player gets bounced back if they haven't purchased the full game, using this code:

Code: Select all

    
label Chapter2:
    if iap.has_purchased("samplename"):
        jump Chapter2_Continued
    else:
        jump EndofDemo
and so if they haven't bought the full game...

Code: Select all

label EndofDemo:
   
    scene black with dissolve
    "{i}This is the end of the Quantum Conscience demo. If you would like to continue, please purchase the full game from Woodsy Studio.{/i}"
    menu:
        "Play the rest of the game!":
            $ iap.purchase("samplename")
        "I previously purchased this game on another device":
            $ iap.restore()
        "Stop playing here":
            pass
    "{i}Thank you for playing!{/i}"
    
    jump Chapter2

Unfortunately, the whole app crashes after the player purchases the full game. Not a great way to thank a new customer :? I'm going to add a chance to save before prompting the in-app purchase, and warn the player that they might need to restart the app. Any other tips would be welcome! And thanks @PyTom for all you've done to help make this possible!
Image
My website: woodsy-studio.com

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: How to implement in-app purchases?

#10 Post by PyTom »

Do you have a screenshot of the crash? This code hasn't been well tested.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
storykween
Regular
Posts: 154
Joined: Mon Sep 30, 2013 1:17 pm
Completed: Serafina's Saga, Quantum Conscience, Echoes of the Fey, miraclr - Divine Dating Sim
Organization: Woodsy Studio
Location: St Louis
Contact:

Re: How to implement in-app purchases?

#11 Post by storykween »

There's not much to see; it totally freezes, and tapping on anything achieves nothing, you can't even back out using phone buttons. Eventually, on my phone, I get this message:

Image

... and only then can I force it to close.
Image
My website: woodsy-studio.com

User avatar
jack_norton
Lemma-Class Veteran
Posts: 4084
Joined: Mon Jul 21, 2008 5:41 pm
Completed: Too many! See my homepage
Projects: A lot! See www.winterwolves.com
Tumblr: winterwolvesgames
Contact:

Re: How to implement in-app purchases?

#12 Post by jack_norton »

I had some users report that behavior, however on my devices always worked fine so was unable to find the problem.
follow me on Image Image Image
computer games

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: How to implement in-app purchases?

#13 Post by PyTom »

Can you send me the .apk?

I want to see if it fails on my device.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

User avatar
storykween
Regular
Posts: 154
Joined: Mon Sep 30, 2013 1:17 pm
Completed: Serafina's Saga, Quantum Conscience, Echoes of the Fey, miraclr - Divine Dating Sim
Organization: Woodsy Studio
Location: St Louis
Contact:

Re: How to implement in-app purchases?

#14 Post by storykween »

I sent you a PM!
Image
My website: woodsy-studio.com

san2aleron
Newbie
Posts: 8
Joined: Fri Nov 23, 2012 2:14 am
Contact:

Re: How to implement in-app purchases?

#15 Post by san2aleron »

The In-App Purchase feature is not working... I can't use In-App Purchase on my game. The game status always ALREADY PURCHASED. So, they not must pay to play the full version of my game. This is my code:

############################################################

On Options.rpy:

build.google_play_key = "mykey"
build.google_play_salt = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19)

init:
define purchase1 = iap.register(
product = "purchase1",
identifier = "com.mycompany.mygame.ag001b",
google = "My Game Title",
)

############################################################

On Script.rpy:

#after label start:

screen purchase_imagemap:
imagemap:
ground "Button/PurchaseIdle.png"
hover "Button/PurchaseHover.png"

hotspot (20, 345, 180, 50) clicked Return("purchase_app")
hotspot (260, 345, 100, 50) clicked Return("quit_app")
hotspot (60, 410, 300, 50) clicked Return("restore_app")

############################################################

#in game

label purchased_or_not:
if iap.has_purchased("purchase1"):
jump Chapter3a
else:
jump EndofDemo

label EndofDemo:

call screen purchase_imagemap

$ result = _return

if result == "purchase_app":
$ iap.purchase("purchase1")
elif result == "quit_app":
jump TheEnd
elif result == "restore_app":
$ iap.Restore()

scene BG Thank You
with Fade(0.5, 0.0, 0.5)
pause

jump Chapter3a

Post Reply

Who is online

Users browsing this forum: DewyNebula