namirasoft-payment 1.4.78 → 1.4.80
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/NamirasoftPaymentServer.js +1 -1
- package/dist/SubscriptionValidation.d.ts +5 -2
- package/dist/SubscriptionValidation.js +15 -8
- package/dist/SubscriptionValidation.js.map +1 -1
- package/package.json +1 -1
- package/src/NamirasoftPaymentServer.ts +1 -1
- package/src/SubscriptionValidation.ts +18 -9
|
@@ -17,7 +17,7 @@ const NamirasoftPaymentServerSubscriptionPaid_1 = require("./NamirasoftPaymentSe
|
|
|
17
17
|
const NamirasoftPaymentServerValue_1 = require("./NamirasoftPaymentServerValue");
|
|
18
18
|
class NamirasoftPaymentServer extends namirasoft_account_1.NSABaseServer {
|
|
19
19
|
constructor(base_url, manager, onError) {
|
|
20
|
-
super(base_url, `1.4.
|
|
20
|
+
super(base_url, `1.4.79`, manager, onError);
|
|
21
21
|
this.healthz = new NamirasoftPaymentServerHealthz_1.NamirasoftPaymentServerHealthz(this);
|
|
22
22
|
this.value = new NamirasoftPaymentServerValue_1.NamirasoftPaymentServerValue(this);
|
|
23
23
|
this.invoice = new NamirasoftPaymentServerInvoice_1.NamirasoftPaymentServerInvoice(this);
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { SubscriptionPaidRow } from "./row/SubscriptionPaidRow";
|
|
2
|
+
import { SubscriptionRow } from "./row/SubscriptionRow";
|
|
2
3
|
export declare class SubscriptionValidation {
|
|
3
4
|
date: Date;
|
|
4
5
|
valid: boolean;
|
|
5
6
|
valid_row: SubscriptionPaidRow | null;
|
|
6
7
|
valid_date: Date | null;
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
subscriptions: SubscriptionRow[] | null;
|
|
9
|
+
paids: SubscriptionPaidRow[] | null;
|
|
10
|
+
constructor(subscriptions: SubscriptionRow[] | null, paids: SubscriptionPaidRow[] | null);
|
|
11
|
+
isSubscribed(sales_item_id: string, offer_id: string): boolean;
|
|
9
12
|
isValid(now?: Date | null): boolean;
|
|
10
13
|
getValid(now?: Date | null): SubscriptionPaidRow | null;
|
|
11
14
|
getValidDateTo(now?: Date | null): Date | null;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SubscriptionValidation = void 0;
|
|
4
|
+
const SubscriptionStatus_1 = require("./enum/SubscriptionStatus");
|
|
4
5
|
class SubscriptionValidation {
|
|
5
|
-
constructor(
|
|
6
|
+
constructor(subscriptions, paids) {
|
|
6
7
|
this.date = new Date();
|
|
7
|
-
this.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
this.subscriptions = subscriptions;
|
|
9
|
+
this.paids = paids;
|
|
10
|
+
if (paids)
|
|
11
|
+
for (let i = 0; i < paids.length; i++) {
|
|
12
|
+
const row = paids[i];
|
|
11
13
|
row.applies_at = new Date(row.applies_at);
|
|
12
14
|
row.expires_at = new Date(row.expires_at);
|
|
13
15
|
}
|
|
@@ -15,15 +17,20 @@ class SubscriptionValidation {
|
|
|
15
17
|
this.valid_row = this.getValid(this.date);
|
|
16
18
|
this.valid_date = this.getValidDateTo(this.date);
|
|
17
19
|
}
|
|
20
|
+
isSubscribed(sales_item_id, offer_id) {
|
|
21
|
+
var _a;
|
|
22
|
+
let s = ((_a = this.subscriptions) !== null && _a !== void 0 ? _a : []).filter(s => s.status === SubscriptionStatus_1.SubscriptionStatus.Active).filter(s => s.sales_item_id == sales_item_id && (offer_id == null || s.offer_id == offer_id));
|
|
23
|
+
return s.length > 0;
|
|
24
|
+
}
|
|
18
25
|
isValid(now = null) {
|
|
19
26
|
return this.getValid(now) != null;
|
|
20
27
|
}
|
|
21
28
|
getValid(now = null) {
|
|
22
29
|
if (now == null)
|
|
23
30
|
now = new Date();
|
|
24
|
-
if (this.
|
|
25
|
-
for (let i = 0; i < this.
|
|
26
|
-
const row = this.
|
|
31
|
+
if (this.paids)
|
|
32
|
+
for (let i = 0; i < this.paids.length; i++) {
|
|
33
|
+
const row = this.paids[i];
|
|
27
34
|
if (row.applies_at <= now)
|
|
28
35
|
if (now <= row.expires_at)
|
|
29
36
|
return row;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SubscriptionValidation.js","sourceRoot":"","sources":["../src/SubscriptionValidation.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"SubscriptionValidation.js","sourceRoot":"","sources":["../src/SubscriptionValidation.ts"],"names":[],"mappings":";;;AAAA,kEAA+D;AAI/D,MAAa,sBAAsB;IAQ/B,YAAY,aAAuC,EAAE,KAAmC;QANjF,SAAI,GAAS,IAAI,IAAI,EAAE,CAAC;QAQ3B,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,KAAK;YACL,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EACrC,CAAC;gBACG,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;gBACrB,GAAG,CAAC,UAAU,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;gBAC1C,GAAG,CAAC,UAAU,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YAC9C,CAAC;QACL,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC1C,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrD,CAAC;IACD,YAAY,CAAC,aAAqB,EAAE,QAAgB;;QAEhD,IAAI,CAAC,GAAG,CAAC,MAA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: NamirasoftPaymentServerProduct;
|
|
52
52
|
constructor(base_url: string, manager: TokenManager, onError: (error: Error) => void)
|
|
53
53
|
{
|
|
54
|
-
super(base_url, `1.4.
|
|
54
|
+
super(base_url, `1.4.79`, manager, onError);
|
|
55
55
|
this.healthz = new NamirasoftPaymentServerHealthz(this);
|
|
56
56
|
this.value = new NamirasoftPaymentServerValue(this);
|
|
57
57
|
this.invoice = new NamirasoftPaymentServerInvoice(this);
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { SubscriptionStatus } from "./enum/SubscriptionStatus";
|
|
1
2
|
import { SubscriptionPaidRow } from "./row/SubscriptionPaidRow";
|
|
3
|
+
import { SubscriptionRow } from "./row/SubscriptionRow";
|
|
2
4
|
|
|
3
5
|
export class SubscriptionValidation
|
|
4
6
|
{
|
|
@@ -6,14 +8,16 @@ export class SubscriptionValidation
|
|
|
6
8
|
public valid: boolean;
|
|
7
9
|
public valid_row: SubscriptionPaidRow | null;
|
|
8
10
|
public valid_date: Date | null;
|
|
9
|
-
public
|
|
10
|
-
|
|
11
|
+
public subscriptions: SubscriptionRow[] | null;
|
|
12
|
+
public paids: SubscriptionPaidRow[] | null;
|
|
13
|
+
constructor(subscriptions: SubscriptionRow[] | null, paids: SubscriptionPaidRow[] | null)
|
|
11
14
|
{
|
|
12
|
-
this.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
this.subscriptions = subscriptions;
|
|
16
|
+
this.paids = paids;
|
|
17
|
+
if (paids)
|
|
18
|
+
for (let i = 0; i < paids.length; i++)
|
|
15
19
|
{
|
|
16
|
-
const row =
|
|
20
|
+
const row = paids[i];
|
|
17
21
|
row.applies_at = new Date(row.applies_at);
|
|
18
22
|
row.expires_at = new Date(row.expires_at);
|
|
19
23
|
}
|
|
@@ -21,6 +25,11 @@ export class SubscriptionValidation
|
|
|
21
25
|
this.valid_row = this.getValid(this.date);
|
|
22
26
|
this.valid_date = this.getValidDateTo(this.date);
|
|
23
27
|
}
|
|
28
|
+
isSubscribed(sales_item_id: string, offer_id: string)
|
|
29
|
+
{
|
|
30
|
+
let s = (this.subscriptions ?? []).filter(s => s.status === SubscriptionStatus.Active).filter(s => s.sales_item_id == sales_item_id && (offer_id == null || s.offer_id == offer_id));
|
|
31
|
+
return s.length > 0;
|
|
32
|
+
}
|
|
24
33
|
isValid(now: Date | null = null)
|
|
25
34
|
{
|
|
26
35
|
return this.getValid(now) != null;
|
|
@@ -29,10 +38,10 @@ export class SubscriptionValidation
|
|
|
29
38
|
{
|
|
30
39
|
if (now == null)
|
|
31
40
|
now = new Date();
|
|
32
|
-
if (this.
|
|
33
|
-
for (let i = 0; i < this.
|
|
41
|
+
if (this.paids)
|
|
42
|
+
for (let i = 0; i < this.paids.length; i++)
|
|
34
43
|
{
|
|
35
|
-
const row = this.
|
|
44
|
+
const row = this.paids[i];
|
|
36
45
|
if (row.applies_at <= now)
|
|
37
46
|
if (now <= row.expires_at)
|
|
38
47
|
return row;
|