mirror of
https://github.com/bitwarden/server.git
synced 2024-11-22 12:15:36 +01:00
verify bank api
This commit is contained in:
parent
45141cf5d2
commit
e470301327
@ -182,6 +182,18 @@ namespace Bit.Api.Controllers
|
||||
await _organizationService.AdjustStorageAsync(orgIdGuid, model.StorageGbAdjustment.Value);
|
||||
}
|
||||
|
||||
[HttpPost("{id}/verify-bank")]
|
||||
public async Task PostVerifyBank(string id, [FromBody]OrganizationVerifyBankRequestModel model)
|
||||
{
|
||||
var orgIdGuid = new Guid(id);
|
||||
if(!_currentContext.OrganizationOwner(orgIdGuid))
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
await _organizationService.VerifyBankAsync(orgIdGuid, model.Amount1.Value, model.Amount2.Value);
|
||||
}
|
||||
|
||||
[HttpPut("{id}/cancel")]
|
||||
[HttpPost("{id}/cancel")]
|
||||
public async Task PutCancel(string id)
|
||||
|
@ -0,0 +1,14 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Bit.Core.Models.Api
|
||||
{
|
||||
public class OrganizationVerifyBankRequestModel
|
||||
{
|
||||
[Required]
|
||||
[Range(1, 99)]
|
||||
public int? Amount1 { get; set; }
|
||||
[Required]
|
||||
[Range(1, 99)]
|
||||
public int? Amount2 { get; set; }
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@ namespace Bit.Core.Services
|
||||
Task UpgradePlanAsync(Guid organizationId, PlanType plan, int additionalSeats);
|
||||
Task AdjustStorageAsync(Guid organizationId, short storageAdjustmentGb);
|
||||
Task AdjustSeatsAsync(Guid organizationId, int seatAdjustment);
|
||||
Task VerifyBankAsync(Guid organizationId, int amount1, int amount2);
|
||||
Task<Tuple<Organization, OrganizationUser>> SignUpAsync(OrganizationSignup organizationSignup);
|
||||
Task DeleteAsync(Organization organization);
|
||||
Task DisableAsync(Guid organizationId, DateTime? expirationDate);
|
||||
|
@ -350,6 +350,49 @@ namespace Bit.Core.Services
|
||||
await _organizationRepository.ReplaceAsync(organization);
|
||||
}
|
||||
|
||||
public async Task VerifyBankAsync(Guid organizationId, int amount1, int amount2)
|
||||
{
|
||||
var organization = await _organizationRepository.GetByIdAsync(organizationId);
|
||||
if(organization == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
|
||||
if(string.IsNullOrWhiteSpace(organization.GatewayCustomerId))
|
||||
{
|
||||
throw new GatewayException("Not a gateway customer.");
|
||||
}
|
||||
|
||||
var bankService = new BankAccountService();
|
||||
var customerService = new StripeCustomerService();
|
||||
var customer = await customerService.GetAsync(organization.GatewayCustomerId);
|
||||
if(customer == null)
|
||||
{
|
||||
throw new GatewayException("Cannot find customer.");
|
||||
}
|
||||
|
||||
var bankAccount = customer.Sources
|
||||
.FirstOrDefault(s => s.BankAccount != null && s.BankAccount.Status != "verified")?.BankAccount;
|
||||
if(bankAccount == null)
|
||||
{
|
||||
throw new GatewayException("Cannot find an unverified bank account.");
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var result = await bankService.VerifyAsync(organization.GatewayCustomerId, bankAccount.Id,
|
||||
new BankAccountVerifyOptions { AmountOne = amount1, AmountTwo = amount2 });
|
||||
if(result.Status != "verified")
|
||||
{
|
||||
throw new GatewayException("Unable to verify account.");
|
||||
}
|
||||
}
|
||||
catch(StripeException e)
|
||||
{
|
||||
throw new GatewayException(e.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Tuple<Organization, OrganizationUser>> SignUpAsync(OrganizationSignup signup)
|
||||
{
|
||||
var plan = StaticStore.Plans.FirstOrDefault(p => p.Type == signup.Plan && !p.Disabled);
|
||||
|
Loading…
Reference in New Issue
Block a user