1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-09 03:43:51 -05:00

process credit from ipn

This commit is contained in:
Kyle Spearrin
2019-02-20 16:03:38 -05:00
parent 312ced0e3b
commit 494b3f18b6
3 changed files with 71 additions and 5 deletions

View File

@ -915,6 +915,33 @@ namespace Bit.Core.Services
return createdCustomer;
}
public async Task<bool> CreditAccountAsync(ISubscriber subscriber, decimal creditAmount)
{
var customerService = new CustomerService();
Customer customer = null;
var customerExists = subscriber.Gateway == GatewayType.Stripe &&
!string.IsNullOrWhiteSpace(subscriber.GatewaySubscriptionId);
if(customerExists)
{
customer = await customerService.GetAsync(subscriber.GatewaySubscriptionId);
}
else
{
customer = await customerService.CreateAsync(new CustomerCreateOptions
{
Email = subscriber.BillingEmailAddress(),
Description = subscriber.BillingName(),
});
subscriber.Gateway = GatewayType.Stripe;
subscriber.GatewayCustomerId = customer.Id;
}
await customerService.UpdateAsync(customer.Id, new CustomerUpdateOptions
{
AccountBalance = customer.AccountBalance - (long)(creditAmount * 100)
});
return !customerExists;
}
public async Task<BillingInfo> GetBillingAsync(ISubscriber subscriber)
{
var billingInfo = new BillingInfo();