@appweaver/payments 0.0.0-stage → 3.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/LICENSE +21 -0
- package/README.md +212 -2
- package/config.d.ts +77 -0
- package/config.js +118 -0
- package/gateway/fake-gateway.d.ts +144 -0
- package/gateway/fake-gateway.js +805 -0
- package/gateway/gateway-registry.d.ts +99 -0
- package/gateway/gateway-registry.js +275 -0
- package/gateway/payment-gateway.d.ts +68 -0
- package/gateway/payment-gateway.js +82 -0
- package/index.d.ts +16 -0
- package/index.js +51 -0
- package/locales/en.json +47 -0
- package/maintenance/payment-maintenance-jobs.d.ts +5 -0
- package/maintenance/payment-maintenance-jobs.js +38 -0
- package/module.d.ts +8 -0
- package/module.js +85 -0
- package/package.json +67 -3
- package/resources/model-util.d.ts +40 -0
- package/resources/model-util.js +30 -0
- package/resources/payment/model.d.ts +2 -0
- package/resources/payment/model.js +106 -0
- package/resources/payment-customer/model.d.ts +2 -0
- package/resources/payment-customer/model.js +53 -0
- package/resources/payment-event/model.d.ts +2 -0
- package/resources/payment-event/model.js +31 -0
- package/resources/payment-invoice/model.d.ts +2 -0
- package/resources/payment-invoice/model.js +55 -0
- package/resources/payment-method/model.d.ts +2 -0
- package/resources/payment-method/model.js +37 -0
- package/resources/payment-plan/model.d.ts +2 -0
- package/resources/payment-plan/model.js +37 -0
- package/resources/payment-subscription/model.d.ts +2 -0
- package/resources/payment-subscription/model.js +82 -0
- package/resources/payment-transaction/model.d.ts +2 -0
- package/resources/payment-transaction/model.js +43 -0
- package/resources/payment-webhook-event/model.d.ts +2 -0
- package/resources/payment-webhook-event/model.js +32 -0
- package/resources/policies.d.ts +15 -0
- package/resources/policies.js +36 -0
- package/resources/services.d.ts +6 -0
- package/resources/services.js +19 -0
- package/resources/subscriptions.d.ts +9 -0
- package/resources/subscriptions.js +30 -0
- package/resources.d.ts +8 -0
- package/resources.js +34 -0
- package/service/payment-emails.d.ts +12 -0
- package/service/payment-emails.js +145 -0
- package/service/payment-events.d.ts +90 -0
- package/service/payment-events.js +472 -0
- package/service/payment-handlers.d.ts +26 -0
- package/service/payment-handlers.js +42 -0
- package/service/payment-store.d.ts +50 -0
- package/service/payment-store.js +95 -0
- package/service/payment-sync.d.ts +113 -0
- package/service/payment-sync.js +745 -0
- package/service/payments-service.d.ts +307 -0
- package/service/payments-service.js +747 -0
- package/service/subscriptions-service.d.ts +178 -0
- package/service/subscriptions-service.js +433 -0
- package/tasks/payments-replay.d.ts +10 -0
- package/tasks/payments-replay.js +36 -0
- package/tasks/payments-sync-plans.d.ts +10 -0
- package/tasks/payments-sync-plans.js +24 -0
- package/templates/emails/payment-action-required.html.hbs +28 -0
- package/templates/emails/payment-action-required.subject.hbs +1 -0
- package/templates/emails/payment-failed.html.hbs +37 -0
- package/templates/emails/payment-failed.subject.hbs +1 -0
- package/templates/emails/payment-receipt.html.hbs +45 -0
- package/templates/emails/payment-receipt.subject.hbs +1 -0
- package/templates/emails/payment-refunded.html.hbs +37 -0
- package/templates/emails/payment-refunded.subject.hbs +1 -0
- package/templates/emails/subscription-canceled.html.hbs +24 -0
- package/templates/emails/subscription-canceled.subject.hbs +1 -0
- package/templates/emails/subscription-trial-ending.html.hbs +25 -0
- package/templates/emails/subscription-trial-ending.subject.hbs +1 -0
- package/templates/layouts/email.html.hbs +36 -0
- package/templates/partials/email-button.html.hbs +15 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/types.d.ts +488 -0
- package/types.js +2 -0
- package/utils/money-util.d.ts +61 -0
- package/utils/money-util.js +124 -0
- package/utils/status-util.d.ts +29 -0
- package/utils/status-util.js +93 -0
- package/utils/telemetry.d.ts +16 -0
- package/utils/telemetry.js +69 -0
- package/web/payment-routes.d.ts +7 -0
- package/web/payment-routes.js +410 -0
- package/web/payment-schemas.d.ts +70 -0
- package/web/payment-schemas.js +101 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.definePaymentMaintenanceJobs = definePaymentMaintenanceJobs;
|
|
4
|
+
const core_1 = require("@appweaver/core");
|
|
5
|
+
const config_1 = require("../config");
|
|
6
|
+
const payment_events_1 = require("../service/payment-events");
|
|
7
|
+
const payments_service_1 = require("../service/payments-service");
|
|
8
|
+
const subscriptions_service_1 = require("../service/subscriptions-service");
|
|
9
|
+
/**
|
|
10
|
+
* Registers the maintenance jobs of the payments: the reconciliation with the gateways, the redelivery of the stored
|
|
11
|
+
* events no job finished, and the retention of the events.
|
|
12
|
+
*/
|
|
13
|
+
function definePaymentMaintenanceJobs() {
|
|
14
|
+
(0, core_1.defineMaintenanceJob)({
|
|
15
|
+
name: 'paymentsReconcile',
|
|
16
|
+
description: 'Reads the payments and subscriptions in a state that is not final from their gateways again, and cancels the payments left unpaid.',
|
|
17
|
+
schedule: '5m',
|
|
18
|
+
applies: () => config_1.paymentsConfig.RECONCILE_AFTER > 0,
|
|
19
|
+
run: async ({ now, batchSize }) => (await (0, core_1.inject)(payments_service_1.PaymentsService).reconcile(now, batchSize)) +
|
|
20
|
+
(config_1.paymentsSubscriptionsConfig.ENABLED
|
|
21
|
+
? await (0, core_1.inject)(subscriptions_service_1.SubscriptionsService).reconcile(now, batchSize)
|
|
22
|
+
: 0)
|
|
23
|
+
});
|
|
24
|
+
(0, core_1.defineMaintenanceJob)({
|
|
25
|
+
name: 'paymentsRedeliver',
|
|
26
|
+
description: 'Queues the received webhook events and the events of the payments no job finished.',
|
|
27
|
+
schedule: '1m',
|
|
28
|
+
run: ({ now, batchSize }) => (0, core_1.inject)(payment_events_1.PaymentEvents).requeue(now, batchSize)
|
|
29
|
+
});
|
|
30
|
+
(0, core_1.defineMaintenanceJob)({
|
|
31
|
+
name: 'paymentEventsRetention',
|
|
32
|
+
description: 'Deletes the processed webhook events and the delivered events of the payments older than their retention.',
|
|
33
|
+
schedule: '1h',
|
|
34
|
+
applies: () => config_1.paymentsWebhooksConfig.RETENTION > 0 ||
|
|
35
|
+
config_1.paymentsConfig.EVENT_RETENTION > 0,
|
|
36
|
+
run: ({ now }) => (0, core_1.inject)(payment_events_1.PaymentEvents).prune(now)
|
|
37
|
+
});
|
|
38
|
+
}
|
package/module.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The online payments: the gateways of the `payments` config, one-time and recurring payments, saved payment
|
|
3
|
+
* methods, refunds, the webhooks and the emails of the payments, and the built-in `fake` gateway. The drivers of the
|
|
4
|
+
* gateways are the `PaymentGateway` providers of the driver modules, i.e. `stripe` of `@appweaver/stripe`, several
|
|
5
|
+
* gateways usable at once.
|
|
6
|
+
*/
|
|
7
|
+
declare const _default: import("@appweaver/common").Module;
|
|
8
|
+
export default _default;
|
package/module.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
const path_1 = __importDefault(require("path"));
|
|
40
|
+
const common_1 = require("@appweaver/common");
|
|
41
|
+
const config_1 = require("./config");
|
|
42
|
+
/**
|
|
43
|
+
* The online payments: the gateways of the `payments` config, one-time and recurring payments, saved payment
|
|
44
|
+
* methods, refunds, the webhooks and the emails of the payments, and the built-in `fake` gateway. The drivers of the
|
|
45
|
+
* gateways are the `PaymentGateway` providers of the driver modules, i.e. `stripe` of `@appweaver/stripe`, several
|
|
46
|
+
* gateways usable at once.
|
|
47
|
+
*/
|
|
48
|
+
exports.default = (0, common_1.defineModule)({
|
|
49
|
+
name: '@appweaver/payments',
|
|
50
|
+
requires: ['@appweaver/data'],
|
|
51
|
+
config: [
|
|
52
|
+
config_1.paymentsConfig,
|
|
53
|
+
config_1.paymentsWebhooksConfig,
|
|
54
|
+
config_1.paymentsRoutesConfig,
|
|
55
|
+
config_1.paymentsSubscriptionsConfig,
|
|
56
|
+
config_1.paymentsEmailsConfig
|
|
57
|
+
],
|
|
58
|
+
loggers: ['payments'],
|
|
59
|
+
services: [
|
|
60
|
+
{
|
|
61
|
+
load: () => Promise.resolve().then(() => __importStar(require('./service/payment-events'))),
|
|
62
|
+
requires: [common_1.Database, common_1.Queue]
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
load: () => Promise.resolve().then(() => __importStar(require('./service/payments-service'))),
|
|
66
|
+
requires: [common_1.Database, common_1.Queue]
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
load: () => Promise.resolve().then(() => __importStar(require('./service/subscriptions-service'))),
|
|
70
|
+
requires: [common_1.Database, common_1.Queue]
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
setup: async () => (await Promise.resolve().then(() => __importStar(require('./maintenance/payment-maintenance-jobs')))).definePaymentMaintenanceJobs(),
|
|
74
|
+
// The models of the subscriptions get no tables with `payments.subscriptions.enabled` off
|
|
75
|
+
resources: async () => ({
|
|
76
|
+
...(await Promise.resolve().then(() => __importStar(require('./resources')))),
|
|
77
|
+
...(config_1.paymentsSubscriptionsConfig.ENABLED
|
|
78
|
+
? await Promise.resolve().then(() => __importStar(require('./resources/subscriptions')))
|
|
79
|
+
: {})
|
|
80
|
+
}),
|
|
81
|
+
web: async () => (await Promise.resolve().then(() => __importStar(require('./web/payment-routes')))).registerPaymentRoutes(),
|
|
82
|
+
tasks: path_1.default.join(__dirname, 'tasks'),
|
|
83
|
+
locales: path_1.default.join(__dirname, 'locales'),
|
|
84
|
+
templates: path_1.default.join(__dirname, 'templates')
|
|
85
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,70 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@appweaver/payments",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "3.1.0",
|
|
4
|
+
"description": "Appweaver - the backend framework for AI-first development (@payments)",
|
|
5
|
+
"author": "Luka Matosevic",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "./index.js",
|
|
8
|
+
"types": "./index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./index.d.ts",
|
|
12
|
+
"default": "./index.js"
|
|
13
|
+
},
|
|
14
|
+
"./package.json": "./package.json"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"appweaver",
|
|
18
|
+
"appweaver-module",
|
|
19
|
+
"payments",
|
|
20
|
+
"payment-gateway",
|
|
21
|
+
"subscriptions",
|
|
22
|
+
"recurring-payments",
|
|
23
|
+
"webhooks",
|
|
24
|
+
"checkout",
|
|
25
|
+
"billing",
|
|
26
|
+
"stripe"
|
|
27
|
+
],
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/lmatosevic/appweaver.git",
|
|
31
|
+
"directory": "packages/payments"
|
|
32
|
+
},
|
|
33
|
+
"maintainers": [
|
|
34
|
+
{
|
|
35
|
+
"name": "Luka Matosevic",
|
|
36
|
+
"email": "lukamatosevic5@gmail.com",
|
|
37
|
+
"web": "https://lukamatosevic.com"
|
|
38
|
+
}
|
|
39
|
+
],
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">= 24.7"
|
|
45
|
+
},
|
|
46
|
+
"appweaver": {
|
|
47
|
+
"module": "./module.js"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"fastify": "5.12.8",
|
|
51
|
+
"typebox": "1.4.7"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"@appweaver/common": "^3.1.0",
|
|
55
|
+
"@appweaver/core": "^3.1.0",
|
|
56
|
+
"@appweaver/data": "^3.1.0",
|
|
57
|
+
"@appweaver/web": "^3.1.0"
|
|
58
|
+
},
|
|
59
|
+
"peerDependenciesMeta": {
|
|
60
|
+
"@appweaver/web": {
|
|
61
|
+
"optional": true
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@appweaver/common": "^2.8.0",
|
|
66
|
+
"@appweaver/core": "^2.8.0",
|
|
67
|
+
"@appweaver/data": "^2.8.0",
|
|
68
|
+
"@appweaver/web": "^2.8.0"
|
|
69
|
+
}
|
|
6
70
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { RelationField } from '@appweaver/common';
|
|
2
|
+
/** An optional string column of a payment model. */
|
|
3
|
+
export declare const text: (maxLength: number) => {
|
|
4
|
+
readonly type: "string";
|
|
5
|
+
readonly required: false;
|
|
6
|
+
readonly maxLength: number;
|
|
7
|
+
};
|
|
8
|
+
/** The name of the gateway of a record, a key of `payments.gateways`. */
|
|
9
|
+
export declare const provider: {
|
|
10
|
+
readonly type: "string";
|
|
11
|
+
readonly maxLength: 64;
|
|
12
|
+
};
|
|
13
|
+
/** An amount in the minor units of its currency. */
|
|
14
|
+
export declare const amount: {
|
|
15
|
+
readonly type: "bigInt";
|
|
16
|
+
readonly minimum: 0;
|
|
17
|
+
readonly default: 0;
|
|
18
|
+
};
|
|
19
|
+
/** An ISO 4217 currency code. */
|
|
20
|
+
export declare const currency: {
|
|
21
|
+
readonly type: "string";
|
|
22
|
+
readonly minLength: 3;
|
|
23
|
+
readonly maxLength: 3;
|
|
24
|
+
readonly example: "USD";
|
|
25
|
+
};
|
|
26
|
+
/** The audit fields of the payment records, written by the module and never by a user. */
|
|
27
|
+
export declare const audit: {
|
|
28
|
+
readonly createdById: false;
|
|
29
|
+
};
|
|
30
|
+
/** A relation the module writes itself, so the routes never take it as input. */
|
|
31
|
+
export declare const internal: {
|
|
32
|
+
readonly input: {
|
|
33
|
+
readonly type: "none";
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* The relations of a payment model to the models of the subscriptions, left out with `payments.subscriptions.enabled`
|
|
38
|
+
* off, when those models get no tables. Typed as present, since a model declares the names of its relations.
|
|
39
|
+
*/
|
|
40
|
+
export declare function subscriptionRelations<T extends Record<string, RelationField>>(relations: T): T;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.internal = exports.audit = exports.currency = exports.amount = exports.provider = exports.text = void 0;
|
|
4
|
+
exports.subscriptionRelations = subscriptionRelations;
|
|
5
|
+
const config_1 = require("../config");
|
|
6
|
+
/** An optional string column of a payment model. */
|
|
7
|
+
const text = (maxLength) => ({ type: 'string', required: false, maxLength });
|
|
8
|
+
exports.text = text;
|
|
9
|
+
/** The name of the gateway of a record, a key of `payments.gateways`. */
|
|
10
|
+
exports.provider = { type: 'string', maxLength: 64 };
|
|
11
|
+
/** An amount in the minor units of its currency. */
|
|
12
|
+
exports.amount = { type: 'bigInt', minimum: 0, default: 0 };
|
|
13
|
+
/** An ISO 4217 currency code. */
|
|
14
|
+
exports.currency = {
|
|
15
|
+
type: 'string',
|
|
16
|
+
minLength: 3,
|
|
17
|
+
maxLength: 3,
|
|
18
|
+
example: 'USD'
|
|
19
|
+
};
|
|
20
|
+
/** The audit fields of the payment records, written by the module and never by a user. */
|
|
21
|
+
exports.audit = { createdById: false };
|
|
22
|
+
/** A relation the module writes itself, so the routes never take it as input. */
|
|
23
|
+
exports.internal = { input: { type: 'none' } };
|
|
24
|
+
/**
|
|
25
|
+
* The relations of a payment model to the models of the subscriptions, left out with `payments.subscriptions.enabled`
|
|
26
|
+
* off, when those models get no tables. Typed as present, since a model declares the names of its relations.
|
|
27
|
+
*/
|
|
28
|
+
function subscriptionRelations(relations) {
|
|
29
|
+
return config_1.paymentsSubscriptionsConfig.ENABLED ? relations : {};
|
|
30
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const data_1 = require("@appweaver/data");
|
|
4
|
+
const model_util_1 = require("../model-util");
|
|
5
|
+
// A payment of a gateway and its state, moved by the webhooks of the gateway
|
|
6
|
+
exports.default = (0, data_1.createModel)({
|
|
7
|
+
name: 'Payment',
|
|
8
|
+
id: { type: 'string', generator: 'uuid(7)' },
|
|
9
|
+
audit: model_util_1.audit,
|
|
10
|
+
scalars: {
|
|
11
|
+
provider: model_util_1.provider,
|
|
12
|
+
// Set once the gateway created the payment
|
|
13
|
+
providerPaymentId: (0, model_util_1.text)(255),
|
|
14
|
+
// The hosted checkout the payment is paid on
|
|
15
|
+
providerCheckoutId: (0, model_util_1.text)(255),
|
|
16
|
+
status: {
|
|
17
|
+
type: 'enum',
|
|
18
|
+
values: [
|
|
19
|
+
'pending',
|
|
20
|
+
'requiresAction',
|
|
21
|
+
'processing',
|
|
22
|
+
'authorized',
|
|
23
|
+
'succeeded',
|
|
24
|
+
'failed',
|
|
25
|
+
'canceled'
|
|
26
|
+
],
|
|
27
|
+
default: 'pending'
|
|
28
|
+
},
|
|
29
|
+
amount: { ...model_util_1.amount, default: undefined, example: 1999 },
|
|
30
|
+
currency: model_util_1.currency,
|
|
31
|
+
amountCaptured: model_util_1.amount,
|
|
32
|
+
amountRefunded: model_util_1.amount,
|
|
33
|
+
captureMethod: {
|
|
34
|
+
type: 'enum',
|
|
35
|
+
values: ['automatic', 'manual'],
|
|
36
|
+
default: 'automatic'
|
|
37
|
+
},
|
|
38
|
+
disputed: { type: 'boolean', default: false },
|
|
39
|
+
livemode: { type: 'boolean', default: false },
|
|
40
|
+
userId: (0, model_util_1.text)(255),
|
|
41
|
+
// Receives the emails of a payment without a customer, i.e. of a guest
|
|
42
|
+
email: (0, model_util_1.text)(320),
|
|
43
|
+
// The ID of the PaymentMethod paying, which may be detached later
|
|
44
|
+
paymentMethodId: (0, model_util_1.text)(255),
|
|
45
|
+
description: (0, model_util_1.text)(1000),
|
|
46
|
+
// What the payment is for in the application, i.e. `Order` and the ID of an order
|
|
47
|
+
reference: (0, model_util_1.text)(255),
|
|
48
|
+
referenceType: (0, model_util_1.text)(255),
|
|
49
|
+
// The same key returns the same payment, so a repeated request never charges twice
|
|
50
|
+
idempotencyKey: { ...(0, model_util_1.text)(255), unique: true, hidden: true },
|
|
51
|
+
failureCode: (0, model_util_1.text)(255),
|
|
52
|
+
failureMessage: (0, model_util_1.text)(1000),
|
|
53
|
+
receiptUrl: (0, model_util_1.text)(2048),
|
|
54
|
+
metadata: { type: 'json', required: false },
|
|
55
|
+
paidAt: { type: 'dateTime', required: false },
|
|
56
|
+
canceledAt: { type: 'dateTime', required: false }
|
|
57
|
+
},
|
|
58
|
+
relations: {
|
|
59
|
+
customer: {
|
|
60
|
+
model: 'PaymentCustomer',
|
|
61
|
+
type: 'manyToOne',
|
|
62
|
+
mappedBy: 'payments',
|
|
63
|
+
required: false,
|
|
64
|
+
onDelete: 'setNull',
|
|
65
|
+
...model_util_1.internal,
|
|
66
|
+
output: { type: 'none' }
|
|
67
|
+
},
|
|
68
|
+
...(0, model_util_1.subscriptionRelations)({
|
|
69
|
+
subscription: {
|
|
70
|
+
model: 'PaymentSubscription',
|
|
71
|
+
type: 'manyToOne',
|
|
72
|
+
mappedBy: 'payments',
|
|
73
|
+
required: false,
|
|
74
|
+
onDelete: 'setNull',
|
|
75
|
+
...model_util_1.internal,
|
|
76
|
+
output: { type: 'none' }
|
|
77
|
+
}
|
|
78
|
+
}),
|
|
79
|
+
// The ledger of the payment: its charge, refunds and disputes
|
|
80
|
+
transactions: {
|
|
81
|
+
model: 'PaymentTransaction',
|
|
82
|
+
type: 'oneToMany',
|
|
83
|
+
mappedBy: 'payment',
|
|
84
|
+
required: false,
|
|
85
|
+
...model_util_1.internal,
|
|
86
|
+
output: { type: 'single' }
|
|
87
|
+
},
|
|
88
|
+
...(0, model_util_1.subscriptionRelations)({
|
|
89
|
+
invoices: {
|
|
90
|
+
model: 'PaymentInvoice',
|
|
91
|
+
type: 'oneToMany',
|
|
92
|
+
mappedBy: 'payment',
|
|
93
|
+
required: false,
|
|
94
|
+
...model_util_1.internal,
|
|
95
|
+
output: { type: 'none' }
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
},
|
|
99
|
+
unique: [['provider', 'providerPaymentId']],
|
|
100
|
+
index: [
|
|
101
|
+
['userId', '-createdAt'],
|
|
102
|
+
['status', 'createdAt'],
|
|
103
|
+
['referenceType', 'reference'],
|
|
104
|
+
['provider', 'providerCheckoutId']
|
|
105
|
+
]
|
|
106
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const data_1 = require("@appweaver/data");
|
|
4
|
+
const model_util_1 = require("../model-util");
|
|
5
|
+
// The customer of a gateway, kept once its user is deleted, since the payments outlive them
|
|
6
|
+
exports.default = (0, data_1.createModel)({
|
|
7
|
+
name: 'PaymentCustomer',
|
|
8
|
+
id: { type: 'string', generator: 'uuid(7)' },
|
|
9
|
+
audit: model_util_1.audit,
|
|
10
|
+
scalars: {
|
|
11
|
+
provider: model_util_1.provider,
|
|
12
|
+
providerCustomerId: { type: 'string', maxLength: 255 },
|
|
13
|
+
// No relation to the auth model, so deleting a user never deletes or blocks the financial records
|
|
14
|
+
userId: (0, model_util_1.text)(255),
|
|
15
|
+
email: (0, model_util_1.text)(320),
|
|
16
|
+
name: (0, model_util_1.text)(255),
|
|
17
|
+
locale: (0, model_util_1.text)(16),
|
|
18
|
+
// The ID of the PaymentMethod charged by default
|
|
19
|
+
defaultPaymentMethodId: (0, model_util_1.text)(255),
|
|
20
|
+
// Set once the customer is deleted at the gateway, its personal data cleared
|
|
21
|
+
deletedAtProvider: { type: 'dateTime', required: false }
|
|
22
|
+
},
|
|
23
|
+
relations: {
|
|
24
|
+
paymentMethods: {
|
|
25
|
+
model: 'PaymentMethod',
|
|
26
|
+
type: 'oneToMany',
|
|
27
|
+
mappedBy: 'customer',
|
|
28
|
+
required: false,
|
|
29
|
+
...model_util_1.internal,
|
|
30
|
+
output: { type: 'none' }
|
|
31
|
+
},
|
|
32
|
+
payments: {
|
|
33
|
+
model: 'Payment',
|
|
34
|
+
type: 'oneToMany',
|
|
35
|
+
mappedBy: 'customer',
|
|
36
|
+
required: false,
|
|
37
|
+
...model_util_1.internal,
|
|
38
|
+
output: { type: 'none' }
|
|
39
|
+
},
|
|
40
|
+
...(0, model_util_1.subscriptionRelations)({
|
|
41
|
+
subscriptions: {
|
|
42
|
+
model: 'PaymentSubscription',
|
|
43
|
+
type: 'oneToMany',
|
|
44
|
+
mappedBy: 'customer',
|
|
45
|
+
required: false,
|
|
46
|
+
...model_util_1.internal,
|
|
47
|
+
output: { type: 'none' }
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
},
|
|
51
|
+
unique: [['provider', 'providerCustomerId']],
|
|
52
|
+
index: [['userId', 'provider']]
|
|
53
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const data_1 = require("@appweaver/data");
|
|
4
|
+
const model_util_1 = require("../model-util");
|
|
5
|
+
// An event of the payments, written with the change it tells of and delivered to the handlers afterwards
|
|
6
|
+
exports.default = (0, data_1.createModel)({
|
|
7
|
+
name: 'PaymentEvent',
|
|
8
|
+
id: { type: 'string', generator: 'uuid(7)' },
|
|
9
|
+
audit: { createdById: false },
|
|
10
|
+
scalars: {
|
|
11
|
+
// The type of the event, i.e. `payment.succeeded`
|
|
12
|
+
type: { type: 'string', maxLength: 64 },
|
|
13
|
+
provider: model_util_1.provider,
|
|
14
|
+
status: {
|
|
15
|
+
type: 'enum',
|
|
16
|
+
values: ['pending', 'delivered', 'failed'],
|
|
17
|
+
default: 'pending'
|
|
18
|
+
},
|
|
19
|
+
attempts: { type: 'int', default: 0, minimum: 0 },
|
|
20
|
+
userId: (0, model_util_1.text)(255),
|
|
21
|
+
// The records the event is about, by their ID
|
|
22
|
+
paymentId: (0, model_util_1.text)(255),
|
|
23
|
+
transactionId: (0, model_util_1.text)(255),
|
|
24
|
+
paymentMethodId: (0, model_util_1.text)(255),
|
|
25
|
+
subscriptionId: (0, model_util_1.text)(255),
|
|
26
|
+
invoiceId: (0, model_util_1.text)(255),
|
|
27
|
+
lastError: (0, model_util_1.text)(2000),
|
|
28
|
+
deliveredAt: { type: 'dateTime', required: false }
|
|
29
|
+
},
|
|
30
|
+
index: [['status', 'createdAt'], ['paymentId'], ['subscriptionId']]
|
|
31
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const data_1 = require("@appweaver/data");
|
|
4
|
+
const model_util_1 = require("../model-util");
|
|
5
|
+
// An invoice of a subscription: one per period, collected by a payment
|
|
6
|
+
exports.default = (0, data_1.createModel)({
|
|
7
|
+
name: 'PaymentInvoice',
|
|
8
|
+
id: { type: 'string', generator: 'uuid(7)' },
|
|
9
|
+
audit: model_util_1.audit,
|
|
10
|
+
scalars: {
|
|
11
|
+
provider: model_util_1.provider,
|
|
12
|
+
providerInvoiceId: { type: 'string', maxLength: 255 },
|
|
13
|
+
status: {
|
|
14
|
+
type: 'enum',
|
|
15
|
+
values: ['draft', 'open', 'paid', 'uncollectible', 'void'],
|
|
16
|
+
default: 'open'
|
|
17
|
+
},
|
|
18
|
+
userId: (0, model_util_1.text)(255),
|
|
19
|
+
// The ID of the PaymentCustomer invoiced
|
|
20
|
+
customerId: (0, model_util_1.text)(255),
|
|
21
|
+
number: (0, model_util_1.text)(255),
|
|
22
|
+
amountDue: model_util_1.amount,
|
|
23
|
+
amountPaid: model_util_1.amount,
|
|
24
|
+
currency: model_util_1.currency,
|
|
25
|
+
attemptCount: { type: 'int', default: 0, minimum: 0 },
|
|
26
|
+
periodStart: { type: 'dateTime', required: false },
|
|
27
|
+
periodEnd: { type: 'dateTime', required: false },
|
|
28
|
+
nextAttemptAt: { type: 'dateTime', required: false },
|
|
29
|
+
hostedUrl: (0, model_util_1.text)(2048),
|
|
30
|
+
pdfUrl: (0, model_util_1.text)(2048),
|
|
31
|
+
paidAt: { type: 'dateTime', required: false }
|
|
32
|
+
},
|
|
33
|
+
relations: {
|
|
34
|
+
subscription: {
|
|
35
|
+
model: 'PaymentSubscription',
|
|
36
|
+
type: 'manyToOne',
|
|
37
|
+
mappedBy: 'invoices',
|
|
38
|
+
required: false,
|
|
39
|
+
onDelete: 'setNull',
|
|
40
|
+
...model_util_1.internal,
|
|
41
|
+
output: { type: 'none' }
|
|
42
|
+
},
|
|
43
|
+
payment: {
|
|
44
|
+
model: 'Payment',
|
|
45
|
+
type: 'manyToOne',
|
|
46
|
+
mappedBy: 'invoices',
|
|
47
|
+
required: false,
|
|
48
|
+
onDelete: 'setNull',
|
|
49
|
+
...model_util_1.internal,
|
|
50
|
+
output: { type: 'none' }
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
unique: [['provider', 'providerInvoiceId']],
|
|
54
|
+
index: [['userId', '-createdAt']]
|
|
55
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const data_1 = require("@appweaver/data");
|
|
4
|
+
const model_util_1 = require("../model-util");
|
|
5
|
+
// A payment method saved at a gateway: what the gateway tells of it, never the number of a card
|
|
6
|
+
exports.default = (0, data_1.createModel)({
|
|
7
|
+
name: 'PaymentMethod',
|
|
8
|
+
id: { type: 'string', generator: 'uuid(7)' },
|
|
9
|
+
audit: model_util_1.audit,
|
|
10
|
+
scalars: {
|
|
11
|
+
provider: model_util_1.provider,
|
|
12
|
+
providerPaymentMethodId: { type: 'string', maxLength: 255 },
|
|
13
|
+
userId: (0, model_util_1.text)(255),
|
|
14
|
+
// The kind of the method, i.e. `card`
|
|
15
|
+
type: { type: 'string', maxLength: 64 },
|
|
16
|
+
brand: (0, model_util_1.text)(64),
|
|
17
|
+
last4: (0, model_util_1.text)(4),
|
|
18
|
+
expMonth: { type: 'int', required: false, minimum: 1, maximum: 12 },
|
|
19
|
+
expYear: { type: 'int', required: false },
|
|
20
|
+
// The same for the same card, telling a card saved twice
|
|
21
|
+
fingerprint: (0, model_util_1.text)(255),
|
|
22
|
+
country: (0, model_util_1.text)(2),
|
|
23
|
+
isDefault: { type: 'boolean', default: false }
|
|
24
|
+
},
|
|
25
|
+
relations: {
|
|
26
|
+
customer: {
|
|
27
|
+
model: 'PaymentCustomer',
|
|
28
|
+
type: 'manyToOne',
|
|
29
|
+
mappedBy: 'paymentMethods',
|
|
30
|
+
onDelete: 'cascade',
|
|
31
|
+
...model_util_1.internal,
|
|
32
|
+
output: { type: 'none' }
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
unique: [['provider', 'providerPaymentMethodId']],
|
|
36
|
+
index: [['userId', 'provider']]
|
|
37
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const data_1 = require("@appweaver/data");
|
|
4
|
+
const model_util_1 = require("../model-util");
|
|
5
|
+
// A recurring price of a gateway the users may subscribe to, named by a key of the application
|
|
6
|
+
exports.default = (0, data_1.createModel)({
|
|
7
|
+
name: 'PaymentPlan',
|
|
8
|
+
id: { type: 'string', generator: 'uuid(7)' },
|
|
9
|
+
audit: model_util_1.audit,
|
|
10
|
+
scalars: {
|
|
11
|
+
// The name the application subscribes by, i.e. `pro-monthly`, the same on every gateway
|
|
12
|
+
key: { type: 'string', maxLength: 255 },
|
|
13
|
+
provider: model_util_1.provider,
|
|
14
|
+
providerPriceId: { type: 'string', maxLength: 255 },
|
|
15
|
+
name: (0, model_util_1.text)(255),
|
|
16
|
+
amount: { ...model_util_1.amount, default: undefined },
|
|
17
|
+
currency: model_util_1.currency,
|
|
18
|
+
interval: { type: 'enum', values: ['day', 'week', 'month', 'year'] },
|
|
19
|
+
intervalCount: { type: 'int', default: 1, minimum: 1 },
|
|
20
|
+
trialDays: { type: 'int', required: false, minimum: 0 },
|
|
21
|
+
active: { type: 'boolean', default: true }
|
|
22
|
+
},
|
|
23
|
+
relations: {
|
|
24
|
+
subscriptions: {
|
|
25
|
+
model: 'PaymentSubscription',
|
|
26
|
+
type: 'oneToMany',
|
|
27
|
+
mappedBy: 'plan',
|
|
28
|
+
required: false,
|
|
29
|
+
...model_util_1.internal,
|
|
30
|
+
output: { type: 'none' }
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
unique: [
|
|
34
|
+
['provider', 'providerPriceId'],
|
|
35
|
+
['key', 'provider']
|
|
36
|
+
]
|
|
37
|
+
});
|