### Navigation

- index
- next |
- previous |
- Ren'Py Home |
- Ren'Py Documentation

# In-App Purchasing

Ren'Py includes a high-level in-app purchasing framework. This framework currently only supports unlock-style purchases from the Apple App Store, Google Play, and the Amazon App Store.

Using this framework is fairly simple, and consists of the following functions.

- In the init phase of your game, register available purchases using the `iap.register()` function.
- Once the game has started, check to see if a purchase has been purchased using the `iap.has_purchased()` function.
- Allow the user to purchase an item using the `iap.purchase()` function or the `iap.Purchase()` action.
- Allow the user to restore purchases bought on other devices using the `iap.restore()` function or the `iap.Restore()` action.

To offer in-app purchases, the purchases (including an associated price) must be set up on the various marketplaces. When building for android, Ren'Py will ask for the marketplace in use when configuring the package.

Apple App Store
  The Apple App Store is based on the package name, and does not require special configuration.
Google Play
  Before Google Play can be used, you must add the google play key and a salt to your project. See the Expansion APK section for information on how to do this.
Amazon App Store
  The Amazon app store is based on the package name, and does not require special configuration.

## IAP Functions

`iap.``get_price`(product)

  Returns a string giving the price of the product in the user's local currency. Returns None if the price of the product is unknown - which indicates the product cannot be purchased.

`iap.``get_store_name`()

  Returns the name of the enabled store for in-app purchase. This currently returns one of "amazon", "google", "ios" or None if no store is available.

`iap.``has_purchased`(product)

  Returns True if the user has purchased product in the past, and False otherwise.

`iap.``is_deferred`(product)

  Returns True if the user has asked to purchase product, but that request has to be approved by a third party, such as a parent or guardian.

`iap.``purchase`(product, interact=True)

  This function requests the purchase of product.

  It returns true if the purchase succeded, now or at any time in the past, and false otherwise.

`iap.``register`(product, identifier=None, amazon=None, google=None, ios=None)

  Registers a product with the in-app purchase system.

  product
    A string giving the high-level name of the product. This is the string that will be passed to `iap.purchase()`, `iap.Purchase()`, and `iap.has_purchased()` to represent this product.
  identifier

    A string that's used to identify the product internally. Once used to represent a product, this must never change. These strings are generall of the form "com.domain.game.product".

    If None, defaults to product.

  amazon
    A string that identifies the product in the Amazon app store. If not given, defaults to identifier.
  google
    A string that identifies the product in the Google Play store. If not given, defaults to identifier.
  ios
    A string that identifies the product in the Apple App store for iOS. If not given, defaults to identifier.

`iap.``restore`(interact=True)

  Contacts the app store and restores any missing purchases.

  interact
    If True, renpy.pause will be called while waiting for the app store to respond.

## IAP Actions

`iap.``Purchase`(product)

  An action that attempts the purchase of product. This action is sensitive iff and only if the product is purchasable (a store is enabled, and the product has not already been purchased.)

`iap.``Restore`()

  An Action that contacts the app store and restores any missing purchases.

### Navigation

- index
- next |
- previous |
- Ren'Py Home |
- Ren'Py Documentation