Select your preferred scripting language. All code snippets will be displayed in this language.
interface in UnityEngine.Purchasing.Extension
Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.
CloseFor some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.
CloseThe public interface of an underlying store system (e.g. Google Play or Apple App Store) typically exposed to Unity IAP extending its in-app purchasing platform support.
Unity IAP is extensible, supporting registration of store systems through IPurchasingModule
implementations shared with Unity IAP via a ConfigurationBuilder
during initialization.
A sample store class:
#pragma strict // Purchases always succeed at the sample store internal class SampleStore implements IStore { public const var Name: String = "samplestore"; private var m_Biller: IStoreCallback; private var m_PurchasedProducts: List.<String> = new List.<String>(); public function Initialize(biller: IStoreCallback) { m_Biller = biller; } public function RetrieveProducts(productDefinitions: ReadOnlyCollection.<ProductDefinition>) { var products = new List.<ProductDescription>(); for (var product in productDefinitions) { var metadata = new ProductMetadata("$123.45", "Fake title for " + product.id, "Fake description", "USD", 123.45m); products.Add(new ProductDescription(product.storeSpecificId, metadata)); } m_Biller.OnProductsRetrieved(products); } public function Purchase(product: ProductDefinition, developerPayload: String) { // Keep track of non consumables. if (product.type != ProductType.Consumable) { m_PurchasedProducts.Add(product.storeSpecificId); } m_Biller.OnPurchaseSucceeded(product.storeSpecificId, "{ \"this\" : \"is a fake receipt\" }", Guid.NewGuid().ToString()); } public function FinishTransaction(product: ProductDefinition, transactionId: String) { } }
using System; using System.Collections.ObjectModel; using System.Collections.Generic; using UnityEngine.Purchasing; using UnityEngine.Purchasing.Extension;
// Purchases always succeed at the sample store internal class SampleStore : IStore { public const string Name = "samplestore"; private IStoreCallback m_Biller; private List<string> m_PurchasedProducts = new List<string>();
public void Initialize(IStoreCallback biller) { m_Biller = biller; }
public void RetrieveProducts(ReadOnlyCollection<ProductDefinition> productDefinitions) { var products = new List<ProductDescription>(); foreach (var product in productDefinitions) { var metadata = new ProductMetadata("$123.45", "Fake title for " + product.id, "Fake description", "USD", 123.45m); products.Add(new ProductDescription(product.storeSpecificId, metadata)); } m_Biller.OnProductsRetrieved(products); }
public void Purchase(ProductDefinition product, string developerPayload) { // Keep track of non consumables. if (product.type != ProductType.Consumable) { m_PurchasedProducts.Add(product.storeSpecificId); } m_Biller.OnPurchaseSucceeded(product.storeSpecificId, "{ \"this\" : \"is a fake receipt\" }", Guid.NewGuid().ToString()); }
public void FinishTransaction(ProductDefinition product, string transactionId) { } }
FinishTransaction | Called by Unity IAP when a transaction has been recorded. |
Initialize | Initialize the store. |
Purchase | Handle a purchase request from a user. |
RetrieveProducts | Fetch the latest product metadata, including purchase receipts, asynchronously with results returned via IStoreCallback. |
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thanks for helping to make the Unity documentation better!