상속: Recurly.RecurlyEntity
예제 #1
0
        public void CreateCouponPercent()
        {
            string s = Factories.GetMockCouponCode();
            Coupon c = new Coupon(s, Factories.GetMockCouponName(), 10);
            c.Create();

            Assert.IsNotNull(c.CreatedAt);

            c = Coupon.Get(s);
            Assert.IsNotNull(s);
            Assert.AreEqual(c.DiscountPercent.Value, 10);
            Assert.AreEqual(c.DiscountType, Coupon.CouponDiscountType.percent);
        }
예제 #2
0
        public void CreateCouponPlan()
        {
            Plan p = new Plan(Factories.GetMockPlanCode("coupon plan"), "Coupon Test");
            p.SetupFeeInCents.Add("USD", 500);
            p.UnitAmountInCents.Add("USD", 5000);
            p.Create();

            string s = Factories.GetMockCouponCode();
            Coupon c = new Coupon(s, Factories.GetMockCouponName(), new Dictionary<string, int>());
            c.DiscountInCents.Add("USD", 100);
            c.Plans.Add(p.PlanCode);

            p.Deactivate();
        }
예제 #3
0
        public void DeactivateCoupon()
        {
            string s = Factories.GetMockCouponCode();
            Coupon c = new Coupon(s, Factories.GetMockCouponName(), new Dictionary<string, int>());
            c.DiscountInCents.Add("USD", 100);
            c.DiscountInCents.Add("EUR", 50);

            c.Create();

            Assert.IsNotNull(c.CreatedAt);

            c.Deactivate();

            c = Coupon.Get(s);
            Assert.IsNotNull(s);
            Assert.AreEqual(c.State, Coupon.CouponState.inactive);
        }
예제 #4
0
        public void CreateCouponDollars()
        {
            string s = Factories.GetMockCouponCode();
            Coupon c = new Coupon(s, Factories.GetMockCouponName(), new Dictionary<string,int>());
            c.DiscountInCents.Add("USD", 100);
            c.DiscountInCents.Add("EUR", 50);

            c.Create();

            Assert.IsNotNull(c.CreatedAt);

            c = Coupon.Get(s);
            Assert.IsNotNull(s);
            Assert.AreEqual(c.DiscountInCents["USD"], 100);
            Assert.AreEqual(c.DiscountInCents["EUR"], 50);
            Assert.AreEqual(c.DiscountType, Coupon.CouponDiscountType.dollars);
        }
        public void RedeemCoupon()
        {
            string s = Factories.GetMockCouponCode();
            Coupon c = new Coupon(s, Factories.GetMockCouponName(), 10);
            c.Create();

            string act = Factories.GetMockAccountName();
            Account acct = new Account(act);
            acct.Create();
            Assert.IsNotNull(acct.CreatedAt);

            CouponRedemption cr = acct.RedeemCoupon(s, "USD");
            Thread.Sleep(2000);
            Assert.IsNotNull(cr);
            Assert.AreEqual(cr.Currency, "USD");
            Assert.AreEqual(cr.AccountCode, act);
        }
        public void LookupRedemption()
        {
            string s = Factories.GetMockCouponCode();
            Coupon c = new Coupon(s, Factories.GetMockCouponName(), 10);
            c.Create();

            string act = Factories.GetMockAccountName();
            Account acct = new Account(act);
            acct.Create();
            Assert.IsNotNull(acct.CreatedAt);

            CouponRedemption cr = acct.RedeemCoupon(s, "USD");

            Assert.IsNotNull(cr);

            cr = acct.GetActiveCoupon();
            Assert.AreEqual(cr.CouponCode, s);
            Assert.AreEqual(cr.AccountCode, act);
        }
        public void LookupCouponInvoice()
        {
            string s = Factories.GetMockCouponCode();
            Dictionary<string, int> discounts = new Dictionary<string,int>();
            discounts.Add("USD",1000);
            Coupon c = new Coupon(s, Factories.GetMockCouponName(), discounts);
            c.Create();

            string act = Factories.GetMockAccountName();
            Account acct = new Account(s, "John", "Doe", "4111111111111111", DateTime.Now.Month, DateTime.Now.Year + 2);
            acct.Create();

            CouponRedemption cr = acct.RedeemCoupon(s, "USD");

            Transaction t = new Transaction(acct, 5000, "USD");
            t.Create();

            CouponRedemption cr2 = Invoice.Get(t.Invoice.Value).GetCoupon();

            Assert.AreEqual(cr, cr2);
        }
예제 #8
0
 /// <summary>
 /// Lists coupons, limited to state
 /// </summary>
 /// <param name="state">Account state to retrieve</param>
 /// <returns></returns>
 public static RecurlyList<Coupon> List(Coupon.CouponState state = Coupon.CouponState.All)
 {
     return new CouponList(Coupon.UrlPrefix + (state != Coupon.CouponState.All ? "?state=" + state.ToString().EnumNameToTransportCase() : ""));
 }
예제 #9
0
        /// <summary>
        /// Look up a coupon
        /// </summary>
        /// <param name="couponCode">Coupon code</param>
        /// <returns></returns>
        public static Coupon Get(string couponCode)
        {
            var coupon = new Coupon();

            var statusCode = Client.Instance.PerformRequest(Client.HttpRequestMethod.Get,
                Coupon.UrlPrefix + Uri.EscapeUriString(couponCode),
                coupon.ReadXml);

            return statusCode == HttpStatusCode.NotFound ? null : coupon;
        }
예제 #10
0
 public bool Equals(Coupon coupon)
 {
     return CouponCode == coupon.CouponCode;
 }
예제 #11
0
 public bool Equals(Coupon coupon)
 {
     return(CouponCode == coupon.CouponCode);
 }
예제 #12
0
        /// <summary>
        /// Look up a coupon
        /// </summary>
        /// <param name="couponCode">Coupon code</param>
        /// <returns></returns>
        public static Coupon Get(string couponCode)
        {
            Coupon coupon = new Coupon();

            HttpStatusCode statusCode = Client.PerformRequest(Client.HttpRequestMethod.Get,
                UrlPrefix + System.Uri.EscapeUriString(couponCode),
                new Client.ReadXmlDelegate(coupon.ReadXml));

            if (statusCode == HttpStatusCode.NotFound)
                return null;

            return coupon;
        }
예제 #13
0
        public void ListCoupons()
        {
            string s = Factories.GetMockCouponCode();
            Coupon c = new Coupon(s, Factories.GetMockCouponName(), 1);
            c.Create();
            s = Factories.GetMockCouponCode();
            c = new Coupon(s, Factories.GetMockCouponName(), 2);
            c.Create();

            CouponList list = CouponList.List();
            Assert.IsTrue(list.Count > 1);
        }
예제 #14
0
        public void ListCouponsRedeemable()
        {
            string s = Factories.GetMockCouponCode();
            Coupon c = new Coupon(s, Factories.GetMockCouponName(), 1);
            c.Create();
            c.Deactivate();
            Thread.Sleep(1000);
            s = Factories.GetMockCouponCode();
            c = new Coupon(s, Factories.GetMockCouponName(), 2);
            c.Create();

            CouponList list = CouponList.List(Coupon.CouponState.redeemable);
            Assert.IsTrue(list.Count > 1);
        }
예제 #15
0
        public void ListCouponsMaxedOut()
        {
            string s = Factories.GetMockCouponCode();
            Coupon c = new Coupon(s, Factories.GetMockCouponName(), 1);
            c.MaxRedemptions = 1;
            c.Create();

            Account t = new Account(Factories.GetMockAccountName("Coupon Redemption Max"));
            t.Create();
            t.RedeemCoupon(s, "USD");

            CouponList list = CouponList.List();
            Assert.IsTrue(list.Count > 1);
        }