@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,99 @@
|
|
|
1
|
+
import { GatewayConfig } from '../types';
|
|
2
|
+
import { PaymentGateway, PaymentGatewayClass } from './payment-gateway';
|
|
3
|
+
/** The name of the built-in gateway of development and tests. */
|
|
4
|
+
export declare const FAKE_GATEWAY = "fake";
|
|
5
|
+
/** What a gateway is selected by: its name, otherwise the country and the currency of the payment. */
|
|
6
|
+
export type GatewaySelection = {
|
|
7
|
+
/** The name of the gateway, used as it is */
|
|
8
|
+
gateway?: string;
|
|
9
|
+
/** The country of the customer, an ISO 3166-1 alpha-2 code */
|
|
10
|
+
country?: string;
|
|
11
|
+
/** The currency of the payment, an ISO 4217 code */
|
|
12
|
+
currency?: string;
|
|
13
|
+
/** The ID of the user paying */
|
|
14
|
+
userId?: string;
|
|
15
|
+
};
|
|
16
|
+
/** Selects the gateway of a payment, `undefined` leaving it to the countries and currencies of the config. */
|
|
17
|
+
export type PaymentGatewayResolver = (selection: GatewaySelection) => string | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Registers a driver class under a name without a module providing it, i.e. a stub in a test. It takes precedence
|
|
20
|
+
* over the driver of a module with the same name.
|
|
21
|
+
*
|
|
22
|
+
* @param {string} name - The name of the driver.
|
|
23
|
+
* @param {PaymentGatewayClass | undefined} driver - The driver class, or `undefined` to remove it.
|
|
24
|
+
*/
|
|
25
|
+
export declare function registerPaymentGateway(name: string, driver: PaymentGatewayClass | undefined): void;
|
|
26
|
+
/**
|
|
27
|
+
* Sets the function selecting the gateway of a payment naming none, i.e. by the legal entity of the country of the
|
|
28
|
+
* customer. A name it returns must be a configured gateway.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* setPaymentGatewayResolver(({ country }) => (country === 'US' ? 'stripeUs' : undefined));
|
|
32
|
+
*
|
|
33
|
+
* @param {PaymentGatewayResolver | undefined} resolver - The function, or `undefined` to remove it.
|
|
34
|
+
*/
|
|
35
|
+
export declare function setPaymentGatewayResolver(resolver: PaymentGatewayResolver | undefined): void;
|
|
36
|
+
/** Resolves the gateways of the `payments.gateways` config, and creates the driver of each one once. */
|
|
37
|
+
export declare class GatewayRegistry {
|
|
38
|
+
/**
|
|
39
|
+
* Returns the names of the gateways: the configured ones, and the built-in `fake` gateway outside of production.
|
|
40
|
+
*
|
|
41
|
+
* @return {string[]} The names.
|
|
42
|
+
*/
|
|
43
|
+
names(): string[];
|
|
44
|
+
/**
|
|
45
|
+
* Returns the gateway of a call naming none: `payments.defaultGateway`, otherwise the only configured gateway,
|
|
46
|
+
* otherwise the `fake` one.
|
|
47
|
+
*
|
|
48
|
+
* @return {string} The name of the gateway.
|
|
49
|
+
* @throws {ConfigurationError} `CONFIGURATION_INVALID` when several gateways are configured without a default, or
|
|
50
|
+
* none in production.
|
|
51
|
+
*/
|
|
52
|
+
defaultName(): string;
|
|
53
|
+
/**
|
|
54
|
+
* Selects the gateway of a payment: the one it names, the one of the resolver, the first gateway taking its
|
|
55
|
+
* country, then its currency, otherwise the default one.
|
|
56
|
+
*
|
|
57
|
+
* @param {GatewaySelection} [selection={}] - The name of the gateway, or the country and currency of the payment.
|
|
58
|
+
* @return {string} The name of the gateway.
|
|
59
|
+
* @throws {PaymentError} `PAYMENT_GATEWAY_UNKNOWN` for a gateway that is not configured.
|
|
60
|
+
*/
|
|
61
|
+
select(selection?: GatewaySelection): string;
|
|
62
|
+
/**
|
|
63
|
+
* Returns the config of a gateway, completed with the defaults of the `payments` config.
|
|
64
|
+
*
|
|
65
|
+
* @param {string} name - The name of the gateway.
|
|
66
|
+
* @return {GatewayConfig} The config.
|
|
67
|
+
* @throws {PaymentError} `PAYMENT_GATEWAY_UNKNOWN` for a gateway that is not configured.
|
|
68
|
+
*/
|
|
69
|
+
config(name: string): GatewayConfig;
|
|
70
|
+
/**
|
|
71
|
+
* Returns the driver of a gateway, created on its first call.
|
|
72
|
+
*
|
|
73
|
+
* @param {string} name - The name of the gateway.
|
|
74
|
+
* @return {Promise<PaymentGateway>} The driver.
|
|
75
|
+
* @throws {PaymentError} `PAYMENT_GATEWAY_UNKNOWN` for a gateway that is not configured.
|
|
76
|
+
* @throws {ConfigurationError} `CONFIGURATION_INVALID` when no enabled module provides its driver.
|
|
77
|
+
*/
|
|
78
|
+
gateway(name: string): Promise<PaymentGateway>;
|
|
79
|
+
/**
|
|
80
|
+
* Checks that the default gateway and the gateways of the health check are configured.
|
|
81
|
+
*
|
|
82
|
+
* @return {string[]} The errors, empty when the config is valid.
|
|
83
|
+
*/
|
|
84
|
+
validate(): string[];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Returns the registry of the gateways, the one instance the services of the module share.
|
|
88
|
+
*
|
|
89
|
+
* @return {GatewayRegistry} The registry.
|
|
90
|
+
*/
|
|
91
|
+
export declare function gatewayRegistry(): GatewayRegistry;
|
|
92
|
+
/**
|
|
93
|
+
* Names the config key and the variable of a property of a gateway, for the message of a missing one.
|
|
94
|
+
*
|
|
95
|
+
* @param {string} gateway - The name of the gateway.
|
|
96
|
+
* @param {string} property - The property in camelCase, i.e. `secretKey`.
|
|
97
|
+
* @return {string} The key and the variable, i.e. `payments.gateways.stripe.secretKey (PAYMENTS_GATEWAYS_STRIPE_SECRET_KEY)`.
|
|
98
|
+
*/
|
|
99
|
+
export declare function gatewayConfigKey(gateway: string, property: string): string;
|
|
@@ -0,0 +1,275 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.GatewayRegistry = exports.FAKE_GATEWAY = void 0;
|
|
37
|
+
exports.registerPaymentGateway = registerPaymentGateway;
|
|
38
|
+
exports.setPaymentGatewayResolver = setPaymentGatewayResolver;
|
|
39
|
+
exports.gatewayRegistry = gatewayRegistry;
|
|
40
|
+
exports.gatewayConfigKey = gatewayConfigKey;
|
|
41
|
+
const common_1 = require("@appweaver/common");
|
|
42
|
+
const core_1 = require("@appweaver/core");
|
|
43
|
+
const internal_1 = require("@appweaver/core/internal");
|
|
44
|
+
const config_1 = require("../config");
|
|
45
|
+
const logger = (0, common_1.createLogger)('payments');
|
|
46
|
+
// Matched by name, like the other contracts, since a module may load its own copy of the class
|
|
47
|
+
const PAYMENT_GATEWAY_CONTRACT = 'PaymentGateway';
|
|
48
|
+
/** The name of the built-in gateway of development and tests. */
|
|
49
|
+
exports.FAKE_GATEWAY = 'fake';
|
|
50
|
+
/** The packages of the known drivers, named when one is not installed. */
|
|
51
|
+
const DRIVER_PACKAGES = {
|
|
52
|
+
stripe: '@appweaver/stripe'
|
|
53
|
+
};
|
|
54
|
+
const PAYMENT_GATEWAYS = Symbol.for('appweaver.PaymentGateways');
|
|
55
|
+
const PAYMENT_GATEWAY_RESOLVER = Symbol.for('appweaver.PaymentGatewayResolver');
|
|
56
|
+
const globals = globalThis;
|
|
57
|
+
const registered = (globals[PAYMENT_GATEWAYS] ??= new Map());
|
|
58
|
+
/**
|
|
59
|
+
* Registers a driver class under a name without a module providing it, i.e. a stub in a test. It takes precedence
|
|
60
|
+
* over the driver of a module with the same name.
|
|
61
|
+
*
|
|
62
|
+
* @param {string} name - The name of the driver.
|
|
63
|
+
* @param {PaymentGatewayClass | undefined} driver - The driver class, or `undefined` to remove it.
|
|
64
|
+
*/
|
|
65
|
+
function registerPaymentGateway(name, driver) {
|
|
66
|
+
if (driver) {
|
|
67
|
+
registered.set(name, driver);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
registered.delete(name);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Sets the function selecting the gateway of a payment naming none, i.e. by the legal entity of the country of the
|
|
75
|
+
* customer. A name it returns must be a configured gateway.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* setPaymentGatewayResolver(({ country }) => (country === 'US' ? 'stripeUs' : undefined));
|
|
79
|
+
*
|
|
80
|
+
* @param {PaymentGatewayResolver | undefined} resolver - The function, or `undefined` to remove it.
|
|
81
|
+
*/
|
|
82
|
+
function setPaymentGatewayResolver(resolver) {
|
|
83
|
+
globals[PAYMENT_GATEWAY_RESOLVER] = resolver;
|
|
84
|
+
}
|
|
85
|
+
/** Resolves the gateways of the `payments.gateways` config, and creates the driver of each one once. */
|
|
86
|
+
class GatewayRegistry {
|
|
87
|
+
/** @internal */
|
|
88
|
+
_gateways = new Map();
|
|
89
|
+
/**
|
|
90
|
+
* Returns the names of the gateways: the configured ones, and the built-in `fake` gateway outside of production.
|
|
91
|
+
*
|
|
92
|
+
* @return {string[]} The names.
|
|
93
|
+
*/
|
|
94
|
+
names() {
|
|
95
|
+
const names = Object.keys(config_1.paymentsConfig.GATEWAYS);
|
|
96
|
+
return fakeAllowed() && !names.includes(exports.FAKE_GATEWAY)
|
|
97
|
+
? [...names, exports.FAKE_GATEWAY]
|
|
98
|
+
: names;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Returns the gateway of a call naming none: `payments.defaultGateway`, otherwise the only configured gateway,
|
|
102
|
+
* otherwise the `fake` one.
|
|
103
|
+
*
|
|
104
|
+
* @return {string} The name of the gateway.
|
|
105
|
+
* @throws {ConfigurationError} `CONFIGURATION_INVALID` when several gateways are configured without a default, or
|
|
106
|
+
* none in production.
|
|
107
|
+
*/
|
|
108
|
+
defaultName() {
|
|
109
|
+
if (config_1.paymentsConfig.DEFAULT_GATEWAY) {
|
|
110
|
+
return config_1.paymentsConfig.DEFAULT_GATEWAY;
|
|
111
|
+
}
|
|
112
|
+
const names = Object.keys(config_1.paymentsConfig.GATEWAYS);
|
|
113
|
+
if (names.length === 1) {
|
|
114
|
+
return names[0];
|
|
115
|
+
}
|
|
116
|
+
if (names.length === 0 && fakeAllowed()) {
|
|
117
|
+
return exports.FAKE_GATEWAY;
|
|
118
|
+
}
|
|
119
|
+
throw new common_1.ConfigurationError(common_1.ErrorCode.ConfigurationInvalid, names.length
|
|
120
|
+
? `Several payment gateways are configured (${names.join(', ')}), set the default one in payments.defaultGateway (PAYMENTS_DEFAULT_GATEWAY)`
|
|
121
|
+
: 'No payment gateway is configured: add one to payments.gateways, i.e. PAYMENTS_GATEWAYS_STRIPE_SECRET_KEY');
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Selects the gateway of a payment: the one it names, the one of the resolver, the first gateway taking its
|
|
125
|
+
* country, then its currency, otherwise the default one.
|
|
126
|
+
*
|
|
127
|
+
* @param {GatewaySelection} [selection={}] - The name of the gateway, or the country and currency of the payment.
|
|
128
|
+
* @return {string} The name of the gateway.
|
|
129
|
+
* @throws {PaymentError} `PAYMENT_GATEWAY_UNKNOWN` for a gateway that is not configured.
|
|
130
|
+
*/
|
|
131
|
+
select(selection = {}) {
|
|
132
|
+
const name = selection.gateway ??
|
|
133
|
+
globals[PAYMENT_GATEWAY_RESOLVER]?.(selection) ??
|
|
134
|
+
this.match('countries', selection.country) ??
|
|
135
|
+
this.match('currencies', selection.currency) ??
|
|
136
|
+
this.defaultName();
|
|
137
|
+
this.config(name);
|
|
138
|
+
return name;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Returns the config of a gateway, completed with the defaults of the `payments` config.
|
|
142
|
+
*
|
|
143
|
+
* @param {string} name - The name of the gateway.
|
|
144
|
+
* @return {GatewayConfig} The config.
|
|
145
|
+
* @throws {PaymentError} `PAYMENT_GATEWAY_UNKNOWN` for a gateway that is not configured.
|
|
146
|
+
*/
|
|
147
|
+
config(name) {
|
|
148
|
+
const config = config_1.paymentsConfig.GATEWAYS[name] ??
|
|
149
|
+
(name === exports.FAKE_GATEWAY && fakeAllowed() ? {} : undefined);
|
|
150
|
+
if (!config) {
|
|
151
|
+
throw new common_1.PaymentError(common_1.ErrorCode.PaymentGatewayUnknown, `No payment gateway '${name}' configured, the gateways are: ${this.names().join(', ') || 'none'}`, { gateway: name });
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
name,
|
|
155
|
+
driver: config.driver ?? name,
|
|
156
|
+
secretKey: config.secretKey,
|
|
157
|
+
publicKey: config.publicKey,
|
|
158
|
+
webhookSecret: config.webhookSecret,
|
|
159
|
+
apiVersion: config.apiVersion,
|
|
160
|
+
apiUrl: config.apiUrl,
|
|
161
|
+
countries: (config.countries ?? []).map((code) => code.toUpperCase()),
|
|
162
|
+
currencies: (config.currencies ?? []).map((code) => code.toUpperCase()),
|
|
163
|
+
timeout: config.timeout ?? config_1.paymentsConfig.TIMEOUT,
|
|
164
|
+
maxRetries: config.maxRetries ?? config_1.paymentsConfig.MAX_RETRIES
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Returns the driver of a gateway, created on its first call.
|
|
169
|
+
*
|
|
170
|
+
* @param {string} name - The name of the gateway.
|
|
171
|
+
* @return {Promise<PaymentGateway>} The driver.
|
|
172
|
+
* @throws {PaymentError} `PAYMENT_GATEWAY_UNKNOWN` for a gateway that is not configured.
|
|
173
|
+
* @throws {ConfigurationError} `CONFIGURATION_INVALID` when no enabled module provides its driver.
|
|
174
|
+
*/
|
|
175
|
+
gateway(name) {
|
|
176
|
+
let gateway = this._gateways.get(name);
|
|
177
|
+
if (!gateway) {
|
|
178
|
+
gateway = this.createGateway(name);
|
|
179
|
+
this._gateways.set(name, gateway);
|
|
180
|
+
gateway.catch(() => this._gateways.delete(name));
|
|
181
|
+
}
|
|
182
|
+
return gateway;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Checks that the default gateway and the gateways of the health check are configured.
|
|
186
|
+
*
|
|
187
|
+
* @return {string[]} The errors, empty when the config is valid.
|
|
188
|
+
*/
|
|
189
|
+
validate() {
|
|
190
|
+
const errors = [];
|
|
191
|
+
const check = (read) => {
|
|
192
|
+
try {
|
|
193
|
+
this.config(read());
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
errors.push(error.message);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
check(() => this.defaultName());
|
|
200
|
+
for (const name of config_1.paymentsConfig.HEALTH_CHECK_GATEWAYS) {
|
|
201
|
+
check(() => name);
|
|
202
|
+
}
|
|
203
|
+
return errors;
|
|
204
|
+
}
|
|
205
|
+
/** @internal */
|
|
206
|
+
match(key, value) {
|
|
207
|
+
if (!value) {
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
const code = value.toUpperCase();
|
|
211
|
+
return Object.keys(config_1.paymentsConfig.GATEWAYS).find((name) => this.config(name)[key].includes(code));
|
|
212
|
+
}
|
|
213
|
+
/** @internal */
|
|
214
|
+
async createGateway(name) {
|
|
215
|
+
const config = this.config(name);
|
|
216
|
+
const Driver = await findDriver(config.driver);
|
|
217
|
+
if (!Driver) {
|
|
218
|
+
const pkg = DRIVER_PACKAGES[config.driver];
|
|
219
|
+
throw new common_1.ConfigurationError(common_1.ErrorCode.ConfigurationInvalid, `No enabled module provides the payment driver '${config.driver}' of the gateway '${name}'${pkg ? `, install ${pkg}` : ''}`);
|
|
220
|
+
}
|
|
221
|
+
logger.debug({ gateway: name, driver: config.driver }, 'Payment gateway connected');
|
|
222
|
+
return new Driver(config);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
exports.GatewayRegistry = GatewayRegistry;
|
|
226
|
+
/**
|
|
227
|
+
* Returns the registry of the gateways, the one instance the services of the module share.
|
|
228
|
+
*
|
|
229
|
+
* @return {GatewayRegistry} The registry.
|
|
230
|
+
*/
|
|
231
|
+
function gatewayRegistry() {
|
|
232
|
+
if (!(0, core_1.isDefined)(GatewayRegistry)) {
|
|
233
|
+
(0, core_1.define)(GatewayRegistry);
|
|
234
|
+
}
|
|
235
|
+
return (0, core_1.inject)(GatewayRegistry);
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Names the config key and the variable of a property of a gateway, for the message of a missing one.
|
|
239
|
+
*
|
|
240
|
+
* @param {string} gateway - The name of the gateway.
|
|
241
|
+
* @param {string} property - The property in camelCase, i.e. `secretKey`.
|
|
242
|
+
* @return {string} The key and the variable, i.e. `payments.gateways.stripe.secretKey (PAYMENTS_GATEWAYS_STRIPE_SECRET_KEY)`.
|
|
243
|
+
*/
|
|
244
|
+
function gatewayConfigKey(gateway, property) {
|
|
245
|
+
const variable = `PAYMENTS_GATEWAYS_${(0, common_1.camelToSnakeCase)(gateway)}_${(0, common_1.camelToSnakeCase)(property)}`;
|
|
246
|
+
return `payments.gateways.${gateway}.${property} (${variable.replace(/-/g, '_').toUpperCase()})`;
|
|
247
|
+
}
|
|
248
|
+
/** The fake gateway moves no money, so it is never used in production. */
|
|
249
|
+
function fakeAllowed() {
|
|
250
|
+
return common_1.appConfig.ENV !== common_1.Environment.Production;
|
|
251
|
+
}
|
|
252
|
+
/** Finds the class of a driver: a registered one, else the provider of an enabled module. */
|
|
253
|
+
async function findDriver(name) {
|
|
254
|
+
const driver = registered.get(name);
|
|
255
|
+
if (driver) {
|
|
256
|
+
return driver;
|
|
257
|
+
}
|
|
258
|
+
const provider = internal_1.context.modules.enabled
|
|
259
|
+
.flatMap((module) => module.providers ?? [])
|
|
260
|
+
.find((entry) => entry.contract.name === PAYMENT_GATEWAY_CONTRACT && entry.name === name);
|
|
261
|
+
if (provider) {
|
|
262
|
+
return driverClass(await provider.load());
|
|
263
|
+
}
|
|
264
|
+
// The fake gateway is built in, also without the module discovered, i.e. in a unit test
|
|
265
|
+
if (name === exports.FAKE_GATEWAY) {
|
|
266
|
+
return driverClass(await Promise.resolve().then(() => __importStar(require('./fake-gateway'))));
|
|
267
|
+
}
|
|
268
|
+
return undefined;
|
|
269
|
+
}
|
|
270
|
+
/** The driver class a module exports, the first export with a `verifyWebhook` method. */
|
|
271
|
+
function driverClass(exports) {
|
|
272
|
+
return Object.values(exports).find((value) => typeof value === 'function' &&
|
|
273
|
+
typeof value.prototype
|
|
274
|
+
?.verifyWebhook === 'function');
|
|
275
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { HealthCheckResult } from '@appweaver/common';
|
|
2
|
+
import { GatewayCheckout, GatewayCheckoutInput, GatewayConfig, GatewayCustomer, GatewayCustomerInput, GatewayEvent, GatewayInvoice, GatewayPayment, GatewayPaymentInput, GatewayPaymentMethod, GatewayPrice, GatewayRefund, GatewayRefundInput, GatewaySetup, GatewaySubscription, GatewaySubscriptionInput, GatewaySubscriptionUpdate, PaymentCapability, WebhookHeaders } from '../types';
|
|
3
|
+
/** The class of a driver, created once per gateway using it. */
|
|
4
|
+
export type PaymentGatewayClass = new (config: GatewayConfig) => PaymentGateway;
|
|
5
|
+
/**
|
|
6
|
+
* The driver of the gateways of one payment provider, provided by a module as a `PaymentGateway` provider named by
|
|
7
|
+
* the driver name, i.e. `stripe` of `@appweaver/stripe`. It speaks the amounts in the minor units of their currency
|
|
8
|
+
* and the statuses of the module, sends the idempotency key of every write, and throws a `PaymentError`:
|
|
9
|
+
* `PAYMENT_DECLINED` for a refused payment, `PAYMENT_REQUEST_INVALID` for a request the provider rejects,
|
|
10
|
+
* `PAYMENT_GATEWAY_UNAVAILABLE` for the errors a retry may not have, `PAYMENT_GATEWAY_FAILED` otherwise.
|
|
11
|
+
*/
|
|
12
|
+
export declare abstract class PaymentGateway {
|
|
13
|
+
readonly config: GatewayConfig;
|
|
14
|
+
/** What the gateway can do, a method of a missing capability throwing `PAYMENT_CAPABILITY_UNSUPPORTED`. */
|
|
15
|
+
abstract readonly capabilities: readonly PaymentCapability[];
|
|
16
|
+
constructor(config: GatewayConfig);
|
|
17
|
+
abstract createCustomer(input: GatewayCustomerInput): Promise<GatewayCustomer>;
|
|
18
|
+
abstract updateCustomer(customerId: string, input: GatewayCustomerInput): Promise<GatewayCustomer>;
|
|
19
|
+
abstract deleteCustomer(customerId: string): Promise<void>;
|
|
20
|
+
/** Creates a payment, confirmed at once with a saved payment method, otherwise by the client. */
|
|
21
|
+
abstract createPayment(input: GatewayPaymentInput): Promise<GatewayPayment>;
|
|
22
|
+
abstract getPayment(paymentId: string): Promise<GatewayPayment>;
|
|
23
|
+
/** Cancels a payment that is not paid, releasing an authorization. */
|
|
24
|
+
abstract cancelPayment(paymentId: string): Promise<GatewayPayment>;
|
|
25
|
+
abstract refundPayment(input: GatewayRefundInput): Promise<GatewayRefund>;
|
|
26
|
+
/**
|
|
27
|
+
* Verifies the signature of a webhook request against the secret of the gateway, and its age against the
|
|
28
|
+
* tolerance, then normalizes its event.
|
|
29
|
+
*
|
|
30
|
+
* @param {Buffer} body - The body of the request as it was received.
|
|
31
|
+
* @param {WebhookHeaders} headers - The headers of the request.
|
|
32
|
+
* @param {number} tolerance - How old the signature may be, in milliseconds.
|
|
33
|
+
* @throws {PaymentError} `PAYMENT_WEBHOOK_INVALID` for a missing or wrong signature, or one too old.
|
|
34
|
+
*/
|
|
35
|
+
abstract verifyWebhook(body: Buffer, headers: WebhookHeaders, tolerance: number): Promise<GatewayEvent>;
|
|
36
|
+
/** Checks that the provider answers the credentials of the gateway. */
|
|
37
|
+
abstract checkHealth(): Promise<HealthCheckResult>;
|
|
38
|
+
/** Takes the money of an authorized payment, a part of it when an amount is given. */
|
|
39
|
+
capturePayment(paymentId: string, amount?: number, idempotencyKey?: string): Promise<GatewayPayment>;
|
|
40
|
+
/** Creates a hosted page the customer pays or subscribes on. */
|
|
41
|
+
createCheckout(input: GatewayCheckoutInput): Promise<GatewayCheckout>;
|
|
42
|
+
getCheckout(checkoutId: string): Promise<GatewayCheckout>;
|
|
43
|
+
/**
|
|
44
|
+
* Closes a hosted page that is still open, so it cannot be paid anymore, and returns the page as it is then: a
|
|
45
|
+
* page that was paid or expired before is returned unchanged.
|
|
46
|
+
*/
|
|
47
|
+
expireCheckout(checkoutId: string): Promise<GatewayCheckout>;
|
|
48
|
+
/** Starts saving a payment method of a customer, confirmed by the client. */
|
|
49
|
+
createSetup(customerId: string, idempotencyKey?: string): Promise<GatewaySetup>;
|
|
50
|
+
listPaymentMethods(customerId: string): Promise<GatewayPaymentMethod[]>;
|
|
51
|
+
detachPaymentMethod(paymentMethodId: string): Promise<void>;
|
|
52
|
+
/** Sets the payment method the subscriptions and the invoices of a customer are charged to. */
|
|
53
|
+
setDefaultPaymentMethod(customerId: string, paymentMethodId: string): Promise<void>;
|
|
54
|
+
createSubscription(input: GatewaySubscriptionInput): Promise<GatewaySubscription>;
|
|
55
|
+
getSubscription(subscriptionId: string): Promise<GatewaySubscription>;
|
|
56
|
+
updateSubscription(subscriptionId: string, update: GatewaySubscriptionUpdate): Promise<GatewaySubscription>;
|
|
57
|
+
/** Ends a subscription at once. Ending it with its period is an update setting `cancelAtPeriodEnd`. */
|
|
58
|
+
cancelSubscription(subscriptionId: string): Promise<GatewaySubscription>;
|
|
59
|
+
getInvoice(invoiceId: string): Promise<GatewayInvoice>;
|
|
60
|
+
/** Lists the recurring prices of the account, synchronized into the plans. */
|
|
61
|
+
listPrices(): Promise<GatewayPrice[]>;
|
|
62
|
+
/** Creates a session of the page of the gateway where a customer manages their payment methods and subscriptions. */
|
|
63
|
+
createPortalSession(customerId: string, returnUrl: string): Promise<{
|
|
64
|
+
url: string;
|
|
65
|
+
}>;
|
|
66
|
+
/** Tells whether the gateway has a capability. */
|
|
67
|
+
supports(capability: PaymentCapability): boolean;
|
|
68
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PaymentGateway = void 0;
|
|
4
|
+
const common_1 = require("@appweaver/common");
|
|
5
|
+
/**
|
|
6
|
+
* The driver of the gateways of one payment provider, provided by a module as a `PaymentGateway` provider named by
|
|
7
|
+
* the driver name, i.e. `stripe` of `@appweaver/stripe`. It speaks the amounts in the minor units of their currency
|
|
8
|
+
* and the statuses of the module, sends the idempotency key of every write, and throws a `PaymentError`:
|
|
9
|
+
* `PAYMENT_DECLINED` for a refused payment, `PAYMENT_REQUEST_INVALID` for a request the provider rejects,
|
|
10
|
+
* `PAYMENT_GATEWAY_UNAVAILABLE` for the errors a retry may not have, `PAYMENT_GATEWAY_FAILED` otherwise.
|
|
11
|
+
*/
|
|
12
|
+
class PaymentGateway {
|
|
13
|
+
config;
|
|
14
|
+
constructor(config) {
|
|
15
|
+
this.config = config;
|
|
16
|
+
}
|
|
17
|
+
/** Takes the money of an authorized payment, a part of it when an amount is given. */
|
|
18
|
+
async capturePayment(paymentId, amount, idempotencyKey) {
|
|
19
|
+
return this.unsupported('manualCapture');
|
|
20
|
+
}
|
|
21
|
+
/** Creates a hosted page the customer pays or subscribes on. */
|
|
22
|
+
async createCheckout(input) {
|
|
23
|
+
return this.unsupported('checkout');
|
|
24
|
+
}
|
|
25
|
+
async getCheckout(checkoutId) {
|
|
26
|
+
return this.unsupported('checkout');
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Closes a hosted page that is still open, so it cannot be paid anymore, and returns the page as it is then: a
|
|
30
|
+
* page that was paid or expired before is returned unchanged.
|
|
31
|
+
*/
|
|
32
|
+
async expireCheckout(checkoutId) {
|
|
33
|
+
return this.unsupported('checkout');
|
|
34
|
+
}
|
|
35
|
+
/** Starts saving a payment method of a customer, confirmed by the client. */
|
|
36
|
+
async createSetup(customerId, idempotencyKey) {
|
|
37
|
+
return this.unsupported('savedMethods');
|
|
38
|
+
}
|
|
39
|
+
async listPaymentMethods(customerId) {
|
|
40
|
+
return this.unsupported('savedMethods');
|
|
41
|
+
}
|
|
42
|
+
async detachPaymentMethod(paymentMethodId) {
|
|
43
|
+
return this.unsupported('savedMethods');
|
|
44
|
+
}
|
|
45
|
+
/** Sets the payment method the subscriptions and the invoices of a customer are charged to. */
|
|
46
|
+
async setDefaultPaymentMethod(customerId, paymentMethodId) {
|
|
47
|
+
return this.unsupported('savedMethods');
|
|
48
|
+
}
|
|
49
|
+
async createSubscription(input) {
|
|
50
|
+
return this.unsupported('subscriptions');
|
|
51
|
+
}
|
|
52
|
+
async getSubscription(subscriptionId) {
|
|
53
|
+
return this.unsupported('subscriptions');
|
|
54
|
+
}
|
|
55
|
+
async updateSubscription(subscriptionId, update) {
|
|
56
|
+
return this.unsupported('subscriptions');
|
|
57
|
+
}
|
|
58
|
+
/** Ends a subscription at once. Ending it with its period is an update setting `cancelAtPeriodEnd`. */
|
|
59
|
+
async cancelSubscription(subscriptionId) {
|
|
60
|
+
return this.unsupported('subscriptions');
|
|
61
|
+
}
|
|
62
|
+
async getInvoice(invoiceId) {
|
|
63
|
+
return this.unsupported('subscriptions');
|
|
64
|
+
}
|
|
65
|
+
/** Lists the recurring prices of the account, synchronized into the plans. */
|
|
66
|
+
async listPrices() {
|
|
67
|
+
return this.unsupported('prices');
|
|
68
|
+
}
|
|
69
|
+
/** Creates a session of the page of the gateway where a customer manages their payment methods and subscriptions. */
|
|
70
|
+
async createPortalSession(customerId, returnUrl) {
|
|
71
|
+
return this.unsupported('portal');
|
|
72
|
+
}
|
|
73
|
+
/** Tells whether the gateway has a capability. */
|
|
74
|
+
supports(capability) {
|
|
75
|
+
return this.capabilities.includes(capability);
|
|
76
|
+
}
|
|
77
|
+
/** @internal */
|
|
78
|
+
unsupported(capability) {
|
|
79
|
+
throw new common_1.PaymentError(common_1.ErrorCode.PaymentCapabilityUnsupported, `The '${this.config.driver}' driver of the '${this.config.name}' gateway has no ${capability}`, { gateway: this.config.name, capability });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.PaymentGateway = PaymentGateway;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * from './config';
|
|
2
|
+
export * from './types';
|
|
3
|
+
export * from './gateway/payment-gateway';
|
|
4
|
+
export { FAKE_GATEWAY, GatewayRegistry, gatewayConfigKey, gatewayRegistry, registerPaymentGateway, setPaymentGatewayResolver } from './gateway/gateway-registry';
|
|
5
|
+
export type { GatewaySelection, PaymentGatewayResolver } from './gateway/gateway-registry';
|
|
6
|
+
export { FAKE_ACTION_METHOD, FAKE_DECLINED_METHOD, FakePaymentGateway, onFakePaymentEvent, setFakeCheckoutUrl } from './gateway/fake-gateway';
|
|
7
|
+
export { PaymentEvents } from './service/payment-events';
|
|
8
|
+
export { onPaymentEvent } from './service/payment-handlers';
|
|
9
|
+
export type { PaymentEventHandler } from './service/payment-handlers';
|
|
10
|
+
export { sendPaymentEmail } from './service/payment-emails';
|
|
11
|
+
export * from './service/payments-service';
|
|
12
|
+
export * from './service/subscriptions-service';
|
|
13
|
+
export { PAYMENT_METADATA_KEY, SUBSCRIPTION_METADATA_KEY } from './service/payment-sync';
|
|
14
|
+
export * from './utils/money-util';
|
|
15
|
+
export { ACTIVE_SUBSCRIPTION_STATUSES, canTransition, isFinalStatus } from './utils/status-util';
|
|
16
|
+
export { isPaymentAdmin } from './resources/policies';
|
package/index.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.isPaymentAdmin = exports.isFinalStatus = exports.canTransition = exports.ACTIVE_SUBSCRIPTION_STATUSES = exports.SUBSCRIPTION_METADATA_KEY = exports.PAYMENT_METADATA_KEY = exports.sendPaymentEmail = exports.onPaymentEvent = exports.PaymentEvents = exports.setFakeCheckoutUrl = exports.onFakePaymentEvent = exports.FakePaymentGateway = exports.FAKE_DECLINED_METHOD = exports.FAKE_ACTION_METHOD = exports.setPaymentGatewayResolver = exports.registerPaymentGateway = exports.gatewayRegistry = exports.gatewayConfigKey = exports.GatewayRegistry = exports.FAKE_GATEWAY = void 0;
|
|
18
|
+
__exportStar(require("./config"), exports);
|
|
19
|
+
__exportStar(require("./types"), exports);
|
|
20
|
+
__exportStar(require("./gateway/payment-gateway"), exports);
|
|
21
|
+
var gateway_registry_1 = require("./gateway/gateway-registry");
|
|
22
|
+
Object.defineProperty(exports, "FAKE_GATEWAY", { enumerable: true, get: function () { return gateway_registry_1.FAKE_GATEWAY; } });
|
|
23
|
+
Object.defineProperty(exports, "GatewayRegistry", { enumerable: true, get: function () { return gateway_registry_1.GatewayRegistry; } });
|
|
24
|
+
Object.defineProperty(exports, "gatewayConfigKey", { enumerable: true, get: function () { return gateway_registry_1.gatewayConfigKey; } });
|
|
25
|
+
Object.defineProperty(exports, "gatewayRegistry", { enumerable: true, get: function () { return gateway_registry_1.gatewayRegistry; } });
|
|
26
|
+
Object.defineProperty(exports, "registerPaymentGateway", { enumerable: true, get: function () { return gateway_registry_1.registerPaymentGateway; } });
|
|
27
|
+
Object.defineProperty(exports, "setPaymentGatewayResolver", { enumerable: true, get: function () { return gateway_registry_1.setPaymentGatewayResolver; } });
|
|
28
|
+
var fake_gateway_1 = require("./gateway/fake-gateway");
|
|
29
|
+
Object.defineProperty(exports, "FAKE_ACTION_METHOD", { enumerable: true, get: function () { return fake_gateway_1.FAKE_ACTION_METHOD; } });
|
|
30
|
+
Object.defineProperty(exports, "FAKE_DECLINED_METHOD", { enumerable: true, get: function () { return fake_gateway_1.FAKE_DECLINED_METHOD; } });
|
|
31
|
+
Object.defineProperty(exports, "FakePaymentGateway", { enumerable: true, get: function () { return fake_gateway_1.FakePaymentGateway; } });
|
|
32
|
+
Object.defineProperty(exports, "onFakePaymentEvent", { enumerable: true, get: function () { return fake_gateway_1.onFakePaymentEvent; } });
|
|
33
|
+
Object.defineProperty(exports, "setFakeCheckoutUrl", { enumerable: true, get: function () { return fake_gateway_1.setFakeCheckoutUrl; } });
|
|
34
|
+
var payment_events_1 = require("./service/payment-events");
|
|
35
|
+
Object.defineProperty(exports, "PaymentEvents", { enumerable: true, get: function () { return payment_events_1.PaymentEvents; } });
|
|
36
|
+
var payment_handlers_1 = require("./service/payment-handlers");
|
|
37
|
+
Object.defineProperty(exports, "onPaymentEvent", { enumerable: true, get: function () { return payment_handlers_1.onPaymentEvent; } });
|
|
38
|
+
var payment_emails_1 = require("./service/payment-emails");
|
|
39
|
+
Object.defineProperty(exports, "sendPaymentEmail", { enumerable: true, get: function () { return payment_emails_1.sendPaymentEmail; } });
|
|
40
|
+
__exportStar(require("./service/payments-service"), exports);
|
|
41
|
+
__exportStar(require("./service/subscriptions-service"), exports);
|
|
42
|
+
var payment_sync_1 = require("./service/payment-sync");
|
|
43
|
+
Object.defineProperty(exports, "PAYMENT_METADATA_KEY", { enumerable: true, get: function () { return payment_sync_1.PAYMENT_METADATA_KEY; } });
|
|
44
|
+
Object.defineProperty(exports, "SUBSCRIPTION_METADATA_KEY", { enumerable: true, get: function () { return payment_sync_1.SUBSCRIPTION_METADATA_KEY; } });
|
|
45
|
+
__exportStar(require("./utils/money-util"), exports);
|
|
46
|
+
var status_util_1 = require("./utils/status-util");
|
|
47
|
+
Object.defineProperty(exports, "ACTIVE_SUBSCRIPTION_STATUSES", { enumerable: true, get: function () { return status_util_1.ACTIVE_SUBSCRIPTION_STATUSES; } });
|
|
48
|
+
Object.defineProperty(exports, "canTransition", { enumerable: true, get: function () { return status_util_1.canTransition; } });
|
|
49
|
+
Object.defineProperty(exports, "isFinalStatus", { enumerable: true, get: function () { return status_util_1.isFinalStatus; } });
|
|
50
|
+
var policies_1 = require("./resources/policies");
|
|
51
|
+
Object.defineProperty(exports, "isPaymentAdmin", { enumerable: true, get: function () { return policies_1.isPaymentAdmin; } });
|
package/locales/en.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"emails": {
|
|
3
|
+
"payments": {
|
|
4
|
+
"labels": {
|
|
5
|
+
"description": "Description",
|
|
6
|
+
"plan": "Plan",
|
|
7
|
+
"reference": "Reference",
|
|
8
|
+
"method": "Payment method",
|
|
9
|
+
"date": "Date",
|
|
10
|
+
"receipt": "Receipt",
|
|
11
|
+
"reason": "Reason",
|
|
12
|
+
"retry": "Next attempt",
|
|
13
|
+
"link": "Confirm the payment"
|
|
14
|
+
},
|
|
15
|
+
"receipt": {
|
|
16
|
+
"subject": "Your receipt for {amount}",
|
|
17
|
+
"message": "Thank you, we received your payment of {amount}.",
|
|
18
|
+
"receipt": "View receipt"
|
|
19
|
+
},
|
|
20
|
+
"failed": {
|
|
21
|
+
"subject": "Your payment of {amount} failed",
|
|
22
|
+
"message": "We could not process your payment of {amount}.",
|
|
23
|
+
"hint": "Please check your payment method and try again."
|
|
24
|
+
},
|
|
25
|
+
"refunded": {
|
|
26
|
+
"subject": "Your refund of {amount}",
|
|
27
|
+
"message": "We refunded {amount} to your payment method.",
|
|
28
|
+
"hint": "It may take a few business days for the refund to appear on your statement."
|
|
29
|
+
},
|
|
30
|
+
"actionRequired": {
|
|
31
|
+
"subject": "Confirm your payment of {amount}",
|
|
32
|
+
"message": "Your bank asks you to confirm the payment of {amount} before it can be completed.",
|
|
33
|
+
"action": "Confirm payment",
|
|
34
|
+
"hint": "Until it is confirmed, the payment stays incomplete."
|
|
35
|
+
},
|
|
36
|
+
"subscriptionCanceled": {
|
|
37
|
+
"subject": "Your subscription was canceled",
|
|
38
|
+
"message": "Your subscription was canceled, and will not renew."
|
|
39
|
+
},
|
|
40
|
+
"trialEnding": {
|
|
41
|
+
"subject": "Your trial ends soon",
|
|
42
|
+
"message": "The trial of your subscription ends on {date}.",
|
|
43
|
+
"hint": "Your payment method is charged once the trial ends. Cancel before then to avoid the charge."
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|