示例#1
0
        public List <Charge> List()
        {
            //StripeConfiguration.SetApiKey(_config.GetSection("api_key").Value);

            var service = new ChargeService();

            var optionsl = new ChargeListOptions
            {
                Limit = 100,
            };
            var orders = service.List(optionsl);

            foreach (var order in orders)
            {
                var services = new ChargeService();
                var options  = new ChargeGetOptions();
                options.AddExpand("customer");
                options.AddExpand("order");
                var charge = service.Get(order.Id, options);
                order.Created        = charge.Created.Date;
                order.Amount         = charge.Amount;
                order.AmountRefunded = charge.AmountRefunded;
                if (order.Customer != null)
                {
                    if (charge.Customer.Email == "*****@*****.**")
                    {
                        charge.Customer.Email = "";
                    }
                }
            }
            return(orders.Data);
        }
        public JsonResult GetAllCharges()
        {
            var            service    = new ChargeService();
            var            collection = service.List();
            List <dynamic> resultData = new List <dynamic>();

            collection.Data.ForEach(a =>
            {
                try
                {
                    resultData.Add(new
                    {
                        Name        = a.Metadata.Where(p => p.Key == "MemberName").First().Value,
                        Service     = a.Metadata.Where(p => p.Key == "ServiceName").First().Value,
                        Amount      = a.Amount > 0 ? (a.Amount / 100) : 0,
                        Email       = a.ReceiptEmail,
                        Token       = a.Id,
                        Paid        = a.Paid,
                        Currency    = a.Currency,
                        Description = a.Description
                    });
                }
                catch (Exception ex) {
                }
            });
            return(new JsonResult()
            {
                Data = new { data = resultData },
                ContentType = "application/json",
                MaxJsonLength = Int32.MaxValue,
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
示例#3
0
        public IActionResult Get()
        {
            var options = new ChargeListOptions();
            var service = new ChargeService();
            var charges = service.List(options);

            return(View("ChargesHistory", charges.Data));
        }
示例#4
0
        private StripeList <Charge> GetCharges(string intent)
        {
            StripeConfiguration.ApiKey = _appKeys.StripeApiKey;

            var options = new ChargeListOptions {
                PaymentIntent = intent
            };
            var service = new ChargeService();
            StripeList <Charge> charges = service.List(
                options
                );

            return(charges);
        }
示例#5
0
        public static StripeList <Charge> GetListCharge(Transactions transactionModel)
        {
            // Set your secret key: remember to change this to your live secret key in production
            // See your keys here: https://dashboard.stripe.com/account/apikeys
            StripeConfiguration.SetApiKey(SecretKey);

            var service = new ChargeService();
            var options = new ChargeListOptions
            {
                Limit = 3,
            };
            var charges = service.List(options);

            return(charges);
        }
        public JsonResult Stripe(string order_id, string pi_id)
        {
            try
            {
                StripeConfiguration.ApiKey = "sk_test_4eC39HqLyjWDarjtT1zdp7dc";

                if (String.IsNullOrEmpty(pi_id))
                {
                    var options = new PaymentIntentCreateOptions
                    {
                        Amount   = 2000,
                        Currency = "usd",
                        //CaptureMethod = "manual",
                        PaymentMethodTypes = new List <string>
                        {
                            "card",
                        },
                        PaymentMethodOptions = new PaymentIntentPaymentMethodOptionsOptions
                        {
                            Card = new PaymentIntentPaymentMethodOptionsCardOptions
                            {
                                RequestThreeDSecure = "any"
                            }
                        },
                        ReceiptEmail = "*****@*****.**"
                    };
                    var service = new PaymentIntentService();
                    var create  = service.Create(options);

                    return(Json(new { status = "Success", response = create }));
                }
                else
                {
                    /*
                     * var service = new PaymentIntentService();
                     * var options = new PaymentIntentCaptureOptions
                     * {
                     *  //ReturnUrl = "https://example.com/return_url",
                     * };
                     * var intent = service.Capture(pi_id, options);
                     * return Json(new { status = "Success", response = intent });
                     */
                    var options = new ChargeListOptions {
                        Limit = 100, PaymentIntent = pi_id
                    };
                    var service = new ChargeService();
                    StripeList <Charge> charges = service.List(options);

                    return(Json(new { status = "Success", response = charges }));
                }
            }
            catch (StripeException se)
            {
                Response.StatusCode = (int)se.HttpStatusCode;
                return(Json(new
                {
                    status = "Failure",
                    code = se.HttpStatusCode,
                    message = se.Message,
                    data = se.Data,
                    error = se.StripeError,
                    response = se.StripeResponse
                }));
            }
        }
示例#7
0
        public Year Summary()
        {
            var year    = new Year();
            var service = new ChargeService();

            service.ExpandCustomer = false;
            service.ExpandOrder    = true;
            var options = new ChargeListOptions
            {
                Limit = 100,
            };
            var orders = service.List(options);

            foreach (var order in orders)
            {
                if (order.Created.Year == DateTime.Now.Year)
                {
                    switch (order.Created.Month)
                    {
                    case 1:
                        year.jan++;
                        break;

                    case 2:
                        year.feb++;
                        break;

                    case 3:
                        year.mar++;
                        break;

                    case 4:
                        year.apr++;
                        break;

                    case 5:
                        year.may++;
                        break;

                    case 6:
                        year.jun++;
                        break;

                    case 7:
                        year.jul++;
                        break;

                    case 8:
                        year.aug++;
                        break;

                    case 9:
                        year.sep++;
                        break;

                    case 10:
                        year.oct++;
                        break;

                    case 11:
                        year.nov++;
                        break;

                    case 12:
                        year.dec++;
                        break;

                    default:
                        Console.WriteLine("Other");
                        break;
                    }
                    year.totalOrders++;
                    year.yearTotal     += order.Amount;
                    year.refundedTotal += order.AmountRefunded;
                }
            }
            year.totalCustomers = _stripeCustomerService.Count();
            //ordersPerMonth = new int[]{0,12,40,50};
            return(year);
        }
示例#8
0
        public Sales Sales()
        {
            var year    = new Sales();
            var service = new ChargeService();

            service.ExpandCustomer = true;
            service.ExpandOrder    = true;
            var options = new ChargeListOptions
            {
                Limit = 100,
            };
            var orders = service.List(options);

            foreach (var order in orders)
            {
                if (order.Created.Year == DateTime.Now.Year)
                {
                    switch (order.Created.Month)
                    {
                    case 1:
                        year.jan += order.Amount;
                        break;

                    case 2:
                        year.feb += order.Amount;
                        break;

                    case 3:
                        year.mar += order.Amount;
                        break;

                    case 4:
                        year.apr += order.Amount;
                        break;

                    case 5:
                        year.may += order.Amount;
                        break;

                    case 6:
                        year.jun += order.Amount;
                        break;

                    case 7:
                        year.jul += order.Amount;
                        break;

                    case 8:
                        year.aug += order.Amount;
                        break;

                    case 9:
                        year.sep += order.Amount;
                        break;

                    case 10:
                        year.oct += order.Amount;
                        break;

                    case 11:
                        year.nov += order.Amount;
                        break;

                    case 12:
                        year.dec += order.Amount;
                        break;

                    default:
                        Console.WriteLine("Other");
                        break;
                    }
                }
                order.Created        = order.Created.Date;
                order.Amount         = order.Amount;
                order.AmountRefunded = order.AmountRefunded;
            }
            return(year);
        }
        private List <Payment> _ExportPayment(DateRangeOptions range)
        {
            var payments = new List <Payment>();

            try
            {
                var options = new PaymentIntentListOptions
                {
                    Limit   = 100,
                    Created = range,
                };
                var paymentIntentService = new PaymentIntentService();
                var transactionService   = new BalanceTransactionService();
                var customerService      = new CustomerService();
                var chargeService        = new ChargeService();

                StripeList <PaymentIntent> pis = paymentIntentService.List(options);

                for (int i = 0; i < pis.Data.Count; i++)
                {
                    var pi = pis.Data[i];

                    var payment = new Payment()
                    {
                        Description         = pi.Description,
                        Created             = pi.Created,
                        Amount              = Convert.ToDecimal(pi.Amount) / 100,
                        Currency            = pi.Currency,
                        Status              = pi.Status,
                        StatementDescriptor = pi.StatementDescriptor,
                        CustomerId          = pi.CustomerId,
                        CardId              = pi.PaymentMethodId,
                        InvoiceId           = pi.InvoiceId
                    };

                    if (pi.Charges.Data.Count > 0)
                    {
                        var charge = pi.Charges.Data[0];
                        try
                        {
                            charge.BalanceTransaction = transactionService.Get(charge.BalanceTransactionId);
                            payment.Id = charge.Id;
                            payment.ConvertedAmount   = Convert.ToDecimal(charge.BalanceTransaction.Amount) / 100;
                            payment.AmountRefunded    = Convert.ToDecimal(charge.AmountRefunded) / 100;
                            payment.Fee               = Convert.ToDecimal(charge.BalanceTransaction.Fee) / 100;
                            payment.ConvertedCurrency = charge.BalanceTransaction.Currency;
                            payment.Tax               = 0;
                            payment.Captured          = charge.Captured;
                            payment.Transfer          = charge.TransferId;
                            try
                            {
                                if (charge.Refunds.Data.Count > 0)
                                {
                                    var refundTx = transactionService.Get(charge.Refunds.Data[0].BalanceTransactionId);
                                    payment.ConvertedAmountRefunded = Convert.ToDecimal(refundTx.Amount) / 100;
                                }
                            }
                            catch (Exception) { }
                        }
                        catch (Exception) { }
                    }

                    try
                    {
                        pi.Customer = customerService.Get(pi.CustomerId);
                        payment.CustomerDescription = pi.Customer.Description;
                        payment.CustomerEmail       = pi.Customer.Email;
                    }
                    catch (Exception) { }


                    payment.Description = pi.Description;
                    payments.Add(payment);
                }

                var optionsC = new ChargeListOptions
                {
                    Limit   = 100,
                    Created = range,
                };
                StripeList <Charge> chs = chargeService.List(optionsC);
                for (int i = 0; i < chs.Data.Count; i++)
                {
                    var ch = chs.Data[i];
                    if (FindPayment(payments, ch.Id))
                    {
                        continue;
                    }

                    var payment = new Payment()
                    {
                        Id                  = ch.Id,
                        Description         = ch.Description,
                        Created             = ch.Created,
                        Amount              = Convert.ToDecimal(ch.Amount) / 100,
                        Currency            = ch.Currency,
                        Status              = ch.Status,
                        StatementDescriptor = ch.StatementDescriptor,
                        CustomerId          = ch.CustomerId,
                        Captured            = ch.Captured,
                        CardId              = ch.PaymentMethod,
                        InvoiceId           = ch.InvoiceId,
                        Transfer            = ch.TransferId
                    };
                    try
                    {
                        ch.BalanceTransaction     = transactionService.Get(ch.BalanceTransactionId);
                        payment.ConvertedAmount   = Convert.ToDecimal(ch.BalanceTransaction.Amount) / 100;
                        payment.AmountRefunded    = Convert.ToDecimal(ch.AmountRefunded) / 100;
                        payment.Fee               = Convert.ToDecimal(ch.BalanceTransaction.Fee) / 100;
                        payment.ConvertedCurrency = ch.BalanceTransaction.Currency;
                        payment.Tax               = 0;
                    }
                    catch (Exception) { }
                    try
                    {
                        ch.Customer = customerService.Get(ch.CustomerId);
                        payment.CustomerDescription = ch.Customer.Description;
                        payment.CustomerEmail       = ch.Customer.Email;
                    }
                    catch (Exception) { }

                    payments.Add(payment);
                }
            }
            catch (Exception) { }

            payments.Sort(
                delegate(Payment a, Payment b)
            {
                return(b.Created.CompareTo(a.Created));
            }
                );
            return(payments);
        }