mirror of
https://github.com/bitwarden/server.git
synced 2025-02-28 03:51:23 +01:00
iap pre-purchase check
This commit is contained in:
parent
9ddfe3e947
commit
e9174ba9f4
21
src/Core/Models/Api/Request/IapCheckRequestModel.cs
Normal file
21
src/Core/Models/Api/Request/IapCheckRequestModel.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Bit.Core.Enums;
|
||||||
|
|
||||||
|
namespace Bit.Core.Models.Api
|
||||||
|
{
|
||||||
|
public class IapCheckRequestModel : IValidatableObject
|
||||||
|
{
|
||||||
|
[Required]
|
||||||
|
public PaymentMethodType? PaymentMethodType { get; set; }
|
||||||
|
|
||||||
|
public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
|
||||||
|
{
|
||||||
|
if(PaymentMethodType != Enums.PaymentMethodType.AppleInApp)
|
||||||
|
{
|
||||||
|
yield return new ValidationResult("Not a supported in-app purchase payment method.",
|
||||||
|
new string[] { nameof(PaymentMethodType) });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -15,6 +15,8 @@ namespace Bit.Core.Models.Business
|
|||||||
|
|
||||||
public class BillingSource
|
public class BillingSource
|
||||||
{
|
{
|
||||||
|
public BillingSource() { }
|
||||||
|
|
||||||
public BillingSource(PaymentMethod method)
|
public BillingSource(PaymentMethod method)
|
||||||
{
|
{
|
||||||
if(method.Card != null)
|
if(method.Card != null)
|
||||||
|
@ -45,6 +45,7 @@ namespace Bit.Core.Services
|
|||||||
Task SendDeleteConfirmationAsync(string email);
|
Task SendDeleteConfirmationAsync(string email);
|
||||||
Task<Tuple<bool, string>> SignUpPremiumAsync(User user, string paymentToken,
|
Task<Tuple<bool, string>> SignUpPremiumAsync(User user, string paymentToken,
|
||||||
PaymentMethodType paymentMethodType, short additionalStorageGb, UserLicense license);
|
PaymentMethodType paymentMethodType, short additionalStorageGb, UserLicense license);
|
||||||
|
Task IapCheckAsync(User user, PaymentMethodType paymentMethodType);
|
||||||
Task UpdateLicenseAsync(User user, UserLicense license);
|
Task UpdateLicenseAsync(User user, UserLicense license);
|
||||||
Task<string> AdjustStorageAsync(User user, short storageAdjustmentGb);
|
Task<string> AdjustStorageAsync(User user, short storageAdjustmentGb);
|
||||||
Task ReplacePaymentMethodAsync(User user, string paymentToken, PaymentMethodType paymentMethodType);
|
Task ReplacePaymentMethodAsync(User user, string paymentToken, PaymentMethodType paymentMethodType);
|
||||||
|
@ -751,6 +751,29 @@ namespace Bit.Core.Services
|
|||||||
paymentIntentClientSecret);
|
paymentIntentClientSecret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task IapCheckAsync(User user, PaymentMethodType paymentMethodType)
|
||||||
|
{
|
||||||
|
if(paymentMethodType != PaymentMethodType.AppleInApp)
|
||||||
|
{
|
||||||
|
throw new BadRequestException("Payment method not supported for in-app purchases.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(user.Premium)
|
||||||
|
{
|
||||||
|
throw new BadRequestException("Already a premium user.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!string.IsNullOrWhiteSpace(user.GatewayCustomerId))
|
||||||
|
{
|
||||||
|
var customerService = new Stripe.CustomerService();
|
||||||
|
var customer = await customerService.GetAsync(user.GatewayCustomerId);
|
||||||
|
if(customer != null && customer.Balance != 0)
|
||||||
|
{
|
||||||
|
throw new BadRequestException("Customer balance cannot exist when using in-app purchases.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task UpdateLicenseAsync(User user, UserLicense license)
|
public async Task UpdateLicenseAsync(User user, UserLicense license)
|
||||||
{
|
{
|
||||||
if(!_globalSettings.SelfHosted)
|
if(!_globalSettings.SelfHosted)
|
||||||
|
Loading…
Reference in New Issue
Block a user