@ordinatio/billing 1.7.0 → 1.7.1
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/README.md +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +6 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,6 +27,6 @@ accessFor(record, new Date());
|
|
|
27
27
|
|
|
28
28
|
The package never reads the clock or the environment and imports no other package; a test in the package fails if that changes.
|
|
29
29
|
- `seatChangeCheck(live, expect)`: may a live Paddle subscription change its number of seats now? Takes Paddle's subscription as it is (untyped, never trusted) and the ids, interval, wanted seats, seats already used, plan, price ids and time. `ok` only for the same subscription and customer, status `active`, nothing scheduled, items exactly what the plan makes (a foreign item would be dropped by a full-list change, so it refuses), the stored interval, more than 30 minutes to the next billing time, and a wanted number inside the plan, not below the seats used and different from the live seats. It returns the COMPLETE body to send (`items` for the new seats, `proration_billing_mode: 'prorated_immediately'`, `on_payment_failure: 'prevent_change'`) and says `up` or `down`; otherwise it says why. It fails closed on garbage and on an invalid time.
|
|
30
|
-
- `readSeatPreview(raw, currency)`: reads Paddle's preview of that change. The money is the transaction totals (what the card pays, tax in, or what goes onto the account balance); a missing,
|
|
30
|
+
- `readSeatPreview(raw, currency)`: reads Paddle's preview of that change. The money is the transaction totals (what the card pays, tax in, or what goes onto the account balance); a missing, fractional or contradicting amount, or another currency, is refused. The card total, the balance credit and the renewal price are never negative; the total and tax of a CREDIT are zero or less (that is how Paddle shows a decrease) and of a charge zero or more.
|
|
31
31
|
- `previewIsWorse(shown, now, toleranceMinor)`: the one-sided "does the price still hold" check: worse only for a bigger charge or a smaller credit beyond the tolerance; anything unreadable counts as worse.
|
|
32
32
|
- `manageActionsFor(...).seats`: true only for an `active` plan.
|
package/dist/index.d.ts
CHANGED
|
@@ -380,15 +380,15 @@ type SeatPreviewReading = {
|
|
|
380
380
|
ok: true;
|
|
381
381
|
action: 'credit' | 'charge'; /** What the card pays now (tax in, any balance already on the account out); 0 for a credit. */
|
|
382
382
|
payNowMinor: number; /** What goes onto the account's balance; 0 for a charge. */
|
|
383
|
-
creditMinor: number;
|
|
384
|
-
taxMinor: number; /** The charge before any balance was used. */
|
|
383
|
+
creditMinor: number; /** Signed: zero or more for a charge, zero or less for a credit. */
|
|
384
|
+
taxMinor: number; /** The charge before any balance was used (a credit's total is negative). Signed like the tax. */
|
|
385
385
|
totalMinor: number;
|
|
386
386
|
currency: string; /** What each renewal will cost after the change. */
|
|
387
387
|
recurringMinor: number;
|
|
388
388
|
} | {
|
|
389
389
|
ok: false;
|
|
390
390
|
};
|
|
391
|
-
/** Reads `data` of `PATCH /subscriptions/{id}/preview` for a change made with `proration_billing_mode: 'prorated_immediately'`. Amounts are Paddle's strings of the smallest unit; zero is valid; a charge must add nothing to the balance and a credit must charge nothing. */
|
|
391
|
+
/** Reads `data` of `PATCH /subscriptions/{id}/preview` for a change made with `proration_billing_mode: 'prorated_immediately'`. Amounts are Paddle's strings of the smallest unit; zero is valid; a charge must add nothing to the balance and a credit must charge nothing. The total and tax are signed: of a charge they are zero or more, of a credit zero or less (checked against Paddle's real answer for a decrease: total -500, credit_to_balance 500, grand_total 0). */
|
|
392
392
|
declare function readSeatPreview(raw: unknown, currency: string): SeatPreviewReading;
|
|
393
393
|
interface SeatMoney {
|
|
394
394
|
action: 'credit' | 'charge';
|
package/dist/index.js
CHANGED
|
@@ -395,7 +395,9 @@ function seatChangeCheck(live, expect) {
|
|
|
395
395
|
}
|
|
396
396
|
var BAD = { ok: false };
|
|
397
397
|
var MINOR = /^\d{1,12}$/;
|
|
398
|
+
var SIGNED = /^-?\d{1,12}$/;
|
|
398
399
|
var minor = (value) => typeof value === "string" && MINOR.test(value) ? Number(value) : null;
|
|
400
|
+
var signedMinor = (value) => typeof value === "string" && SIGNED.test(value) ? Number(value) || 0 : null;
|
|
399
401
|
var dig = (value, ...path) => {
|
|
400
402
|
let at = value;
|
|
401
403
|
for (const step of path) {
|
|
@@ -415,13 +417,14 @@ function readSeatPreview(raw, currency) {
|
|
|
415
417
|
if (result.currency_code !== currency || totals.currency_code !== currency || recurring.currency_code !== currency) return BAD;
|
|
416
418
|
const payNowMinor = minor(totals.grand_total);
|
|
417
419
|
const creditMinor = minor(totals.credit_to_balance);
|
|
418
|
-
const taxMinor =
|
|
419
|
-
const totalMinor =
|
|
420
|
+
const taxMinor = signedMinor(totals.tax);
|
|
421
|
+
const totalMinor = signedMinor(totals.total);
|
|
420
422
|
const recurringMinor = minor(recurring.grand_total);
|
|
421
423
|
if (payNowMinor === null || creditMinor === null || taxMinor === null || totalMinor === null || recurringMinor === null) return BAD;
|
|
422
424
|
if (action === "charge" && creditMinor !== 0) return BAD;
|
|
423
425
|
if (action === "credit" && payNowMinor !== 0) return BAD;
|
|
424
|
-
if (payNowMinor > totalMinor) return BAD;
|
|
426
|
+
if (action === "charge" && (totalMinor < 0 || taxMinor < 0 || payNowMinor > totalMinor)) return BAD;
|
|
427
|
+
if (action === "credit" && (totalMinor > 0 || taxMinor > 0 || creditMinor > -totalMinor)) return BAD;
|
|
425
428
|
return { ok: true, action, payNowMinor, creditMinor, taxMinor, totalMinor, currency, recurringMinor };
|
|
426
429
|
}
|
|
427
430
|
var validMoney = (value) => isObject3(value) && (value.action === "credit" || value.action === "charge") && typeof value.amountMinor === "number" && Number.isSafeInteger(value.amountMinor) && value.amountMinor >= 0 && typeof value.currency === "string" && value.currency !== "";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ordinatio/billing",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Billing rules for any subscription product, pure and with no database: graduated seat pricing from a plan you pass in (validated once, in integer cents), the trial / paying / locked state machine, which team to use when one is locked, and seat counting with the can-add-a-seat rule",
|