Exemplo n.º 1
0
        public charges_fixture()
        {
            // make sure there's a charge
            Charge = Cache.GetStripeCharge(Cache.ApiKey);

            ChargeListOptions = new StripeChargeListOptions
            {
                IncludeTotalCount = true
            };

            var service = new StripeChargeService(Cache.ApiKey);

            Charges = service.List(ChargeListOptions);

            ChargeUpdateOptions = new StripeChargeUpdateOptions
            {
                Description = "updatd description",
                // setting the updated shipping object to the same object used for the create charge
                // i attempted to just create a new shipping object and set one property,
                // but it threw an error 'name' was not supplied (which was on the original)
                Shipping = Cache.GetStripeChargeCreateOptions().Shipping
            };

            ChargeUpdateOptions.Shipping.Phone = "8675309";

            UpdatedCharge = service.Update(Charge.Id, ChargeUpdateOptions);
        }
Exemplo n.º 2
0
        public StripeChargeServiceTest()
        {
            this.service = new StripeChargeService();

            this.captureOptions = new StripeChargeCaptureOptions()
            {
                Amount = 123,
            };

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

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

            this.listOptions = new StripeChargeListOptions()
            {
                Limit = 1,
            };
        }
        static void GetNewCharges(StripeChargeService chargeService, TraceWriter log)
        {
            string lastObjectId = null;
            StripeList <StripeCharge> response = null;

            var greaterThanCreatedFilter = GetLatestCreatedTime();

            log.Info($"Latest Created Time: {greaterThanCreatedFilter}");

            var listOptions = new StripeChargeListOptions()
            {
                Limit   = 100,
                Created = new StripeDateFilter {
                    GreaterThan = greaterThanCreatedFilter
                },
                StartingAfter = lastObjectId
            };

            do
            {
                response = chargeService.List(listOptions);

                foreach (var c in response.Data)
                {
                    var trans = StripeChargeToStripeTransaction(c);
                    UpsertStripeTransaction(trans, log);
                }
                lastObjectId = response.Data.LastOrDefault()?.Id;
                listOptions.StartingAfter = lastObjectId;
                log.Info($"Charge last ObjectId: {lastObjectId}. More responses? {response.HasMore}");
            }while (response.HasMore);
        }
Exemplo n.º 4
0
        public charges_fixture()
        {
            // make sure there's a charge
            Charge = Cache.GetStripeCharge(Cache.ApiKey);

            ChargeListOptions = new StripeChargeListOptions();

            var service = new StripeChargeService(Cache.ApiKey);

            Charges = service.List(ChargeListOptions);

            ChargeUpdateOptions = new StripeChargeUpdateOptions
            {
                Description = "updatd description",
                // setting the updated shipping object to the same object used for the create charge
                // i attempted to just create a new shipping object and set one property,
                // but it threw an error 'name' was not supplied (which was on the original)
                Shipping = Cache.GetStripeChargeCreateOptions().Shipping
            };

            ChargeUpdateOptions.Shipping.Phone          = "8675309";
            ChargeUpdateOptions.Shipping.TrackingNumber = "56789";

            UpdatedCharge = service.Update(Charge.Id, ChargeUpdateOptions);

            UncapturedCharge = Cache.GetStripeChargeUncaptured(Cache.ApiKey);

            ChargeCaptureOptions = new StripeChargeCaptureOptions
            {
                Amount = 123,
                StatementDescriptor = "CapturedCharge"
            };
            CapturedCharge = service.Capture(UncapturedCharge.Id, ChargeCaptureOptions);
        }
Exemplo n.º 5
0
        // Get a charge objects starting from fd to td (both inclusive, in UTC)
        // Returns List of StripeCharge
        public static List <StripeCharge> GetStripeChargeList(DateTime fd, DateTime td)
        {
            List <StripeCharge> chargeItems = new List <StripeCharge>();
            var  chargeService = new StripeChargeService();
            bool noErr         = true;

            // get some filtering
            // '2017-12-13 00:00:00', '2017-12-13 23:59:59'
            var opt = new StripeChargeListOptions();

            opt.Limit             = 20;
            opt.IncludeTotalCount = true;
            opt.Created           = new StripeDateFilter()
            {
                GreaterThanOrEqual = fd, //new DateTime(2017, 12, 13, 0, 0, 0, DateTimeKind.Utc),
                LessThanOrEqual    = td  //new DateTime(2017, 12, 13, 23, 59, 59, DateTimeKind.Utc)
            };

            while (noErr)
            {
                StripeList <StripeCharge> s = null;
                try
                {
                    s = chargeService.List(opt);
                    chargeItems.AddRange(s.Data);
                    if (s.HasMore)
                    {
                        // get the object id of last item, so that next loop will fetch
                        // from that id onwards, until limit..
                        // int count = s.Data.Count;
                        // opt.StartingAfter = s.Data[count - 1].Id;
                        opt.StartingAfter = s.LastOrDefault().Id;
                    }
                    else
                    {
                        noErr = false;
                    }
                }
                catch (StripeException e)
                {
                    StripeExceptionHandler(e);
                    noErr = false;
                }
                catch (Exception exp)
                {
                    Console.WriteLine(exp.Message);
                    noErr = false;
                }
            }

            return(chargeItems);
        }
Exemplo n.º 6
0
        public charges_fixture()
        {
            // make sure there's a charge
            Cache.GetStripeCharge(Cache.ApiKey);

            ChargeListOptions = new StripeChargeListOptions
            {
            };

            var service = new StripeChargeService(Cache.ApiKey);

            Charges = service.List(ChargeListOptions);
        }
Exemplo n.º 7
0
        public JsonResult SubscriptionTransactionHistoryQuery(string inputDirection = null, string trxId = null)
        {
            //GET STRIPE CUSTOMER ID/TOKEN
            StripeIdRequest customerId = _userService.GetStripeCustomerId(_userService.GetCurrentUserId());

            //IF WE'VE CHARGED THIS CUSTOMER BEFORE, THEN SEND A REQUEST TO STRIPE FOR USER'S TRANSACTION
            //HISTORY. WE ALSO HAVE PAGINATION OPTIONS TOWARDS THE END OF THIS CONDITIONAL. THE WAY STRIPE'S PAGINATION
            //WORKS IS THAT THEY ALLOW YOU TO GET DATA AFTER A CERTAIN ID, OR BEFORE. SO WHEN WE PERFORM THIS REQUEST
            //WE ARE PASSING IN A TRANSACTION ID AND AN INPUT DIRECTION.
            if (customerId.Token != null)
            {
                var chargeService = new StripeChargeService();

                StripeChargeListOptions opts = new StripeChargeListOptions
                {
                    Limit      = 100,
                    CustomerId = customerId.Token
                };

                if (!string.IsNullOrEmpty(trxId) && inputDirection == "next")
                {
                    opts.StartingAfter = trxId; //LAST TRANSACTION NUMBER FROM SET
                }
                if (!string.IsNullOrEmpty(trxId) && inputDirection == "prev")
                {
                    opts.EndingBefore = trxId; //FIRST TRANSACTION NUMBER FROM SET
                }
                StripeList <StripeCharge> chargeItems = chargeService.List(opts);
                return(Json(chargeItems, JsonRequestBehavior.AllowGet));
            }
            //IF WE'VE NEVER CHARGED THE CURRENT USER BEFORE, YOU WOULDN'T HAVE ANY HISTORY, SO RETURN ERROR
            else
            {
                return(Json(new { message = "You have no transaction history!" }, JsonRequestBehavior.AllowGet));
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// As long as payments continue the users account will not expire
        /// </summary>
        private void CheckForNewPayments()
        {
            // retrieve all events for the past day and proceed to process
            // subscription cancellations.

            using (var db = InitializeSettings.DbFactory)
            {
                var data = db.Query <Majorsilence.Vpn.Poco.DatabaseInfo>("SELECT * FROM DatabaseInfo");

                if (data.Count() != 1)
                {
                    throw new Majorsilence.Vpn.Logic.Exceptions.InvalidDataException("Incorrect data in DatabaseInfo table.  To many or too few rows.");
                }


                Helpers.SslSecurity.Callback();

                var eventService = new StripeChargeService(Majorsilence.Vpn.Logic.Helpers.SiteInfo.StripeAPISecretKey);
                var options      = new StripeChargeListOptions()
                {
                    Limit   = 1000,
                    Created = new StripeDateFilter
                    {
                        GreaterThanOrEqual = data.First().LastDailyProcess
                    }
                };


                IEnumerable <StripeCharge> response = eventService.List(options);

                foreach (var evt in response)
                {
                    //if (evt.LiveMode == false)
                    //{
                    //    continue;
                    //}

                    // A new payment has been made.

                    string stripeCustomerId = evt.CustomerId;


                    //var users = db.Select<Majorsilence.Vpn.Poco.Users>(q => q.PaymentExpired == false);
                    var user = db.Query <Majorsilence.Vpn.Poco.Users>("SELECT * FROM Users WHERE StripeCustomerAccount=@StripeCustomerAccount",
                                                                      new { StripeCustomerAccount = stripeCustomerId });

                    if (user == null || user.Count() != 1)
                    {
                        var ex = new Majorsilence.Vpn.Logic.Exceptions.InvalidDataException("Cannot find stripe customer data in users table.  Stripe Customer Account: " +
                                                                                            stripeCustomerId);

                        Majorsilence.Vpn.Logic.Helpers.Logging.Log(ex);
                        InitializeSettings.Email.SendMail_BackgroundThread("Error running DailyProcessing: " + ex.Message,
                                                                           "Error running DailyProcessing", Majorsilence.Vpn.Logic.Helpers.SiteInfo.AdminEmail, true, null,
                                                                           Email.EmailTemplates.Generic);

                        continue;
                    }

                    int userid = user.First().Id;
                    var pay    = new Payments.Payment(userid);

                    // amount in cents
                    pay.SaveUserPayment((decimal)(evt.Amount / 100.0m), evt.Created, Helpers.SiteInfo.MonthlyPaymentId);

                    Majorsilence.Vpn.Logic.ActionLog.Log_BackgroundThread("Payment made", userid);
                }



                data.First().LastDailyProcess = DateTime.UtcNow;

                db.Update(data.First());
            }
        }
Exemplo n.º 9
0
        public charges_fixture()
        {
            // make sure there's a charge
            Charge = Cache.GetStripeCharge(Cache.ApiKey);

            ChargeListOptions = new StripeChargeListOptions();

            var service = new StripeChargeService(Cache.ApiKey);

            Charges = service.List(ChargeListOptions);

            ChargeUpdateOptions = new StripeChargeUpdateOptions
            {
                Description = "updatd description",
                // setting the updated shipping object to the same object used for the create charge
                // i attempted to just create a new shipping object and set one property,
                // but it threw an error 'name' was not supplied (which was on the original)
                Shipping = Cache.GetStripeChargeCreateOptions().Shipping
            };

            ChargeUpdateOptions.Shipping.Phone          = "8675309";
            ChargeUpdateOptions.Shipping.TrackingNumber = "56789";

            UpdatedCharge = service.Update(Charge.Id, ChargeUpdateOptions);

            UncapturedCharge = Cache.GetStripeChargeUncaptured(Cache.ApiKey);

            ChargeCaptureOptions = new StripeChargeCaptureOptions
            {
                Amount = 123,
                StatementDescriptor = "CapturedCharge"
            };
            CapturedCharge = service.Capture(UncapturedCharge.Id, ChargeCaptureOptions);

            // Create a charge with Level 3 data
            var chargeLevel3Options = Cache.GetStripeChargeCreateOptions();

            chargeLevel3Options.Amount = 11700;
            chargeLevel3Options.Level3 = new StripeChargeLevel3Options
            {
                CustomerReference  = "customer 1",
                MerchantReference  = "1234",
                ShippingFromZip    = "90210",
                ShippingAddressZip = "94110",
                ShippingAmount     = 700,
                LineItems          = new List <StripeChargeLevel3LineItemOptions>
                {
                    new StripeChargeLevel3LineItemOptions
                    {
                        DiscountAmount     = 200,
                        ProductCode        = "1234",
                        ProductDescription = "description 1",
                        Quantity           = 2,
                        TaxAmount          = 200,
                        UnitCost           = 1000,
                    },
                    new StripeChargeLevel3LineItemOptions
                    {
                        DiscountAmount     = 300,
                        ProductCode        = "1235",
                        ProductDescription = "description 2",
                        Quantity           = 3,
                        TaxAmount          = 300,
                        UnitCost           = 3000,
                    },
                },
            };
            Level3Charge = service.Create(chargeLevel3Options);
        }