Ejemplo n.º 1
0
        public static void AssertChargeReqAndRes(ChargeRequest req, Charge res)
        {
            Assert.AreEqual(res.ObjectType, "charge");

            Assert.AreEqual(res.Amount, req.Amount);
            Assert.AreEqual(res.Description, req.Description);
            Assert.AreEqual(res.Customer, req.Customer);
            Assert.AreEqual(res.Currency, req.Currency);
            Assert.AreEqual(res.Customer, req.Customer);
        }
Ejemplo n.º 2
0
        public void ChargeCapture()
        {
            var row = this.TestContext.DataRow;

            Charge response = null;
            {
                //カードを作る
                CardRequest card = Helper.CreateCard(row);

                //課金を作成
                ChargeRequest charge = new ChargeRequest();
                charge.Amount = 500;
                charge.Description = "仮の売上";
                charge.Capture = false;//これで仮売上
                charge.Card = card;

                response = client.Charge.Create(charge);
                {
                    Helper.AssertChargeReqAndRes(charge, response);
                    Assert.AreEqual(response.AmountRefunded, 0);

                    Assert.IsFalse(response.Paid);
                    Assert.IsFalse(response.Captured);
                    Assert.IsFalse(response.Refunded);

                    Assert.IsNull(response.Customer);
                    Assert.IsNull(response.FailureMessage);

                    Helper.AssertCardAndCSV(response.Card, row);
                }
            }

            {
                var captured = this.client.Charge.Capture(response.ID, response.Amount);

                Assert.AreEqual(captured.Amount, response.Amount);
                Assert.IsTrue(captured.Captured);
                Assert.IsNull(captured.FailureMessage);
            }
        }
Ejemplo n.º 3
0
        public void ChargeCreateFromCard()
        {
            var row = this.TestContext.DataRow;

            //カードを作る
            CardRequest card = Helper.CreateCard(row);

            //課金を作成
            ChargeRequest charge = new ChargeRequest();
            charge.Amount = 500;
            charge.Description = "カードから直接課金";
            charge.Card = card;

            var res = client.Charge.Create(charge);
            {
                Helper.AssertChargeReqAndRes(charge, res);
                Assert.AreEqual(res.AmountRefunded, 0);

                Assert.IsTrue(res.Captured);
                Assert.IsTrue(res.Paid);
                Assert.IsFalse(res.Refunded);

                Assert.IsNull(res.Customer);
                Assert.IsNull(res.FailureMessage);

                Helper.AssertCardAndCSV(res.Card, row);
            }

            //課金を検証
            var retrieved = client.Charge.Retrieve(res.ID);
            {
                Helper.AssertChargeAndCharge(res, retrieved);
            }
        }
Ejemplo n.º 4
0
        public void ChargeCreateFromToken()
        {
            var row = this.TestContext.DataRow;

            //カードを作る
            CardRequest card = Helper.CreateCard(row);

            //トークン作る
            Token token = this.client.Token.Create(card);
            {
                Assert.AreEqual(token.ObjectType, "token");
                Assert.IsFalse(token.Used);

                Helper.AssertCardAndCSV(token.Cards, row);
            }

            //課金を作成
            ChargeRequest charge = new ChargeRequest();
            charge.Amount = 500;
            charge.Description = "トークンから課金";
            charge.CardToken = token.ID;

            var res = client.Charge.Create(charge);
            {
                Helper.AssertChargeReqAndRes(charge, res);
                Assert.AreEqual(res.AmountRefunded, 0);

                Assert.IsTrue(res.Captured);
                Assert.IsTrue(res.Paid);
                Assert.IsFalse(res.Refunded);

                Assert.IsNull(res.Customer);
                Assert.IsNull(res.FailureMessage);

                Helper.AssertCardAndCSV(res.Card, row);
            }

            //課金を検証
            var retrieved = client.Charge.Retrieve(res.ID);
            {
                Helper.AssertChargeAndCharge(res, retrieved);
            }

            //使い終わったトークンを検証
            var usedToken = this.client.Token.Retrieve(token.ID);
            {
                Assert.AreEqual(usedToken.ObjectType, "token");
                Assert.AreEqual(usedToken.Created, token.Created);
                Assert.IsTrue(usedToken.Used);

                Helper.AssertCardAndCard(token.Cards, usedToken.Cards);
            }
        }
Ejemplo n.º 5
0
        public void ChargeCreateFromCustomer()
        {
            CustomerList list = this.client.Customer.All();
            Customer customer = list.Customers[0];

            //課金を作成
            ChargeRequest charge = new ChargeRequest();
            charge.Amount = 500;
            charge.Description = "顧客から課金";
            charge.Customer = customer.ID;

            var res = client.Charge.Create(charge);
            {
                Helper.AssertChargeReqAndRes(charge, res);
                Assert.AreEqual(res.AmountRefunded, 0);

                Assert.IsTrue(res.Captured);
                Assert.IsTrue(res.Paid);
                Assert.IsFalse(res.Refunded);

                Assert.IsNull(res.FailureMessage);

                Helper.AssertCardAndCard(customer.ActiveCard, res.Card);
            }

            //課金を検証
            var retrieved = client.Charge.Retrieve(res.ID);
            {
                Helper.AssertChargeAndCharge(res, retrieved);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 新たに課金を作成します。
        /// </summary>
        /// <param name="charge">新たな課金情報</param>
        /// <returns>作成された課金情報</returns>
        public Charge Create(ChargeRequest charge)
        {
            HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, new Uri(parent.BaseUri, "charges"));
            message.Content = new FormUrlEncodedContent(charge.ToFormContent(new Dictionary<string, string>()));

            Charge retval = this.parent.SendRequest<Charge>(message);

            return retval;
        }