Ejemplo n.º 1
0
        public static bool StartBillingService(ServerConfig cfg, int replacePort, string token)
        {
            Common.WriteLine("StartEnquiryServer", new string[0]);
            ServicesAPI._billingHandler = new BillingHandler();
            ServicesAPI._billingHandler.Start(true);
            ServerConfig serverConfig = cfg;

            if (cfg == null)
            {
                serverConfig            = new ServerConfig();
                serverConfig.ssl        = false;
                serverConfig.MaxListen  = 100;
                serverConfig.BufferSize = 4096;
                serverConfig.Protocol   = ecoServerProtocol.ServerTypes.TCP;
                serverConfig.serverName = "Billing Server";
                serverConfig.port       = 8888;
                serverConfig.MaxConnect = 3000;
                if (replacePort > 0)
                {
                    serverConfig.port = replacePort;
                }
                serverConfig.tokenList = "12345678";
                if (token != null && token != string.Empty)
                {
                    serverConfig.tokenList = token;
                }
            }
            if (serverConfig.Protocol == ecoServerProtocol.ServerTypes.TCP)
            {
                ServicesAPI._billingService = new BaseTCPServer <BillingContext, BillingHandler>(serverConfig);
                if (ServicesAPI._billingService != null)
                {
                    ServicesAPI._billingService.setAuthorizedString(true, serverConfig.tokenList);
                    if (ServicesAPI._billingService.Start(ServicesAPI._billingHandler, -1))
                    {
                        Common.WriteLine("Billing Listener is started successfully, port=" + serverConfig.port, new string[0]);
                        return(true);
                    }
                }
                Common.WriteLine("Failed to start Billing Listener, port=" + serverConfig.port, new string[0]);
                return(false);
            }
            throw new InvalidOperationException("Protocol not supported.");
        }
Ejemplo n.º 2
0
        private async void ServiceConnection_OnConnected()
        {
            // Subscribe to event where the billing handler could be wrong
            BillingHandler = ServiceConnection.BillingHandler;
            BillingHandler.InAppBillingProcesingError += BillingHandler_InAppBillingProcesingError;
            BillingHandler.QueryInventoryError        += BillingHandler_QueryInventoryError;
            BillingHandler.OnPurchaseConsumed         += BillingHandler_OnPurchaseConsumed;

            // Get the list of product from the playstore
            LsProducts = await BillingHandler.QueryInventoryAsync(new string[]
            {
                "observation_pack"
                , "discovery_pack"
                , "exploration_pack"
                , "adventure_pack"
                , "epic_pack"
            }, ItemType.Product);

            // Initalize the view with the values from the playstore
            if (LsProducts?.Count > 0)
            {
                InitializeObservationLayout();
                InitializeDiscoveryLayout();
                InitializeExplorationLayout();
                InitializeAdventureLayout();
                InitializeEpicLayout();
                LoadingLayout.Visibility = ViewStates.Gone;
            }
            else
            {
                await App.Locator.ReloadCredit.ShowMessage(
                    Resources.GetString(Resource.String.packOnGetProductsError)
                    , Resources.GetString(Resource.String.packOnErrorTitle));

                Finish();
            }
        }
Ejemplo n.º 3
0
 public static void StopBillingService()
 {
     try
     {
         Common.WriteLine("StopBillingService", new string[0]);
         if (ServicesAPI._billingHandler != null)
         {
             ServicesAPI._billingHandler.Stop();
         }
         ServicesAPI._billingHandler = null;
         if (ServicesAPI._billingService != null)
         {
             ServicesAPI._billingService.Stop();
         }
         ServicesAPI._billingService = null;
     }
     catch (Exception ex)
     {
         Common.WriteLine("StopBillingService: {0}", new string[]
         {
             ex.Message
         });
     }
 }
Ejemplo n.º 4
0
 private void OnClickBuyEpicPack(object sender, EventArgs args)
 {
     BillingHandler.BuyProduct(LsProducts.FirstOrDefault(el => el.ProductId == "epic_pack"));
 }
Ejemplo n.º 5
0
        protected async override void OnActivityResult(int requestCode, Result resultCode, Intent data)
        {
            Log.Info("Seekios", "requestCode: " + resultCode + " resultCode: " + resultCode + " data: " + data.GetReponseCodeFromIntent());

            // Get data from the callback
            BillingHandler.HandleActivityResult(requestCode, resultCode, data);
            var      inAppPurchaseData  = data.GetStringExtra(Response.InAppPurchaseData);
            var      inAppDataSignature = data.GetStringExtra(Response.InAppDataSignature);
            Purchase purchaseItem       = null;

            try
            {
                // Deserialize data
                purchaseItem = JsonConvert.DeserializeObject <Purchase>(inAppPurchaseData);

                if (purchaseItem == null)
                {
                    Log.Info("Seekios", "Error deserialize purchaseItem ! InAppPurchaseData: " + inAppPurchaseData + " InAppDataSignature: " + inAppDataSignature);
                    return;
                }
                else if (purchaseItem.ProductId.Contains("android.test.")) //this should disapear in production code
                {
                    Log.Info("Seekios", "Error productId contains android.test ! InAppPurchaseData: " + inAppPurchaseData + " InAppDataSignature: " + inAppDataSignature);
                    return;
                }
                else
                {
                    // Save the in app purchase in the database
                    Log.Info("Seekios", "Sucess deserialize purchaseItem ! InAppPurchaseData: " + inAppPurchaseData + " InAppDataSignature: " + inAppDataSignature);
                    var resultServer = await App.Locator.ReloadCredit.InsertPurchase(purchaseItem.ProductId
                                                                                     , inAppPurchaseData
                                                                                     , inAppDataSignature
                                                                                     , PlateformeVersionEnum.Android);

                    Log.Info("Seekios", "resultServer: " + resultServer);
                    if (resultServer == 1)
                    {
                        // Consume all the purchases
                        Log.Info("Seekios", "The InsertPurchases succed ! resultServer" + resultServer);
                        var purchases = BillingHandler.GetPurchases(ItemType.Product);
                        if (purchases?.Count > 0)
                        {
                            foreach (var purchase in purchases)
                            {
                                BillingHandler.ConsumePurchase(purchase);
                                Log.Info("Seekios", "Consume purchase ! productId: " + purchase.ProductId);
                            }
                        }
                        else
                        {
                            Log.Info("Seekios", "No purchase(s) to consume");
                        }
                    }
                    else
                    {
                        OnWebservicesError(resultServer.ToString());
                    }
                }
            }
            catch (Exception) { /*OnError();*/ }
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            BillingHandler handler = new BillingHandler();

            //handler.Add( new Terminal(Guid.NewGuid(), "101"));
            //var client2 = new Client(){Id = Guid.NewGuid(), FullName = "Петя Огурцов"};
            //handler.Add( client2);
            //handler.Add( new Contract()
            //{
            //    Id = Guid.NewGuid(),
            //    ContractStartDate = new DateTime(2016, 7, 1),
            //    ContractCloseDate=null,
            //    Client = client2,
            //    Terminal = handler.GetTerminals(x=>x.TerminalNumber=="101").FirstOrDefault()
            //});

            //var plan = handler.GetBillingPlans().FirstOrDefault();

            //handler.Add(new ContractBillingPlanBinding()
            //{
            //    Id = Guid.NewGuid(),
            //    Contract = handler.GetContracts(x=>x.Terminal.TerminalNumber=="000-00-0").FirstOrDefault(),
            //    BindingDate = new DateTime(2016, 7, 1),
            //    BillingPlan = plan
            //});

            //handler.Add(new ContractBillingPlanBinding()
            //{
            //    Id = Guid.NewGuid(),
            //    Contract = handler.GetContracts(x=>x.Terminal.TerminalNumber=="101").FirstOrDefault(),
            //    BindingDate = new DateTime(2016, 7, 1),
            //    BillingPlan = plan
            //});

            //var info = new CallInfo()
            //{
            //    Id = Guid.NewGuid(),
            //    Source = handler.GetTerminals(x=>x.TerminalNumber =="000-00-0").FirstOrDefault() ,
            //    Target= handler.GetTerminals(x=>x.TerminalNumber =="101").FirstOrDefault(),
            //    Started = new DateTime(2016, 7, 2),
            //    Duration = new TimeSpan(0, 2, 15)
            //};
            //handler.CalculateCost(info);
            //handler.Add(info);

            //handler.Add(new Terminal(Guid.NewGuid(), "102"));
            //handler.Add(new Client() { Id = Guid.NewGuid(), FullName = "Шериф" });
            //handler.Add(new Contract()
            //{
            //    Id = Guid.NewGuid(),
            //    Terminal = handler.GetTerminals(x => x.TerminalNumber == "102").FirstOrDefault(),
            //    Client = handler.GetClients(x => x.FullName == "Шериф").FirstOrDefault(),
            //    ContractStartDate = new DateTime(2016, 7, 1),
            //    ContractCloseDate = null
            //});

            //handler.Add(new Terminal(Guid.NewGuid(), "103"));
            //handler.Add(new ContractBillingPlanBinding()
            //{
            //    Id = Guid.NewGuid(),
            //    BillingPlan = handler.GetBillingPlans().FirstOrDefault(),
            //    Contract = handler.GetContracts(x => x.Client.FullName == "Шериф").FirstOrDefault(),
            //    BindingDate = new DateTime(2016, 7, 1)
            //});

            //var c = handler.GetContracts(x => x.Client.FullName == "Шериф").FirstOrDefault() as Contract;
            //var p = handler.CloseContract(c, new DateTime(2016, 7, 2));

            var c = handler.GetContractBillingPalnBindings(x => true).FirstOrDefault();

            // new comment
            // comment
        }