Ejemplo n.º 1
0
 /// <summary>
 /// Initialise Unibill.
 /// Before calling this method, ensure you have subscribed to onBillerReady to
 /// ensure you receive Unibill's initialisation response.
 /// This method should be called once as soon as your Application launches.
 ///
 /// runtimeProducts is an optional parameter that allows you to tell Unibill about additional
 /// products to those defined in your inventory.
 ///
 /// You can opt to use runtimeProducts exclusively if you choose.
 /// </summary>
 public static void Initialise(List <ProductDefinition> runtimeProducts = null)
 {
     if (Unibiller.biller == null)
     {
         var mgr    = new RemoteConfigManager(new UnityResourceLoader(), new UnityPlayerPrefsStorage(), new UnityLogger(), UnityEngine.Application.platform, runtimeProducts);
         var config = mgr.Config;
         var o      = new GameObject();
         UnityEngine.Object.DontDestroyOnLoad(o);
         var util    = o.AddComponent <UnityUtil> ();
         var factory = new BillerFactory(new UnityResourceLoader(), new UnityLogger(), new UnityPlayerPrefsStorage(), new RawBillingPlatformProvider(config), config, util);
         Unibiller.biller = factory.instantiate();
         _internal_hook_events(Unibiller.biller, factory);
     }
     biller.Initialise();
 }
Ejemplo n.º 2
0
    /// <summary>
    /// Visible only for unit testing.
    /// Do NOT call this method.
    /// </summary>
    public static void _internal_hook_events(Biller biller, BillerFactory factory)
    {
        biller.onBillerReady += (success) => {
            if (onBillerReady != null)
            {
                if (success)
                {
                    onBillerReady(biller.State == Unibill.Impl.BillerState.INITIALISED ? UnibillState.SUCCESS : UnibillState.SUCCESS_WITH_ERRORS);
                }
                else
                {
                    onBillerReady(UnibillState.CRITICAL_ERROR);
                }
            }
        };

        biller.onPurchaseComplete     += _onPurchaseComplete;
        biller.onPurchaseFailed       += _onPurchaseFailed;
        biller.onPurchaseDeferred     += _onPurchaseDeferred;
        biller.onPurchaseRefunded     += _onPurchaseRefunded;
        biller.onTransactionsRestored += _onTransactionsRestored;
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Visible only for unit testing.
    /// Do NOT call this method.
    /// </summary>
    public static void _internal_hook_events(Biller biller, BillerFactory factory)
    {
        biller.onBillerReady += (success) => {
            if (onBillerReady != null)
            {
                if (success)
                {
                    #if !(UNITY_WP8 || UNITY_METRO || UNITY_WEBPLAYER)
                    // Download manager needs Unibill to be initialised to get purchase receipts.
                    downloadManager = factory.instantiateDownloadManager(biller);
                    downloadManager.onDownloadCompletedEvent += (item, path) => {
                        if (null != onDownloadCompletedEvent)
                        {
                            onDownloadCompletedEvent(item, new DirectoryInfo(path));
                        }
                    };
                    downloadManager.onDownloadCompletedEvent  += onDownloadCompletedEventString;
                    downloadManager.onDownloadFailedEvent     += onDownloadFailedEvent;
                    downloadManager.onDownloadProgressedEvent += onDownloadProgressedEvent;
                    #else
                    onDownloadCompletedEventString += (x, y) => { };
                    #endif
                    onBillerReady(biller.State == Unibill.Impl.BillerState.INITIALISED ? UnibillState.SUCCESS : UnibillState.SUCCESS_WITH_ERRORS);
                }
                else
                {
                    onBillerReady(UnibillState.CRITICAL_ERROR);
                }
            }
        };

        biller.onPurchaseCancelled    += _onPurchaseCancelled;
        biller.onPurchaseComplete     += _onPurchaseComplete;
        biller.onPurchaseFailed       += _onPurchaseFailed;
        biller.onPurchaseDeferred     += _onPurchaseDeferred;
        biller.onPurchaseRefunded     += _onPurchaseRefunded;
        biller.onTransactionsRestored += _onTransactionsRestored;
    }