Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using Prime31;
- public class StoreController : MonoBehaviour {
- void OnEnable()
- {
- // Listen to all events for illustration purposes
- GoogleIABManager.billingSupportedEvent += billingSupportedEvent;
- GoogleIABManager.billingNotSupportedEvent += billingNotSupportedEvent;
- GoogleIABManager.queryInventorySucceededEvent += queryInventorySucceededEvent;
- GoogleIABManager.queryInventoryFailedEvent += queryInventoryFailedEvent;
- GoogleIABManager.purchaseCompleteAwaitingVerificationEvent += purchaseCompleteAwaitingVerificationEvent;
- GoogleIABManager.purchaseSucceededEvent += purchaseSucceededEvent;
- GoogleIABManager.purchaseFailedEvent += purchaseFailedEvent;
- GoogleIABManager.consumePurchaseSucceededEvent += consumePurchaseSucceededEvent;
- GoogleIABManager.consumePurchaseFailedEvent += consumePurchaseFailedEvent;
- }
- void OnDisable()
- {
- // Remove all event handlers
- GoogleIABManager.billingSupportedEvent -= billingSupportedEvent;
- GoogleIABManager.billingNotSupportedEvent -= billingNotSupportedEvent;
- GoogleIABManager.queryInventorySucceededEvent -= queryInventorySucceededEvent;
- GoogleIABManager.queryInventoryFailedEvent -= queryInventoryFailedEvent;
- GoogleIABManager.purchaseCompleteAwaitingVerificationEvent += purchaseCompleteAwaitingVerificationEvent;
- GoogleIABManager.purchaseSucceededEvent -= purchaseSucceededEvent;
- GoogleIABManager.purchaseFailedEvent -= purchaseFailedEvent;
- GoogleIABManager.consumePurchaseSucceededEvent -= consumePurchaseSucceededEvent;
- GoogleIABManager.consumePurchaseFailedEvent -= consumePurchaseFailedEvent;
- }
- public void init(){
- var key = "<my key>";
- GoogleIAB.init( key );
- }
- public void queryInventory(){
- // enter all the available skus from the Play Developer Console in this array so that item information can be fetched for them
- var skus = new string[] {
- "leap_issue_0",
- "leap_issue_1"
- };
- GoogleIAB.queryInventory( skus );
- }
- public bool areSubscriptionsSupported(){
- return GoogleIAB.areSubscriptionsSupported();
- }
- bool billingSupported;
- public bool isBillingSupported(){
- return billingSupported;
- }
- public void purchaseProduct(string productID){
- GoogleIAB.purchaseProduct(productID);
- }
- public void consumeProduct(string productID){
- GoogleIAB.consumeProduct (productID);
- }
- //Android IAB Events
- void billingSupportedEvent(){
- Debug.Log( "billingSupportedEvent" );
- billingSupported = true;
- }
- void billingNotSupportedEvent(string error){
- Debug.Log( "billingNotSupportedEvent: " + error );
- billingSupported = false;
- }
- public List<string> skuNames;
- public List<string> skuPrices;
- public List<string> skuDescriptions;
- void queryInventorySucceededEvent(List<GooglePurchase> purchases, List<GoogleSkuInfo> skus){
- //Clear sku stuff incase we queryInventory more than once
- skuNames.Clear ();
- skuPrices.Clear ();
- skuDescriptions.Clear ();
- //Store sku names for purchases and prices and descriptions so it can be added to labels etc
- for(int i = 0; i < skus.Count; i++){
- skuNames.Add(skus[i].productId);
- skuPrices.Add(skus[i].price);
- skuDescriptions.Add(skus[i].description);
- }
- //Find previous purchases and set them in playerprefs
- for (int i = 0; i < purchases.Count; i++) {
- PlayerPrefs.SetString(purchases[i].productId, "Purchased");
- Debug.Log(PlayerPrefs.GetString(purchases[i].productId));
- }
- Debug.Log( string.Format( "queryInventorySucceededEvent. total purchases: {0}, total skus: {1}", purchases.Count, skus.Count ) );
- //Debug purchases and skus
- Debug.Log ("purchases"+ "\n");
- for (int i = 0; i < purchases.Count; i++) {
- Debug.Log("Purchase ID: " + purchases[i].productId + "\n" +
- "Purchase State: " + purchases[i].purchaseState + "\n");
- }
- Debug.Log ("skus "+ "\n");
- for (int i = 0; i < skus.Count; i++) {
- Debug.Log("Sku Name: " + skuNames[i] + "\n" +
- "Sku Description: " + skuDescriptions[i] + "\n" +
- "Sku Price: " + skuPrices[i] + "\n");
- }
- }
- void queryInventoryFailedEvent(string error){
- Debug.Log( "queryInventoryFailedEvent: " + error );
- }
- void purchaseCompleteAwaitingVerificationEvent(string purchaseData, string signature){
- Debug.Log( "purchaseCompleteAwaitingVerificationEvent. purchaseData: " + purchaseData + ", signature: " + signature );
- }
- void purchaseSucceededEvent(GooglePurchase purchase){
- Debug.Log( "purchaseSucceededEvent: " + purchase );
- }
- void purchaseFailedEvent(string error){
- Debug.Log( "purchaseFailedEvent: " + error );
- }
- void consumePurchaseSucceededEvent(GooglePurchase purchase){
- Debug.Log( "consumePurchaseSucceededEvent: " + purchase );
- }
- void consumePurchaseFailedEvent(string error){
- Debug.Log( "consumePurchaseFailedEvent: " + error );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement