Beispiel #1
0
        public CustomerResponse CreateCustomer(CreditCardRequest card = null, string coupon = null, string email = null, string description = null, string plan = null, DateTimeOffset? trialEnd = null)
        {
            if (card != null)
            {
                Require.Argument("card[number]", card.Number);
                Require.Argument("card[exp_month]", card.ExpMonth);
                Require.Argument("card[exp_year]", card.ExpYear);
            }

            var request = new RestRequest();
            request.Method = Method.POST;
            request.Resource = "customers";

            if (card != null)
            {
                request.AddParameter("card[number]", card.Number);
                request.AddParameter("card[exp_month]", card.ExpMonth);
                request.AddParameter("card[exp_year]", card.ExpYear);
                if (card.Cvc.HasValue()) request.AddParameter("card[cvc]", card.ExpYear);
                if (card.Name.HasValue()) request.AddParameter("card[name]", card.ExpYear);
                if (card.AddressLine1.HasValue()) request.AddParameter("card[address_line1]", card.ExpYear);
                if (card.AddressLine2.HasValue()) request.AddParameter("card[address_line2]", card.ExpYear);
                if (card.AddressZip.HasValue()) request.AddParameter("card[address_zip]", card.ExpYear);
                if (card.AddressState.HasValue()) request.AddParameter("card[address_state]", card.ExpYear);
                if (card.AddressCountry.HasValue()) request.AddParameter("card[address_country]", card.ExpYear);
            }
            if (coupon.HasValue()) request.AddParameter("coupon", coupon);
            if (email.HasValue()) request.AddParameter("email", email);
            if (description.HasValue()) request.AddParameter("description", description);
            if (plan.HasValue()) request.AddParameter("plan", plan);
            if (trialEnd.HasValue) request.AddParameter("trialEnd", trialEnd.Value.ToUnixEpoch());

            return Execute<CustomerResponse>(request);
        }
Beispiel #2
0
        public ChargeResponse CreateCharge(decimal amount, string currency, CreditCardRequest card, string description = null)
        {
            Require.Argument("amount", amount);
            Require.Argument("currency", currency);
            Require.Argument("card", card);
            Require.Argument("card[number]", card.Number);
            Require.Argument("card[exp_month]", card.ExpMonth);
            Require.Argument("card[exp_year]", card.ExpYear);

            if (amount < 0.5M)
                throw new ArgumentOutOfRangeException("amount", amount, "Amount must be at least 50 cents");

            Validate.IsBetween(card.ExpMonth, 1, 12);
            Validate.IsBetween(card.ExpYear, DateTime.Now.Year, 2050);

            var request = new RestRequest();
            request.Method = Method.POST;
            request.Resource = "charges";

            request.AddParameter("amount", Convert.ToInt32(amount * 100M));
            request.AddParameter("currency", currency);
            request.AddParameter("card[number]", card.Number);
            request.AddParameter("card[exp_month]", card.ExpMonth);
            request.AddParameter("card[exp_year]", card.ExpYear);
            if (card.Cvc.HasValue()) request.AddParameter("card[cvc]", card.ExpYear);
            if (card.Name.HasValue()) request.AddParameter("card[name]", card.ExpYear);
            if (card.AddressLine1.HasValue()) request.AddParameter("card[address_line1]", card.ExpYear);
            if (card.AddressLine2.HasValue()) request.AddParameter("card[address_line2]", card.ExpYear);
            if (card.AddressZip.HasValue()) request.AddParameter("card[address_zip]", card.ExpYear);
            if (card.AddressState.HasValue()) request.AddParameter("card[address_state]", card.ExpYear);
            if (card.AddressCountry.HasValue()) request.AddParameter("card[address_country]", card.ExpYear);
            if (description.HasValue()) request.AddParameter("description", description);

            return Execute<ChargeResponse>(request);
        }
        public void Setup()
        {
            _card = new CreditCardRequest {
                Number = "4111111111111111",
                ExpMonth = 3,
                ExpYear = 2015
            };

            _client = new StripeClient(Constants.ApiKey);
        }
        public void Setup()
        {
            _client = new StripeClient(Constants.ApiKey);

            var id = Guid.NewGuid().ToString();
            var card = new CreditCardRequest {
                Number = "4111111111111111",
                ExpMonth = 3,
                ExpYear = 2015
            };

            _plan = _client.CreatePlan(id, 400M, "usd", PlanFrequency.Month, id);
            _customer = _client.CreateCustomer(card);
        }
        public void UpdateCustomer_Test()
        {
            var newCard = new CreditCardRequest {
                Number = "378734493671000",
                ExpMonth = 12,
                ExpYear = 2016
            };

            var customer = _client.CreateCustomer(_card, email: _email);
            var response = _client.UpdateCustomer(customer.Id, newCard);

            Assert.IsNotNull(response);
            Assert.IsFalse(response.IsError);
            Assert.AreEqual(customer.Id, response.Id);
            Assert.AreNotEqual(customer.ActiveCard.Last4, response.ActiveCard.Last4);
        }
        public CustomerSubscriptionResponse UpdateCustomersSubscription(string customerId, string planId, string coupon = null, bool? prorate = null, DateTimeOffset? trialEnd = null, CreditCardRequest card = null)
        {
            Require.Argument("customerId", customerId);
            Require.Argument("planId", planId);

            if (card != null)
            {
                Require.Argument("card[number]", card.Number);
                Require.Argument("card[exp_month]", card.ExpMonth);
                Require.Argument("card[exp_year]", card.ExpYear);
            }

            var request = new RestRequest();
            request.Method = Method.POST;
            request.Resource = "customers/{customerId}/subscription";

            request.AddUrlSegment("customerId", customerId);

            request.AddParameter("plan", planId);
            if (coupon.HasValue()) request.AddParameter("coupon", coupon);
            if (prorate.HasValue) request.AddParameter("prorate", prorate.Value);
            if (trialEnd.HasValue) request.AddParameter("trial_end", trialEnd.Value.ToUnixEpoch());
            if (card != null)
            {
                request.AddParameter("card[number]", card.Number);
                request.AddParameter("card[exp_month]", card.ExpMonth);
                request.AddParameter("card[exp_year]", card.ExpYear);
                if (card.Cvc.HasValue()) request.AddParameter("card[cvc]", card.ExpYear);
                if (card.Name.HasValue()) request.AddParameter("card[name]", card.ExpYear);
                if (card.AddressLine1.HasValue()) request.AddParameter("card[address_line1]", card.ExpYear);
                if (card.AddressLine2.HasValue()) request.AddParameter("card[address_line2]", card.ExpYear);
                if (card.AddressZip.HasValue()) request.AddParameter("card[address_zip]", card.ExpYear);
                if (card.AddressState.HasValue()) request.AddParameter("card[address_state]", card.ExpYear);
                if (card.AddressCountry.HasValue()) request.AddParameter("card[address_country]", card.ExpYear);
            }

            return Execute<CustomerSubscriptionResponse>(request);
        }
Beispiel #7
0
        public CustomerResponse UpdateCustomer(string customerId, CreditCardRequest card = null, string coupon = null, string email = null, string description = null)
        {
            if (card != null)
            {
                Require.Argument("card[number]", card.Number);
                Require.Argument("card[exp_month]", card.ExpMonth);
                Require.Argument("card[exp_year]", card.ExpYear);
            }

            var request = new RestRequest();
            request.Method = Method.POST;
            request.Resource = "customers/{customerId}";

            request.AddUrlSegment("customerId", customerId);

            if (card != null)
            {
                request.AddParameter("card[number]", card.Number);
                request.AddParameter("card[exp_month]", card.ExpMonth);
                request.AddParameter("card[exp_year]", card.ExpYear);
                if (card.Cvc.HasValue()) request.AddParameter("card[cvc]", card.ExpYear);
                if (card.Name.HasValue()) request.AddParameter("card[name]", card.ExpYear);
                if (card.AddressLine1.HasValue()) request.AddParameter("card[address_line1]", card.ExpYear);
                if (card.AddressLine2.HasValue()) request.AddParameter("card[address_line2]", card.ExpYear);
                if (card.AddressZip.HasValue()) request.AddParameter("card[address_zip]", card.ExpYear);
                if (card.AddressState.HasValue()) request.AddParameter("card[address_state]", card.ExpYear);
                if (card.AddressCountry.HasValue()) request.AddParameter("card[address_country]", card.ExpYear);
            }
            if (coupon.HasValue()) request.AddParameter("coupon", coupon);
            if (email.HasValue()) request.AddParameter("email", email);
            if (description.HasValue()) request.AddParameter("description", description);

            return Execute<CustomerResponse>(request);
        }