Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // (c) Copyright HutongGames, LLC 2010-2013. All rights reserved.
- using UnityEngine;
- using System.Collections.Generic;
- using Prime31;
- namespace HutongGames.PlayMaker.Actions
- {
- [ActionCategory("StoreKit")]
- [Tooltip("Make a purchase")]
- public class PurchaseProduct : FsmStateAction
- {
- [RequiredField]
- [Tooltip("product ID from iTunesConnect. MUST match exactly what you have there!")]
- public FsmString productIdentifier;
- [RequiredField]
- [Tooltip("How many of this product would you like to buy? Often 1. iOS Only")]
- public FsmInt quantity;
- [RequiredField]
- public FsmEvent purchaseFinished;
- public FsmEvent purchaseFailed;
- public FsmEvent purchaseCancelled;
- [Tooltip("If a error occurs where should it be stored")]
- public FsmString errorString;
- [Tooltip("Is this purchase a consumable? Only required for Android")]
- public FsmBool isAConsumable;
- [Tooltip("Is this purchase a subscription? Only Required for Android")]
- public FsmBool isASubscription;
- public override void OnEnter()
- {
- #if UNITY_IOS
- StoreKitManager.purchaseSuccessfulEvent += purchaseSuccessfulEvent;
- StoreKitManager.purchaseCancelledEvent += purchaseCancelledEvent;
- StoreKitManager.purchaseFailedEvent += purchaseFailedEvent;
- var products = StoreKitHelper.Instance.GetProducts();
- if( products != null && products.Count > 0 )
- {
- StoreKitBinding.purchaseProduct( productIdentifier.Value, quantity.Value );
- }
- else {
- errorString.Value = "No Products found. Make sure you request the products first";
- Fsm.Event(purchaseFailed);
- Finish();
- }
- #elif UNITY_ANDROID
- GoogleIABManager.purchaseSucceededEvent += purchaseSucceededEvent;
- GoogleIABManager.purchaseFailedEvent += purchaseFailedEvent;
- GoogleIABManager.consumePurchaseSucceededEvent += purchaseSucceededEvent;
- GoogleIABManager.consumePurchaseFailedEvent += purchaseFailedEvent;
- if(isASubscription.Value) {
- GoogleIAB.purchaseProduct( productIdentifier.Value, "THIS02983049IS098093ONE08MIGHTY92834PROFESSIONAL09283049PAYLOAD)(*&@" );
- }
- else {
- GoogleIAB.purchaseProduct( productIdentifier.Value, "THIS02983049IS098093ONE08MIGHTY92834PROFESSIONAL09283049PAYLOAD)(*&@" );
- }
- #else
- Finish();
- #endif
- }
- #if UNITY_IOS
- void purchaseFailedEvent( string error )
- {
- Debug.Log( "purchaseFailedEvent: " + error );
- errorString.Value = error;
- Fsm.Event(purchaseFailed);
- Finish();
- }
- void purchaseCancelledEvent( string error )
- {
- Debug.Log( "purchaseCancelledEvent: " + error );
- errorString.Value = error;
- Fsm.Event(purchaseCancelled);
- Finish();
- }
- void purchaseSuccessfulEvent( StoreKitTransaction transaction )
- {
- Debug.Log( "purchaseSuccessfulEvent: " + transaction );
- Fsm.Event(purchaseFinished);
- Finish();
- }
- public override void OnExit()
- {
- StoreKitManager.purchaseSuccessfulEvent -= purchaseSuccessfulEvent;
- StoreKitManager.purchaseCancelledEvent -= purchaseCancelledEvent;
- StoreKitManager.purchaseFailedEvent -= purchaseFailedEvent;
- }
- #elif UNITY_ANDROID
- void purchaseSucceededEvent( GooglePurchase purchase )
- {
- Debug.Log( "purchaseSuccessfulEvent: " + purchase );
- if(isAConsumable.Value) {
- GoogleIAB.consumeProduct( productIdentifier.Value );
- }
- Fsm.Event(purchaseFinished);
- Finish();
- }
- void purchaseFailedEvent( string error )
- {
- if (error.ToLower().Contains ("cancel")) {
- Debug.Log( "purchaseCancelledEvent: " + error );
- errorString.Value = error;
- Fsm.Event(purchaseCancelled);
- Finish();
- } else {
- Debug.Log( "purchaseFailedEvent: " + error );
- errorString.Value = error;
- Fsm.Event(purchaseFailed);
- Finish();
- }
- }
- public override void OnExit()
- {
- GoogleIABManager.purchaseSucceededEvent -= purchaseSucceededEvent;
- GoogleIABManager.purchaseFailedEvent -= purchaseFailedEvent;
- GoogleIABManager.consumePurchaseSucceededEvent -= purchaseSucceededEvent;
- GoogleIABManager.consumePurchaseFailedEvent -= purchaseFailedEvent;
- }
- #endif
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement