@pax2pay/model-banking 0.1.452 → 0.1.454
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/Card/Operation/index.ts +4 -12
- package/Client/Transactions/index.ts +1 -1
- package/Operation/Changes.ts +1 -1
- package/Operation/Creatable.ts +1 -1
- package/Settlement/Entry/Creatable.ts +111 -11
- package/Settlement/Entry/Failed.ts +27 -0
- package/Settlement/Entry/{Cancel.ts → Legacy/Cancel.ts} +5 -5
- package/Settlement/Entry/{Capture.ts → Legacy/Capture.ts} +5 -5
- package/Settlement/Entry/Legacy/Creatable.ts +15 -0
- package/Settlement/Entry/{Refund.ts → Legacy/Refund.ts} +8 -8
- package/Settlement/Entry/{Unknown.ts → Legacy/Unknown.ts} +3 -3
- package/Settlement/Entry/Legacy/index.ts +55 -0
- package/Settlement/Entry/Succeeded.ts +22 -0
- package/Settlement/Entry/fromCreatable.ts +38 -0
- package/Settlement/Entry/fromLegacy.ts +86 -0
- package/Settlement/Entry/index.ts +19 -50
- package/Settlement/Entry/type.ts +6 -0
- package/Settlement/index.ts +1 -1
- package/Transaction/Incoming.ts +1 -1
- package/Transaction/index.ts +1 -1
- package/Warning/Settlement/UnknownEntry.ts +6 -3
- package/dist/Card/Operation/index.d.ts +1 -2
- package/dist/Card/Operation/index.js +3 -12
- package/dist/Card/Operation/index.js.map +1 -1
- package/dist/Client/Transactions/index.js +1 -1
- package/dist/Client/Transactions/index.js.map +1 -1
- package/dist/Operation/Changes.d.ts +1 -1
- package/dist/Operation/Creatable.d.ts +1 -1
- package/dist/Settlement/Entry/Creatable.d.ts +51 -6
- package/dist/Settlement/Entry/Creatable.js +88 -5
- package/dist/Settlement/Entry/Creatable.js.map +1 -1
- package/dist/Settlement/Entry/Failed.d.ts +11 -0
- package/dist/Settlement/Entry/Failed.js +12 -0
- package/dist/Settlement/Entry/Failed.js.map +1 -0
- package/dist/Settlement/Entry/{Cancel.d.ts → Legacy/Cancel.d.ts} +5 -5
- package/dist/Settlement/Entry/{Cancel.js → Legacy/Cancel.js} +5 -5
- package/dist/Settlement/Entry/Legacy/Cancel.js.map +1 -0
- package/dist/Settlement/Entry/{Capture.d.ts → Legacy/Capture.d.ts} +5 -5
- package/dist/Settlement/Entry/{Capture.js → Legacy/Capture.js} +5 -5
- package/dist/Settlement/Entry/Legacy/Capture.js.map +1 -0
- package/dist/Settlement/Entry/Legacy/Creatable.d.ts +9 -0
- package/dist/Settlement/Entry/Legacy/Creatable.js +10 -0
- package/dist/Settlement/Entry/Legacy/Creatable.js.map +1 -0
- package/dist/Settlement/Entry/{Refund.d.ts → Legacy/Refund.d.ts} +8 -8
- package/dist/Settlement/Entry/{Refund.js → Legacy/Refund.js} +7 -7
- package/dist/Settlement/Entry/Legacy/Refund.js.map +1 -0
- package/dist/Settlement/Entry/{Unknown.d.ts → Legacy/Unknown.d.ts} +3 -3
- package/dist/Settlement/Entry/{Unknown.js → Legacy/Unknown.js} +3 -3
- package/dist/Settlement/Entry/Legacy/Unknown.js.map +1 -0
- package/dist/Settlement/Entry/Legacy/index.d.ts +19 -0
- package/dist/Settlement/Entry/Legacy/index.js +50 -0
- package/dist/Settlement/Entry/Legacy/index.js.map +1 -0
- package/dist/Settlement/Entry/Succeeded.d.ts +14 -0
- package/dist/Settlement/Entry/Succeeded.js +17 -0
- package/dist/Settlement/Entry/Succeeded.js.map +1 -0
- package/dist/Settlement/Entry/fromCreatable.d.ts +6 -0
- package/dist/Settlement/Entry/fromCreatable.js +30 -0
- package/dist/Settlement/Entry/fromCreatable.js.map +1 -0
- package/dist/Settlement/Entry/fromLegacy.d.ts +3 -0
- package/dist/Settlement/Entry/fromLegacy.js +78 -0
- package/dist/Settlement/Entry/fromLegacy.js.map +1 -0
- package/dist/Settlement/Entry/index.d.ts +19 -16
- package/dist/Settlement/Entry/index.js +13 -45
- package/dist/Settlement/Entry/index.js.map +1 -1
- package/dist/Settlement/Entry/type.d.ts +3 -0
- package/dist/Settlement/Entry/type.js +5 -0
- package/dist/Settlement/Entry/type.js.map +1 -0
- package/dist/Settlement/index.d.ts +1 -1
- package/dist/Settlement/index.js.map +1 -1
- package/dist/Transaction/Incoming.d.ts +1 -1
- package/dist/Transaction/index.d.ts +1 -1
- package/dist/Warning/Settlement/UnknownEntry.d.ts +6 -2
- package/dist/Warning/Settlement/UnknownEntry.js +2 -1
- package/dist/Warning/Settlement/UnknownEntry.js.map +1 -1
- package/package.json +1 -1
- package/dist/Settlement/Entry/Cancel.js.map +0 -1
- package/dist/Settlement/Entry/Capture.js.map +0 -1
- package/dist/Settlement/Entry/Refund.js.map +0 -1
- package/dist/Settlement/Entry/Unknown.js.map +0 -1
package/Card/Operation/index.ts
CHANGED
|
@@ -16,23 +16,15 @@ export namespace Operation {
|
|
|
16
16
|
created: isoly.DateTime.now(),
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
export function fromEntry(entry: Entry): Operation | undefined {
|
|
20
|
-
return entry.
|
|
19
|
+
export function fromEntry(entry: Entry | Entry.Failed): Operation | undefined {
|
|
20
|
+
return entry.status == "failed"
|
|
21
21
|
? undefined
|
|
22
22
|
: {
|
|
23
23
|
type: "authorization",
|
|
24
|
-
id:
|
|
25
|
-
status:
|
|
24
|
+
id: entry.transaction ?? "unknown",
|
|
25
|
+
status: entry.type == "capture" ? "captured" : "refunded",
|
|
26
26
|
created: isoly.DateTime.now(),
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
export function fromEntryStatus(status: Exclude<Entry.Type, "unknown">): OperationAuthorization.Status {
|
|
30
|
-
const statusConverter: Record<Exclude<Entry.Type, "unknown">, OperationAuthorization.Status> = {
|
|
31
|
-
capture: "captured",
|
|
32
|
-
cancel: "cancelled",
|
|
33
|
-
refund: "refunded",
|
|
34
|
-
}
|
|
35
|
-
return statusConverter[status]
|
|
36
|
-
}
|
|
37
29
|
export const type = isly.union(Card.type, OperationAuthorization.type)
|
|
38
30
|
}
|
|
@@ -42,7 +42,7 @@ export class Transactions extends rest.Collection<gracely.Error> {
|
|
|
42
42
|
)
|
|
43
43
|
}
|
|
44
44
|
async getOperations(transactionId: string): Promise<Operation[] | gracely.Error> {
|
|
45
|
-
return this.client.get<Operation[]>(`/transaction/${transactionId}/
|
|
45
|
+
return this.client.get<Operation[]>(`/transaction/${transactionId}/operation`)
|
|
46
46
|
}
|
|
47
47
|
async statistics(
|
|
48
48
|
range: isoly.DateRange,
|
package/Operation/Changes.ts
CHANGED
|
@@ -114,7 +114,7 @@ export namespace Changes {
|
|
|
114
114
|
}
|
|
115
115
|
export function fromRefund(
|
|
116
116
|
settlement: string | undefined, // FIXME: remove | undefined when we're sure we send the id
|
|
117
|
-
refund: Settlement.Entry.Refund
|
|
117
|
+
refund: Settlement.Entry.Creatable.Refund,
|
|
118
118
|
charge: number | undefined,
|
|
119
119
|
sum: Sum
|
|
120
120
|
): Changes {
|
package/Operation/Creatable.ts
CHANGED
|
@@ -36,7 +36,7 @@ export namespace Creatable {
|
|
|
36
36
|
changes: Changes.type,
|
|
37
37
|
type: isly.string(types),
|
|
38
38
|
})
|
|
39
|
-
export function fromRefund(account: string, settlement: string, entry: Settlement.Entry.Refund
|
|
39
|
+
export function fromRefund(account: string, settlement: string, entry: Settlement.Entry.Creatable.Refund): Creatable {
|
|
40
40
|
// The Entry.Refund.Creatable has negative amount and fee
|
|
41
41
|
// The operation amounts should always be positive
|
|
42
42
|
const [currency, entryAmount] = entry.amount
|
|
@@ -1,15 +1,115 @@
|
|
|
1
1
|
import { isly } from "isly"
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { Acquirer } from "../../Acquirer"
|
|
3
|
+
import { Amount } from "../../Amount"
|
|
4
|
+
import { Merchant } from "../../Merchant"
|
|
5
|
+
import { Batch } from "../Batch"
|
|
6
|
+
import { Fee } from "../Fee"
|
|
7
|
+
import { Identifier as SettlementIdentifier } from "../Identifier"
|
|
8
|
+
import { Entry as LegacyEntry } from "./Legacy"
|
|
6
9
|
|
|
7
|
-
export type Creatable =
|
|
10
|
+
export type Creatable = Creatable.Known | Creatable.Unknown
|
|
8
11
|
export namespace Creatable {
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
export interface Base {
|
|
13
|
+
card: string
|
|
14
|
+
transaction?: string
|
|
15
|
+
account: string
|
|
16
|
+
approvalCode: string
|
|
17
|
+
merchant: Merchant
|
|
18
|
+
acquirer: Acquirer
|
|
19
|
+
reference: string
|
|
20
|
+
batch: Batch
|
|
21
|
+
fee: Fee
|
|
22
|
+
amount: Amount
|
|
23
|
+
settlement: SettlementIdentifier
|
|
24
|
+
}
|
|
25
|
+
export namespace Base {
|
|
26
|
+
export const type = isly.object<Base>({
|
|
27
|
+
card: isly.string(),
|
|
28
|
+
transaction: isly.string().optional(),
|
|
29
|
+
account: isly.string(),
|
|
30
|
+
approvalCode: isly.string(),
|
|
31
|
+
merchant: Merchant.type,
|
|
32
|
+
acquirer: Acquirer.type,
|
|
33
|
+
reference: isly.string(),
|
|
34
|
+
batch: Batch.type,
|
|
35
|
+
fee: Fee.type,
|
|
36
|
+
amount: Amount.type,
|
|
37
|
+
settlement: SettlementIdentifier.type,
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
export interface Capture extends Base {
|
|
41
|
+
type: "capture"
|
|
42
|
+
}
|
|
43
|
+
export namespace Capture {
|
|
44
|
+
export const type = Base.type.extend<Capture>({
|
|
45
|
+
type: isly.string("capture"),
|
|
46
|
+
})
|
|
47
|
+
export function fromLegacy(maybeLegacy: Capture | LegacyEntry.Capture.Creatable): Capture {
|
|
48
|
+
return type.is(maybeLegacy)
|
|
49
|
+
? maybeLegacy
|
|
50
|
+
: {
|
|
51
|
+
type: maybeLegacy.type,
|
|
52
|
+
card: maybeLegacy.authorization.card.id,
|
|
53
|
+
transaction: maybeLegacy.authorization.transaction?.id,
|
|
54
|
+
account: maybeLegacy.authorization.account || "unknown",
|
|
55
|
+
approvalCode: maybeLegacy.authorization.approvalCode ?? "unknown",
|
|
56
|
+
merchant: maybeLegacy.authorization.merchant,
|
|
57
|
+
acquirer: maybeLegacy.authorization.acquirer,
|
|
58
|
+
reference: maybeLegacy.reference,
|
|
59
|
+
batch: maybeLegacy.batch,
|
|
60
|
+
fee: maybeLegacy.fee,
|
|
61
|
+
amount: maybeLegacy.amount,
|
|
62
|
+
settlement: maybeLegacy.settlement ?? "unknown",
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
export interface Refund extends Base {
|
|
67
|
+
type: "refund"
|
|
68
|
+
}
|
|
69
|
+
export namespace Refund {
|
|
70
|
+
export const type = Base.type.extend<Refund>({
|
|
71
|
+
type: isly.string("refund"),
|
|
72
|
+
})
|
|
73
|
+
export function fromLegacy(maybeLegacy: Refund | LegacyEntry.Refund.Creatable): Refund {
|
|
74
|
+
return type.is(maybeLegacy)
|
|
75
|
+
? maybeLegacy
|
|
76
|
+
: {
|
|
77
|
+
type: maybeLegacy.type,
|
|
78
|
+
card: maybeLegacy.card,
|
|
79
|
+
account: maybeLegacy.account ?? "unknown",
|
|
80
|
+
approvalCode: maybeLegacy.authorization.approvalCode ?? "unknown",
|
|
81
|
+
merchant: maybeLegacy.merchant,
|
|
82
|
+
acquirer: maybeLegacy.acquirer,
|
|
83
|
+
reference: maybeLegacy.reference,
|
|
84
|
+
batch: maybeLegacy.batch,
|
|
85
|
+
fee: maybeLegacy.fee,
|
|
86
|
+
amount: maybeLegacy.amount,
|
|
87
|
+
settlement: maybeLegacy.settlement ?? "unknown",
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
export type Known = Capture | Refund
|
|
92
|
+
|
|
93
|
+
export namespace Known {
|
|
94
|
+
export const type = isly.union(Capture.type, Refund.type)
|
|
95
|
+
export function fromLegacy(
|
|
96
|
+
maybeLegacy: Creatable.Known | LegacyEntry.Capture.Creatable | LegacyEntry.Refund.Creatable
|
|
97
|
+
): Creatable.Known {
|
|
98
|
+
return maybeLegacy.type == "capture" ? Capture.fromLegacy(maybeLegacy) : Refund.fromLegacy(maybeLegacy)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
export interface Unknown extends Partial<Base> {
|
|
102
|
+
type: "unknown"
|
|
103
|
+
data: Record<string, unknown>
|
|
104
|
+
}
|
|
105
|
+
export namespace Unknown {
|
|
106
|
+
export const type = isly.object<Unknown>({
|
|
107
|
+
...(Object.fromEntries(
|
|
108
|
+
Object.entries(Base.type.getProperties()).map(([k, v]) => [k, v.optional()])
|
|
109
|
+
) as isly.object.Properties<Partial<Base>>), // TODO: Add "Partial" to isly
|
|
110
|
+
type: isly.string("unknown"),
|
|
111
|
+
data: isly.record<Record<string, unknown>>(isly.string(), isly.any()),
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
export const type = isly.union(Known.type, Unknown.type)
|
|
15
115
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { isoly } from "isoly"
|
|
2
|
+
import { isly } from "isly"
|
|
3
|
+
import { Creatable } from "./Creatable"
|
|
4
|
+
|
|
5
|
+
export type Failed = Creatable & {
|
|
6
|
+
status: "failed"
|
|
7
|
+
reason: string
|
|
8
|
+
created: isoly.DateTime
|
|
9
|
+
}
|
|
10
|
+
export namespace Failed {
|
|
11
|
+
export const type = isly.intersection<
|
|
12
|
+
Failed,
|
|
13
|
+
Creatable,
|
|
14
|
+
{
|
|
15
|
+
status: "failed"
|
|
16
|
+
reason: string
|
|
17
|
+
created: isoly.DateTime
|
|
18
|
+
}
|
|
19
|
+
>(
|
|
20
|
+
Creatable.type,
|
|
21
|
+
isly.object({
|
|
22
|
+
status: isly.string<"failed">("failed"),
|
|
23
|
+
reason: isly.string(),
|
|
24
|
+
created: isly.fromIs("isoly.DateTime", isoly.DateTime.is),
|
|
25
|
+
})
|
|
26
|
+
)
|
|
27
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { isoly } from "isoly"
|
|
2
2
|
import { isly } from "isly"
|
|
3
|
-
import { Amount } from "
|
|
4
|
-
import { Authorization } from "
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
3
|
+
import { Amount } from "../../../Amount"
|
|
4
|
+
import { Authorization } from "../../../Authorization"
|
|
5
|
+
import { Batch } from "../../Batch"
|
|
6
|
+
import { Fee } from "../../Fee"
|
|
7
|
+
import { Identifier as SettlementIdentifier } from "../../Identifier"
|
|
8
8
|
|
|
9
9
|
export interface Cancel extends Omit<Cancel.Creatable, "settlement"> {
|
|
10
10
|
status: "succeeded" | "failed"
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { isoly } from "isoly"
|
|
2
2
|
import { isly } from "isly"
|
|
3
|
-
import { Amount } from "
|
|
4
|
-
import { Authorization } from "
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
3
|
+
import { Amount } from "../../../Amount"
|
|
4
|
+
import { Authorization } from "../../../Authorization"
|
|
5
|
+
import { Batch } from "../../Batch"
|
|
6
|
+
import { Fee } from "../../Fee"
|
|
7
|
+
import { Identifier as SettlementIdentifier } from "../../Identifier"
|
|
8
8
|
|
|
9
9
|
export interface Capture extends Omit<Capture.Creatable, "settlement"> {
|
|
10
10
|
status: "succeeded" | "failed"
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isly } from "isly"
|
|
2
|
+
import { Cancel as EntryCancel } from "./Cancel"
|
|
3
|
+
import { Capture as EntryCapture } from "./Capture"
|
|
4
|
+
import { Refund as EntryRefund } from "./Refund"
|
|
5
|
+
import { Unknown as EntryUnknown } from "./Unknown"
|
|
6
|
+
|
|
7
|
+
export type Creatable = EntryCancel.Creatable | EntryCapture.Creatable | EntryRefund.Creatable | EntryUnknown.Creatable
|
|
8
|
+
export namespace Creatable {
|
|
9
|
+
export const type = isly.union(
|
|
10
|
+
EntryCancel.Creatable.type,
|
|
11
|
+
EntryCapture.Creatable.type,
|
|
12
|
+
EntryRefund.Creatable.type,
|
|
13
|
+
EntryUnknown.Creatable.type
|
|
14
|
+
)
|
|
15
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { isoly } from "isoly"
|
|
2
2
|
import { isly } from "isly"
|
|
3
|
-
import { Acquirer } from "
|
|
4
|
-
import { Amount } from "
|
|
5
|
-
import { Authorization } from "
|
|
6
|
-
import { Merchant } from "
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
3
|
+
import { Acquirer } from "../../../Acquirer"
|
|
4
|
+
import { Amount } from "../../../Amount"
|
|
5
|
+
import { Authorization } from "../../../Authorization"
|
|
6
|
+
import { Merchant } from "../../../Merchant"
|
|
7
|
+
import { Transaction } from "../../../Transaction"
|
|
8
|
+
import { Batch } from "../../Batch"
|
|
9
|
+
import { Fee } from "../../Fee"
|
|
10
|
+
import { Identifier as SettlementIdentifier } from "../../Identifier"
|
|
11
11
|
|
|
12
12
|
export interface Refund extends Omit<Refund.Creatable, "settlement"> {
|
|
13
13
|
status: "succeeded" | "failed"
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { isoly } from "isoly"
|
|
2
2
|
import { isly } from "isly"
|
|
3
|
-
import { Authorization } from "
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { Authorization } from "../../../Authorization"
|
|
4
|
+
import { Batch } from "../../Batch"
|
|
5
|
+
import { Identifier as SettlementIdentifier } from "../../Identifier"
|
|
6
6
|
|
|
7
7
|
export interface Unknown extends Omit<Unknown.Creatable, "settlement"> {
|
|
8
8
|
status: "succeeded" | "failed"
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { gracely } from "gracely"
|
|
2
|
+
import { isoly } from "isoly"
|
|
3
|
+
import { isly } from "isly"
|
|
4
|
+
import { Transaction } from "../../../Transaction"
|
|
5
|
+
import { Cancel as EntryCancel } from "./Cancel"
|
|
6
|
+
import { Capture as EntryCapture } from "./Capture"
|
|
7
|
+
import { Creatable as EntryCreatable } from "./Creatable"
|
|
8
|
+
import { Refund as EntryRefund } from "./Refund"
|
|
9
|
+
import { Unknown as EntryUnknown } from "./Unknown"
|
|
10
|
+
|
|
11
|
+
export type Entry = Entry.Cancel | Entry.Capture | Entry.Refund | Entry.Unknown
|
|
12
|
+
export namespace Entry {
|
|
13
|
+
export import Cancel = EntryCancel
|
|
14
|
+
export import Capture = EntryCapture
|
|
15
|
+
export import Refund = EntryRefund
|
|
16
|
+
export import Unknown = EntryUnknown
|
|
17
|
+
export type Type = "unknown" | "refund" | "capture" | "cancel"
|
|
18
|
+
export import Creatable = EntryCreatable
|
|
19
|
+
export function from(creatable: Entry.Creatable, transaction: Transaction | gracely.Error | string): Entry {
|
|
20
|
+
let result: Entry
|
|
21
|
+
const created = isoly.DateTime.now()
|
|
22
|
+
if (!Transaction.type.is(transaction) || transaction.status != "finalized")
|
|
23
|
+
result = { status: "failed", reason: reason(creatable, transaction), ...creatable, created }
|
|
24
|
+
else
|
|
25
|
+
switch (creatable.type) {
|
|
26
|
+
case "capture":
|
|
27
|
+
result = Capture.from(creatable)
|
|
28
|
+
break
|
|
29
|
+
case "refund":
|
|
30
|
+
result = Refund.from(creatable, transaction)
|
|
31
|
+
break
|
|
32
|
+
default:
|
|
33
|
+
result = { ...creatable, status: "failed", reason: "Entry type not implemented yet.", created }
|
|
34
|
+
break
|
|
35
|
+
}
|
|
36
|
+
return result
|
|
37
|
+
}
|
|
38
|
+
function reason(creatable: Entry.Creatable, transaction: Transaction | gracely.Error | string): string {
|
|
39
|
+
const result: string[] = []
|
|
40
|
+
!creatable.authorization && result.push("Missing authorization.")
|
|
41
|
+
if (gracely.Error.is(transaction))
|
|
42
|
+
result.push(`gracely error: ${JSON.stringify(transaction)}`)
|
|
43
|
+
else if (typeof transaction != "string")
|
|
44
|
+
result.push(`Transaction ${transaction.id} on account ${transaction.accountId} unable to be finalized.`)
|
|
45
|
+
else
|
|
46
|
+
result.push(transaction || "No reason provided")
|
|
47
|
+
return result.join("\n")
|
|
48
|
+
}
|
|
49
|
+
export const type = isly.union<Entry, Entry.Cancel, Entry.Capture, Entry.Refund, Entry.Unknown>(
|
|
50
|
+
Entry.Cancel.type,
|
|
51
|
+
Entry.Capture.type,
|
|
52
|
+
Entry.Refund.type,
|
|
53
|
+
Entry.Unknown.type
|
|
54
|
+
)
|
|
55
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isoly } from "isoly"
|
|
2
|
+
import { isly } from "isly"
|
|
3
|
+
import { Rail } from "../../Rail"
|
|
4
|
+
import { Creatable } from "./Creatable"
|
|
5
|
+
|
|
6
|
+
export interface Succeeded extends Omit<Creatable.Known, "transaction" | "card"> {
|
|
7
|
+
status: "succeeded"
|
|
8
|
+
card: Rail.Address.Card
|
|
9
|
+
transaction: string
|
|
10
|
+
created: isoly.DateTime
|
|
11
|
+
}
|
|
12
|
+
export namespace Succeeded {
|
|
13
|
+
export const type = Creatable.Base.type
|
|
14
|
+
.omit<"transaction" | "card">(["card", "transaction"])
|
|
15
|
+
.extend<Succeeded & { type: "capture" | "refund" }>({
|
|
16
|
+
type: isly.string(["capture", "refund"]),
|
|
17
|
+
status: isly.string<"succeeded">("succeeded"),
|
|
18
|
+
card: Rail.Address.Card.type,
|
|
19
|
+
transaction: isly.string(),
|
|
20
|
+
created: isly.fromIs("isoly.DateTime", isoly.DateTime.is),
|
|
21
|
+
})
|
|
22
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { gracely } from "gracely"
|
|
2
|
+
import { isoly } from "isoly"
|
|
3
|
+
import { Card } from "../../Card"
|
|
4
|
+
import { Rail } from "../../Rail"
|
|
5
|
+
import { Transaction } from "../../Transaction"
|
|
6
|
+
import type { Entry } from "."
|
|
7
|
+
import { Creatable } from "./Creatable"
|
|
8
|
+
|
|
9
|
+
export function fromCreatable(
|
|
10
|
+
creatable: Creatable,
|
|
11
|
+
transaction: Transaction.CardTransaction | gracely.Error | string,
|
|
12
|
+
card?: Card
|
|
13
|
+
): Entry {
|
|
14
|
+
let result: Entry
|
|
15
|
+
const reasons: string[] = []
|
|
16
|
+
const created = isoly.DateTime.now()
|
|
17
|
+
if (creatable.type == "unknown")
|
|
18
|
+
reasons.push("Unknown entry type.")
|
|
19
|
+
if (gracely.Error.is(transaction))
|
|
20
|
+
reasons.push(`gracely error: ${JSON.stringify(transaction)}`)
|
|
21
|
+
else if (typeof transaction == "string")
|
|
22
|
+
reasons.push(transaction || "No reason provided.")
|
|
23
|
+
else if (transaction.status != "finalized")
|
|
24
|
+
reasons.push(`Transaction ${transaction.id} on account ${transaction.accountId} unable to be finalized.`)
|
|
25
|
+
if (reasons.length > 0)
|
|
26
|
+
result = { status: "failed", reason: reasons.join("\n"), ...creatable, created }
|
|
27
|
+
else if (!card)
|
|
28
|
+
result = { status: "failed", reason: "Missing card", ...creatable, created }
|
|
29
|
+
else
|
|
30
|
+
result = {
|
|
31
|
+
status: "succeeded",
|
|
32
|
+
...(creatable as Creatable.Known),
|
|
33
|
+
created,
|
|
34
|
+
card: Rail.Address.Card.from(card),
|
|
35
|
+
transaction: (transaction as Transaction.CardTransaction).id,
|
|
36
|
+
}
|
|
37
|
+
return result
|
|
38
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { isoly } from "isoly"
|
|
2
|
+
import { Card } from "../../Card"
|
|
3
|
+
import { Rail } from "../../Rail"
|
|
4
|
+
import { Identifier as SettlementIdentifier } from "../Identifier"
|
|
5
|
+
import type { Entry } from "."
|
|
6
|
+
import type { Failed } from "./Failed"
|
|
7
|
+
import { Entry as LegacyEntry } from "./Legacy"
|
|
8
|
+
import { type } from "./type"
|
|
9
|
+
|
|
10
|
+
function toFailed(legacy: LegacyEntry.Unknown | LegacyEntry.Cancel): Failed {
|
|
11
|
+
return {
|
|
12
|
+
type: "unknown",
|
|
13
|
+
status: "failed",
|
|
14
|
+
data: legacy.type == "cancel" ? legacy : legacy.data,
|
|
15
|
+
reason: legacy.reason ?? "unknown",
|
|
16
|
+
created: legacy.created ?? isoly.DateTime.now(),
|
|
17
|
+
settlement: legacy.settlement ?? "unknown",
|
|
18
|
+
reference: ("reference" in legacy && legacy.reference) || "unknown",
|
|
19
|
+
batch: legacy.batch,
|
|
20
|
+
...("authorization" in legacy &&
|
|
21
|
+
legacy.authorization && {
|
|
22
|
+
account: legacy.authorization.account ?? "unknown",
|
|
23
|
+
approvalCode: legacy.authorization.approvalCode,
|
|
24
|
+
merchant: legacy.authorization.merchant,
|
|
25
|
+
acquirer: legacy.authorization.acquirer,
|
|
26
|
+
card: legacy.authorization.card.id,
|
|
27
|
+
transaction: legacy.authorization.transaction?.id,
|
|
28
|
+
}),
|
|
29
|
+
...("fee" in legacy && { fee: legacy.fee }),
|
|
30
|
+
...("amount" in legacy && { amount: legacy.amount }),
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function toEntry(legacy: LegacyEntry.Capture | LegacyEntry.Refund, card?: Rail.Address.Card): Entry {
|
|
34
|
+
return {
|
|
35
|
+
type: legacy.type,
|
|
36
|
+
created: legacy.created ?? isoly.DateTime.now(),
|
|
37
|
+
...(legacy.status == "failed"
|
|
38
|
+
? {
|
|
39
|
+
card: legacy.type == "refund" ? legacy.card : legacy.authorization.card.id,
|
|
40
|
+
status: "failed",
|
|
41
|
+
reason: legacy.reason ?? "unknown",
|
|
42
|
+
}
|
|
43
|
+
: {
|
|
44
|
+
card: card ?? {
|
|
45
|
+
type: "card",
|
|
46
|
+
scheme: (stack => (stack ? Card.Stack.toScheme(stack) : "unknown"))(
|
|
47
|
+
legacy.settlement && SettlementIdentifier.toProcessor(legacy.settlement)
|
|
48
|
+
) as Card.Scheme,
|
|
49
|
+
...(legacy.type == "refund"
|
|
50
|
+
? { id: legacy.card, iin: "unknown", last4: "unknown" }
|
|
51
|
+
: {
|
|
52
|
+
id: legacy.authorization.card.id,
|
|
53
|
+
iin: legacy.authorization.card.iin ?? "unknown",
|
|
54
|
+
last4: legacy.authorization.card.last4 ?? "unknown",
|
|
55
|
+
}),
|
|
56
|
+
expiry: [0, 0] as unknown as Card.Expiry,
|
|
57
|
+
holder: "unknown",
|
|
58
|
+
},
|
|
59
|
+
status: "succeeded",
|
|
60
|
+
}),
|
|
61
|
+
transaction:
|
|
62
|
+
("transaction" in legacy
|
|
63
|
+
? legacy.transaction?.id
|
|
64
|
+
: "authorization" in legacy && "transaction" in legacy.authorization
|
|
65
|
+
? legacy.authorization.transaction?.id
|
|
66
|
+
: "unknown") ?? "unknown",
|
|
67
|
+
account: legacy.account ?? (("transaction" in legacy && legacy.transaction?.accountId) || "unknown"),
|
|
68
|
+
approvalCode: legacy.authorization.approvalCode ?? "unknown",
|
|
69
|
+
...(legacy.type == "refund"
|
|
70
|
+
? { merchant: legacy.merchant, acquirer: legacy.acquirer }
|
|
71
|
+
: { merchant: legacy.authorization.merchant, acquirer: legacy.authorization.acquirer }),
|
|
72
|
+
reference: legacy.reference,
|
|
73
|
+
batch: legacy.batch,
|
|
74
|
+
fee: legacy.fee,
|
|
75
|
+
amount: legacy.amount,
|
|
76
|
+
settlement: legacy.settlement ?? "unknown",
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function fromLegacy(maybeLegacy: LegacyEntry | Entry): Entry {
|
|
81
|
+
return type.is(maybeLegacy)
|
|
82
|
+
? maybeLegacy
|
|
83
|
+
: maybeLegacy.type == "cancel" || maybeLegacy.type == "unknown"
|
|
84
|
+
? toFailed(maybeLegacy)
|
|
85
|
+
: toEntry(maybeLegacy)
|
|
86
|
+
}
|
|
@@ -1,57 +1,26 @@
|
|
|
1
|
-
import { gracely } from "gracely"
|
|
2
|
-
import { isoly } from "isoly"
|
|
3
|
-
import { isly } from "isly"
|
|
4
|
-
import { Transaction } from "../../Transaction"
|
|
5
|
-
import { Cancel as EntryCancel } from "./Cancel"
|
|
6
|
-
import { Capture as EntryCapture } from "./Capture"
|
|
7
1
|
import { Creatable as EntryCreatable } from "./Creatable"
|
|
8
|
-
import {
|
|
2
|
+
import { Failed as EntryFailed } from "./Failed"
|
|
3
|
+
import { fromCreatable } from "./fromCreatable"
|
|
4
|
+
import { fromLegacy as entryFromLegacy } from "./fromLegacy"
|
|
5
|
+
import { Entry as LegacyEntry } from "./Legacy"
|
|
6
|
+
import { Succeeded as EntrySucceeded } from "./Succeeded"
|
|
9
7
|
import { Summary as EntrySummary } from "./Summary"
|
|
10
|
-
import {
|
|
8
|
+
import { type as entryType } from "./type"
|
|
11
9
|
|
|
12
|
-
export type Entry =
|
|
10
|
+
export type Entry = EntrySucceeded | EntryFailed
|
|
13
11
|
export namespace Entry {
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
export import Refund = EntryRefund
|
|
17
|
-
export import Unknown = EntryUnknown
|
|
18
|
-
export type Type = "unknown" | "refund" | "capture" | "cancel"
|
|
19
|
-
export import Summary = EntrySummary
|
|
20
|
-
export import Creatable = EntryCreatable
|
|
21
|
-
export function from(creatable: Entry.Creatable, transaction: Transaction | gracely.Error | string): Entry {
|
|
22
|
-
let result: Entry
|
|
23
|
-
const created = isoly.DateTime.now()
|
|
24
|
-
if (!Transaction.type.is(transaction) || transaction.status != "finalized")
|
|
25
|
-
result = { status: "failed", reason: reason(creatable, transaction), ...creatable, created }
|
|
26
|
-
else
|
|
27
|
-
switch (creatable.type) {
|
|
28
|
-
case "capture":
|
|
29
|
-
result = Capture.from(creatable)
|
|
30
|
-
break
|
|
31
|
-
case "refund":
|
|
32
|
-
result = Refund.from(creatable, transaction)
|
|
33
|
-
break
|
|
34
|
-
default:
|
|
35
|
-
result = { ...creatable, status: "failed", reason: "Entry type not implemented yet.", created }
|
|
36
|
-
break
|
|
37
|
-
}
|
|
38
|
-
return result
|
|
12
|
+
export interface Capture extends EntrySucceeded {
|
|
13
|
+
type: "capture"
|
|
39
14
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
!creatable.authorization && result.push("Missing authorization.")
|
|
43
|
-
if (gracely.Error.is(transaction))
|
|
44
|
-
result.push(`gracely error: ${JSON.stringify(transaction)}`)
|
|
45
|
-
else if (typeof transaction != "string")
|
|
46
|
-
result.push(`Transaction ${transaction.id} on account ${transaction.accountId} unable to be finalized.`)
|
|
47
|
-
else
|
|
48
|
-
result.push(transaction || "No reason provided")
|
|
49
|
-
return result.join("\n")
|
|
15
|
+
export interface Refund extends EntrySucceeded {
|
|
16
|
+
type: "refund"
|
|
50
17
|
}
|
|
51
|
-
export
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
18
|
+
export import Creatable = EntryCreatable
|
|
19
|
+
export import Failed = EntryFailed
|
|
20
|
+
export import Succeeded = EntrySucceeded
|
|
21
|
+
export import Summary = EntrySummary
|
|
22
|
+
export import Legacy = LegacyEntry
|
|
23
|
+
export const type = entryType
|
|
24
|
+
export const fromLegacy = entryFromLegacy
|
|
25
|
+
export const from = fromCreatable
|
|
57
26
|
}
|
package/Settlement/index.ts
CHANGED
|
@@ -40,7 +40,7 @@ export namespace Settlement {
|
|
|
40
40
|
entries: { count: 0 },
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
export function compile(settlement: Settlement, entries: Settlement.Entry[]): Settlement {
|
|
43
|
+
export function compile(settlement: Settlement, entries: (Settlement.Entry | Settlement.Entry.Failed)[]): Settlement {
|
|
44
44
|
const result = { ...settlement }
|
|
45
45
|
for (const entry of entries) {
|
|
46
46
|
switch (entry.status) {
|
package/Transaction/Incoming.ts
CHANGED
|
@@ -26,7 +26,7 @@ export namespace Incoming {
|
|
|
26
26
|
reference: TransactionReference.type.optional(),
|
|
27
27
|
})
|
|
28
28
|
|
|
29
|
-
export function fromRefund(entry: Settlement.Entry.Refund
|
|
29
|
+
export function fromRefund(entry: Settlement.Entry.Creatable.Refund, card: Rail.Address.Card): Incoming {
|
|
30
30
|
const [currency, amount] = entry.amount
|
|
31
31
|
return {
|
|
32
32
|
account: card,
|
package/Transaction/index.ts
CHANGED
|
@@ -335,7 +335,7 @@ export namespace Transaction {
|
|
|
335
335
|
}
|
|
336
336
|
}
|
|
337
337
|
export function fromRefund(
|
|
338
|
-
refund: Settlement.Entry.Refund
|
|
338
|
+
refund: Settlement.Entry.Creatable.Refund,
|
|
339
339
|
id: string,
|
|
340
340
|
account: { id: string; name: string; organization: string },
|
|
341
341
|
card: Rail.Address.Card,
|
|
@@ -2,14 +2,16 @@ import { cryptly } from "cryptly"
|
|
|
2
2
|
import { isoly } from "isoly"
|
|
3
3
|
import { isly } from "isly"
|
|
4
4
|
import { Authorization } from "../../Authorization"
|
|
5
|
-
import {
|
|
5
|
+
import { Entry } from "../../Settlement/Entry"
|
|
6
6
|
import { Identifier } from "../../Settlement/Identifier"
|
|
7
|
+
import { Transaction } from "../../Transaction"
|
|
7
8
|
import { Base } from "../Base"
|
|
8
9
|
|
|
9
10
|
export interface UnknownEntry extends Base {
|
|
10
11
|
type: "unknown-entry"
|
|
11
12
|
resource: Identifier
|
|
12
13
|
authorization?: Authorization["id"]
|
|
14
|
+
transaction?: Transaction["id"]
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
export namespace UnknownEntry {
|
|
@@ -17,12 +19,13 @@ export namespace UnknownEntry {
|
|
|
17
19
|
type: isly.string("unknown-entry"),
|
|
18
20
|
resource: Identifier.type,
|
|
19
21
|
authorization: isly.fromIs("Authorization.id", cryptly.Identifier.is).optional(),
|
|
22
|
+
transaction: isly.string().optional(),
|
|
20
23
|
})
|
|
21
|
-
export function create(entry:
|
|
24
|
+
export function create(entry: Extract<Entry.Failed, { type: "unknown" }>, resource: Identifier): UnknownEntry {
|
|
22
25
|
return {
|
|
23
26
|
type: "unknown-entry",
|
|
24
27
|
resource,
|
|
25
|
-
|
|
28
|
+
transaction: entry.transaction,
|
|
26
29
|
date: isoly.Date.now(),
|
|
27
30
|
}
|
|
28
31
|
}
|