mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 07:36:14 -05:00
upgrade stripe lib and breaking changes
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
using Bit.Core.Enums;
|
||||
using Braintree;
|
||||
using Stripe;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -16,40 +15,37 @@ namespace Bit.Core.Models.Business
|
||||
|
||||
public class BillingSource
|
||||
{
|
||||
public BillingSource(Source source)
|
||||
public BillingSource(IPaymentSource source)
|
||||
{
|
||||
switch(source.Type)
|
||||
if(source is BankAccount bankAccount)
|
||||
{
|
||||
case SourceType.Card:
|
||||
Type = PaymentMethodType.Card;
|
||||
Description = $"{source.Card.Brand}, *{source.Card.Last4}, " +
|
||||
string.Format("{0}/{1}",
|
||||
string.Concat(source.Card.ExpirationMonth < 10 ?
|
||||
"0" : string.Empty, source.Card.ExpirationMonth),
|
||||
source.Card.ExpirationYear);
|
||||
CardBrand = source.Card.Brand;
|
||||
break;
|
||||
case SourceType.BankAccount:
|
||||
Type = PaymentMethodType.BankAccount;
|
||||
Description = $"{source.BankAccount.BankName}, *{source.BankAccount.Last4} - " +
|
||||
(source.BankAccount.Status == "verified" ? "verified" :
|
||||
source.BankAccount.Status == "errored" ? "invalid" :
|
||||
source.BankAccount.Status == "verification_failed" ? "verification failed" : "unverified");
|
||||
NeedsVerification = source.BankAccount.Status == "new" || source.BankAccount.Status == "validated";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
Type = PaymentMethodType.BankAccount;
|
||||
Description = $"{bankAccount.BankName}, *{bankAccount.Last4} - " +
|
||||
(bankAccount.Status == "verified" ? "verified" :
|
||||
bankAccount.Status == "errored" ? "invalid" :
|
||||
bankAccount.Status == "verification_failed" ? "verification failed" : "unverified");
|
||||
NeedsVerification = bankAccount.Status == "new" || bankAccount.Status == "validated";
|
||||
}
|
||||
else if(source is Card card)
|
||||
{
|
||||
Type = PaymentMethodType.Card;
|
||||
Description = $"{card.Brand}, *{card.Last4}, " +
|
||||
string.Format("{0}/{1}",
|
||||
string.Concat(card.ExpMonth < 10 ?
|
||||
"0" : string.Empty, card.ExpMonth),
|
||||
card.ExpYear);
|
||||
CardBrand = card.Brand;
|
||||
}
|
||||
}
|
||||
|
||||
public BillingSource(PaymentMethod method)
|
||||
public BillingSource(Braintree.PaymentMethod method)
|
||||
{
|
||||
if(method is PayPalAccount paypal)
|
||||
if(method is Braintree.PayPalAccount paypal)
|
||||
{
|
||||
Type = PaymentMethodType.PayPal;
|
||||
Description = paypal.Email;
|
||||
}
|
||||
else if(method is CreditCard card)
|
||||
else if(method is Braintree.CreditCard card)
|
||||
{
|
||||
Type = PaymentMethodType.Card;
|
||||
Description = $"{card.CardType.ToString()}, *{card.LastFour}, " +
|
||||
@ -59,7 +55,7 @@ namespace Bit.Core.Models.Business
|
||||
card.ExpirationYear);
|
||||
CardBrand = card.CardType.ToString();
|
||||
}
|
||||
else if(method is UsBankAccount bank)
|
||||
else if(method is Braintree.UsBankAccount bank)
|
||||
{
|
||||
Type = PaymentMethodType.BankAccount;
|
||||
Description = $"{bank.BankName}, *{bank.Last4}";
|
||||
@ -70,13 +66,13 @@ namespace Bit.Core.Models.Business
|
||||
}
|
||||
}
|
||||
|
||||
public BillingSource(UsBankAccountDetails bank)
|
||||
public BillingSource(Braintree.UsBankAccountDetails bank)
|
||||
{
|
||||
Type = PaymentMethodType.BankAccount;
|
||||
Description = $"{bank.BankName}, *{bank.Last4}";
|
||||
}
|
||||
|
||||
public BillingSource(PayPalDetails paypal)
|
||||
public BillingSource(Braintree.PayPalDetails paypal)
|
||||
{
|
||||
Type = PaymentMethodType.PayPal;
|
||||
Description = paypal.PayerEmail;
|
||||
@ -90,7 +86,7 @@ namespace Bit.Core.Models.Business
|
||||
|
||||
public class BillingSubscription
|
||||
{
|
||||
public BillingSubscription(StripeSubscription sub)
|
||||
public BillingSubscription(Subscription sub)
|
||||
{
|
||||
Status = sub.Status;
|
||||
TrialStartDate = sub.TrialStart;
|
||||
@ -106,14 +102,14 @@ namespace Bit.Core.Models.Business
|
||||
}
|
||||
}
|
||||
|
||||
public BillingSubscription(Subscription sub, Plan plan)
|
||||
public BillingSubscription(Braintree.Subscription sub, Braintree.Plan plan)
|
||||
{
|
||||
Status = sub.Status.ToString();
|
||||
|
||||
if(sub.HasTrialPeriod.GetValueOrDefault() && sub.CreatedAt.HasValue && sub.TrialDuration.HasValue)
|
||||
{
|
||||
TrialStartDate = sub.CreatedAt.Value;
|
||||
if(sub.TrialDurationUnit == SubscriptionDurationUnit.DAY)
|
||||
if(sub.TrialDurationUnit == Braintree.SubscriptionDurationUnit.DAY)
|
||||
{
|
||||
TrialEndDate = TrialStartDate.Value.AddDays(sub.TrialDuration.Value);
|
||||
}
|
||||
@ -127,7 +123,7 @@ namespace Bit.Core.Models.Business
|
||||
PeriodEndDate = sub.BillingPeriodEndDate;
|
||||
|
||||
CancelAtEndDate = !sub.NeverExpires.GetValueOrDefault();
|
||||
Cancelled = sub.Status == SubscriptionStatus.CANCELED;
|
||||
Cancelled = sub.Status == Braintree.SubscriptionStatus.CANCELED;
|
||||
if(Cancelled)
|
||||
{
|
||||
CancelledDate = sub.UpdatedAt.Value;
|
||||
@ -159,7 +155,7 @@ namespace Bit.Core.Models.Business
|
||||
|
||||
public class BillingSubscriptionItem
|
||||
{
|
||||
public BillingSubscriptionItem(StripeSubscriptionItem item)
|
||||
public BillingSubscriptionItem(SubscriptionItem item)
|
||||
{
|
||||
if(item.Plan != null)
|
||||
{
|
||||
@ -168,10 +164,10 @@ namespace Bit.Core.Models.Business
|
||||
Interval = item.Plan.Interval;
|
||||
}
|
||||
|
||||
Quantity = item.Quantity;
|
||||
Quantity = (int)item.Quantity;
|
||||
}
|
||||
|
||||
public BillingSubscriptionItem(Plan plan)
|
||||
public BillingSubscriptionItem(Braintree.Plan plan)
|
||||
{
|
||||
Name = plan.Name;
|
||||
Amount = plan.Price.GetValueOrDefault();
|
||||
@ -179,7 +175,7 @@ namespace Bit.Core.Models.Business
|
||||
Quantity = 1;
|
||||
}
|
||||
|
||||
public BillingSubscriptionItem(Plan plan, AddOn addon)
|
||||
public BillingSubscriptionItem(Braintree.Plan plan, Braintree.AddOn addon)
|
||||
{
|
||||
Name = addon.Name;
|
||||
Amount = addon.Amount.GetValueOrDefault();
|
||||
@ -196,13 +192,13 @@ namespace Bit.Core.Models.Business
|
||||
|
||||
public class BillingInvoice
|
||||
{
|
||||
public BillingInvoice(StripeInvoice inv)
|
||||
public BillingInvoice(Invoice inv)
|
||||
{
|
||||
Amount = inv.AmountDue / 100M;
|
||||
Date = inv.Date.Value;
|
||||
}
|
||||
|
||||
public BillingInvoice(Subscription sub)
|
||||
public BillingInvoice(Braintree.Subscription sub)
|
||||
{
|
||||
Amount = sub.NextBillAmount.GetValueOrDefault() + sub.Balance.GetValueOrDefault();
|
||||
if(Amount < 0)
|
||||
@ -218,7 +214,7 @@ namespace Bit.Core.Models.Business
|
||||
|
||||
public class BillingCharge
|
||||
{
|
||||
public BillingCharge(StripeCharge charge)
|
||||
public BillingCharge(Charge charge)
|
||||
{
|
||||
Amount = charge.Amount / 100M;
|
||||
RefundedAmount = charge.AmountRefunded / 100M;
|
||||
@ -230,7 +226,7 @@ namespace Bit.Core.Models.Business
|
||||
InvoiceId = charge.InvoiceId;
|
||||
}
|
||||
|
||||
public BillingCharge(Transaction transaction)
|
||||
public BillingCharge(Braintree.Transaction transaction)
|
||||
{
|
||||
Amount = transaction.Amount.GetValueOrDefault();
|
||||
RefundedAmount = 0; // TODO?
|
||||
@ -239,7 +235,8 @@ namespace Bit.Core.Models.Business
|
||||
{
|
||||
PaymentSource = new BillingSource(transaction.PayPalDetails);
|
||||
}
|
||||
else if(transaction.CreditCard != null && transaction.CreditCard.CardType != CreditCardCardType.UNRECOGNIZED)
|
||||
else if(transaction.CreditCard != null &&
|
||||
transaction.CreditCard.CardType != Braintree.CreditCardCardType.UNRECOGNIZED)
|
||||
{
|
||||
PaymentSource = new BillingSource(transaction.CreditCard);
|
||||
}
|
||||
|
Reference in New Issue
Block a user