コード例 #1
0
        public void CreatePrimaryMarketInvestmentOk()
        {
            var investmentRequest = new PrimaryMarketInvestment()
            {
                Amount          = 200,
                LoanId          = 1,
                CaptchaResponse = "..."
            };

            _zonkyApi.CreatePrimaryMarketInvestmentAsync(investmentRequest, _tokenProvider.GetToken(), CancellationToken.None).GetAwaiter().GetResult();
        }
コード例 #2
0
        /// <summary>
        /// Create primary market investment
        /// </summary>
        /// <param name="investment">Primary market investment</param>
        /// <param name="authorizationToken"></param>
        /// <param name="ct"></param>
        /// <returns></returns>
        public async Task CreatePrimaryMarketInvestmentAsync(PrimaryMarketInvestment investment, AuthorizationToken authorizationToken, CancellationToken ct = default)
        {
            CheckAuthorizationToken(authorizationToken);

            using (var request = PrepareAuthorizedRequest("/marketplace/investment", HttpMethod.Post, authorizationToken).AddJsonContent(investment, Settings))
                using (var response = await _httpClient.SendAsync(request, HttpCompletionOption.ResponseContentRead, ct).ConfigureAwait(false))
                {
                    await _resolverFactory.Create(Settings, true)
                    .ConfigureStatusResponce(HttpStatusCode.OK, (message) => { })
                    .ConfigureStatusResponce(HttpStatusCode.BadRequest, (message) => throw new PrimaryMarketInvestmentException(investment, message))
                    .ConfigureStatusResponce(HttpStatusCode.Forbidden, (message) => throw new CaptchaValidationException(message))
                    .ConfigureDefaultResponce((message) => throw new ServerErrorException(message))
                    .ExtractDataAsync(response);
                }
        }
コード例 #3
0
 /// <summary>
 /// Primary market investment failed
 /// The input is invalid.
 /// Possible error codes are:
 /// CAPTCHA_REQUIRED - Captcha verification is required
 /// insufficientBalance - The user cannot invest because of a low wallet balance
 /// cancelled - The loan has been canceled
 /// withdrawn - The loan has been withdrawn by the borrower
 /// reservedInvestmentOnly - The user cannot invest without a reservation. The whole remaining investment is reserved for other users.
 /// overInvestment - The amount for investment is too high
 /// multipleInvestment - The user has already invested to this loan. Try increasing the investment instead
 /// alreadyCovered - The whole loan amount has been already covered
 /// </summary>
 /// <param name="investment"></param>
 /// <param name="message"></param>
 public PrimaryMarketInvestmentException(PrimaryMarketInvestment investment, HttpResponseMessage message) : base($"Buy primary market participation {investment.ToString()} failed \r\nServer return \r\n {message.ToString()} \r\n with content {message.Content.ReadAsStringAsync().GetAwaiter().GetResult()}")
 {
 }
コード例 #4
0
        /// <summary>
        /// Create primary market investment
        /// </summary>
        /// <param name="investment">Primary market investment</param>
        /// <param name="ct"></param>
        /// <returns></returns>
        public async Task CreatePrimaryMarketInvestmentAsync(PrimaryMarketInvestment investment, CancellationToken ct = default)
        {
            CheckTradingPrerequisites();

            await HandleAuthorizedRequestAsync(() => ZonkyApi.CreatePrimaryMarketInvestmentAsync(investment, AuthorizationToken, ct), ct).ConfigureAwait(false);
        }