2020-07-21 13:20:51 +00:00
|
|
|
import {BaseEntity, Column, Entity, JoinColumn, ManyToOne, OneToMany, PrimaryGeneratedColumn} from 'typeorm';
|
|
|
|
import {BillingAccountManager} from 'app/gen-server/entity/BillingAccountManager';
|
|
|
|
import {Organization} from 'app/gen-server/entity/Organization';
|
|
|
|
import {Product} from 'app/gen-server/entity/Product';
|
|
|
|
import {nativeValues} from 'app/gen-server/lib/values';
|
2023-07-05 15:36:45 +00:00
|
|
|
import {Limit} from 'app/gen-server/entity/Limit';
|
2020-07-21 13:20:51 +00:00
|
|
|
|
|
|
|
// This type is for billing account status information. Intended for stuff
|
|
|
|
// like "free trial running out in N days".
|
2023-07-05 15:36:45 +00:00
|
|
|
export interface BillingAccountStatus {
|
2020-07-21 13:20:51 +00:00
|
|
|
stripeStatus?: string;
|
2023-07-05 15:36:45 +00:00
|
|
|
currentPeriodEnd?: string;
|
2020-07-21 13:20:51 +00:00
|
|
|
message?: string;
|
|
|
|
}
|
|
|
|
|
2021-06-17 20:48:46 +00:00
|
|
|
// A structure for billing options relevant to an external authority, for sites
|
|
|
|
// created outside of Grist's regular billing flow.
|
|
|
|
export interface ExternalBillingOptions {
|
|
|
|
authority: string; // The name of the external authority.
|
|
|
|
invoiceId?: string; // An id of an invoice or other external billing context.
|
|
|
|
}
|
|
|
|
|
2020-07-21 13:20:51 +00:00
|
|
|
/**
|
|
|
|
* This relates organizations to products. It holds any stripe information
|
|
|
|
* needed to be able to update and pay for the product that applies to the
|
|
|
|
* organization. It has a list of managers detailing which users have the
|
|
|
|
* right to view and edit these settings.
|
|
|
|
*/
|
|
|
|
@Entity({name: 'billing_accounts'})
|
|
|
|
export class BillingAccount extends BaseEntity {
|
|
|
|
@PrimaryGeneratedColumn()
|
|
|
|
public id: number;
|
|
|
|
|
|
|
|
@ManyToOne(type => Product)
|
|
|
|
@JoinColumn({name: 'product_id'})
|
|
|
|
public product: Product;
|
|
|
|
|
2023-05-23 19:17:28 +00:00
|
|
|
@Column({type: Boolean})
|
2020-07-21 13:20:51 +00:00
|
|
|
public individual: boolean;
|
|
|
|
|
|
|
|
// A flag for when all is well with the user's subscription.
|
|
|
|
// Probably shouldn't use this to drive whether service is provided or not.
|
|
|
|
// Strip recommends updating an end-of-service datetime every time payment
|
|
|
|
// is received, adding on a grace period of some days.
|
2023-05-23 19:17:28 +00:00
|
|
|
@Column({name: 'in_good_standing', type: Boolean, default: nativeValues.trueValue})
|
2020-07-21 13:20:51 +00:00
|
|
|
public inGoodStanding: boolean;
|
|
|
|
|
|
|
|
@Column({type: nativeValues.jsonEntityType, nullable: true})
|
|
|
|
public status: BillingAccountStatus;
|
|
|
|
|
|
|
|
@Column({name: 'stripe_customer_id', type: String, nullable: true})
|
|
|
|
public stripeCustomerId: string | null;
|
|
|
|
|
|
|
|
@Column({name: 'stripe_subscription_id', type: String, nullable: true})
|
|
|
|
public stripeSubscriptionId: string | null;
|
|
|
|
|
|
|
|
@Column({name: 'stripe_plan_id', type: String, nullable: true})
|
|
|
|
public stripePlanId: string | null;
|
|
|
|
|
2021-06-17 20:48:46 +00:00
|
|
|
@Column({name: 'external_id', type: String, nullable: true})
|
|
|
|
public externalId: string | null;
|
|
|
|
|
|
|
|
@Column({name: 'external_options', type: nativeValues.jsonEntityType, nullable: true})
|
|
|
|
public externalOptions: ExternalBillingOptions | null;
|
|
|
|
|
2020-07-21 13:20:51 +00:00
|
|
|
@OneToMany(type => BillingAccountManager, manager => manager.billingAccount)
|
|
|
|
public managers: BillingAccountManager[];
|
|
|
|
|
|
|
|
@OneToMany(type => Organization, org => org.billingAccount)
|
|
|
|
public orgs: Organization[];
|
|
|
|
|
2023-07-05 15:36:45 +00:00
|
|
|
@OneToMany(type => Limit, limit => limit.billingAccount)
|
|
|
|
public limits: Limit[];
|
|
|
|
|
2020-07-21 13:20:51 +00:00
|
|
|
// A calculated column that is true if it looks like there is a paid plan.
|
|
|
|
@Column({name: 'paid', type: 'boolean', insert: false, select: false})
|
|
|
|
public paid?: boolean;
|
|
|
|
|
|
|
|
// A calculated column summarizing whether active user is a manager of the billing account.
|
|
|
|
// (No @Column needed since calculation is done in javascript not sql)
|
|
|
|
public isManager?: boolean;
|
|
|
|
}
|