@pax2pay/model-banking 0.1.118 → 0.1.120

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.
Files changed (128) hide show
  1. package/Amount.ts +10 -0
  2. package/Amounts.ts +10 -0
  3. package/Authorization/Creatable.ts +2 -1
  4. package/Authorization/Status.ts +47 -0
  5. package/Authorization/index.ts +92 -18
  6. package/Card/Changeable.ts +2 -1
  7. package/Card/Creatable.ts +2 -1
  8. package/Card/Operation/Settlement.ts +2 -2
  9. package/Card/Preset.ts +1 -0
  10. package/Card/index.ts +3 -2
  11. package/Client/Settlements.ts +2 -2
  12. package/Identifier.ts +12 -0
  13. package/{Realm/index.ts → Realm.ts} +2 -1
  14. package/Rule/State/index.ts +1 -1
  15. package/Settlement/Creatable.ts +18 -0
  16. package/Settlement/Entry/Cancel.ts +34 -0
  17. package/Settlement/Entry/Capture.ts +34 -0
  18. package/Settlement/Entry/Creatable.ts +18 -0
  19. package/Settlement/Entry/Refund.ts +34 -0
  20. package/Settlement/Entry/Summary.ts +21 -0
  21. package/Settlement/Entry/Unknown.ts +29 -0
  22. package/Settlement/Entry/index.ts +49 -0
  23. package/Settlement/Fee.ts +12 -0
  24. package/Settlement/Settled.ts +19 -0
  25. package/Settlement/Status.ts +13 -0
  26. package/Settlement/Total.ts +17 -0
  27. package/Settlement/index.ts +67 -75
  28. package/Treasury/Balance/index.ts +5 -9
  29. package/dist/Amount.d.ts +8 -0
  30. package/dist/Amount.js +9 -0
  31. package/dist/Amount.js.map +1 -0
  32. package/dist/Amounts.d.ts +8 -0
  33. package/dist/Amounts.js +9 -0
  34. package/dist/Amounts.js.map +1 -0
  35. package/dist/Authorization/Creatable.d.ts +2 -2
  36. package/dist/Authorization/Creatable.js.map +1 -1
  37. package/dist/Authorization/Status.d.ts +16 -0
  38. package/dist/Authorization/Status.js +38 -0
  39. package/dist/Authorization/Status.js.map +1 -0
  40. package/dist/Authorization/index.d.ts +30 -9
  41. package/dist/Authorization/index.js +66 -11
  42. package/dist/Authorization/index.js.map +1 -1
  43. package/dist/Card/Changeable.d.ts +2 -2
  44. package/dist/Card/Changeable.js.map +1 -1
  45. package/dist/Card/Creatable.d.ts +2 -2
  46. package/dist/Card/Creatable.js.map +1 -1
  47. package/dist/Card/Operation/Settlement.d.ts +1 -1
  48. package/dist/Card/Operation/Settlement.js +1 -1
  49. package/dist/Card/Operation/Settlement.js.map +1 -1
  50. package/dist/Card/Preset.js.map +1 -1
  51. package/dist/Card/index.d.ts +3 -2
  52. package/dist/Card/index.js.map +1 -1
  53. package/dist/Client/Settlements.d.ts +1 -1
  54. package/dist/Client/Settlements.js.map +1 -1
  55. package/dist/Identifier.d.ts +5 -0
  56. package/dist/Identifier.js +10 -0
  57. package/dist/Identifier.js.map +1 -0
  58. package/dist/{Realm/index.d.ts → Realm.d.ts} +2 -1
  59. package/dist/{Realm/index.js → Realm.js} +2 -1
  60. package/dist/Realm.js.map +1 -0
  61. package/dist/Rule/State/index.d.ts +1 -1
  62. package/dist/Rule/State/index.js.map +1 -1
  63. package/dist/Settlement/Creatable.d.ts +12 -0
  64. package/dist/Settlement/Creatable.js +13 -0
  65. package/dist/Settlement/Creatable.js.map +1 -0
  66. package/dist/Settlement/Entry/Cancel.d.ts +24 -0
  67. package/dist/Settlement/Entry/Cancel.js +25 -0
  68. package/dist/Settlement/Entry/Cancel.js.map +1 -0
  69. package/dist/Settlement/Entry/Capture.d.ts +24 -0
  70. package/dist/Settlement/Entry/Capture.js +25 -0
  71. package/dist/Settlement/Entry/Capture.js.map +1 -0
  72. package/dist/Settlement/Entry/Creatable.d.ts +11 -0
  73. package/dist/Settlement/Entry/Creatable.js +12 -0
  74. package/dist/Settlement/Entry/Creatable.js.map +1 -0
  75. package/dist/Settlement/Entry/Refund.d.ts +24 -0
  76. package/dist/Settlement/Entry/Refund.js +25 -0
  77. package/dist/Settlement/Entry/Refund.js.map +1 -0
  78. package/dist/Settlement/Entry/Summary.d.ts +12 -0
  79. package/dist/Settlement/Entry/Summary.js +15 -0
  80. package/dist/Settlement/Entry/Summary.js.map +1 -0
  81. package/dist/Settlement/Entry/Unknown.d.ts +21 -0
  82. package/dist/Settlement/Entry/Unknown.js +23 -0
  83. package/dist/Settlement/Entry/Unknown.js.map +1 -0
  84. package/dist/Settlement/Entry/index.d.ts +31 -0
  85. package/dist/Settlement/Entry/index.js +33 -0
  86. package/dist/Settlement/Entry/index.js.map +1 -0
  87. package/dist/Settlement/Fee.d.ts +10 -0
  88. package/dist/Settlement/Fee.js +9 -0
  89. package/dist/Settlement/Fee.js.map +1 -0
  90. package/dist/Settlement/Settled.d.ts +13 -0
  91. package/dist/Settlement/Settled.js +14 -0
  92. package/dist/Settlement/Settled.js.map +1 -0
  93. package/dist/Settlement/Status.d.ts +7 -0
  94. package/dist/Settlement/Status.js +8 -0
  95. package/dist/Settlement/Status.js.map +1 -0
  96. package/dist/Settlement/Total.d.ts +13 -0
  97. package/dist/Settlement/Total.js +14 -0
  98. package/dist/Settlement/Total.js.map +1 -0
  99. package/dist/Settlement/index.d.ts +46 -45
  100. package/dist/Settlement/index.js +49 -47
  101. package/dist/Settlement/index.js.map +1 -1
  102. package/dist/Treasury/Balance/index.d.ts +5 -3
  103. package/dist/Treasury/Balance/index.js +4 -7
  104. package/dist/Treasury/Balance/index.js.map +1 -1
  105. package/dist/pax2pay.d.ts +3 -0
  106. package/dist/pax2pay.js +3 -0
  107. package/dist/pax2pay.js.map +1 -1
  108. package/global.d.ts +2 -0
  109. package/package.json +8 -8
  110. package/pax2pay.ts +3 -0
  111. package/tsconfig.json +3 -1
  112. package/Authorization/Approved.ts +0 -21
  113. package/Authorization/Base.ts +0 -43
  114. package/Authorization/Failed.ts +0 -46
  115. package/Settlement/Entry.ts +0 -87
  116. package/dist/Authorization/Approved.d.ts +0 -14
  117. package/dist/Authorization/Approved.js +0 -16
  118. package/dist/Authorization/Approved.js.map +0 -1
  119. package/dist/Authorization/Base.d.ts +0 -22
  120. package/dist/Authorization/Base.js +0 -34
  121. package/dist/Authorization/Base.js.map +0 -1
  122. package/dist/Authorization/Failed.d.ts +0 -18
  123. package/dist/Authorization/Failed.js +0 -41
  124. package/dist/Authorization/Failed.js.map +0 -1
  125. package/dist/Realm/index.js.map +0 -1
  126. package/dist/Settlement/Entry.d.ts +0 -59
  127. package/dist/Settlement/Entry.js +0 -64
  128. package/dist/Settlement/Entry.js.map +0 -1
package/Amount.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { isoly } from "isoly"
2
+ import { isly } from "isly"
3
+
4
+ export type Amount = [isoly.Currency, number]
5
+
6
+ export namespace Amount {
7
+ export const type = isly.tuple<Amount>(isly.string(isoly.Currency.types), isly.number())
8
+ export const is = type.is
9
+ export const flaw = type.flaw
10
+ }
package/Amounts.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { isoly } from "isoly"
2
+ import { isly } from "isly"
3
+
4
+ export type Amounts = Partial<Record<isoly.Currency, number>>
5
+
6
+ export namespace Amounts {
7
+ export const type = isly.record<Amounts>(isly.string(isoly.Currency.types), isly.number())
8
+ export const is = type.is
9
+ export const flaw = type.flaw
10
+ }
@@ -1,11 +1,12 @@
1
1
  import { isoly } from "isoly"
2
2
  import { isly } from "isly"
3
3
  import { Acquirer } from "../Acquirer"
4
+ import { Amount } from "../Amount"
4
5
  import { Merchant } from "../Merchant"
5
6
 
6
7
  export interface Creatable {
7
8
  card: string
8
- amount: [isoly.Currency, number]
9
+ amount: Amount
9
10
  merchant: Merchant
10
11
  acquirer: Acquirer
11
12
  reference: string
@@ -0,0 +1,47 @@
1
+ import { gracely } from "gracely"
2
+ import { isly } from "isly"
3
+ import { Transaction } from "../Transaction"
4
+
5
+ export type Status = "approved" | Status.Failed
6
+
7
+ export namespace Status {
8
+ export interface Failed {
9
+ code: string
10
+ reason: string | string[]
11
+ error?: gracely.Error
12
+ }
13
+ export namespace Failed {
14
+ export function from(error?: gracely.Error): Failed {
15
+ let result: Status
16
+ if (error?.error?.includes("Card with id"))
17
+ result = { code: "14", reason: "Invalid card number" }
18
+ else if (error?.error?.includes("must correspond to card limit")) {
19
+ result = { code: "13", reason: "Invalid amount" }
20
+ } else if (error?.error?.includes("Failed to reach account")) {
21
+ result = { code: "78", reason: "Invalid/nonexistent account specified (general)" }
22
+ } else if (gracely.client.InvalidContent.is(error) && error.content.description.includes("rules")) {
23
+ const reasons: string[] = error.content.details?.notes.reduce(
24
+ (a: string[], c: Transaction.Note) => [...a, `${c.created} ${c.author}: ${c.text ?? ""}`],
25
+ []
26
+ )
27
+ result = {
28
+ code: "62", //Restricted card: "This means that the card that you processed is restricted to where it can be used.
29
+ //The restricted card is only allowed to be used for certain types of businesses or purchases."
30
+ reason: ["Restricted card.", ...reasons],
31
+ }
32
+ } else
33
+ result = { code: "05", reason: "Do not honor" } //default
34
+ return result
35
+ }
36
+ }
37
+ export const type = isly.union(
38
+ isly.string("approved"),
39
+ isly.object<Status.Failed>({
40
+ code: isly.string(),
41
+ reason: isly.union(isly.string(), isly.string().array()),
42
+ error: isly.fromIs("gracely.Error", gracely.Error.is).optional(),
43
+ })
44
+ )
45
+ export const is = type.is
46
+ export const flaw = type.flaw
47
+ }
@@ -1,33 +1,107 @@
1
+ import { cryptly } from "cryptly"
1
2
  import { gracely } from "gracely"
3
+ import { isoly } from "isoly"
2
4
  import { isly } from "isly"
5
+ import { Acquirer } from "../Acquirer"
6
+ import { Amount } from "../Amount"
3
7
  import { Card } from "../Card"
8
+ import { Identifier } from "../Identifier"
9
+ import { Merchant } from "../Merchant"
4
10
  import { Transaction } from "../Transaction"
5
- import { Approved as AuthorizationApproved } from "./Approved"
6
11
  import { Creatable as AuthorizationCreatable } from "./Creatable"
7
- import { Failed as AuthorizationFailed } from "./Failed"
12
+ import { Status } from "./Status"
8
13
 
9
- export type Authorization = Authorization.Failed | Authorization.Approved
14
+ export interface Authorization {
15
+ id: cryptly.Identifier
16
+ created: isoly.DateTime
17
+ status: Status
18
+ reference: string
19
+ amount: Amount
20
+ card: {
21
+ id: string
22
+ token?: string
23
+ iin?: string
24
+ last4?: string
25
+ }
26
+ transaction?: {
27
+ id: string
28
+ posted: isoly.DateTime
29
+ description: string
30
+ }
31
+ account?: string
32
+ merchant: Merchant
33
+ acquirer: Acquirer
34
+ description: string
35
+ }
10
36
  export namespace Authorization {
11
- export type Approved = AuthorizationApproved
12
- export const Approved = AuthorizationApproved
13
- export type Failed = AuthorizationFailed
14
- export const Failed = AuthorizationFailed
15
37
  export type Creatable = AuthorizationCreatable
16
38
  export const Creatable = AuthorizationCreatable
39
+
40
+ export const type = isly.object<Authorization>({
41
+ id: isly.fromIs("Authorization.id", cryptly.Identifier.is),
42
+ status: Status.type,
43
+ transaction: isly
44
+ .object<Required<Authorization>["transaction"]>({
45
+ id: isly.string(),
46
+ posted: isly.fromIs("isoly.DateTime", isoly.DateTime.is),
47
+ description: isly.string(),
48
+ })
49
+ .optional(),
50
+ card: isly.object<Authorization["card"]>({
51
+ id: isly.string(),
52
+ token: isly.string().optional(),
53
+ iin: isly.string().optional(),
54
+ last4: isly.string().optional(),
55
+ }),
56
+ created: isly.fromIs("Authorization.created", isoly.DateTime.is),
57
+ amount: isly.tuple(isly.fromIs("isoly.Currency", isoly.Currency.is), isly.number()),
58
+ account: isly.string().optional(),
59
+ merchant: Merchant.type,
60
+ acquirer: Acquirer.type,
61
+ reference: isly.string(),
62
+ description: isly.string(),
63
+ })
64
+ export const is = type.is
65
+ export const flaw = type.flaw
17
66
  export function fromCreatable(
18
- authorization: Authorization.Creatable,
19
- transaction: Transaction | gracely.Error
67
+ creatable: Creatable,
68
+ card: Card | gracely.Error,
69
+ transaction?: Transaction | gracely.Error
20
70
  ): Authorization {
21
- return gracely.Error.is(transaction)
22
- ? Authorization.Failed.fromCreatable(authorization, transaction)
23
- : Authorization.Approved.fromCreatable(authorization, transaction)
71
+ const partial: Pick<Authorization, "created" | "amount" | "merchant" | "acquirer" | "reference" | "description"> = {
72
+ created: isoly.DateTime.now(),
73
+ amount: creatable.amount,
74
+ merchant: creatable.merchant,
75
+ acquirer: creatable.acquirer,
76
+ reference: creatable.reference,
77
+ description: creatable.description,
78
+ }
79
+ let result: Authorization
80
+ if (gracely.Error.is(card))
81
+ result = {
82
+ id: Identifier.generate(),
83
+ status: Status.Failed.from(card),
84
+ ...partial,
85
+ card: { id: creatable.card },
86
+ }
87
+ else if (gracely.Error.is(transaction) || !transaction)
88
+ result = {
89
+ id: Identifier.generate(),
90
+ status: Status.Failed.from(transaction),
91
+ ...partial,
92
+ card: { id: card.id, iin: card.details.iin, last4: card.details.last4, token: card.details.token },
93
+ }
94
+ else
95
+ result = {
96
+ id: transaction.id,
97
+ status: "approved",
98
+ ...partial,
99
+ card: { id: card.id, iin: card.details.iin, last4: card.details.last4, token: card.details.token },
100
+ account: card.account,
101
+ transaction: { id: transaction?.id, posted: transaction?.posted, description: transaction.description },
102
+ }
103
+ return result
24
104
  }
25
- export const type = isly.union<Authorization, Authorization.Failed, Authorization.Approved>(
26
- Authorization.Failed.type,
27
- Authorization.Approved.type
28
- )
29
- export const is = type.is
30
- export const flaw = type.flaw
31
105
 
32
106
  export function toTransaction(authorization: Authorization, card: Card): Transaction.Creatable {
33
107
  return {
@@ -1,9 +1,10 @@
1
1
  import { isoly } from "isoly"
2
2
  import { isly } from "isly"
3
+ import { Amount } from "../Amount"
3
4
  import { Meta } from "./Meta"
4
5
 
5
6
  export type Changeable = {
6
- limit?: [isoly.Currency, number]
7
+ limit?: Amount
7
8
  meta?: Meta
8
9
  }
9
10
 
package/Card/Creatable.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { isoly } from "isoly"
2
2
  import { isly } from "isly"
3
+ import { Amount } from "../Amount"
3
4
  import { Rule, type as ruleType } from "../Rule/Rule"
4
5
  import { Expiry } from "./Expiry"
5
6
  import { Meta } from "./Meta"
@@ -13,7 +14,7 @@ export interface Creatable {
13
14
  expiry: Expiry
14
15
  holder: string
15
16
  }
16
- limit: [isoly.Currency, number]
17
+ limit: Amount
17
18
  rules?: Rule[]
18
19
  meta?: Meta
19
20
  }
@@ -3,7 +3,7 @@ import { isly } from "isly"
3
3
 
4
4
  export interface Settlement {
5
5
  type: "settlement"
6
- status: "capture" | "cancel" | "refund"
6
+ status: "capture" | "cancel" | "refund" | "unknown"
7
7
  transaction?: string
8
8
  created: isoly.DateTime
9
9
  }
@@ -11,7 +11,7 @@ export interface Settlement {
11
11
  export namespace Settlement {
12
12
  export const type = isly.object<Settlement>({
13
13
  type: isly.string("settlement"),
14
- status: isly.union(isly.string("capture"), isly.string("cancel"), isly.string("refund")),
14
+ status: isly.union(isly.string("capture"), isly.string("cancel"), isly.string("refund"), isly.string("unknown")),
15
15
  transaction: isly.string().optional(),
16
16
  created: isly.fromIs("isoly.DateTime", isoly.DateTime.is),
17
17
  })
package/Card/Preset.ts CHANGED
@@ -2,6 +2,7 @@ import { isly } from "isly"
2
2
 
3
3
  export type Preset = typeof Preset.names[number]
4
4
 
5
+ // "realm-scheme-interchange"
5
6
  export namespace Preset {
6
7
  export const names = ["p2p-mc-200", "test-mc-200", "test-pg-200", "test-ta-pg-200", "test-ta-mc-200"] as const
7
8
  export const type = isly.string(names)
package/Card/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { isoly } from "isoly"
2
2
  import { isly } from "isly"
3
+ import { Amount } from "../Amount"
3
4
  import { Realm } from "../Realm"
4
5
  import { Rule, type as ruleType } from "../Rule/Rule"
5
6
  import { Changeable as CardChangeable } from "./Changeable"
@@ -27,8 +28,8 @@ export interface Card {
27
28
  holder: string
28
29
  token: string
29
30
  }
30
- limit: [isoly.Currency, number]
31
- spent: [isoly.Currency, number]
31
+ limit: Amount
32
+ spent: Amount
32
33
  status: "active" | "cancelled"
33
34
  history: CardOperation[]
34
35
  rules: Rule[]
@@ -15,8 +15,8 @@ export class Settlements extends rest.Collection<gracely.Error> {
15
15
  async fetch(id: string, created: isoly.DateTime): Promise<Settlement | gracely.Error> {
16
16
  return this.client.get<Settlement>(`/settlement/${id}?created=${created}`)
17
17
  }
18
- async list(): Promise<Settlement.Summary[] | gracely.Error> {
19
- return this.client.get<Settlement.Summary[] & { cursor?: string | undefined }>(`/settlement`)
18
+ async list(): Promise<Settlement[] | gracely.Error> {
19
+ return this.client.get<Settlement[] & { cursor?: string | undefined }>(`/settlement`)
20
20
  }
21
21
  async remove(settlement: string): Promise<Settlement | gracely.Error> {
22
22
  return this.client.delete<Settlement>(`/settlement/${settlement}`)
package/Identifier.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { cryptly } from "cryptly"
2
+ import { isoly } from "isoly"
3
+
4
+ export namespace Identifier {
5
+ export function generate(
6
+ length: cryptly.Identifier.Length = 16,
7
+ ordering: "ordered" | "reversed" = "reversed",
8
+ date: isoly.DateTime = isoly.DateTime.now()
9
+ ): string {
10
+ return cryptly.Identifier.generate(length, ordering, isoly.DateTime.epoch(date))
11
+ }
12
+ }
@@ -1,5 +1,5 @@
1
1
  import { isly } from "isly"
2
- import { Supplier as modelSupplier } from "../Supplier"
2
+ import { Supplier as modelSupplier } from "./Supplier"
3
3
 
4
4
  export type Realm = typeof Realm.realms[number]
5
5
 
@@ -7,6 +7,7 @@ export namespace Realm {
7
7
  export const realms = ["test", "testUK", "uk", "eu", "upcheck"] as const
8
8
  export const type: isly.Type<Realm> = isly.string(realms)
9
9
  export const is = type.is
10
+ export const flaw = type.flaw
10
11
  export function toString(): string {
11
12
  return realms.toString().replaceAll(",", ", ") + "."
12
13
  }
@@ -19,7 +19,7 @@ export namespace State {
19
19
  export function from(
20
20
  account: ModelAccount,
21
21
  transaction: ModelTransaction,
22
- authorization?: ModelAuthorization,
22
+ authorization?: ModelAuthorization.Creatable,
23
23
  card?: ModelCard
24
24
  ): State {
25
25
  return {
@@ -0,0 +1,18 @@
1
+ import { isly } from "isly"
2
+ import { Total } from "./Total"
3
+
4
+ export interface Creatable {
5
+ expected?: Total
6
+ processor: string
7
+ reference: string
8
+ }
9
+
10
+ export namespace Creatable {
11
+ export const type = isly.object<Creatable>({
12
+ expected: Total.type.optional(),
13
+ processor: isly.string(),
14
+ reference: isly.string(),
15
+ })
16
+ export const is = type.is
17
+ export const flaw = type.flaw
18
+ }
@@ -0,0 +1,34 @@
1
+ import { isly } from "isly"
2
+ import { Amount } from "../../Amount"
3
+ import { Authorization } from "../../Authorization"
4
+ import { Fee } from "../Fee"
5
+
6
+ export interface Cancel extends Cancel.Creatable {
7
+ status: "succeeded" | "failed"
8
+ }
9
+
10
+ export namespace Cancel {
11
+ export interface Creatable {
12
+ type: "cancel"
13
+ authorization?: Authorization
14
+ reference: string
15
+ fee?: Fee
16
+ amount?: Amount
17
+ }
18
+ export namespace Creatable {
19
+ export const type = isly.object<Creatable>({
20
+ type: isly.string("cancel"),
21
+ authorization: Authorization.type.optional(),
22
+ reference: isly.string(),
23
+ fee: Fee.type.optional(),
24
+ amount: Amount.type.optional(),
25
+ })
26
+ export const is = type.is
27
+ export const flaw = type.flaw
28
+ }
29
+ export const type = Creatable.type.extend<Cancel>({
30
+ status: isly.string(["succeeded", "failed"]),
31
+ })
32
+ export const is = type.is
33
+ export const flaw = type.flaw
34
+ }
@@ -0,0 +1,34 @@
1
+ import { isly } from "isly"
2
+ import { Amount } from "../../Amount"
3
+ import { Authorization } from "../../Authorization"
4
+ import { Fee } from "../Fee"
5
+
6
+ export interface Capture extends Capture.Creatable {
7
+ status: "succeeded" | "failed"
8
+ }
9
+
10
+ export namespace Capture {
11
+ export interface Creatable {
12
+ type: "capture"
13
+ authorization?: Authorization
14
+ reference: string
15
+ fee?: Fee
16
+ amount?: Amount
17
+ }
18
+ export namespace Creatable {
19
+ export const type = isly.object<Creatable>({
20
+ type: isly.string("capture"),
21
+ authorization: Authorization.type.optional(),
22
+ reference: isly.string(),
23
+ fee: Fee.type.optional(),
24
+ amount: Amount.type.optional(),
25
+ })
26
+ export const is = type.is
27
+ export const flaw = type.flaw
28
+ }
29
+ export const type = Creatable.type.extend<Capture>({
30
+ status: isly.string(["succeeded", "failed"]),
31
+ })
32
+ export const is = type.is
33
+ export const flaw = type.flaw
34
+ }
@@ -0,0 +1,18 @@
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
+
9
+ export namespace Creatable {
10
+ export const type = isly.union(
11
+ EntryCancel.Creatable.type,
12
+ EntryCapture.Creatable.type,
13
+ EntryRefund.Creatable.type,
14
+ EntryUnknown.Creatable.type
15
+ )
16
+ export const is = type.is
17
+ export const flaw = type.flaw
18
+ }
@@ -0,0 +1,34 @@
1
+ import { isly } from "isly"
2
+ import { Amount } from "../../Amount"
3
+ import { Authorization } from "../../Authorization"
4
+ import { Fee } from "../Fee"
5
+
6
+ export interface Refund extends Refund.Creatable {
7
+ status: "succeeded" | "failed"
8
+ }
9
+
10
+ export namespace Refund {
11
+ export interface Creatable {
12
+ type: "refund"
13
+ authorization?: Authorization
14
+ reference: string
15
+ fee?: Fee
16
+ amount?: Amount
17
+ }
18
+ export namespace Creatable {
19
+ export const type = isly.object<Creatable>({
20
+ type: isly.string("refund"),
21
+ authorization: Authorization.type.optional(),
22
+ reference: isly.string(),
23
+ fee: Fee.type.optional(),
24
+ amount: Amount.type.optional(),
25
+ })
26
+ export const is = type.is
27
+ export const flaw = type.flaw
28
+ }
29
+ export const type = Creatable.type.extend<Refund>({
30
+ status: isly.string(["succeeded", "failed"]),
31
+ })
32
+ export const is = type.is
33
+ export const flaw = type.flaw
34
+ }
@@ -0,0 +1,21 @@
1
+ import { isly } from "isly"
2
+
3
+ export interface Summary {
4
+ count: number
5
+ failed?: {
6
+ count: number
7
+ }
8
+ }
9
+
10
+ export namespace Summary {
11
+ export const type = isly.object<Summary>({
12
+ count: isly.number(),
13
+ failed: isly
14
+ .object<{ count: number }>({
15
+ count: isly.number(),
16
+ })
17
+ .optional(),
18
+ })
19
+ export const is = type.is
20
+ export const flaw = type.flaw
21
+ }
@@ -0,0 +1,29 @@
1
+ import { isly } from "isly"
2
+ import { Authorization } from "../../Authorization"
3
+
4
+ export interface Unknown extends Unknown.Creatable {
5
+ status: "succeeded" | "failed"
6
+ }
7
+
8
+ export namespace Unknown {
9
+ export interface Creatable {
10
+ type: "unknown"
11
+ authorization?: Authorization
12
+ data: Record<string, any>
13
+ }
14
+ export namespace Creatable {
15
+ export const type = isly.object<Creatable>({
16
+ type: isly.string("unknown"),
17
+ authorization: Authorization.type.optional(),
18
+ data: isly.record(isly.string(), isly.any()),
19
+ })
20
+ export const is = Unknown.is
21
+ export const flaw = Unknown.flaw
22
+ }
23
+ export function from(creatable: Creatable): Unknown {
24
+ return { ...creatable, status: "failed" }
25
+ }
26
+ export const type = Creatable.type.extend<Unknown>({ status: isly.string(["succeeded", "failed"]) })
27
+ export const is = type.is
28
+ export const flaw = type.flaw
29
+ }
@@ -0,0 +1,49 @@
1
+ import { gracely } from "gracely"
2
+ import { isly } from "isly"
3
+ import { Authorization } from "../../Authorization"
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 { Summary as EntrySummary } from "./Summary"
10
+ import { Unknown as EntryUnknown } from "./Unknown"
11
+
12
+ export type Entry = Entry.Cancel | Entry.Capture | Entry.Refund | Entry.Unknown
13
+
14
+ export namespace Entry {
15
+ export type Cancel = EntryCancel
16
+ export const Cancel = EntryCancel
17
+ export type Capture = EntryCapture
18
+ export const Capture = EntryCapture
19
+ export type Creatable = EntryCreatable
20
+ export const Creatable = EntryCreatable
21
+ export type Refund = EntryRefund
22
+ export const Refund = EntryRefund
23
+ export type Summary = EntrySummary
24
+ export const Summary = EntrySummary
25
+ export type Unknown = EntryUnknown
26
+ export const Unknown = EntryUnknown
27
+ export namespace Unknown {
28
+ export type Creatable = EntryUnknown.Creatable
29
+ }
30
+ export function from(creatable: Entry.Creatable, transaction?: Transaction | gracely.Error): Entry {
31
+ return Transaction.is(transaction) && creatable.authorization
32
+ ? {
33
+ status: "succeeded",
34
+ ...creatable,
35
+ }
36
+ : {
37
+ status: "failed",
38
+ ...creatable,
39
+ }
40
+ }
41
+ export const type = isly.union<Entry, Entry.Cancel, Entry.Capture, Entry.Refund, Entry.Unknown>(
42
+ Entry.Cancel.type,
43
+ Entry.Capture.type,
44
+ Entry.Refund.type,
45
+ Entry.Unknown.type
46
+ )
47
+ export const is = type.is
48
+ export const flaw = type.flaw
49
+ }
@@ -0,0 +1,12 @@
1
+ import { isly } from "isly"
2
+ import { Amounts } from "../Amounts"
3
+
4
+ export interface Fee {
5
+ other: Amounts
6
+ }
7
+
8
+ export namespace Fee {
9
+ export const type = isly.object<Fee>({ other: Amounts.type })
10
+ export const is = type.is
11
+ export const flaw = type.flaw
12
+ }
@@ -0,0 +1,19 @@
1
+ import { isoly } from "isoly"
2
+ import { isly } from "isly"
3
+ import { Amount } from "../Amount"
4
+
5
+ export interface Settled {
6
+ by?: string
7
+ created: isoly.DateTime
8
+ transactions: Record<string, Amount>
9
+ }
10
+
11
+ export namespace Settled {
12
+ export const type = isly.object<Settled>({
13
+ by: isly.string().optional(),
14
+ created: isly.fromIs("isoly.DateTime", isoly.DateTime.is),
15
+ transactions: isly.record(isly.string(), Amount.type),
16
+ })
17
+ export const is = type.is
18
+ export const flaw = type.flaw
19
+ }
@@ -0,0 +1,13 @@
1
+ import { isly } from "isly"
2
+
3
+ export type Status = "succeeded" | ["failed", string] | "ongoing"
4
+
5
+ export namespace Status {
6
+ export const type = isly.union(
7
+ isly.string("succeeded"),
8
+ isly.string("ongoing"),
9
+ isly.tuple(isly.string("failed"), isly.string())
10
+ )
11
+ export const is = type.is
12
+ export const flaw = type.flaw
13
+ }
@@ -0,0 +1,17 @@
1
+ import { isly } from "isly"
2
+ import { Amounts } from "../Amounts"
3
+ import { Fee } from "./Fee"
4
+
5
+ export type Total = {
6
+ amount: Amounts
7
+ fee: Fee
8
+ }
9
+
10
+ export namespace Total {
11
+ export function initiate(): Total {
12
+ return { amount: {}, fee: { other: {} } }
13
+ }
14
+ export const type = isly.object<Total>({ amount: Amounts.type, fee: Fee.type })
15
+ export const is = type.is
16
+ export const flaw = type.flaw
17
+ }