{"id":18750741,"url":"https://github.com/cafebazaar/unityiap","last_synced_at":"2025-11-26T21:30:15.350Z","repository":{"id":14507691,"uuid":"17221176","full_name":"cafebazaar/UnityIAP","owner":"cafebazaar","description":"A plugin for Unity to use Bazaar in-app purchase in Android","archived":false,"fork":false,"pushed_at":"2019-06-08T06:35:00.000Z","size":7,"stargazers_count":1,"open_issues_count":1,"forks_count":1,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-12-28T22:54:50.578Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cafebazaar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-02-26T18:50:32.000Z","updated_at":"2020-06-17T07:51:43.000Z","dependencies_parsed_at":"2022-07-22T03:02:08.340Z","dependency_job_id":null,"html_url":"https://github.com/cafebazaar/UnityIAP","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cafebazaar%2FUnityIAP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cafebazaar%2FUnityIAP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cafebazaar%2FUnityIAP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cafebazaar%2FUnityIAP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cafebazaar","download_url":"https://codeload.github.com/cafebazaar/UnityIAP/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239636387,"owners_count":19672342,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T17:12:56.704Z","updated_at":"2025-11-26T21:30:15.303Z","avatar_url":"https://github.com/cafebazaar.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003carticle class=\"markdown-body entry-content\" itemprop=\"mainContentOfPage\"\u003e\n  \u003ch2\u003eBazaar In-app Billing for Unity3d\u003c/h2\u003e\n  \u003cp\u003e\u003cem\u003eIn order to provide Iab for Unity3d, Bazaar used \u003ca href=\"http://soom.la\"\u003eSOOMLA\u003c/a\u003e which is the first store creation platform for mobile games. SOOMLA   helps you to easily create your in-game economy and storefront. You can check SOOMLA's github  \u003ca href=\"https://github.com/soomla/unity3d-store\"\u003e (here\u003c/a\u003e) for more information.\u003c/em\u003e\u003c/p\u003e\n  \u003ch2\u003e\u003ca name=\"getting-started\" class=\"anchor\" href=\"#getting-started\"\u003e\u003cspan class=\"octicon octicon-link\"\u003e\u003c/span\u003e\u003c/a\u003eGetting Started\u003c/h2\u003e\u003col\u003e\n    \u003cli\u003eDownload  Bazaar unitypackage file here and double-click on it. It'll import all the necessary files into your project.\u003c/li\u003e\u003cli\u003eDrag the \"StoreEvents\" Prefab from \u003ccode\u003e../Assets/Soomla/Prefabs\u003c/code\u003e into your scene. You should see it listed in the \"Hierarchy\" panel.\u003c/li\u003e\u003cli\u003eOn the menu bar click \"Soomla -\u0026gt; Edit Settings\" and change the values for \"Custom Secret\", \"Public Key\" and \"Soom Sec\":\n\n\u003cul\u003e\u003cli\u003e\u003cem\u003eCustom Secret\u003c/em\u003e - is an encryption secret you provide that will be used to secure your data.\u003c/li\u003e\n\u003cli\u003e\u003cem\u003ePublic Key\u003c/em\u003e - is the public key given to you from \u003ca href=\"http://pardakht.cafebazaar.ir/panel/?l=en\"\u003eBazaar\u003c/a\u003e. (iOS doesn't have a public key).\u003c/li\u003e\u003cli\u003e\u003cem\u003eSoom Sec\u003c/em\u003e - is a special secret SOOMLA uses to increase your data protection.\u003cbr\u003e\u003cstrong\u003eChoose both secrets wisely. You can't change them after you launch your game!\u003c/strong\u003e\u003c/li\u003e\u003c/ul\u003e\u003c/li\u003e\u003cli\u003e\u003cp\u003eCreate your own implementation of \u003cem\u003eIStoreAssets\u003c/em\u003e in order to describe your specific game's assets (\u003ca href=\"https://github.com/soomla/unity3d-store/blob/master/unity4.0/Assets/Examples/MuffinRush/MuffinRushAssets.cs\"\u003eexample\u003c/a\u003e). Initialize \u003cem\u003eStoreController\u003c/em\u003e with the class you just created:\u003c/p\u003e\u003cdiv class=\"highlight highlight-cs\"\u003e\u003cpre\u003e\u003cspan class=\"n\"\u003eStoreController\u003c/span\u003e\u003cspan class=\"p\"\u003e.\u003c/span\u003e\u003cspan class=\"n\"\u003eInitialize\u003c/span\u003e\u003cspan class=\"p\"\u003e(\u003c/span\u003e\u003cspan class=\"k\"\u003enew\u003c/span\u003e\u003cspan class=\"n\"\u003eYourStoreAssetsImplementation\u003c/span\u003e\u003cspan class=\"p\"\u003e());\u003c/span\u003e\u003c/pre\u003e\u003c/div\u003e\u003cblockquote\u003e\u003cp style=\"font-size:14px\"\u003eInitialize \u003cem\u003eStoreController\u003c/em\u003e ONLY ONCE when your application loads.\u003c/p\u003e\u003cp style=\"font-size:14px\"\u003eInitialize \u003cem\u003eStoreController\u003c/em\u003e in the \"Start()\" function of a 'MonoBehaviour' and \u003cstrong\u003eNOT\u003c/strong\u003e in the \"Awake()\" function. SOOMLA has its own 'MonoBehaviour' and it needs to be \"Awakened\" before you initialize.\u003c/p\u003e\u003c/blockquote\u003e\u003c/li\u003e\u003cli\u003e\u003cp\u003eYou'll need an event handler in order to be notified about in-app purchasing related events. refer to the \u003ca href=\"#event-handling\"\u003eEvent Handling\u003c/a\u003e section for more information.\u003c/p\u003e\u003c/li\u003e\u003c/ol\u003e\u003cp\u003eAnd that's it ! You have storage and in-app purchasing capabilities... ALL-IN-ONE.\u003c/p\u003e\u003ch3\u003e\u003ca name=\"unity--android\" class=\"anchor\" href=\"#unity--android\"\u003e\u003cspan class=\"octicon octicon-link\"\u003e\u003c/span\u003e\u003c/a\u003eUnity \u0026amp; Android\u003c/h3\u003e\u003ch4\u003e\u003ca name=\"starting-iab-service-in-background\" class=\"anchor\" href=\"#starting-iab-service-in-background\"\u003e\u003cspan class=\"octicon octicon-link\"\u003e\u003c/span\u003e\u003c/a\u003eStarting IAB Service in background\u003c/h4\u003e\u003cp\u003eIf you have your own storefront implemented inside your game, it's recommended that you open the IAB Service in the background when the store opens and close it when the store is closed.\u003c/p\u003e\u003cdiv class=\"highlight highlight-cs\"\u003e\u003cpre\u003e\u003cspan class=\"c1\"\u003e// Start Iab Service\u003c/span\u003e\u003cspan class=\"n\"\u003eStoreController\u003c/span\u003e\u003cspan class=\"p\"\u003e.\u003c/span\u003e\u003cspan class=\"n\"\u003eStartIabServiceInBg\u003c/span\u003e\u003cspan class=\"p\"\u003e();\u003c/span\u003e\u003cspan class=\"c1\"\u003e// Stop Iab Service\u003c/span\u003e\u003cspan class=\"n\"\u003eStoreController\u003c/span\u003e\u003cspan class=\"p\"\u003e.\u003c/span\u003e\u003cspan class=\"n\"\u003eStopIabServiceInBg\u003c/span\u003e\u003cspan class=\"p\"\u003e();\u003c/span\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003eDon't forget to close the Iab Service when your store is closed. You don't have to do this at all, this is just an optimization.\u003c/p\u003e\u003ch2\u003e\u003ca name=\"whats-next-in-app-purchasing\" class=\"anchor\" href=\"#whats-next-in-app-purchasing\"\u003e\u003cspan class=\"octicon octicon-link\"\u003e\u003c/span\u003e\u003c/a\u003eWhat's next? In App Purchasing.\u003c/h2\u003e\n\u003cp\u003eSoomla  designed the new modelV3 to support 2 ways you can let your users purchase stuff in your game: PurchaseWithMarket and PurchaseWithVirtualItem.\u003c/p\u003e\u003cp\u003e\u003cstrong\u003ePurchaseWithMarket\u003c/strong\u003e is a PurchaseType that allows users to purchase a VirtualItem with Google Play or the App Store.\u003cbr\u003e\u003cstrong\u003ePurchaseWithVirtualItem\u003c/strong\u003e is a PurchaseType that lets your users purchase a VirtualItem with a different VirtualItem. For Example: Buying 1 Sword with 100 Gems.\u003c/p\u003e\u003cp\u003eIn order to define the way your various virtual items (Goods, Coins ...) are purchased, you'll need to create your implementation of IStoreAsset (the same one from step 4 in the \"Getting Started\" above).\u003c/p\u003e\u003cp\u003eHere is an example:\u003c/p\u003e\u003cp\u003eLets say you have a \u003cem\u003eVirtualCurrencyPack\u003c/em\u003e you call \u003ccode\u003eTEN_COINS_PACK\u003c/code\u003e and a \u003cem\u003eVirtualCurrency\u003c/em\u003e you call \u003ccode\u003eCOIN_CURRENCY\u003c/code\u003e:\u003c/p\u003e\u003cdiv class=\"highlight highlight-cs\"\u003e\u003cpre\u003e\u003cspan class=\"n\"\u003eVirtualCurrencyPack\u003c/span\u003e\u003cspan class=\"n\"\u003eTEN_COINS_PACK\u003c/span\u003e\u003cspan class=\"p\"\u003e=\u003c/span\u003e\u003cspan class=\"k\"\u003enew\u003c/span\u003e\u003cspan class=\"n\"\u003eVirtualCurrencyPack\u003c/span\u003e\u003cspan class=\"p\"\u003e(\u003c/span\u003e\u003cspan class=\"s\"\u003e\"10 Coins\"\u003c/span\u003e\u003cspan class=\"p\"\u003e,\u003c/span\u003e\u003cspan class=\"c1\"\u003e// name\u003c/span\u003e\u003cspan class=\"s\"\u003e\"A pack of 10 coins\"\u003c/span\u003e\u003cspan class=\"p\"\u003e,\u003c/span\u003e\u003cspan class=\"c1\"\u003e// description\u003c/span\u003e\u003cspan class=\"s\"\u003e\"10_coins\"\u003c/span\u003e\u003cspan class=\"p\"\u003e,\u003c/span\u003e\u003cspan class=\"c1\"\u003e// item id\u003c/span\u003e\u003cspan class=\"m\"\u003e10\u003c/span\u003e\u003cspan class=\"p\"\u003e,\u003c/span\u003e\u003cspan class=\"c1\"\u003e// number of currencies in the pack\u003c/span\u003e\u003cspan class=\"n\"\u003eCOIN_CURRENCY_ITEM_ID\u003c/span\u003e\u003cspan class=\"p\"\u003e,\u003c/span\u003e\u003cspan class=\"c1\"\u003e// the currency associated with this pack\u003c/span\u003e\u003cspan class=\"k\"\u003enew\u003c/span\u003e\u003cspan class=\"nf\"\u003ePurchaseWithMarket\u003c/span\u003e\u003cspan class=\"p\"\u003e(\u003c/span\u003e\u003cspan class=\"s\"\u003e\"com.soomla.ten_coin_pack\"\u003c/span\u003e\u003cspan class=\"p\"\u003e,\u003c/span\u003e\u003cspan class=\"m\"\u003e1.99\u003c/span\u003e\u003cspan class=\"p\"\u003e)\u003c/span\u003e\u003cspan class=\"p\"\u003e);\u003c/span\u003e\u003c/pre\u003e\u003c/div\u003e\u003cp\u003eNow you can use \u003cem\u003eStoreInventory\u003c/em\u003e to buy your new VirtualCurrencyPack:\u003c/p\u003e\u003cdiv class=\"highlight highlight-cs\"\u003e\u003cpre\u003e\u003cspan class=\"n\"\u003eStoreInventory\u003c/span\u003e\u003cspan class=\"p\"\u003e.\u003c/span\u003e\u003cspan class=\"n\"\u003ebuyItem\u003c/span\u003e\u003cspan class=\"p\"\u003e(\u003c/span\u003e\u003cspan class=\"n\"\u003eTEN_COINS_PACK\u003c/span\u003e\u003cspan class=\"p\"\u003e.\u003c/span\u003e\u003cspan class=\"n\"\u003eItemId\u003c/span\u003e\u003cspan class=\"p\"\u003e);\u003c/span\u003e\u003c/pre\u003e\u003c/div\u003e\n\u003cp\u003eAnd that's it! SOOMLA knows how to contact Bazaar  and will redirect your users to their purchasing system to complete the transaction. Don't forget to subscribe to store events in order to get the notified of successful or failed purchases (see \u003ca href=\"#event-handling\"\u003eEvent Handling\u003c/a\u003e).\u003c/p\u003e\u003ch2\u003e\u003ca name=\"storage--meta-data\" class=\"anchor\" href=\"#storage--meta-data\"\u003e\u003cspan class=\"octicon octicon-link\"\u003e\u003c/span\u003e\u003c/a\u003eStorage \u0026amp; Meta-Data\u003c/h2\u003e\u003cp\u003eWhen you initialize \u003cem\u003eStoreController\u003c/em\u003e, it automatically initializes two other classes: \u003cem\u003eStoreInventory\u003c/em\u003e and \u003cem\u003eStoreInfo\u003c/em\u003e:  \u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003cem\u003eStoreInventory\u003c/em\u003e is a convenience class to let you perform operations on VirtualCurrencies and VirtualGoods. Use it to fetch/change the balances of VirtualItems in your game (using their ItemIds!)\u003cbr\u003e\u003c/li\u003e\u003cli\u003e\u003cem\u003eStoreInfo\u003c/em\u003e is where all meta data information about your specific game can be retrieved. It is initialized with your implementation of \u003ccode\u003eIStoreAssets\u003c/code\u003e and you can use it to retrieve information about your specific game.\u003c/li\u003e\u003c/ul\u003e\n\u003cp\u003e\u003cstrong\u003eATTENTION: because SOOMLA is using JNI (Android)  you should make as little calls as possible to \u003cem\u003eStoreInfo\u003c/em\u003e. Look in the example project for the way SOOMLA created a sort of a cache to hold your game's information in order to not make too many calls to \u003cem\u003eStoreInfo\u003c/em\u003e. SOOMLA updates this cache using an event handler. (see \u003ca href=\"https://github.com/soomla/unity3d-store/blob/master/unity4.0/Assets/Soomla/Code/ExampleLocalStoreInfo.cs\"\u003eExampleLocalStoreInfo\u003c/a\u003e and \u003ca href=\"https://github.com/soomla/unity3d-store/blob/master/unity4.0/Assets/Soomla/Code/ExampleEventHandler.cs\"\u003eExampleEventHandler\u003c/a\u003e).\u003c/strong\u003e\u003c/p\u003e\u003cp\u003e\u003cstrong\u003eExample Usages\u003c/strong\u003e\u003c/p\u003e\u003cul\u003e\u003cli\u003e\u003cp\u003eGet VirtualCurrency with itemId \"currency_coin\":\u003c/p\u003e\u003cdiv class=\"highlight highlight-cs\"\u003e\u003cpre\u003e\u003cspan class=\"n\"\u003eVirtualCurrency\u003c/span\u003e\u003cspan class=\"n\"\u003ecoin\u003c/span\u003e\u003cspan class=\"p\"\u003e=\u003c/span\u003e\u003cspan class=\"n\"\u003eStoreInfo\u003c/span\u003e\u003cspan class=\"p\"\u003e.\u003c/span\u003e\u003cspan class=\"n\"\u003eGetVirtualCurrencyByItemId\u003c/span\u003e\u003cspan class=\"p\"\u003e(\u003c/span\u003e\u003cspan class=\"s\"\u003e\"currency_coin\"\u003c/span\u003e\u003cspan class=\"p\"\u003e);\u003c/span\u003e\u003c/pre\u003e\u003c/div\u003e\u003c/li\u003e\u003cli\u003e\u003cp\u003eGive the user 10 pieces of a virtual currency with itemId \"currency_coin\":\u003c/p\u003e\u003cdiv class=\"highlight highlight-cs\"\u003e\u003cpre\u003e\u003cspan class=\"n\"\u003eStoreInventory\u003c/span\u003e\u003cspan class=\"p\"\u003e.\u003c/span\u003e\u003cspan class=\"n\"\u003eGiveItem\u003c/span\u003e\u003cspan class=\"p\"\u003e(\u003c/span\u003e\u003cspan class=\"s\"\u003e\"currency_coin\"\u003c/span\u003e\u003cspan class=\"p\"\u003e,\u003c/span\u003e\u003cspan class=\"m\"\u003e10\u003c/span\u003e\u003cspan class=\"p\"\u003e);\u003c/span\u003e\u003c/pre\u003e\u003c/div\u003e\u003c/li\u003e\u003cli\u003e\u003cp\u003eTake 10 virtual goods with itemId \"green_hat\":\u003c/p\u003e\u003cdiv class=\"highlight highlight-cs\"\u003e\u003cpre\u003e\u003cspan class=\"n\"\u003eStoreInventory\u003c/span\u003e\u003cspan class=\"p\"\u003e.\u003c/span\u003e\u003cspan class=\"n\"\u003eTakeItem\u003c/span\u003e\u003cspan class=\"p\"\u003e(\u003c/span\u003e\u003cspan class=\"s\"\u003e\"green_hat\"\u003c/span\u003e\u003cspan class=\"p\"\u003e,\u003c/span\u003e\u003cspan class=\"m\"\u003e10\u003c/span\u003e\u003cspan class=\"p\"\u003e);\u003c/span\u003e\u003c/pre\u003e\u003c/div\u003e\u003c/li\u003e\u003cli\u003e\u003cp\u003eGet the current balance of green hats (virtual goods with itemId \"green_hat\"):\u003c/p\u003e\u003cdiv class=\"highlight highlight-cs\"\u003e\u003cpre\u003e\u003cspan class=\"kt\"\u003eint\u003c/span\u003e\u003cspan class=\"n\"\u003egreenHatsBalance\u003c/span\u003e\u003cspan class=\"p\"\u003e=\u003c/span\u003e\u003cspan class=\"n\"\u003eStoreInventory\u003c/span\u003e\u003cspan class=\"p\"\u003e.\u003c/span\u003e\u003cspan class=\"n\"\u003eGetItemBalance\u003c/span\u003e\u003cspan class=\"p\"\u003e(\u003c/span\u003e\u003cspan class=\"s\"\u003e\"green_hat\"\u003c/span\u003e\u003cspan class=\"p\"\u003e);\u003c/span\u003e\u003c/pre\u003e\u003c/div\u003e\u003c/li\u003e\u003c/ul\u003e\u003ch2\u003e\u003ca name=\"event-handling\" class=\"anchor\" href=\"#event-handling\"\u003e\u003cspan class=\"octicon octicon-link\"\u003e\u003c/span\u003e\u003c/a\u003eEvent Handling\u003c/h2\u003e\u003cp\u003eSOOMLA lets you subscribe to store events, get notified and implement your own application specific behaviour to those events.\u003c/p\u003e\u003cblockquote\u003e\u003cp style=\"font-size:14px\"\u003eYour behaviour is an addition to the default behaviour implemented by SOOMLA. You don't replace SOOMLA's behaviour.\u003c/p\u003e\u003c/blockquote\u003e\u003cp\u003eThe 'Events' class is where all event go through. To handle various events, just add your specific behaviour to the delegates in the Events class.\u003c/p\u003e\u003cp\u003eFor example, if you want to 'listen' to a MerketPurchase event:\u003c/p\u003e\u003cdiv class=\"highlight highlight-cs\"\u003e\n\u003cpre\u003e\nEvents.OnMarketPurchase += onMarketPurchase;\n\npublic void onMarketPurchase(PurchasableVirtualItem pvi) {\n    Debug.Log(\"Going to purchase an item with productId: \" + pvi.ItemId);\n}\n\u003c/pre\u003e\n\u003c/div\u003e\u003c/article\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcafebazaar%2Funityiap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcafebazaar%2Funityiap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcafebazaar%2Funityiap/lists"}