Ejemplo n.º 1
0
        /// <summary>
        /// Refresh OAuth credential.
        /// </summary>
        /// <param name="refreshToken">Refresh token.</param>
        /// <param name="requestOptions"><see cref="RequestOptions"/>.</param>
        /// <returns>The refreshed OAuth credential.</returns>
        /// <exception cref="MercadoPagoException">If a unexpected exception occurs.</exception>
        /// <exception cref="MercadoPagoApiException">If the API returns a error.</exception>
        public OAuthCredential RefreshOAuthCredential(
            string refreshToken,
            RequestOptions requestOptions = null)
        {
            string accessToken;

            if (requestOptions != null)
            {
                accessToken = string.IsNullOrWhiteSpace(requestOptions.AccessToken) ?
                              MercadoPagoConfig.AccessToken : requestOptions.AccessToken;
            }
            else
            {
                accessToken = MercadoPagoConfig.AccessToken;
            }

            var request = new RefreshOAuthCredentialRequest
            {
                ClientSecret = accessToken,
                RefreshToken = refreshToken,
            };

            return(Send(
                       "/oauth/token",
                       HttpMethod.POST,
                       request,
                       requestOptions));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Refresh OAuth credential async.
        /// </summary>
        /// <param name="refreshToken">Refresh token.</param>
        /// <param name="requestOptions"><see cref="RequestOptions"/>.</param>
        /// <param name="cancellationToken">Cancellation token.</param>
        /// <returns>A task whose the result is the refreshed OAuth credential.</returns>
        /// <exception cref="MercadoPagoException">If a unexpected exception occurs.</exception>
        /// <exception cref="MercadoPagoApiException">If the API returns a error.</exception>
        public Task <OAuthCredential> RefreshOAuthCredentialAsync(
            string refreshToken,
            RequestOptions requestOptions       = null,
            CancellationToken cancellationToken = default)
        {
            string accessToken;

            if (requestOptions != null)
            {
                accessToken = string.IsNullOrWhiteSpace(requestOptions.AccessToken) ?
                              MercadoPagoConfig.AccessToken : requestOptions.AccessToken;
            }
            else
            {
                accessToken = MercadoPagoConfig.AccessToken;
            }

            var request = new RefreshOAuthCredentialRequest
            {
                ClientSecret = accessToken,
                RefreshToken = refreshToken,
            };

            return(SendAsync(
                       "/oauth/token",
                       HttpMethod.POST,
                       request,
                       requestOptions,
                       cancellationToken));
        }