@shaxpir/duiduidui-models 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/models/{content/ArrayView.d.ts → ArrayView.d.ts} +1 -1
- package/dist/models/{content/ArrayView.js → ArrayView.js} +14 -14
- package/dist/models/BayesianScore.d.ts +9 -0
- package/dist/models/BayesianScore.js +27 -0
- package/dist/models/{markup/ChangeModel.d.ts → ChangeModel.d.ts} +2 -3
- package/dist/models/{markup/ChangeModel.js → ChangeModel.js} +20 -10
- package/dist/models/{content/Content.d.ts → Content.d.ts} +9 -10
- package/dist/models/{content/Content.js → Content.js} +2 -6
- package/dist/models/{content/ContentKind.d.ts → ContentKind.d.ts} +3 -0
- package/dist/models/{content/ContentKind.js → ContentKind.js} +5 -1
- package/dist/models/{content/Device.d.ts → Device.d.ts} +15 -7
- package/dist/models/{content/Device.js → Device.js} +14 -18
- package/dist/models/Hanzi.d.ts +15 -0
- package/dist/models/{content/Manifest.d.ts → Manifest.d.ts} +7 -3
- package/dist/models/{content/Manifest.js → Manifest.js} +12 -8
- package/dist/models/{content/Media.d.ts → Media.d.ts} +2 -3
- package/dist/models/{content/Media.js → Media.js} +4 -5
- package/dist/models/{content/Metric.d.ts → Metric.d.ts} +2 -3
- package/dist/models/{content/Metric.js → Metric.js} +18 -20
- package/dist/models/{content/Model.d.ts → Model.d.ts} +3 -5
- package/dist/models/{content/Model.js → Model.js} +5 -6
- package/dist/models/{markup/Operation.d.ts → Operation.d.ts} +2 -5
- package/dist/models/{markup/Operation.js → Operation.js} +30 -25
- package/dist/models/Phrase.d.ts +39 -0
- package/dist/models/{content/Profile.d.ts → Profile.d.ts} +1 -2
- package/dist/models/{content/Profile.js → Profile.js} +7 -9
- package/dist/models/Progress.d.ts +26 -0
- package/dist/models/Progress.js +39 -0
- package/dist/models/Review.d.ts +14 -0
- package/dist/models/{content/Session.d.ts → Session.d.ts} +7 -15
- package/dist/models/Session.js +103 -0
- package/dist/models/Term.d.ts +36 -0
- package/dist/models/Term.js +82 -0
- package/dist/models/User.d.ts +32 -0
- package/dist/models/User.js +65 -0
- package/dist/models/Workspace.d.ts +37 -0
- package/dist/models/Workspace.js +94 -0
- package/dist/models/index.d.ts +22 -4
- package/dist/models/index.js +22 -4
- package/dist/repo/PermissiveJson1.d.ts +16 -16
- package/dist/repo/PermissiveJson1.js +17 -7
- package/dist/repo/ShareSync.d.ts +6 -6
- package/dist/repo/ShareSync.js +26 -19
- package/dist/repo/index.d.ts +1 -0
- package/dist/repo/index.js +1 -0
- package/dist/util/index.d.ts +0 -14
- package/dist/util/index.js +0 -14
- package/lib/index.ts +5 -0
- package/lib/models/{content/ArrayView.ts → ArrayView.ts} +2 -2
- package/lib/models/BayesianScore.ts +32 -0
- package/lib/models/{markup/ChangeModel.ts → ChangeModel.ts} +3 -4
- package/lib/models/{content/Content.ts → Content.ts} +15 -18
- package/lib/models/{content/ContentKind.ts → ContentKind.ts} +6 -1
- package/lib/models/{content/Device.ts → Device.ts} +26 -22
- package/lib/models/Hanzi.ts +16 -0
- package/lib/models/{content/Manifest.ts → Manifest.ts} +15 -6
- package/lib/models/{content/Media.ts → Media.ts} +3 -4
- package/lib/models/Metric.ts +233 -0
- package/lib/models/{content/Model.ts → Model.ts} +4 -6
- package/lib/models/{markup/Operation.ts → Operation.ts} +6 -16
- package/lib/models/{content/Permissions.ts → Permissions.ts} +0 -2
- package/lib/models/Phrase.ts +53 -0
- package/lib/models/{content/Profile.ts → Profile.ts} +4 -6
- package/lib/models/Progress.ts +66 -0
- package/lib/models/Review.ts +18 -0
- package/lib/models/Session.ts +140 -0
- package/lib/models/Term.ts +139 -0
- package/lib/models/User.ts +97 -0
- package/lib/models/Workspace.ts +129 -0
- package/lib/models/index.ts +24 -0
- package/lib/repo/ShareSync.ts +9 -13
- package/lib/repo/index.ts +6 -0
- package/lib/util/index.ts +4 -0
- package/package.json +4 -15
- package/dist/models/OutboundMessage.d.ts +0 -18
- package/dist/models/OutboundMessage.js +0 -25
- package/dist/models/content/Activity.d.ts +0 -10
- package/dist/models/content/Billing.d.ts +0 -144
- package/dist/models/content/Billing.js +0 -418
- package/dist/models/content/Book.d.ts +0 -77
- package/dist/models/content/Book.js +0 -407
- package/dist/models/content/Category.d.ts +0 -16
- package/dist/models/content/Category.js +0 -20
- package/dist/models/content/Checkpointable.d.ts +0 -21
- package/dist/models/content/Checkpointable.js +0 -156
- package/dist/models/content/Comment.d.ts +0 -19
- package/dist/models/content/Comment.js +0 -53
- package/dist/models/content/ConceptArt.d.ts +0 -31
- package/dist/models/content/ConceptArt.js +0 -84
- package/dist/models/content/Context.d.ts +0 -28
- package/dist/models/content/Context.js +0 -162
- package/dist/models/content/DevEnv.d.ts +0 -5
- package/dist/models/content/DevEnv.js +0 -9
- package/dist/models/content/Dictionary.d.ts +0 -31
- package/dist/models/content/Dictionary.js +0 -5
- package/dist/models/content/DictionaryEntry.d.ts +0 -20
- package/dist/models/content/DictionaryEntry.js +0 -2
- package/dist/models/content/ElasticModel.d.ts +0 -149
- package/dist/models/content/ElasticModel.js +0 -179
- package/dist/models/content/Environment.d.ts +0 -61
- package/dist/models/content/Environment.js +0 -124
- package/dist/models/content/ExportOptions.d.ts +0 -64
- package/dist/models/content/ExportOptions.js +0 -213
- package/dist/models/content/Folder.d.ts +0 -16
- package/dist/models/content/Folder.js +0 -33
- package/dist/models/content/Fragment.d.ts +0 -54
- package/dist/models/content/Fragment.js +0 -181
- package/dist/models/content/Hanzi.d.ts +0 -21
- package/dist/models/content/HighlightRule.d.ts +0 -9
- package/dist/models/content/HighlightRule.js +0 -2
- package/dist/models/content/Migration.d.ts +0 -68
- package/dist/models/content/Migration.js +0 -155
- package/dist/models/content/Phrase.d.ts +0 -8
- package/dist/models/content/Placeholder.d.ts +0 -8
- package/dist/models/content/Placeholder.js +0 -36
- package/dist/models/content/RichText.d.ts +0 -58
- package/dist/models/content/RichText.js +0 -79
- package/dist/models/content/Session.js +0 -173
- package/dist/models/content/Speech.d.ts +0 -67
- package/dist/models/content/Speech.js +0 -97
- package/dist/models/content/Stub.d.ts +0 -24
- package/dist/models/content/Stub.js +0 -179
- package/dist/models/content/Time.d.ts +0 -56
- package/dist/models/content/Time.js +0 -295
- package/dist/models/content/User.d.ts +0 -36
- package/dist/models/content/User.js +0 -95
- package/dist/models/content/Workspace.d.ts +0 -71
- package/dist/models/content/Workspace.js +0 -237
- package/dist/models/content/index.d.ts +0 -36
- package/dist/models/content/index.js +0 -53
- package/dist/models/legacy/LegacyBodyFormat.d.ts +0 -9
- package/dist/models/legacy/LegacyBodyFormat.js +0 -2
- package/dist/models/legacy/LegacyComment.d.ts +0 -12
- package/dist/models/legacy/LegacyComment.js +0 -2
- package/dist/models/legacy/LegacyContent.d.ts +0 -53
- package/dist/models/legacy/LegacyContent.js +0 -55
- package/dist/models/legacy/LegacyConversion.d.ts +0 -55
- package/dist/models/legacy/LegacyConversion.js +0 -401
- package/dist/models/legacy/LegacyFragment.d.ts +0 -21
- package/dist/models/legacy/LegacyFragment.js +0 -2
- package/dist/models/legacy/LegacyLocator.d.ts +0 -8
- package/dist/models/legacy/LegacyLocator.js +0 -31
- package/dist/models/legacy/LegacyOutboundMessage.d.ts +0 -16
- package/dist/models/legacy/LegacyOutboundMessage.js +0 -13
- package/dist/models/legacy/LegacyPicture.d.ts +0 -14
- package/dist/models/legacy/LegacyPicture.js +0 -2
- package/dist/models/legacy/LegacyProfile.d.ts +0 -9
- package/dist/models/legacy/LegacyProfile.js +0 -2
- package/dist/models/legacy/LegacySession.d.ts +0 -41
- package/dist/models/legacy/LegacySession.js +0 -35
- package/dist/models/legacy/LegacyStory.d.ts +0 -23
- package/dist/models/legacy/LegacyStory.js +0 -2
- package/dist/models/legacy/LegacyStub.d.ts +0 -15
- package/dist/models/legacy/LegacyStub.js +0 -2
- package/dist/models/legacy/LegacyTransaction.d.ts +0 -14
- package/dist/models/legacy/LegacyTransaction.js +0 -49
- package/dist/models/legacy/LegacyUser.d.ts +0 -28
- package/dist/models/legacy/LegacyUser.js +0 -32
- package/dist/models/legacy/LegacyWorkspace.d.ts +0 -23
- package/dist/models/legacy/LegacyWorkspace.js +0 -6
- package/dist/models/legacy/index.d.ts +0 -15
- package/dist/models/legacy/index.js +0 -32
- package/dist/models/markup/BodyFormat.d.ts +0 -14
- package/dist/models/markup/BodyFormat.js +0 -190
- package/dist/models/markup/DeltaOps.d.ts +0 -5
- package/dist/models/markup/DeltaOps.js +0 -74
- package/dist/models/markup/HtmlMarkup.d.ts +0 -4
- package/dist/models/markup/HtmlMarkup.js +0 -21
- package/dist/models/markup/index.d.ts +0 -6
- package/dist/models/markup/index.js +0 -23
- package/dist/util/Async.d.ts +0 -8
- package/dist/util/Async.js +0 -18
- package/dist/util/Base62.d.ts +0 -6
- package/dist/util/Base62.js +0 -47
- package/dist/util/BinarySearch.d.ts +0 -7
- package/dist/util/BinarySearch.js +0 -46
- package/dist/util/CachingHasher.d.ts +0 -8
- package/dist/util/CachingHasher.js +0 -41
- package/dist/util/Color.d.ts +0 -32
- package/dist/util/Color.js +0 -204
- package/dist/util/Dispatch.d.ts +0 -15
- package/dist/util/Dispatch.js +0 -79
- package/dist/util/EditDistance.d.ts +0 -13
- package/dist/util/EditDistance.js +0 -184
- package/dist/util/NumberFormat.d.ts +0 -14
- package/dist/util/NumberFormat.js +0 -224
- package/dist/util/Struct.d.ts +0 -4
- package/dist/util/Struct.js +0 -15
- package/dist/util/Template.d.ts +0 -16
- package/dist/util/Template.js +0 -128
- package/dist/util/Text.d.ts +0 -45
- package/dist/util/Text.js +0 -243
- package/dist/util/Tuples.d.ts +0 -9
- package/dist/util/Tuples.js +0 -135
- package/dist/util/Validate.d.ts +0 -4
- package/dist/util/Validate.js +0 -11
- package/dist/util/Vocabulary.d.ts +0 -3
- package/dist/util/Vocabulary.js +0 -35
- package/lib/models/content/Billing.ts +0 -558
- package/lib/models/content/DevEnv.ts +0 -5
- package/lib/models/content/DictionaryEntry.ts +0 -22
- package/lib/models/content/Hanzi.ts +0 -25
- package/lib/models/content/Phrase.ts +0 -10
- package/lib/models/content/Time.ts +0 -328
- package/lib/models/content/User.ts +0 -130
- package/lib/models/markup/DeltaOps.ts +0 -71
- package/lib/util/Base62.ts +0 -47
- package/lib/util/CachingHasher.ts +0 -38
- package/lib/util/Dispatch.ts +0 -92
- package/lib/util/NumberFormat.ts +0 -194
- package/lib/util/Struct.ts +0 -14
- package/lib/util/Tuples.ts +0 -131
- /package/dist/models/{content/GeoLocation.d.ts → GeoLocation.d.ts} +0 -0
- /package/dist/models/{content/GeoLocation.js → GeoLocation.js} +0 -0
- /package/dist/models/{content/Hanzi.js → Hanzi.js} +0 -0
- /package/dist/models/{content/Permissions.d.ts → Permissions.d.ts} +0 -0
- /package/dist/models/{content/Permissions.js → Permissions.js} +0 -0
- /package/dist/models/{content/Phrase.js → Phrase.js} +0 -0
- /package/dist/models/{content/Activity.js → Review.js} +0 -0
- /package/dist/{models/markup → repo}/TextEditOps.d.ts +0 -0
- /package/dist/{models/markup → repo}/TextEditOps.js +0 -0
- /package/lib/models/{content/GeoLocation.ts → GeoLocation.ts} +0 -0
- /package/lib/{models/markup → repo}/TextEditOps.ts +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shaxpir/duiduidui-models",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/shaxpir/duiduidui-models"
|
|
@@ -13,26 +13,15 @@
|
|
|
13
13
|
"main": "dist/index.js",
|
|
14
14
|
"types": "dist/index.d.ts",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@shaxpir/quill-delta": "^6.1.1",
|
|
17
|
-
"@shaxpir/rich-text": "^5.0.2",
|
|
18
16
|
"@shaxpir/sharedb": "^5.3.0",
|
|
19
|
-
"
|
|
20
|
-
"hsluv": "latest",
|
|
17
|
+
"@shaxpir/shaxpir-common": "1.3.0",
|
|
21
18
|
"ot-json1": "1.0.1",
|
|
22
19
|
"ot-text-unicode": "4.0.0",
|
|
23
|
-
"
|
|
24
|
-
"json-diff-ts": "1.2.4",
|
|
25
|
-
"md5": "2.x",
|
|
26
|
-
"pluralize": "latest",
|
|
27
|
-
"reconnecting-websocket": "4.4.0",
|
|
28
|
-
"fast-deep-equal": "^3.1.3",
|
|
29
|
-
"rfdc": "^1.1.4"
|
|
20
|
+
"reconnecting-websocket": "4.4.0"
|
|
30
21
|
},
|
|
31
22
|
"devDependencies": {
|
|
32
|
-
"@types/lodash": "
|
|
33
|
-
"@types/md5": "^2.1.33",
|
|
23
|
+
"@types/lodash": "^4.17.20",
|
|
34
24
|
"@types/node": "^18.0.50",
|
|
35
|
-
"@types/pluralize": "0.0.29",
|
|
36
25
|
"chai": "^4.3.7",
|
|
37
26
|
"mocha": "^10.2.0",
|
|
38
27
|
"tslint": "^5.12.1",
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { CompactDateTime } from "./content/Time";
|
|
2
|
-
export declare enum OutboundChannel {
|
|
3
|
-
EMAIL = "EMAIL"
|
|
4
|
-
}
|
|
5
|
-
export interface OutboundMessage {
|
|
6
|
-
id: string;
|
|
7
|
-
at_utc_time: CompactDateTime;
|
|
8
|
-
user_id: string;
|
|
9
|
-
campaign: string;
|
|
10
|
-
channel: OutboundChannel;
|
|
11
|
-
template: string;
|
|
12
|
-
recipient: string;
|
|
13
|
-
dryrun: boolean;
|
|
14
|
-
params: any;
|
|
15
|
-
}
|
|
16
|
-
export declare class OutboundMessageModel {
|
|
17
|
-
static create(userId: string, template: string, recipient: string, params: any): OutboundMessage;
|
|
18
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OutboundMessageModel = exports.OutboundChannel = void 0;
|
|
4
|
-
const Time_1 = require("./content/Time");
|
|
5
|
-
var OutboundChannel;
|
|
6
|
-
(function (OutboundChannel) {
|
|
7
|
-
OutboundChannel["EMAIL"] = "EMAIL";
|
|
8
|
-
})(OutboundChannel || (exports.OutboundChannel = OutboundChannel = {}));
|
|
9
|
-
class OutboundMessageModel {
|
|
10
|
-
static create(userId, template, recipient, params) {
|
|
11
|
-
params.email = recipient;
|
|
12
|
-
return {
|
|
13
|
-
"id": null,
|
|
14
|
-
"at_utc_time": Time_1.Time.utc(),
|
|
15
|
-
"user_id": userId,
|
|
16
|
-
"campaign": null,
|
|
17
|
-
"channel": OutboundChannel.EMAIL,
|
|
18
|
-
"template": template,
|
|
19
|
-
"recipient": recipient,
|
|
20
|
-
"dryrun": false,
|
|
21
|
-
"params": params
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.OutboundMessageModel = OutboundMessageModel;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ContentId } from "./Content";
|
|
2
|
-
import { ContentKind } from "./ContentKind";
|
|
3
|
-
import { CompactDateTime } from "./Time";
|
|
4
|
-
export interface Activity {
|
|
5
|
-
kind: ContentKind;
|
|
6
|
-
id: ContentId;
|
|
7
|
-
before: CompactDateTime;
|
|
8
|
-
after: CompactDateTime;
|
|
9
|
-
word_count?: number;
|
|
10
|
-
}
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/// <reference path="../../../decs.d.ts" />
|
|
2
|
-
import { Doc } from '@shaxpir/sharedb/lib/client';
|
|
3
|
-
import { ShareSync } from '../../repo/ShareSync';
|
|
4
|
-
import { ArrayView } from './ArrayView';
|
|
5
|
-
import { Content, ContentBody, ContentId, ContentMeta } from "./Content";
|
|
6
|
-
import { CompactDateTime, MultiTime } from './Time';
|
|
7
|
-
export interface CreditCardHarvest {
|
|
8
|
-
name: string;
|
|
9
|
-
number: string;
|
|
10
|
-
cvc: string;
|
|
11
|
-
exp_month: string;
|
|
12
|
-
exp_year: string;
|
|
13
|
-
}
|
|
14
|
-
export interface CreditCard {
|
|
15
|
-
name: string;
|
|
16
|
-
brand: string;
|
|
17
|
-
last4: string;
|
|
18
|
-
exp_month: string;
|
|
19
|
-
exp_year: string;
|
|
20
|
-
country: string;
|
|
21
|
-
funding: string;
|
|
22
|
-
wallet?: string;
|
|
23
|
-
}
|
|
24
|
-
export interface TransactionPayload {
|
|
25
|
-
at_utc_time?: CompactDateTime;
|
|
26
|
-
topic: TransactionTopic;
|
|
27
|
-
details?: any;
|
|
28
|
-
}
|
|
29
|
-
export declare enum TransactionTopic {
|
|
30
|
-
START_7_DAY_TRIAL = "START_7_DAY_TRIAL",
|
|
31
|
-
APPLY_COUPON = "APPLY_COUPON",
|
|
32
|
-
PAYMENT_SUCCESS = "PAYMENT_SUCCESS",
|
|
33
|
-
PAYMENT_FAIL = "PAYMENT_FAIL",
|
|
34
|
-
CANCEL_SUBSCRIPTION = "CANCEL_SUBSCRIPTION",
|
|
35
|
-
RESTART_SUBSCRIPTION = "RESTART_SUBSCRIPTION"
|
|
36
|
-
}
|
|
37
|
-
export declare enum Interval {
|
|
38
|
-
MONTHLY = "MONTHLY",
|
|
39
|
-
ANNUAL = "ANNUAL"
|
|
40
|
-
}
|
|
41
|
-
export declare enum ProductLevel {
|
|
42
|
-
FREE = "FREE",
|
|
43
|
-
BASIC = "BASIC",
|
|
44
|
-
PRO = "PRO"
|
|
45
|
-
}
|
|
46
|
-
export interface BillingProduct {
|
|
47
|
-
id: string;
|
|
48
|
-
name: string;
|
|
49
|
-
level: ProductLevel;
|
|
50
|
-
}
|
|
51
|
-
export interface BillingPrice {
|
|
52
|
-
id: string;
|
|
53
|
-
name: string;
|
|
54
|
-
amount: number;
|
|
55
|
-
interval: Interval;
|
|
56
|
-
product_id: string;
|
|
57
|
-
trial_days: number;
|
|
58
|
-
}
|
|
59
|
-
export interface BillingPlan {
|
|
60
|
-
id: string;
|
|
61
|
-
name: string;
|
|
62
|
-
amount: number;
|
|
63
|
-
level: ProductLevel;
|
|
64
|
-
interval: Interval;
|
|
65
|
-
trial_days: number;
|
|
66
|
-
}
|
|
67
|
-
export interface ProductCatalogConfig {
|
|
68
|
-
products: BillingProduct[];
|
|
69
|
-
prices: BillingPrice[];
|
|
70
|
-
plans: BillingPlan[];
|
|
71
|
-
}
|
|
72
|
-
export declare class ProductCatalog {
|
|
73
|
-
private productsById;
|
|
74
|
-
private pricesById;
|
|
75
|
-
private plansById;
|
|
76
|
-
constructor(config: ProductCatalogConfig);
|
|
77
|
-
getProductById(id: string): BillingProduct;
|
|
78
|
-
getPriceById(id: string): BillingPrice;
|
|
79
|
-
getPlanById(id: string): BillingPlan;
|
|
80
|
-
getProductsByPredicate(predicate: (product: BillingProduct) => boolean): BillingProduct[];
|
|
81
|
-
getPricesByPredicate(predicate: (price: BillingPrice) => boolean): BillingPrice[];
|
|
82
|
-
getPlansByPredicate(predicate: (plan: BillingPlan) => boolean): BillingPlan[];
|
|
83
|
-
}
|
|
84
|
-
export declare enum PaymentStatus {
|
|
85
|
-
PRE_TRIAL = "PRE_TRIAL",
|
|
86
|
-
IN_TRIAL = "IN_TRIAL",
|
|
87
|
-
PAID = "PAID",
|
|
88
|
-
UNPAID = "UNPAID",
|
|
89
|
-
CANCELLED = "CANCELLED"
|
|
90
|
-
}
|
|
91
|
-
export interface BillingBody extends ContentBody {
|
|
92
|
-
meta: ContentMeta;
|
|
93
|
-
payload: BillingPayload;
|
|
94
|
-
}
|
|
95
|
-
export interface BillingPayload {
|
|
96
|
-
payment_status: PaymentStatus;
|
|
97
|
-
paid_until: CompactDateTime;
|
|
98
|
-
stripe_customer_id: string;
|
|
99
|
-
stripe_payment_method_id?: string;
|
|
100
|
-
stripe_payment_method_type?: string;
|
|
101
|
-
transactions: TransactionPayload[];
|
|
102
|
-
credit_card?: CreditCard;
|
|
103
|
-
product_id?: string;
|
|
104
|
-
price_id?: string;
|
|
105
|
-
}
|
|
106
|
-
export declare class Billing extends Content {
|
|
107
|
-
private _transactionsView;
|
|
108
|
-
constructor(doc: Doc, shouldAcquire: boolean, shareSync: ShareSync);
|
|
109
|
-
get payload(): BillingPayload;
|
|
110
|
-
static makeBillingId(userId: ContentId): ContentId;
|
|
111
|
-
static create(userId: ContentId, payload: BillingPayload, createdAt?: MultiTime): Billing;
|
|
112
|
-
isSubscribedToPricedProduct(): boolean;
|
|
113
|
-
get priceId(): string;
|
|
114
|
-
setPriceId(value: string): void;
|
|
115
|
-
get productId(): string;
|
|
116
|
-
setProductId(value: string): void;
|
|
117
|
-
get paidUntil(): CompactDateTime;
|
|
118
|
-
setPaidUntil(value: CompactDateTime): void;
|
|
119
|
-
get paymentStatus(): PaymentStatus;
|
|
120
|
-
setPaymentStatus(value: PaymentStatus): void;
|
|
121
|
-
get stripeCustomerId(): string;
|
|
122
|
-
setStripeCustomerId(value: string): void;
|
|
123
|
-
get stripePaymentMethodId(): string;
|
|
124
|
-
setStripePaymentMethodId(value: string): void;
|
|
125
|
-
get stripePaymentMethodType(): string;
|
|
126
|
-
setStripePaymentMethodType(value: string): void;
|
|
127
|
-
get creditCard(): CreditCard;
|
|
128
|
-
setCreditCard(value: CreditCard): void;
|
|
129
|
-
get transactions(): ArrayView<TransactionPayload>;
|
|
130
|
-
get sortedTransactions(): TransactionPayload[];
|
|
131
|
-
getLastTransaction(): TransactionPayload;
|
|
132
|
-
getLastPaymentTransaction(): TransactionPayload;
|
|
133
|
-
getActiveUserCoupon(): any;
|
|
134
|
-
daysPastDue(): number;
|
|
135
|
-
didLastPaymentFail(): boolean;
|
|
136
|
-
didLastPaymentSucceed(): boolean;
|
|
137
|
-
findTransactionByTopic(topic: TransactionTopic): TransactionPayload;
|
|
138
|
-
cancel(): void;
|
|
139
|
-
restartPlan(plan: string, paidUntilEpochSeconds: number): void;
|
|
140
|
-
restartPricedProduct(productId: string, priceId: string, paidUntilEpochSeconds: number): void;
|
|
141
|
-
static findByStripeCustomerId(stripeCustomerId: string): Promise<Billing[]>;
|
|
142
|
-
static describeCoupon(coupon: any): string;
|
|
143
|
-
static normalizeCreditCardBrand(brand: string): string;
|
|
144
|
-
}
|
|
@@ -1,418 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Billing = exports.PaymentStatus = exports.ProductCatalog = exports.ProductLevel = exports.Interval = exports.TransactionTopic = void 0;
|
|
4
|
-
const ShareSync_1 = require("../../repo/ShareSync");
|
|
5
|
-
const Struct_1 = require("../../util/Struct");
|
|
6
|
-
const CachingHasher_1 = require("../../util/CachingHasher");
|
|
7
|
-
const NumberFormat_1 = require("../../util/NumberFormat");
|
|
8
|
-
const Operation_1 = require("../markup/Operation");
|
|
9
|
-
const ArrayView_1 = require("./ArrayView");
|
|
10
|
-
const Content_1 = require("./Content");
|
|
11
|
-
const ContentKind_1 = require("./ContentKind");
|
|
12
|
-
const Time_1 = require("./Time");
|
|
13
|
-
var TransactionTopic;
|
|
14
|
-
(function (TransactionTopic) {
|
|
15
|
-
TransactionTopic["START_7_DAY_TRIAL"] = "START_7_DAY_TRIAL";
|
|
16
|
-
TransactionTopic["APPLY_COUPON"] = "APPLY_COUPON";
|
|
17
|
-
TransactionTopic["PAYMENT_SUCCESS"] = "PAYMENT_SUCCESS";
|
|
18
|
-
TransactionTopic["PAYMENT_FAIL"] = "PAYMENT_FAIL";
|
|
19
|
-
TransactionTopic["CANCEL_SUBSCRIPTION"] = "CANCEL_SUBSCRIPTION";
|
|
20
|
-
TransactionTopic["RESTART_SUBSCRIPTION"] = "RESTART_SUBSCRIPTION";
|
|
21
|
-
})(TransactionTopic || (exports.TransactionTopic = TransactionTopic = {}));
|
|
22
|
-
var Interval;
|
|
23
|
-
(function (Interval) {
|
|
24
|
-
Interval["MONTHLY"] = "MONTHLY";
|
|
25
|
-
Interval["ANNUAL"] = "ANNUAL";
|
|
26
|
-
})(Interval || (exports.Interval = Interval = {}));
|
|
27
|
-
;
|
|
28
|
-
var ProductLevel;
|
|
29
|
-
(function (ProductLevel) {
|
|
30
|
-
ProductLevel["FREE"] = "FREE";
|
|
31
|
-
ProductLevel["BASIC"] = "BASIC";
|
|
32
|
-
ProductLevel["PRO"] = "PRO";
|
|
33
|
-
})(ProductLevel || (exports.ProductLevel = ProductLevel = {}));
|
|
34
|
-
;
|
|
35
|
-
;
|
|
36
|
-
class ProductCatalog {
|
|
37
|
-
constructor(config) {
|
|
38
|
-
this.productsById = new Map();
|
|
39
|
-
this.pricesById = new Map();
|
|
40
|
-
this.plansById = new Map();
|
|
41
|
-
for (const product of config.products) {
|
|
42
|
-
this.productsById.set(product.id, product);
|
|
43
|
-
}
|
|
44
|
-
for (const price of config.prices) {
|
|
45
|
-
this.pricesById.set(price.id, price);
|
|
46
|
-
}
|
|
47
|
-
for (const plan of config.plans) {
|
|
48
|
-
this.plansById.set(plan.id, plan);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
getProductById(id) {
|
|
52
|
-
return this.productsById.get(id);
|
|
53
|
-
}
|
|
54
|
-
getPriceById(id) {
|
|
55
|
-
return this.pricesById.get(id);
|
|
56
|
-
}
|
|
57
|
-
getPlanById(id) {
|
|
58
|
-
return this.plansById.get(id);
|
|
59
|
-
}
|
|
60
|
-
getProductsByPredicate(predicate) {
|
|
61
|
-
const products = [];
|
|
62
|
-
for (const product of this.productsById.values()) {
|
|
63
|
-
if (predicate(product)) {
|
|
64
|
-
products.push(product);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return products;
|
|
68
|
-
}
|
|
69
|
-
getPricesByPredicate(predicate) {
|
|
70
|
-
const prices = [];
|
|
71
|
-
for (const price of this.pricesById.values()) {
|
|
72
|
-
if (predicate(price)) {
|
|
73
|
-
prices.push(price);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return prices;
|
|
77
|
-
}
|
|
78
|
-
getPlansByPredicate(predicate) {
|
|
79
|
-
const plans = [];
|
|
80
|
-
for (const plan of this.plansById.values()) {
|
|
81
|
-
if (predicate(plan)) {
|
|
82
|
-
plans.push(plan);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
return plans;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
exports.ProductCatalog = ProductCatalog;
|
|
89
|
-
// TODO: cleanup "PRE_TRIAL" status, and update all users who have this status
|
|
90
|
-
var PaymentStatus;
|
|
91
|
-
(function (PaymentStatus) {
|
|
92
|
-
PaymentStatus["PRE_TRIAL"] = "PRE_TRIAL";
|
|
93
|
-
PaymentStatus["IN_TRIAL"] = "IN_TRIAL";
|
|
94
|
-
PaymentStatus["PAID"] = "PAID";
|
|
95
|
-
PaymentStatus["UNPAID"] = "UNPAID";
|
|
96
|
-
PaymentStatus["CANCELLED"] = "CANCELLED";
|
|
97
|
-
})(PaymentStatus || (exports.PaymentStatus = PaymentStatus = {}));
|
|
98
|
-
class Billing extends Content_1.Content {
|
|
99
|
-
constructor(doc, shouldAcquire, shareSync) {
|
|
100
|
-
super(doc, shouldAcquire, shareSync);
|
|
101
|
-
this._transactionsView = new ArrayView_1.ArrayView(this, ['payload', 'transactions']);
|
|
102
|
-
}
|
|
103
|
-
get payload() {
|
|
104
|
-
this.checkDisposed("Billing.payload");
|
|
105
|
-
return this.doc.data.payload;
|
|
106
|
-
}
|
|
107
|
-
static makeBillingId(userId) {
|
|
108
|
-
return CachingHasher_1.CachingHasher.makeMd5ContentId(userId + "-" + ContentKind_1.ContentKind.BILLING);
|
|
109
|
-
}
|
|
110
|
-
static create(userId, payload, createdAt) {
|
|
111
|
-
// Billing creation always happens in UTC time
|
|
112
|
-
const now = Time_1.MultiClock.utcNow();
|
|
113
|
-
// If the createdAt time is not provided, use the current time
|
|
114
|
-
createdAt ??= now;
|
|
115
|
-
const billingId = Billing.makeBillingId(userId);
|
|
116
|
-
return ShareSync_1.ShareSyncFactory.get().createContent({
|
|
117
|
-
meta: {
|
|
118
|
-
ref: billingId,
|
|
119
|
-
is_head: true,
|
|
120
|
-
kind: ContentKind_1.ContentKind.BILLING,
|
|
121
|
-
id: billingId,
|
|
122
|
-
owner: userId,
|
|
123
|
-
created_at: createdAt,
|
|
124
|
-
updated_at: now,
|
|
125
|
-
},
|
|
126
|
-
payload: payload
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
isSubscribedToPricedProduct() {
|
|
130
|
-
this.checkDisposed("Billing.isSubscribedToPricedProduct");
|
|
131
|
-
return this.priceId != null && this.productId != null;
|
|
132
|
-
}
|
|
133
|
-
get priceId() {
|
|
134
|
-
this.checkDisposed("Billing.priceId");
|
|
135
|
-
return this.payload.price_id || null;
|
|
136
|
-
}
|
|
137
|
-
setPriceId(value) {
|
|
138
|
-
this.checkDisposed("Billing.setPriceId");
|
|
139
|
-
if (this.payload.price_id !== value) {
|
|
140
|
-
const batch = new Operation_1.BatchOperation(this);
|
|
141
|
-
batch.setPathValue(['payload', 'price_id'], value);
|
|
142
|
-
batch.commit();
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
get productId() {
|
|
146
|
-
this.checkDisposed("Billing.productId");
|
|
147
|
-
return this.payload.product_id || null;
|
|
148
|
-
}
|
|
149
|
-
setProductId(value) {
|
|
150
|
-
this.checkDisposed("Billing.setProductId");
|
|
151
|
-
if (this.payload.product_id !== value) {
|
|
152
|
-
const batch = new Operation_1.BatchOperation(this);
|
|
153
|
-
batch.setPathValue(['payload', 'product_id'], value);
|
|
154
|
-
batch.commit();
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
get paidUntil() {
|
|
158
|
-
this.checkDisposed("Billing.paidUntil");
|
|
159
|
-
return this.payload.paid_until;
|
|
160
|
-
}
|
|
161
|
-
setPaidUntil(value) {
|
|
162
|
-
this.checkDisposed("Billing.setPaidUntil");
|
|
163
|
-
if (this.paidUntil !== value) {
|
|
164
|
-
const batch = new Operation_1.BatchOperation(this);
|
|
165
|
-
batch.setPathValue(['payload', 'paid_until'], value);
|
|
166
|
-
batch.commit();
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
get paymentStatus() {
|
|
170
|
-
this.checkDisposed("Billing.paymentStatus");
|
|
171
|
-
return this.payload.payment_status;
|
|
172
|
-
}
|
|
173
|
-
setPaymentStatus(value) {
|
|
174
|
-
this.checkDisposed("Billing.setPaymentStatus");
|
|
175
|
-
if (this.paymentStatus !== value) {
|
|
176
|
-
const batch = new Operation_1.BatchOperation(this);
|
|
177
|
-
batch.setPathValue(['payload', 'payment_status'], value);
|
|
178
|
-
batch.commit();
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
get stripeCustomerId() {
|
|
182
|
-
this.checkDisposed("Billing.stripeCustomerId");
|
|
183
|
-
return this.payload.stripe_customer_id;
|
|
184
|
-
}
|
|
185
|
-
setStripeCustomerId(value) {
|
|
186
|
-
this.checkDisposed("Billing.setStripeCustomerId");
|
|
187
|
-
if (this.stripeCustomerId !== value) {
|
|
188
|
-
const batch = new Operation_1.BatchOperation(this);
|
|
189
|
-
batch.setPathValue(['payload', 'stripe_customer_id'], value);
|
|
190
|
-
batch.commit();
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
get stripePaymentMethodId() {
|
|
194
|
-
this.checkDisposed("Billing.stripePaymentMethodId");
|
|
195
|
-
return this.payload.stripe_payment_method_id;
|
|
196
|
-
}
|
|
197
|
-
setStripePaymentMethodId(value) {
|
|
198
|
-
this.checkDisposed("Billing.setStripePaymentMethodId");
|
|
199
|
-
if (this.stripeCustomerId !== value) {
|
|
200
|
-
const batch = new Operation_1.BatchOperation(this);
|
|
201
|
-
batch.setPathValue(['payload', 'stripe_payment_method_id'], value);
|
|
202
|
-
batch.commit();
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
get stripePaymentMethodType() {
|
|
206
|
-
this.checkDisposed("Billing.stripePaymentMethodType");
|
|
207
|
-
return this.payload.stripe_payment_method_id;
|
|
208
|
-
}
|
|
209
|
-
setStripePaymentMethodType(value) {
|
|
210
|
-
this.checkDisposed("Billing.setStripePaymentMethodType");
|
|
211
|
-
if (this.stripeCustomerId !== value) {
|
|
212
|
-
const batch = new Operation_1.BatchOperation(this);
|
|
213
|
-
batch.setPathValue(['payload', 'stripe_payment_method_type'], value);
|
|
214
|
-
batch.commit();
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
get creditCard() {
|
|
218
|
-
this.checkDisposed("Billing.creditCard");
|
|
219
|
-
return this.payload.credit_card;
|
|
220
|
-
}
|
|
221
|
-
setCreditCard(value) {
|
|
222
|
-
this.checkDisposed("Billing.setCreditCard");
|
|
223
|
-
if (this.creditCard != value) {
|
|
224
|
-
const batch = new Operation_1.BatchOperation(this);
|
|
225
|
-
batch.setPathValue(['payload', 'credit_card'], value);
|
|
226
|
-
batch.commit();
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
get transactions() {
|
|
230
|
-
this.checkDisposed("Billing.transactions");
|
|
231
|
-
return this._transactionsView;
|
|
232
|
-
}
|
|
233
|
-
// Somehow, the transactions array on many users is not in the correct order. Some users have
|
|
234
|
-
// transactions in reverse order, and some have transactions in random order. Eventually, we
|
|
235
|
-
// will correct the stored data, but for now, we will clone the transactions array and sort it
|
|
236
|
-
// by the transaction time, so that we can correctly iterate through the transactions.
|
|
237
|
-
get sortedTransactions() {
|
|
238
|
-
this.checkDisposed("Billing.sortedTransactions");
|
|
239
|
-
return Struct_1.Struct.clone(this._transactionsView.values).sort((a, b) => {
|
|
240
|
-
return Time_1.Time.compareDateTime(a.at_utc_time, b.at_utc_time);
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
getLastTransaction() {
|
|
244
|
-
this.checkDisposed("Billing.getLastTransaction");
|
|
245
|
-
if (this._transactionsView.length > 0) {
|
|
246
|
-
const transactions = this.sortedTransactions;
|
|
247
|
-
return transactions[transactions.length - 1];
|
|
248
|
-
}
|
|
249
|
-
else {
|
|
250
|
-
return null;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
getLastPaymentTransaction() {
|
|
254
|
-
this.checkDisposed("Billing.getLastPaymentTransaction");
|
|
255
|
-
// Starts iterating from the most-recent transaction, so this function will
|
|
256
|
-
// return only the most-recent matching transaction.
|
|
257
|
-
const transactions = this.sortedTransactions;
|
|
258
|
-
for (let i = transactions.length - 1; i >= 0; i--) {
|
|
259
|
-
const transaction = transactions[i];
|
|
260
|
-
const topic = transaction.topic;
|
|
261
|
-
if (topic === TransactionTopic.PAYMENT_FAIL || topic === TransactionTopic.PAYMENT_SUCCESS) {
|
|
262
|
-
return transaction;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
return null;
|
|
266
|
-
}
|
|
267
|
-
getActiveUserCoupon() {
|
|
268
|
-
this.checkDisposed("Billing.getActiveUserCoupon");
|
|
269
|
-
const nowInSeconds = (new Date()).getTime() / 1000;
|
|
270
|
-
// Coupons with a duration of "once" or "forever" have a null "end" value. We treat "once" coupons
|
|
271
|
-
// as being still-in-effect until a payment on the next invoice is attempted (either a pass or fail
|
|
272
|
-
// tells us that the billing period has completed).
|
|
273
|
-
const transactions = this.sortedTransactions;
|
|
274
|
-
for (let i = transactions.length - 1; i >= 0; i--) {
|
|
275
|
-
const transaction = transactions[i];
|
|
276
|
-
const topic = transaction.topic;
|
|
277
|
-
if (topic === TransactionTopic.CANCEL_SUBSCRIPTION) {
|
|
278
|
-
return null;
|
|
279
|
-
}
|
|
280
|
-
if (topic === TransactionTopic.APPLY_COUPON) {
|
|
281
|
-
const discount = transaction.details;
|
|
282
|
-
const coupon = discount.coupon;
|
|
283
|
-
if (coupon.duration === "forever" || (nowInSeconds >= discount.start && nowInSeconds <= discount.end)) {
|
|
284
|
-
return coupon;
|
|
285
|
-
}
|
|
286
|
-
else {
|
|
287
|
-
return null;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
return null;
|
|
292
|
-
}
|
|
293
|
-
daysPastDue() {
|
|
294
|
-
this.checkDisposed("Billing.daysPastDue");
|
|
295
|
-
const daysSincePaidUntil = Time_1.Time.timeSince(this.paidUntil, 'days');
|
|
296
|
-
return daysSincePaidUntil < 0 ? 0 : daysSincePaidUntil;
|
|
297
|
-
}
|
|
298
|
-
didLastPaymentFail() {
|
|
299
|
-
this.checkDisposed("Billing.didLastPaymentFail");
|
|
300
|
-
const t = this.getLastPaymentTransaction();
|
|
301
|
-
return t != null && t.topic === TransactionTopic.PAYMENT_FAIL;
|
|
302
|
-
}
|
|
303
|
-
didLastPaymentSucceed() {
|
|
304
|
-
this.checkDisposed("Billing.didLastPaymentSucceed");
|
|
305
|
-
const t = this.getLastPaymentTransaction();
|
|
306
|
-
return t != null && t.topic === TransactionTopic.PAYMENT_SUCCESS;
|
|
307
|
-
}
|
|
308
|
-
findTransactionByTopic(topic) {
|
|
309
|
-
this.checkDisposed("Billing.findTransactionByTopic");
|
|
310
|
-
const transactions = this.sortedTransactions;
|
|
311
|
-
// Starts iterating from the most-recent transaction, so this function will
|
|
312
|
-
// return only the most-recent matching transaction.
|
|
313
|
-
for (let i = transactions.length - 1; i >= 0; i--) {
|
|
314
|
-
const transaction = transactions[i];
|
|
315
|
-
if (transaction.topic === topic) {
|
|
316
|
-
return transaction;
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
return null;
|
|
320
|
-
}
|
|
321
|
-
cancel() {
|
|
322
|
-
this.checkDisposed("Billing.cancel");
|
|
323
|
-
const now = Time_1.MultiClock.utcNow();
|
|
324
|
-
const transaction = {
|
|
325
|
-
at_utc_time: now.utc_time,
|
|
326
|
-
topic: TransactionTopic.CANCEL_SUBSCRIPTION
|
|
327
|
-
};
|
|
328
|
-
const batch = new Operation_1.BatchOperation(this, now);
|
|
329
|
-
// Add a transaction to the billing model for this cancellation
|
|
330
|
-
batch.pushIntoArray(['payload', 'transactions'], transaction);
|
|
331
|
-
batch.setPathValue(['payload', 'plan'], null);
|
|
332
|
-
batch.setPathValue(['payload', 'price_id'], null);
|
|
333
|
-
batch.setPathValue(['payload', 'product_id'], null);
|
|
334
|
-
batch.setPathValue(['payload', 'paid_until'], null);
|
|
335
|
-
batch.setPathValue(['payload', 'payment_status'], PaymentStatus.CANCELLED);
|
|
336
|
-
batch.commit();
|
|
337
|
-
}
|
|
338
|
-
restartPlan(plan, paidUntilEpochSeconds) {
|
|
339
|
-
this.checkDisposed("Billing.restartPlan");
|
|
340
|
-
const now = Time_1.MultiClock.utcNow();
|
|
341
|
-
const transaction = {
|
|
342
|
-
at_utc_time: now.utc_time,
|
|
343
|
-
topic: TransactionTopic.RESTART_SUBSCRIPTION
|
|
344
|
-
};
|
|
345
|
-
const batch = new Operation_1.BatchOperation(this, now);
|
|
346
|
-
// Add a transaction to the billing model for this cancellation
|
|
347
|
-
batch.pushIntoArray(['payload', 'transactions'], transaction);
|
|
348
|
-
batch.setPathValue(['payload', 'plan'], plan);
|
|
349
|
-
batch.setPathValue(['payload', 'product_id'], null);
|
|
350
|
-
batch.setPathValue(['payload', 'price_id'], null);
|
|
351
|
-
batch.setPathValue(['payload', 'paid_until'], Time_1.Time.utcFromEpochSeconds(paidUntilEpochSeconds));
|
|
352
|
-
batch.setPathValue(['payload', 'payment_status'], PaymentStatus.PAID);
|
|
353
|
-
batch.commit();
|
|
354
|
-
}
|
|
355
|
-
restartPricedProduct(productId, priceId, paidUntilEpochSeconds) {
|
|
356
|
-
this.checkDisposed("Billing.restartPricedProduct");
|
|
357
|
-
const now = Time_1.MultiClock.utcNow();
|
|
358
|
-
const transaction = {
|
|
359
|
-
at_utc_time: now.utc_time,
|
|
360
|
-
topic: TransactionTopic.RESTART_SUBSCRIPTION
|
|
361
|
-
};
|
|
362
|
-
const batch = new Operation_1.BatchOperation(this, now);
|
|
363
|
-
// Add a transaction to the billing model for this cancellation
|
|
364
|
-
batch.pushIntoArray(['payload', 'transactions'], transaction);
|
|
365
|
-
batch.setPathValue(['payload', 'plan'], null);
|
|
366
|
-
batch.setPathValue(['payload', 'product_id'], productId);
|
|
367
|
-
batch.setPathValue(['payload', 'price_id'], priceId);
|
|
368
|
-
batch.setPathValue(['payload', 'paid_until'], Time_1.Time.utcFromEpochSeconds(paidUntilEpochSeconds));
|
|
369
|
-
batch.setPathValue(['payload', 'payment_status'], PaymentStatus.PAID);
|
|
370
|
-
batch.commit();
|
|
371
|
-
}
|
|
372
|
-
static async findByStripeCustomerId(stripeCustomerId) {
|
|
373
|
-
const shareSync = ShareSync_1.ShareSyncFactory.get();
|
|
374
|
-
return shareSync.findAndAcquire(ContentKind_1.ContentKind.BILLING, { "payload.stripe_customer_id": stripeCustomerId });
|
|
375
|
-
}
|
|
376
|
-
static describeCoupon(coupon) {
|
|
377
|
-
let description = "";
|
|
378
|
-
if (coupon.hasOwnProperty("percent_off") && coupon.percent_off !== null) {
|
|
379
|
-
description = coupon.percent_off + "% OFF";
|
|
380
|
-
}
|
|
381
|
-
else if (coupon.hasOwnProperty("amount_off") && coupon.amount_off !== null) {
|
|
382
|
-
description = NumberFormat_1.NumberFormat.dollarsFromCents(coupon.amount_off) + " OFF";
|
|
383
|
-
}
|
|
384
|
-
if (coupon.duration === "forever") {
|
|
385
|
-
description += ", FOREVER";
|
|
386
|
-
}
|
|
387
|
-
else if (coupon.duration === "once") {
|
|
388
|
-
description += " YOUR NEXT INVOICE";
|
|
389
|
-
}
|
|
390
|
-
else if (coupon.duration === "repeating") {
|
|
391
|
-
description += " FOR " + coupon.duration_in_months + " MONTHS";
|
|
392
|
-
}
|
|
393
|
-
return description;
|
|
394
|
-
}
|
|
395
|
-
static normalizeCreditCardBrand(brand) {
|
|
396
|
-
const lowerCaseNoSpaces = brand.toLowerCase().replace(/\s/g, '');
|
|
397
|
-
if (lowerCaseNoSpaces.startsWith("visa")) {
|
|
398
|
-
return "VISA";
|
|
399
|
-
}
|
|
400
|
-
else if (lowerCaseNoSpaces.startsWith("mastercard")) {
|
|
401
|
-
return "MC";
|
|
402
|
-
}
|
|
403
|
-
else if (lowerCaseNoSpaces.startsWith("americanexpress")) {
|
|
404
|
-
return "AMEX";
|
|
405
|
-
}
|
|
406
|
-
else if (lowerCaseNoSpaces.startsWith("diners")) {
|
|
407
|
-
return "DINERS";
|
|
408
|
-
}
|
|
409
|
-
else if (lowerCaseNoSpaces.startsWith("jcb")) {
|
|
410
|
-
return "JCB";
|
|
411
|
-
}
|
|
412
|
-
else if (lowerCaseNoSpaces.startsWith("discover")) {
|
|
413
|
-
return "DISC";
|
|
414
|
-
}
|
|
415
|
-
return brand;
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
exports.Billing = Billing;
|