Exemple #1
0
        public payouts_fixture()
        {
            // make sure the account has sufficient funds first
            new StripeChargeService(Cache.ApiKey).Create(new StripeChargeCreateOptions
            {
                Amount     = 2000,
                Currency   = "usd",
                SourceCard = new SourceCard
                {
                    Number          = "4000000000000077",
                    ExpirationMonth = 10,
                    ExpirationYear  = 2019,
                    Cvc             = "123"
                }
            });

            PayoutCreateOptions = new StripePayoutCreateOptions
            {
                Amount   = 1000,
                Currency = "usd"
            };

            PayoutUpdateOptions = new StripePayoutUpdateOptions
            {
                Metadata = new Dictionary <string, string>()
                {
                    { "some-key", "some-value" }
                }
            };

            var service = new StripePayoutService(Cache.ApiKey);

            Payout          = service.Create(PayoutCreateOptions);
            PayoutUpdated   = service.Update(Payout.Id, PayoutUpdateOptions);
            PayoutRetrieved = service.Get(Payout.Id);

            PayoutListOptions = new StripePayoutListOptions
            {
                Created = new StripeDateFilter {
                    EqualTo = Payout.Created
                },
                ArrivalDate = new StripeDateFilter {
                    EqualTo = Payout.ArrivalDate
                }
            };

            PayoutList = service.List(PayoutListOptions).ToList();
        }
Exemple #2
0
        public payouts_fixture()
        {
            // make sure the account has sufficient funds first
            new StripeChargeService(Cache.ApiKey).Create(new StripeChargeCreateOptions
            {
                Amount   = 2000,
                Currency = "usd",
                SourceTokenOrExistingSourceId = "tok_bypassPending"
            });

            PayoutCreateOptions = new StripePayoutCreateOptions
            {
                Amount   = 1000,
                Currency = "usd"
            };

            PayoutUpdateOptions = new StripePayoutUpdateOptions
            {
                Metadata = new Dictionary <string, string>()
                {
                    { "some-key", "some-value" }
                }
            };

            var service = new StripePayoutService(Cache.ApiKey);

            Payout          = service.Create(PayoutCreateOptions);
            PayoutUpdated   = service.Update(Payout.Id, PayoutUpdateOptions);
            PayoutRetrieved = service.Get(Payout.Id);

            PayoutListOptions = new StripePayoutListOptions
            {
                Created = new StripeDateFilter {
                    EqualTo = Payout.Created
                },
                ArrivalDate = new StripeDateFilter {
                    EqualTo = Payout.ArrivalDate
                }
            };

            PayoutList = service.List(PayoutListOptions);
        }
        public StripePayoutServiceTest()
        {
            this.service = new StripePayoutService();

            this.createOptions = new StripePayoutCreateOptions()
            {
                Amount   = 123,
                Currency = "usd",
            };

            this.updateOptions = new StripePayoutUpdateOptions()
            {
                Metadata = new Dictionary <string, string>()
                {
                    { "key", "value" },
                },
            };

            this.listOptions = new StripePayoutListOptions()
            {
                Limit = 1,
            };
        }
        public static async Task <List <StripeTransaction> > GetStripePayoutTransactionsAsync(IMyConfiguration configuration, DateTime from, DateTime to)
        {
            // get stripe configuration parameters
            string stripeApiKey = configuration.GetValue("StripeApiKey");

            StripeConfiguration.SetApiKey(stripeApiKey);

            var payoutService         = new StripePayoutService();
            var allPayoutTransactions = new List <StripePayout>();
            var lastId = String.Empty;

            int MAX_PAGINATION = 100;
            int itemsExpected  = MAX_PAGINATION;

            while (itemsExpected == MAX_PAGINATION)
            {
                IEnumerable <StripePayout> charges = null;
                if (String.IsNullOrEmpty(lastId))
                {
                    charges = await payoutService.ListAsync(
                        new StripePayoutListOptions()
                    {
                        Limit   = MAX_PAGINATION,
                        Created = new StripeDateFilter
                        {
                            GreaterThanOrEqual = from,
                            LessThanOrEqual    = to
                        }
                    });

                    itemsExpected = charges.Count();
                }
                else
                {
                    charges = await payoutService.ListAsync(
                        new StripePayoutListOptions()
                    {
                        Limit         = MAX_PAGINATION,
                        StartingAfter = lastId,
                        Created       = new StripeDateFilter
                        {
                            GreaterThanOrEqual = from,
                            LessThanOrEqual    = to
                        }
                    });

                    itemsExpected = charges.Count();
                }

                allPayoutTransactions.AddRange(charges);
                if (allPayoutTransactions.Count() > 0)
                {
                    lastId = charges.LastOrDefault().Id;
                }
            }

            var stripeTransactions = new List <StripeTransaction>();

            foreach (var payoutTransaction in allPayoutTransactions)
            {
                // only process the charges that are payouts
                if (payoutTransaction.Object == "payout")
                {
                    var stripeTransaction = new StripeTransaction();
                    stripeTransaction.TransactionID = payoutTransaction.Id;
                    stripeTransaction.Created       = payoutTransaction.Created;
                    stripeTransaction.AvailableOn   = payoutTransaction.ArrivalDate;
                    stripeTransaction.Paid          = (payoutTransaction.Status == "paid");
                    stripeTransaction.Amount        = (decimal)payoutTransaction.Amount / 100;
                    stripeTransaction.Currency      = payoutTransaction.Currency;
                    stripeTransaction.Description   = payoutTransaction.Description;
                    stripeTransaction.Status        = payoutTransaction.Status;

                    stripeTransactions.Add(stripeTransaction);
                }
            }
            return(stripeTransactions);
        }
Exemple #5
0
        public UpdatePayoutsData()
        {
            try
            {
                // Get active Stripe keys
                var getStripeKeys = db.stripes.GroupBy(s => s.SecretKey).Select(x => x.FirstOrDefault()).ToList();

                foreach (var stripe in getStripeKeys)
                {
                    StripeConfiguration.SetApiKey(stripe.SecretKey);
                    // Get Payouts
                    var payoutService = new StripePayoutService();
                    StripeList <StripePayout> payoutItems = payoutService.List(
                        new StripePayoutListOptions()
                    {
                        Limit = 100
                    }
                        );
                    foreach (var payout in payoutItems)
                    {
                        if (payout.Status == "paid")
                        {
                            var checkPayout = db.stripepayouts.Where(p => p.StripePayoutID == payout.Id).ToList();
                            if (checkPayout.Count == 0)
                            {
                                // Insert Payout
                                stripepayout insertPayout = new stripepayout();
                                insertPayout.StripePayoutID = payout.Id;
                                insertPayout.PaidDate       = payout.ArrivalDate;
                                insertPayout.PropertyID     = stripe.PropertyID;
                                db.stripepayouts.Add(insertPayout);
                                db.SaveChanges();

                                // Get Payouts Payments
                                var balanceService = new StripeBalanceService();
                                StripeList <StripeBalanceTransaction> balanceTransactions = balanceService.List(
                                    new StripeBalanceTransactionListOptions()
                                {
                                    Limit    = 100,
                                    PayoutId = payout.Id
                                }
                                    );
                                foreach (var transaction in balanceTransactions)
                                {
                                    if (transaction.Description != "STRIPE PAYOUT")
                                    {
                                        stripepayoutdetail payoutDetails = new stripepayoutdetail();
                                        payoutDetails.AmountGross    = (transaction.Amount / 100.0M);
                                        payoutDetails.Fee            = (transaction.Fee / 100.0M);
                                        payoutDetails.AmountNet      = (transaction.Net / 100.0M);
                                        payoutDetails.Description    = transaction.Description;
                                        payoutDetails.StripePayoutID = insertPayout.ID;
                                        db.stripepayoutdetails.Add(payoutDetails);
                                        db.SaveChanges();
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                SendUsEmail error = new SendUsEmail();
                error.sendError(e.ToString(), "Error getting iRent Payouts");
            }
        }