Example #1
0
        /// <summary>
        /// Creates a new authorization request
        /// </summary>
        /// <param name="credentials">PagSeguro credentials. Required</param>
        /// <param name="authorizationRequest">PagSeguro AuthorizationRequest</param>
        /// <param name="onlyAuthorizationCode"></param>
        /// <returns></returns>
        public static String CreateAuthorizationRequest(Credentials credentials, AuthorizationRequest authorizationRequest, Boolean onlyAuthorizationCode)
        {
            PagSeguroTrace.Info(String.Format(CultureInfo.InvariantCulture, "AuthorizationService.CreateAuthorizationRequest() - begin"));

            try
            {
                using (HttpWebResponse response = HttpURLConnectionUtil.GetHttpPostConnection(
                    PagSeguroConfiguration.AuthorizarionRequestUri.AbsoluteUri, buildAuthorizationRequestUrl(credentials, authorizationRequest)))
                {
                    using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
                    {
                        AuthorizationResponse authorization = new AuthorizationResponse();
                        AuthorizationSerializer.Read(reader, authorization);

                        if (onlyAuthorizationCode) {
                            return authorization.Code;
                        } else {
                            return BuildAuthorizationURL(authorization.Code);
                        }
                    }
                }
            }
            catch (WebException pse)
            {
                throw pse;
            }
            catch (PagSeguroServiceException pse)
            {
                throw pse;
            }
        }
Example #2
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="authorization">PagSeguro AuthorizationResponse</param>
        internal static void Read(XmlReader reader, AuthorizationResponse authorization)
        {
            if (reader.IsEmptyElement)
            {
                XMLParserUtils.SkipNode(reader);
                return;
            }

            reader.ReadStartElement();
            reader.MoveToContent();

            while (!reader.EOF)
            {

                if (XMLParserUtils.IsEndElement(reader, SerializerHelper.PreApproval))
                {
                    XMLParserUtils.SkipNode(reader);
                    break;
                }

                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                        case SerializerHelper.Code:
                            authorization.Code = reader.ReadElementContentAsString();
                            break;
                        case SerializerHelper.Date:
                            authorization.Date = reader.ReadElementContentAsDateTime();
                            break;
                    }
                }
                else
                {
                    XMLParserUtils.SkipNode(reader);
                }
            }
        }