Exemple #1
0
        /// <summary>
        /// Supply your Merchant ID and Secret Key. These can be found in the API Keys menu item in the Pinch Portal.
        /// </summary>
        /// <param name="merchantId">Your Merchant ID</param>
        /// <param name="secretKey">Your Secret Key</param>
        /// <param name="options">Mostly used to set IsLive. There are a few things you can override in here.</param>
        /// <param name="httpClientFactory">A function to get an instance of HttpClient. Use this to manage your own instance or make use of the HttpClientFactory to manage instances for you. If no factory is supplied, an instance is created per PinchApi instance.</param>
        public PinchApi(string merchantId, string secretKey, PinchApiOptions options, Func <HttpClient> httpClientFactory = null)
        {
            _httpClientFactory = httpClientFactory;

            options.ApiVersion = !string.IsNullOrEmpty(options.ApiVersion)
                ? options.ApiVersion
                : Settings.LatestApiVersion;

            if (!string.IsNullOrEmpty(options.BaseUri))
            {
                options.BaseUri = $"{options.BaseUri.TrimEnd('/')}/{(options.IsLive ? "live" : "test")}/";
            }
            else
            {
                options.BaseUri = options.IsLive ? Settings.ApiBaseUri_Production : Settings.ApiBaseUri_Test;
            }

            options.AuthUri = !string.IsNullOrEmpty(options.AuthUri) ? options.AuthUri : Settings.AuthBaseUri_Production;

            _secretKey     = secretKey;
            _clientId      = merchantId;
            _accessToken   = options.AccessToken;
            _refreshToken  = options.RefreshToken;
            _applicationId = options.ApplicationId;
            _options       = options;
        }
Exemple #2
0
        public PinchApi(string clientId, string secretKey, PinchApiOptions options)
        {
            if (!string.IsNullOrEmpty(options.BaseUri))
            {
                _baseUri = options.BaseUri;
            }
            else
            {
                _baseUri = options.IsLive ? Settings.ApiBaseUri_Production : Settings.ApiBaseUri_Test;
            }

            _authUri = !string.IsNullOrEmpty(options.AuthUri) ? options.AuthUri : Settings.AuthBaseUri_Production;

            _secretKey     = secretKey;
            _clientId      = clientId;
            _accessToken   = options.AccessToken;
            _refreshToken  = options.RefreshToken;
            _applicationId = options.ApplicationId;
        }
Exemple #3
0
 public BaseClient(PinchApiOptions options, Func <bool, Task <string> > getAccessToken, Func <HttpClient> httpClientFactory)
 {
     _httpClientFactory = httpClientFactory;
     _getAccessToken    = getAccessToken;
     Options            = options;
 }