Exemplo n.º 1
0
 public void Error(string message)
 {
     System.Console.WriteLine(message);
     try {
         FileController.AppendLineAs("errors", message);
     } catch (System.Exception)
     { }
 }
Exemplo n.º 2
0
        public override Task Execute(MessageData data)
        {
            var args = data.GetAs <Params>();
            OrdersGetRequest request = new OrdersGetRequest(args.OrderId);

            if (string.IsNullOrEmpty(clientId))
            {
                throw new CoflnetException("unavailable", "checkout via paypal has not yet been enabled, please contact an admin");
            }
            var client = new PayPalHttpClient(new LiveEnvironment(clientId, clientSecret));

            //3. Call PayPal to get the transaction
            PayPalHttp.HttpResponse response;
            try
            {
                response = client.Execute(request).Result;
            }
            catch (Exception e)
            {
                dev.Logger.Instance.Error(e, "payPalPayment");
                throw new CoflnetException("payment_failed", "The provided orderId has not vaid payment asociated");
            }
            //4. Save the transaction in your database. Implement logic to save transaction to your database for future reference.
            var result = response.Result <Order>();

            Console.WriteLine(JSON.Stringify(result));
            Console.WriteLine("Retrieved Order Status");
            Console.WriteLine("Status: {0}", result.Status);
            Console.WriteLine("Order Id: {0}", result.Id);
            AmountWithBreakdown amount = result.PurchaseUnits[0].AmountWithBreakdown;

            Console.WriteLine("Total Amount: {0} {1}", amount.CurrencyCode, amount.Value);
            if (result.Status != "COMPLETED")
            {
                throw new CoflnetException("order_incomplete", "The order is not yet completed");
            }

            if (UsedIds.Contains(args.OrderId))
            {
                throw new CoflnetException("payment_timeout", "the provied order id was already used");
            }

            if (DateTime.Parse(result.PurchaseUnits[0].Payments.Captures[0].UpdateTime) < DateTime.Now.Subtract(TimeSpan.FromHours(1)))
            {
                throw new CoflnetException("payment_timeout", "the provied order id is too old, please contact support for manual review");
            }
            var user          = data.User;
            var days          = args.Days;
            var transactionId = result.Id;

            UserService.Instance.SavePurchase(user, days, transactionId);



            UsedIds.Add(args.OrderId);
            FileController.AppendLineAs("purchases", JSON.Stringify(result));
            return(data.Ok());
        }
Exemplo n.º 3
0
        /// <summary>
        /// Save the specified data. Will drop the data if the receiver and sender are the same.
        /// </summary>
        /// <param name="commandData">Data to save.</param>
        public override void SaveMessage(CommandData commandData)
        {
            // messages to oneself won't be saved
            if (commandData.SenderId == commandData.Recipient)
            {
                return;
            }
            var serverData = commandData as ServerCommandData;

            if (serverData == null)
            {
                serverData = new ServerCommandData(commandData);
            }
            FileController.AppendLineAs <ServerCommandData>(PathToSource(commandData.Recipient), serverData);
        }
Exemplo n.º 4
0
 public void SaveMessage(LocalChatMessage message)
 {
     FileController.AppendLineAs <LocalChatMessage>(FileName(message.chatId, message.id.IdfromSource), message);
 }
Exemplo n.º 5
0
 public void Log(string message)
 {
     FileController.AppendLineAs("log", message);
 }