public async Task DoNotRetryOnCancel() { var requestCount = 0; this.MockHttpClientFixture.MockHandler.Protected() .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .Returns <HttpRequestMessage, CancellationToken>(async(_, t) => { requestCount += 1; await Task.Delay(TimeSpan.FromSeconds(1), t).ConfigureAwait(false); return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("{}", Encoding.UTF8), }); }); var service = new BalanceService(this.StripeClient); var source = new CancellationTokenSource(); source.CancelAfter(TimeSpan.FromMilliseconds(10)); await Assert.ThrowsAsync <TaskCanceledException>(async() => await service.GetAsync(null, source.Token)); Assert.Equal(1, requestCount); }
public async Task <IActionResult> GetBalance() { var service = new BalanceService(); Balance balance = await service.GetAsync(); //IsExistingCustomer("*****@*****.**"); return(new OkObjectResult(new { success = "true", bal = balance.Object })); }
public async Task TelemetryWorksWithConcurrentRequests() { this.MockHttpClientFixture.Reset(); var fakeServer = FakeServer.ForMockHandler(this.MockHttpClientFixture.MockHandler); fakeServer.Delay = TimeSpan.FromMilliseconds(20); var service = new BalanceService(this.StripeClient); // the first 2 requests will not contain telemetry await Task.WhenAll(service.GetAsync(), service.GetAsync()); // the following 2 requests will contain telemetry await Task.WhenAll(service.GetAsync(), service.GetAsync()); this.MockHttpClientFixture.MockHandler.Protected() .Verify( "SendAsync", Times.Exactly(2), ItExpr.Is <HttpRequestMessage>(m => !m.Headers.Contains("X-Stripe-Client-Telemetry")), ItExpr.IsAny <CancellationToken>()); this.MockHttpClientFixture.MockHandler.Protected() .Verify( "SendAsync", Times.Once(), ItExpr.Is <HttpRequestMessage>(m => TelemetryHeaderMatcher( m.Headers, (s) => s == "req_1", (d) => d >= 15)), ItExpr.IsAny <CancellationToken>()); this.MockHttpClientFixture.MockHandler.Protected() .Verify( "SendAsync", Times.Once(), ItExpr.Is <HttpRequestMessage>(m => TelemetryHeaderMatcher( m.Headers, (s) => s == "req_2", (d) => d >= 15)), ItExpr.IsAny <CancellationToken>()); }
public async Task <Balance> GetBalanceFor(string connectedAcctId) { var service = new BalanceService(); RequestOptions ro = new RequestOptions() { StripeAccount = connectedAcctId }; return(await service.GetAsync(ro)); }
public async Task <IActionResult> GetBalance([FromRoute] string userId) { try { StripeConfiguration.ApiKey = ServiceKey; var user = await _accountsRepository.GetByUserId(userId); var service = new BalanceService(); Balance balance = await service.GetAsync(new RequestOptions { StripeAccount = user.StripeUserId }); return(Ok(balance)); } catch (Exception e) { return(BadRequest(new MessageObj(e.Message))); } }
public async Task <int> PaymentCredit(string token, int amount, string bank_account, string routing_number, string account_name) { try { long userId = (long)Session["USER_ID"]; user residentUser = entities.users.Find(userId); // Charge using Credit Card StripeConfiguration.SetApiKey(ep.GetStripeSecretKey()); var chargeOptions = new ChargeCreateOptions { Amount = amount + 20000, Currency = "usd", Description = "Charge for [email protected]", SourceId = token // obtained with Stripe.js, }; var chargeService = new ChargeService(); Charge charge = chargeService.Create(chargeOptions); // Payout to coamdin bank // Get Bank Info string bankAccountStr = bank_account; //"000123456789";// string bankRoutingStr = routing_number; // "110000000";// // Get self account var accountOptions = new AccountCreateOptions { Email = "*****@*****.**", Type = AccountType.Custom, Country = "US", ExternalBankAccount = new AccountBankAccountOptions() { Country = "US", Currency = "usd", AccountHolderName = "John Brown",//account_name AccountHolderType = "individual", RoutingNumber = bankRoutingStr, AccountNumber = bankAccountStr }, PayoutSchedule = new AccountPayoutScheduleOptions() { Interval = "daily" }, TosAcceptance = new AccountTosAcceptanceOptions() { Date = DateTime.Now.AddDays(-10), Ip = "202.47.115.80", UserAgent = "Chrome" }, LegalEntity = new AccountLegalEntityOptions() { Dob = new AccountDobOptions() { Day = 1, Month = 4, Year = 1991 }, FirstName = "John", LastName = "Brown", Type = "individual" } }; var accountService = new AccountService(); Account account = await accountService.CreateAsync(accountOptions); StripeConfiguration.SetApiKey(ep.GetStripeSecretKey()); var service = new BalanceService(); Balance balance = await service.GetAsync(); var transOptions = new TransferCreateOptions { Amount = amount, Currency = "usd", Destination = account.Id }; var transferService = new TransferService(); Transfer Transfer = transferService.Create(transOptions); var payoutOptions = new PayoutCreateOptions { Amount = amount, Currency = "usd", Destination = account.ExternalAccounts.First().Id, SourceType = "card", StatementDescriptor = "PAYOUT", //Method = "instant" }; var requestOptions = new RequestOptions(); requestOptions.ApiKey = ep.GetStripeSecretKey(); requestOptions.StripeConnectAccountId = account.Id; var payoutService = new PayoutService(); var payout = await payoutService.CreateAsync(payoutOptions, requestOptions); return(1); } catch (Exception ex) { return(0); } }
public async Task <int> PaymentAch(string bankToken, int amount, string account_number, string rounting_number) { try { // Create an ACH charge StripeConfiguration.SetApiKey(ep.GetStripeSecretKey()); CustomerService customerService = new CustomerService(); var customerOptions = new CustomerCreateOptions { }; Customer achCustomer = customerService.Create(customerOptions); // Create Bank Account var bankAccountOptions = new BankAccountCreateOptions { SourceToken = bankToken }; var bankService = new BankAccountService(); BankAccount bankAccount = bankService.Create(achCustomer.Id, bankAccountOptions); // Verify BankAccount List <long> Amounts = new List <long>(); Amounts.Add(32); Amounts.Add(45); var verifyOptions = new BankAccountVerifyOptions { Amounts = Amounts }; bankAccount = bankService.Verify(achCustomer.Id, bankAccount.Id, verifyOptions); var chargeOptions = new ChargeCreateOptions { Amount = amount, Currency = "usd", Description = "Charge for [email protected]", CustomerId = achCustomer.Id }; var chargeService = new ChargeService(); Charge charge = chargeService.Create(chargeOptions); // Payout from Stripe to Bank Account string bankAccountStr = account_number; // "000123456789"; string bankRoutingStr = rounting_number; // "110000000"; // Get self account var accountOptions = new AccountCreateOptions { Email = "*****@*****.**", Type = AccountType.Custom, Country = "US", ExternalBankAccount = new AccountBankAccountOptions() { Country = "US", Currency = "usd", AccountHolderName = "John Brown",//account_name AccountHolderType = "individual", RoutingNumber = bankRoutingStr, AccountNumber = bankAccountStr }, PayoutSchedule = new AccountPayoutScheduleOptions() { Interval = "daily" }, TosAcceptance = new AccountTosAcceptanceOptions() { Date = DateTime.Now.AddDays(-10), Ip = "202.47.115.80", UserAgent = "Chrome" }, LegalEntity = new AccountLegalEntityOptions() { Dob = new AccountDobOptions() { Day = 1, Month = 4, Year = 1991 }, FirstName = "John", LastName = "Brown", Type = "individual" } }; var accountService = new AccountService(); Account account = await accountService.CreateAsync(accountOptions); StripeConfiguration.SetApiKey(ep.GetStripeSecretKey()); var service = new BalanceService(); Balance balance = await service.GetAsync(); var transOptions = new TransferCreateOptions { Amount = amount, Currency = "usd", Destination = account.Id }; var transferService = new TransferService(); Transfer Transfer = transferService.Create(transOptions); var payoutOptions = new PayoutCreateOptions { Amount = amount, Currency = "usd", Destination = account.ExternalAccounts.First().Id, SourceType = "card", StatementDescriptor = "PAYOUT", //Method = "instant" }; var requestOptions = new RequestOptions(); requestOptions.ApiKey = ep.GetStripeSecretKey(); requestOptions.StripeConnectAccountId = account.Id; var payoutService = new PayoutService(); var payout = await payoutService.CreateAsync(payoutOptions, requestOptions); return(1); } catch (Exception) { return(0); } }