Beispiel #1
0
        public void Should_Parse_Correctly_A_Collect_With_Credit()
        {
            string data = JsonConvert.SerializeObject(new
            {
                locale = "en_US",
                payer  = new
                {
                    document     = "123456789",
                    documentType = "CC",
                    name         = "Simon",
                    surname      = "Godoy",
                    email        = "*****@*****.**",
                },
                payment = new
                {
                    reference   = "Testing_2020",
                    description = "Testing payment for NUnit",
                    amount      = new
                    {
                        currency = "COP",
                        total    = 143000,
                    },
                    allowPartial = false,
                    subscribe    = false,
                },
                instrument = new
                {
                    credit = new
                    {
                        code        = 500,
                        type        = "02",
                        groupCode   = "P",
                        installment = 3,
                    },
                    token = new
                    {
                        token = "e317950201950c59e91b6a59b25d439888a504579715a09bc0862c76b64335d9",
                    },
                },
            });

            JObject json = JObject.Parse(data);

            var request = new CollectRequest(json);

            Assert.AreEqual((int)json["instrument"]["credit"]["code"], request.Instrument.Credit.Code);
            Assert.AreEqual((string)json["instrument"]["credit"]["type"], request.Instrument.Credit.Type);
            Assert.AreEqual((string)json["instrument"]["credit"]["groupCode"], request.Instrument.Credit.GroupCode);
            Assert.AreEqual((int)json["instrument"]["credit"]["installment"], request.Instrument.Credit.Installment);
            Assert.AreEqual((int)json["payment"]["amount"]["total"], request.Payment.Amount.Total);
            Assert.AreEqual(JObject.Parse(JsonConvert.SerializeObject(json["instrument"])), request.Instrument.ToJsonObject());
            Assert.AreEqual(json, request.ToJsonObject());
        }
        /// <summary>
        /// Collect endpoint.
        /// </summary>
        /// <param name="collectRequest">collect request instance object.</param>
        /// <returns>redirect information instance object.</returns>
        public override RedirectInformation Collect(CollectRequest collectRequest)
        {
            XmlDocument response = new XmlDocument();
            XmlDocument payload  = JsonConvert.DeserializeXmlNode(collectRequest.ToJsonObject().ToString(), "payload");
            XElement    body     = new XElement(wsdl.GetName("collect"), XElement.Parse(payload.InnerXml));

            response.LoadXml(MakeRequest(body));
            response = RemoveNullFields(response);

            XmlNode data = response.SelectSingleNode("descendant::collectResult");
            JObject json = JObject.Parse(JsonConvert.SerializeXmlNode(data));

            return(new RedirectInformation(json.GetValue("collectResult").ToString()));
        }
Beispiel #3
0
        /// <summary>
        /// Make collect endpoint.
        /// </summary>
        /// <param name="collectRequest">CollectRequest</param>
        /// <returns>RedirectInformation</returns>
        public override RedirectInformation Collect(CollectRequest collectRequest)
        {
            string result = MakeRequest("POST", "api/collect", collectRequest.ToJsonObject());

            return(new RedirectInformation(result));
        }