@pax2pay/model-banking 0.1.567 → 0.1.568

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 (96) hide show
  1. package/Account/Charge/Fx/index.ts +29 -0
  2. package/Account/Charge/Merchant/index.ts +42 -0
  3. package/Account/Charge/Preset/index.ts +15 -0
  4. package/Account/Charge/index.ts +13 -40
  5. package/Account/index.ts +2 -2
  6. package/Card/Restriction/Merchant.ts +9 -0
  7. package/Client/Accounts/Charge.ts +2 -6
  8. package/Settlement/Entry/index.ts +4 -4
  9. package/Transaction/Amount/Charge/index.ts +86 -0
  10. package/Transaction/{Amount.ts → Amount/index.ts} +13 -21
  11. package/Transaction/Creatable.ts +2 -2
  12. package/Transaction/index.ts +3 -3
  13. package/dist/cjs/Account/Charge/Fx/index.d.ts +10 -0
  14. package/dist/cjs/Account/Charge/Fx/index.js +23 -0
  15. package/dist/cjs/Account/Charge/Fx/index.js.map +1 -0
  16. package/dist/cjs/Account/Charge/Merchant/index.d.ts +15 -0
  17. package/dist/cjs/Account/Charge/Merchant/index.js +34 -0
  18. package/dist/cjs/Account/Charge/Merchant/index.js.map +1 -0
  19. package/dist/cjs/Account/Charge/Preset/index.d.ts +8 -0
  20. package/dist/cjs/Account/Charge/Preset/index.js +15 -0
  21. package/dist/cjs/Account/Charge/Preset/index.js.map +1 -0
  22. package/dist/cjs/Account/Charge/index.d.ts +10 -18
  23. package/dist/cjs/Account/Charge/index.js +11 -33
  24. package/dist/cjs/Account/Charge/index.js.map +1 -1
  25. package/dist/cjs/Account/index.d.ts +1 -1
  26. package/dist/cjs/Account/index.js +1 -1
  27. package/dist/cjs/Account/index.js.map +1 -1
  28. package/dist/cjs/Card/Restriction/Merchant.d.ts +1 -0
  29. package/dist/cjs/Card/Restriction/Merchant.js +10 -0
  30. package/dist/cjs/Card/Restriction/Merchant.js.map +1 -1
  31. package/dist/cjs/Client/Accounts/Charge.d.ts +2 -2
  32. package/dist/cjs/Client/Accounts/Charge.js.map +1 -1
  33. package/dist/cjs/Client/Transactions/index.d.ts +1 -1
  34. package/dist/cjs/Rail/index.d.ts +2 -2
  35. package/dist/cjs/Settlement/Entry/index.d.ts +1 -1
  36. package/dist/cjs/Settlement/Entry/index.js +2 -2
  37. package/dist/cjs/Settlement/Entry/index.js.map +1 -1
  38. package/dist/cjs/Transaction/Amount/Charge/index.d.ts +39 -0
  39. package/dist/cjs/Transaction/Amount/Charge/index.js +58 -0
  40. package/dist/cjs/Transaction/Amount/Charge/index.js.map +1 -0
  41. package/dist/cjs/Transaction/Amount/index.d.ts +17 -0
  42. package/dist/cjs/Transaction/{Amount.js → Amount/index.js} +6 -17
  43. package/dist/cjs/Transaction/Amount/index.js.map +1 -0
  44. package/dist/cjs/Transaction/Creatable.d.ts +1 -1
  45. package/dist/cjs/Transaction/Creatable.js +2 -2
  46. package/dist/cjs/Transaction/Creatable.js.map +1 -1
  47. package/dist/cjs/Transaction/index.d.ts +2 -2
  48. package/dist/cjs/Transaction/index.js.map +1 -1
  49. package/dist/mjs/Account/Charge/Fx/index.d.ts +10 -0
  50. package/dist/mjs/Account/Charge/Fx/index.js +20 -0
  51. package/dist/mjs/Account/Charge/Fx/index.js.map +1 -0
  52. package/dist/mjs/Account/Charge/Merchant/index.d.ts +15 -0
  53. package/dist/mjs/Account/Charge/Merchant/index.js +31 -0
  54. package/dist/mjs/Account/Charge/Merchant/index.js.map +1 -0
  55. package/dist/mjs/Account/Charge/Preset/index.d.ts +8 -0
  56. package/dist/mjs/Account/Charge/Preset/index.js +12 -0
  57. package/dist/mjs/Account/Charge/Preset/index.js.map +1 -0
  58. package/dist/mjs/Account/Charge/index.d.ts +10 -18
  59. package/dist/mjs/Account/Charge/index.js +11 -33
  60. package/dist/mjs/Account/Charge/index.js.map +1 -1
  61. package/dist/mjs/Account/index.d.ts +1 -1
  62. package/dist/mjs/Account/index.js +1 -1
  63. package/dist/mjs/Account/index.js.map +1 -1
  64. package/dist/mjs/Card/Restriction/Merchant.d.ts +1 -0
  65. package/dist/mjs/Card/Restriction/Merchant.js +10 -0
  66. package/dist/mjs/Card/Restriction/Merchant.js.map +1 -1
  67. package/dist/mjs/Client/Accounts/Charge.d.ts +2 -2
  68. package/dist/mjs/Client/Accounts/Charge.js.map +1 -1
  69. package/dist/mjs/Client/Transactions/index.d.ts +1 -1
  70. package/dist/mjs/Rail/index.d.ts +2 -2
  71. package/dist/mjs/Settlement/Entry/index.d.ts +1 -1
  72. package/dist/mjs/Settlement/Entry/index.js +2 -2
  73. package/dist/mjs/Settlement/Entry/index.js.map +1 -1
  74. package/dist/mjs/Transaction/Amount/Charge/index.d.ts +39 -0
  75. package/dist/mjs/Transaction/Amount/Charge/index.js +55 -0
  76. package/dist/mjs/Transaction/Amount/Charge/index.js.map +1 -0
  77. package/dist/mjs/Transaction/Amount/index.d.ts +17 -0
  78. package/dist/mjs/Transaction/{Amount.js → Amount/index.js} +6 -17
  79. package/dist/mjs/Transaction/Amount/index.js.map +1 -0
  80. package/dist/mjs/Transaction/Creatable.d.ts +1 -1
  81. package/dist/mjs/Transaction/Creatable.js +2 -2
  82. package/dist/mjs/Transaction/Creatable.js.map +1 -1
  83. package/dist/mjs/Transaction/index.d.ts +2 -2
  84. package/dist/mjs/Transaction/index.js.map +1 -1
  85. package/package.json +1 -1
  86. package/Account/Charge/Applies.ts +0 -53
  87. package/dist/cjs/Account/Charge/Applies.d.ts +0 -23
  88. package/dist/cjs/Account/Charge/Applies.js +0 -44
  89. package/dist/cjs/Account/Charge/Applies.js.map +0 -1
  90. package/dist/cjs/Transaction/Amount.d.ts +0 -24
  91. package/dist/cjs/Transaction/Amount.js.map +0 -1
  92. package/dist/mjs/Account/Charge/Applies.d.ts +0 -23
  93. package/dist/mjs/Account/Charge/Applies.js +0 -41
  94. package/dist/mjs/Account/Charge/Applies.js.map +0 -1
  95. package/dist/mjs/Transaction/Amount.d.ts +0 -24
  96. package/dist/mjs/Transaction/Amount.js.map +0 -1
@@ -0,0 +1,29 @@
1
+ import { isoly } from "isoly"
2
+ import { Card } from "../../../Card"
3
+ import { Amount } from "../../../Transaction/Amount"
4
+ import { Exchange } from "../../../Transaction/Exchange"
5
+ import { Preset } from "../Preset"
6
+
7
+ export type Fx = Preset
8
+
9
+ export namespace Fx {
10
+ export const type = Preset.type
11
+ export function evaluate(
12
+ charge: Fx,
13
+ currency: isoly.Currency,
14
+ amount: number,
15
+ preset?: Card.Preset,
16
+ exchange?: Exchange
17
+ ): Amount.Charge.Fx | undefined {
18
+ let result: Amount.Charge.Fx | undefined
19
+ const chargePreset = preset && charge[preset] ? preset : "default"
20
+ const chargeRate = charge[chargePreset] ?? 0
21
+ if (exchange)
22
+ result = {
23
+ preset: chargePreset,
24
+ rate: chargeRate,
25
+ amount: -isoly.Currency.multiply(currency, amount, chargeRate),
26
+ }
27
+ return result
28
+ }
29
+ }
@@ -0,0 +1,42 @@
1
+ import { isoly } from "isoly"
2
+ import { isly } from "isly"
3
+ import { Card } from "../../../Card"
4
+ import { Rail } from "../../../Rail"
5
+ import { Amount } from "../../../Transaction/Amount"
6
+ import { Preset } from "../Preset"
7
+
8
+ export interface Merchant {
9
+ destination: { account: string }
10
+ merchants: Partial<Record<Card.Restriction.Merchant, Preset>>
11
+ }
12
+ export namespace Merchant {
13
+ export const type = isly.object<Merchant>({
14
+ destination: isly.object({
15
+ account: isly.string(),
16
+ }),
17
+ merchants: isly.record<Card.Restriction.Merchant, Preset>(Card.Restriction.Merchant.type, Preset.type),
18
+ })
19
+
20
+ export function evaluate(
21
+ charge: Merchant,
22
+ currency: isoly.Currency,
23
+ amount: number,
24
+ counterpart: Rail.Address.Card.Counterpart,
25
+ preset?: Card.Preset
26
+ ): Amount.Charge.Merchant | undefined {
27
+ let result: Amount.Charge.Merchant | undefined
28
+ const merchant = Card.Restriction.Merchant.resolve(counterpart)
29
+ if (merchant) {
30
+ const chargePreset = preset && charge.merchants?.[merchant]?.[preset] ? preset : "default"
31
+ const chargeRate = charge.merchants?.[merchant]?.[chargePreset] ?? 0
32
+ result = {
33
+ merchant,
34
+ preset: chargePreset,
35
+ destination: charge.destination,
36
+ rate: chargeRate,
37
+ amount: -isoly.Currency.multiply(currency, amount, chargeRate),
38
+ }
39
+ }
40
+ return result
41
+ }
42
+ }
@@ -0,0 +1,15 @@
1
+ import { isly } from "isly"
2
+ import { Card } from "../../../Card"
3
+
4
+ export type Preset = Partial<Record<Card.Preset, number>> & {
5
+ default: number
6
+ }
7
+
8
+ export namespace Preset {
9
+ const recordType = isly.record<Preset>(isly.string(Card.Preset.names), isly.number())
10
+ const defaultType = isly.object<{ default: number }>({ default: isly.number() })
11
+ function is(value: unknown): value is Preset {
12
+ return defaultType.is(value) && recordType.is((({ default: _, ...rest }) => rest)(value))
13
+ }
14
+ export const type = isly.fromIs("Preset", is)
15
+ }
@@ -1,58 +1,31 @@
1
- import { cryptly } from "cryptly"
2
1
  import { isoly } from "isoly"
3
2
  import { isly } from "isly"
4
3
  import type { Card } from "../../Card"
5
4
  import type { Rail } from "../../Rail"
6
5
  import type { Transaction } from "../../Transaction"
7
- import { Applies } from "./Applies"
6
+ import { Fx as ChargeFx } from "./Fx"
7
+ import { Merchant as ChargeMerchant } from "./Merchant"
8
8
 
9
- export interface Charge extends Charge.Creatable {
10
- id: string
11
- }
9
+ export type Charge = { merchant?: Charge.Merchant; fx?: Charge.Fx }
12
10
  export namespace Charge {
13
- export interface Creatable {
14
- destination: { account: string }
15
- rate: number // rate: 0.01 for 1%
16
- applies: Applies
17
- }
18
- export namespace Creatable {
19
- export const type = isly.object<Creatable>({
20
- destination: isly.object({ account: isly.string() }),
21
- rate: isly.number(),
22
- applies: Applies.type,
23
- })
24
- }
25
- export const type = Creatable.type.extend<Charge>({
26
- id: isly.string(),
27
- })
28
- export function fromCreatable(creatable: Creatable): Charge {
29
- return { ...creatable, id: cryptly.Identifier.generate(4) }
30
- }
11
+ export import Merchant = ChargeMerchant
12
+ export import Fx = ChargeFx
13
+ export const type = isly.object<Charge>({ merchant: ChargeMerchant.type, fx: ChargeFx.type })
31
14
  export function evaluate(
32
- charges: Charge[] = [],
33
15
  counterpart: Rail.Address.Card.Counterpart,
34
16
  currency: isoly.Currency,
35
17
  amount: number,
36
18
  preset?: Card.Preset,
19
+ charges?: Charge,
37
20
  exchange?: Transaction.Exchange
38
- ): Transaction.Amount.Charge[] {
39
- const result: Transaction.Amount.Charge[] = []
40
- for (const charge of charges)
41
- if (Applies.evaluate(charge.applies, counterpart, preset, exchange))
42
- result.push(toTransactionAmountCharge(currency, amount, charge))
43
- return result
44
- }
45
- function toTransactionAmountCharge(
46
- currency: isoly.Currency,
47
- amount: number,
48
- charge: Charge
49
21
  ): Transaction.Amount.Charge {
22
+ const merchant =
23
+ charges?.merchant && ChargeMerchant.evaluate(charges.merchant, currency, amount, counterpart, preset)
24
+ const fx = charges?.fx && ChargeFx.evaluate(charges.fx, currency, amount, preset, exchange)
25
+
50
26
  return {
51
- amount: -isoly.Currency.multiply(currency, amount, charge.rate),
52
- charge,
27
+ ...(merchant && { merchant }),
28
+ ...(fx && { fx }),
53
29
  }
54
30
  }
55
- export function sum(charges: Transaction.Amount.Charge[], currency: isoly.Currency): number {
56
- return charges.reduce((sum, charge) => isoly.Currency.add(currency, sum, charge.amount), 0)
57
- }
58
31
  }
package/Account/index.ts CHANGED
@@ -19,7 +19,7 @@ export interface Account extends Account.Creatable {
19
19
  details?: Account.Details
20
20
  counterparts?: Record<string, Rail.Address>
21
21
  key?: string
22
- charges?: AccountCharge[]
22
+ charges?: AccountCharge
23
23
  rules?: Rule[]
24
24
  status: Account.Status
25
25
  }
@@ -42,7 +42,7 @@ export namespace Account {
42
42
  details: Details.type.optional(),
43
43
  counterparts: isly.record<Record<string, Rail.Address>>(isly.string(), Rail.Address.type).optional(),
44
44
  key: isly.string().optional(),
45
- charges: AccountCharge.type.array().optional(),
45
+ charges: AccountCharge.type.optional(),
46
46
  rules: Rule.type.array().optional(),
47
47
  status: AccountStatus.type,
48
48
  })
@@ -27,4 +27,13 @@ export namespace Merchant {
27
27
  result = false
28
28
  return result
29
29
  }
30
+ export function resolve(counterpart: Rail.Address.Card.Counterpart): Merchant | undefined {
31
+ let result: Merchant | undefined
32
+ for (const merchant of values)
33
+ if (check(merchant, counterpart)) {
34
+ result = merchant
35
+ break
36
+ }
37
+ return result
38
+ }
30
39
  }
@@ -4,17 +4,13 @@ import { Account } from "../../Account"
4
4
 
5
5
  export class Charge {
6
6
  constructor(private readonly client: http.Client) {}
7
- async create(account: string, charge: Account.Charge.Creatable): Promise<Account.Charge | gracely.Error> {
7
+ async create(account: string, charge: Account.Charge): Promise<Account.Charge | gracely.Error> {
8
8
  return this.client.post<Account.Charge>(`/account/${account}/charge`, charge)
9
9
  }
10
10
  async remove(account: string, id: string): Promise<Account.Charge | gracely.Error> {
11
11
  return this.client.delete<Account.Charge>(`/account/${account}/charge/${id}`)
12
12
  }
13
- async replace(
14
- account: string,
15
- id: string,
16
- charge: Account.Charge.Creatable
17
- ): Promise<Account.Charge | gracely.Error> {
13
+ async replace(account: string, id: string, charge: Account.Charge): Promise<Account.Charge | gracely.Error> {
18
14
  return this.client.put<Account.Charge>(`/account/${account}/charge/${id}`, charge)
19
15
  }
20
16
  }
@@ -25,17 +25,17 @@ export namespace Entry {
25
25
  export const type = entryType
26
26
  export const from = fromCreatable
27
27
  export function charge(
28
- charges: Account.Charge[] = [],
29
28
  counterpart: Rail.Address.Card.Counterpart,
30
29
  capture: Creatable.Capture,
31
- preset?: Preset
32
- ): Transaction.Amount.Charge[] {
30
+ preset?: Preset,
31
+ charges?: Account.Charge
32
+ ): Transaction.Amount.Charge {
33
33
  return Account.Charge.evaluate(
34
- charges,
35
34
  counterpart,
36
35
  capture.amount[0],
37
36
  isoly.Currency.add(capture.amount[0], capture.amount[1], capture.fee.other[capture.amount[0]] ?? 0),
38
37
  preset,
38
+ charges,
39
39
  capture.exchange
40
40
  )
41
41
  }
@@ -0,0 +1,86 @@
1
+ import { isoly } from "isoly"
2
+ import { isly } from "isly"
3
+ import { Card } from "../../../Card"
4
+ import { Rail } from "../../../Rail"
5
+ import { PreTransaction } from "../../PreTransaction"
6
+
7
+ export interface Charge {
8
+ merchant?: Charge.Merchant
9
+ fx?: Charge.Fx
10
+ }
11
+ export namespace Charge {
12
+ export interface Fx {
13
+ amount: number
14
+ rate: number
15
+ preset: Card.Preset | "default"
16
+ }
17
+ export namespace Fx {
18
+ export const type = isly.object<Fx>({
19
+ amount: isly.number(),
20
+ rate: isly.number(),
21
+ preset: isly.union(Card.Preset.type, isly.string("default")),
22
+ })
23
+ }
24
+ export interface Merchant {
25
+ amount: number
26
+ rate: number
27
+ merchant: Card.Restriction.Merchant
28
+ preset: Card.Preset | "default"
29
+ destination: { account: string }
30
+ }
31
+ export namespace Merchant {
32
+ export const type = isly.object<Merchant>({
33
+ amount: isly.number(),
34
+ rate: isly.number(),
35
+ merchant: Card.Restriction.Merchant.type,
36
+ preset: isly.union(Card.Preset.type, isly.string("default")),
37
+ destination: isly.object({
38
+ account: isly.string(),
39
+ }),
40
+ })
41
+ }
42
+ export type ChargeTransaction = PreTransaction.Incoming & { counterpart: Rail.Address.Internal }
43
+ export function total(currency: isoly.Currency, charges: Charge): number {
44
+ return isoly.Currency.add(currency, charges.fx?.amount ?? 0, charges.merchant?.amount ?? 0)
45
+ }
46
+ export function toTransactions(
47
+ charge: Charge,
48
+ account: string,
49
+ id: string,
50
+ currency: isoly.Currency,
51
+ fxCollectAccount: string
52
+ ): {
53
+ merchant: ChargeTransaction | undefined
54
+ fx: ChargeTransaction | undefined
55
+ } {
56
+ const merchant =
57
+ charge.merchant && toTransaction(charge.merchant, account, id, currency, fxCollectAccount, "merchant")
58
+ const fx = charge.fx && toTransaction(charge.fx, account, id, currency, fxCollectAccount, "fx")
59
+ return { merchant, fx }
60
+ }
61
+ function toTransaction(
62
+ charge: Charge.Merchant | Charge.Fx,
63
+ account: string,
64
+ id: string,
65
+ currency: isoly.Currency,
66
+ fxCollectAccount: string,
67
+ type: "merchant" | "fx"
68
+ ): ChargeTransaction {
69
+ const accountId = Merchant.type.is(charge) ? charge.destination.account : fxCollectAccount
70
+ return {
71
+ type: "incoming",
72
+ account: { type: "internal", identifier: accountId },
73
+ counterpart: { type: "internal", identifier: account },
74
+ currency: currency,
75
+ amount: charge.amount,
76
+ description: `${type} charge for transaction ${id}`,
77
+ posted: isoly.DateTime.now(),
78
+ rail: "internal",
79
+ reference: { reference: id, returnId: id },
80
+ }
81
+ }
82
+ export const type = isly.object<Charge>({
83
+ merchant: Charge.Merchant.type.optional(),
84
+ fx: Charge.Fx.type.optional(),
85
+ })
86
+ }
@@ -1,47 +1,39 @@
1
1
  import { isoly } from "isoly"
2
2
  import { isly } from "isly"
3
- import { Charge as AccountCharge } from "../Account/Charge"
4
- import type { Rule } from "../Rule"
5
- import { Exchange } from "./Exchange"
3
+ import type { Rule } from "../../Rule"
4
+ import { Exchange } from "../Exchange"
5
+ import { Charge as AmountCharge } from "./Charge"
6
6
 
7
7
  export interface Amount {
8
8
  original: number
9
9
  charge: number //Legacy
10
- charges?: Amount.Charge[]
10
+ charges?: Amount.Charge
11
11
  total: number
12
12
  exchange?: Exchange
13
13
  }
14
14
  export namespace Amount {
15
- export interface Charge {
16
- amount: number
17
- charge: AccountCharge
18
- }
19
- export namespace Charge {
20
- export const type = isly.object<Charge>({
21
- amount: isly.number(),
22
- charge: AccountCharge.type,
23
- })
24
- export function total(currency: isoly.Currency, charges: Charge[] = []): number {
25
- return charges.reduce((r, c) => isoly.Currency.add(currency, r, c.amount), 0)
26
- }
27
- }
15
+ export import Charge = AmountCharge
28
16
  export const type = isly.object<Amount>({
29
17
  original: isly.number(),
30
18
  charge: isly.number(),
31
- charges: Charge.type.array().optional(),
19
+ charges: Amount.Charge.type.optional(),
32
20
  total: isly.number(),
33
21
  exchange: Exchange.type.optional(),
34
22
  })
35
- export function fromState(state: Rule.State, charges?: Charge[]): Amount {
23
+ export function fromState(state: Rule.State, charges?: Charge): Amount {
36
24
  const sign = ["outbound", "authorization", "capture"].some(direction => direction == state.transaction.kind)
37
25
  ? -1
38
26
  : 1
39
- const charge = Amount.Charge.total(state.transaction.original.currency, charges)
27
+
40
28
  return {
41
29
  original: sign * state.transaction.original.amount,
42
30
  charge: 0,
43
31
  charges,
44
- total: isoly.Currency.add(state.transaction.original.currency, sign * state.transaction.original.total, charge),
32
+ total: isoly.Currency.add(
33
+ state.transaction.original.currency,
34
+ sign * state.transaction.original.total,
35
+ Amount.Charge.total(state.transaction.original.currency, charges ?? {})
36
+ ),
45
37
  exchange: state?.transaction.exchange ?? state.authorization?.exchange,
46
38
  }
47
39
  }
@@ -37,13 +37,13 @@ export namespace Creatable {
37
37
  reference: isly.object<{ reference: string }>({ reference: isly.string() }),
38
38
  approvalCode: isly.string().optional(),
39
39
  })
40
- export function charge(charges: Account.Charge[], creatable: CardTransaction, preset?: Preset): Amount.Charge[] {
40
+ export function charge(creatable: CardTransaction, preset: Preset, charges?: Account.Charge): Amount.Charge {
41
41
  return Account.Charge.evaluate(
42
- charges,
43
42
  creatable.counterpart,
44
43
  creatable.currency,
45
44
  creatable.amount,
46
45
  preset,
46
+ charges,
47
47
  creatable.exchange
48
48
  )
49
49
  }
@@ -89,7 +89,7 @@ export namespace Transaction {
89
89
  export function amountFromOperations(
90
90
  transaction: Transaction,
91
91
  operations: Operation[],
92
- charges?: Amount.Charge[]
92
+ charges?: Amount.Charge
93
93
  ): Amount {
94
94
  const changes = Operation.sum(operations)
95
95
  const reserved = isoly.Currency.add(
@@ -148,8 +148,8 @@ export namespace Transaction {
148
148
  account: { id: string; name: string; organization: string; address: Rail.Address },
149
149
  balance: { actual: number; reserved: number; available: number },
150
150
  operation: Operation | Status.Reason,
151
- charges: Amount.Charge[],
152
- by: string | undefined
151
+ charges?: Amount.Charge,
152
+ by?: string
153
153
  ): Transaction {
154
154
  const status: Status =
155
155
  typeof operation == "string"
@@ -0,0 +1,10 @@
1
+ import { isoly } from "isoly";
2
+ import { Card } from "../../../Card";
3
+ import { Amount } from "../../../Transaction/Amount";
4
+ import { Exchange } from "../../../Transaction/Exchange";
5
+ import { Preset } from "../Preset";
6
+ export type Fx = Preset;
7
+ export declare namespace Fx {
8
+ const type: import("isly/dist/cjs/Type").Type<Preset>;
9
+ function evaluate(charge: Fx, currency: isoly.Currency, amount: number, preset?: Card.Preset, exchange?: Exchange): Amount.Charge.Fx | undefined;
10
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Fx = void 0;
4
+ const isoly_1 = require("isoly");
5
+ const Preset_1 = require("../Preset");
6
+ var Fx;
7
+ (function (Fx) {
8
+ Fx.type = Preset_1.Preset.type;
9
+ function evaluate(charge, currency, amount, preset, exchange) {
10
+ let result;
11
+ const chargePreset = preset && charge[preset] ? preset : "default";
12
+ const chargeRate = charge[chargePreset] ?? 0;
13
+ if (exchange)
14
+ result = {
15
+ preset: chargePreset,
16
+ rate: chargeRate,
17
+ amount: -isoly_1.isoly.Currency.multiply(currency, amount, chargeRate),
18
+ };
19
+ return result;
20
+ }
21
+ Fx.evaluate = evaluate;
22
+ })(Fx || (exports.Fx = Fx = {}));
23
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../Account/Charge/Fx/index.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAI7B,sCAAkC;AAIlC,IAAiB,EAAE,CAoBlB;AApBD,WAAiB,EAAE;IACL,OAAI,GAAG,eAAM,CAAC,IAAI,CAAA;IAC/B,SAAgB,QAAQ,CACvB,MAAU,EACV,QAAwB,EACxB,MAAc,EACd,MAAoB,EACpB,QAAmB;QAEnB,IAAI,MAAoC,CAAA;QACxC,MAAM,YAAY,GAAG,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAA;QAClE,MAAM,UAAU,GAAG,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAA;QAC5C,IAAI,QAAQ;YACX,MAAM,GAAG;gBACR,MAAM,EAAE,YAAY;gBACpB,IAAI,EAAE,UAAU;gBAChB,MAAM,EAAE,CAAC,aAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC;aAC9D,CAAA;QACF,OAAO,MAAM,CAAA;IACd,CAAC;IAjBe,WAAQ,WAiBvB,CAAA;AACF,CAAC,EApBgB,EAAE,kBAAF,EAAE,QAoBlB"}
@@ -0,0 +1,15 @@
1
+ import { isoly } from "isoly";
2
+ import { Card } from "../../../Card";
3
+ import { Rail } from "../../../Rail";
4
+ import { Amount } from "../../../Transaction/Amount";
5
+ import { Preset } from "../Preset";
6
+ export interface Merchant {
7
+ destination: {
8
+ account: string;
9
+ };
10
+ merchants: Partial<Record<Card.Restriction.Merchant, Preset>>;
11
+ }
12
+ export declare namespace Merchant {
13
+ const type: import("isly/dist/cjs/object").IslyObject<Merchant, object>;
14
+ function evaluate(charge: Merchant, currency: isoly.Currency, amount: number, counterpart: Rail.Address.Card.Counterpart, preset?: Card.Preset): Amount.Charge.Merchant | undefined;
15
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Merchant = void 0;
4
+ const isoly_1 = require("isoly");
5
+ const isly_1 = require("isly");
6
+ const Card_1 = require("../../../Card");
7
+ const Preset_1 = require("../Preset");
8
+ var Merchant;
9
+ (function (Merchant) {
10
+ Merchant.type = isly_1.isly.object({
11
+ destination: isly_1.isly.object({
12
+ account: isly_1.isly.string(),
13
+ }),
14
+ merchants: isly_1.isly.record(Card_1.Card.Restriction.Merchant.type, Preset_1.Preset.type),
15
+ });
16
+ function evaluate(charge, currency, amount, counterpart, preset) {
17
+ let result;
18
+ const merchant = Card_1.Card.Restriction.Merchant.resolve(counterpart);
19
+ if (merchant) {
20
+ const chargePreset = preset && charge.merchants?.[merchant]?.[preset] ? preset : "default";
21
+ const chargeRate = charge.merchants?.[merchant]?.[chargePreset] ?? 0;
22
+ result = {
23
+ merchant,
24
+ preset: chargePreset,
25
+ destination: charge.destination,
26
+ rate: chargeRate,
27
+ amount: -isoly_1.isoly.Currency.multiply(currency, amount, chargeRate),
28
+ };
29
+ }
30
+ return result;
31
+ }
32
+ Merchant.evaluate = evaluate;
33
+ })(Merchant || (exports.Merchant = Merchant = {}));
34
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../Account/Charge/Merchant/index.ts"],"names":[],"mappings":";;;AAAA,iCAA6B;AAC7B,+BAA2B;AAC3B,wCAAoC;AAGpC,sCAAkC;AAMlC,IAAiB,QAAQ,CA8BxB;AA9BD,WAAiB,QAAQ;IACX,aAAI,GAAG,WAAI,CAAC,MAAM,CAAW;QACzC,WAAW,EAAE,WAAI,CAAC,MAAM,CAAC;YACxB,OAAO,EAAE,WAAI,CAAC,MAAM,EAAE;SACtB,CAAC;QACF,SAAS,EAAE,WAAI,CAAC,MAAM,CAAoC,WAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,EAAE,eAAM,CAAC,IAAI,CAAC;KACtG,CAAC,CAAA;IAEF,SAAgB,QAAQ,CACvB,MAAgB,EAChB,QAAwB,EACxB,MAAc,EACd,WAA0C,EAC1C,MAAoB;QAEpB,IAAI,MAA0C,CAAA;QAC9C,MAAM,QAAQ,GAAG,WAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,CAAA;QAC/D,IAAI,QAAQ,EAAE,CAAC;YACd,MAAM,YAAY,GAAG,MAAM,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAA;YAC1F,MAAM,UAAU,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAA;YACpE,MAAM,GAAG;gBACR,QAAQ;gBACR,MAAM,EAAE,YAAY;gBACpB,WAAW,EAAE,MAAM,CAAC,WAAW;gBAC/B,IAAI,EAAE,UAAU;gBAChB,MAAM,EAAE,CAAC,aAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC;aAC9D,CAAA;QACF,CAAC;QACD,OAAO,MAAM,CAAA;IACd,CAAC;IArBe,iBAAQ,WAqBvB,CAAA;AACF,CAAC,EA9BgB,QAAQ,wBAAR,QAAQ,QA8BxB"}
@@ -0,0 +1,8 @@
1
+ import { isly } from "isly";
2
+ import { Card } from "../../../Card";
3
+ export type Preset = Partial<Record<Card.Preset, number>> & {
4
+ default: number;
5
+ };
6
+ export declare namespace Preset {
7
+ const type: isly.Type<Preset>;
8
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Preset = void 0;
4
+ const isly_1 = require("isly");
5
+ const Card_1 = require("../../../Card");
6
+ var Preset;
7
+ (function (Preset) {
8
+ const recordType = isly_1.isly.record(isly_1.isly.string(Card_1.Card.Preset.names), isly_1.isly.number());
9
+ const defaultType = isly_1.isly.object({ default: isly_1.isly.number() });
10
+ function is(value) {
11
+ return defaultType.is(value) && recordType.is((({ default: _, ...rest }) => rest)(value));
12
+ }
13
+ Preset.type = isly_1.isly.fromIs("Preset", is);
14
+ })(Preset || (exports.Preset = Preset = {}));
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../Account/Charge/Preset/index.ts"],"names":[],"mappings":";;;AAAA,+BAA2B;AAC3B,wCAAoC;AAMpC,IAAiB,MAAM,CAOtB;AAPD,WAAiB,MAAM;IACtB,MAAM,UAAU,GAAG,WAAI,CAAC,MAAM,CAAS,WAAI,CAAC,MAAM,CAAC,WAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,WAAI,CAAC,MAAM,EAAE,CAAC,CAAA;IACrF,MAAM,WAAW,GAAG,WAAI,CAAC,MAAM,CAAsB,EAAE,OAAO,EAAE,WAAI,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;IAChF,SAAS,EAAE,CAAC,KAAc;QACzB,OAAO,WAAW,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAA;IAC1F,CAAC;IACY,WAAI,GAAG,WAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;AAC9C,CAAC,EAPgB,MAAM,sBAAN,MAAM,QAOtB"}
@@ -2,23 +2,15 @@ import { isoly } from "isoly";
2
2
  import type { Card } from "../../Card";
3
3
  import type { Rail } from "../../Rail";
4
4
  import type { Transaction } from "../../Transaction";
5
- import { Applies } from "./Applies";
6
- export interface Charge extends Charge.Creatable {
7
- id: string;
8
- }
5
+ import { Fx as ChargeFx } from "./Fx";
6
+ import { Merchant as ChargeMerchant } from "./Merchant";
7
+ export type Charge = {
8
+ merchant?: Charge.Merchant;
9
+ fx?: Charge.Fx;
10
+ };
9
11
  export declare namespace Charge {
10
- interface Creatable {
11
- destination: {
12
- account: string;
13
- };
14
- rate: number;
15
- applies: Applies;
16
- }
17
- namespace Creatable {
18
- const type: import("isly/dist/cjs/object").IslyObject<Creatable, object>;
19
- }
20
- const type: import("isly/dist/cjs/object").IslyObject<Charge, Creatable>;
21
- function fromCreatable(creatable: Creatable): Charge;
22
- function evaluate(charges: Charge[] | undefined, counterpart: Rail.Address.Card.Counterpart, currency: isoly.Currency, amount: number, preset?: Card.Preset, exchange?: Transaction.Exchange): Transaction.Amount.Charge[];
23
- function sum(charges: Transaction.Amount.Charge[], currency: isoly.Currency): number;
12
+ export import Merchant = ChargeMerchant;
13
+ export import Fx = ChargeFx;
14
+ const type: import("isly/dist/cjs/object").IslyObject<Charge, object>;
15
+ function evaluate(counterpart: Rail.Address.Card.Counterpart, currency: isoly.Currency, amount: number, preset?: Card.Preset, charges?: Charge, exchange?: Transaction.Exchange): Transaction.Amount.Charge;
24
16
  }
@@ -1,44 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Charge = void 0;
4
- const cryptly_1 = require("cryptly");
5
- const isoly_1 = require("isoly");
6
4
  const isly_1 = require("isly");
7
- const Applies_1 = require("./Applies");
5
+ const Fx_1 = require("./Fx");
6
+ const Merchant_1 = require("./Merchant");
8
7
  var Charge;
9
8
  (function (Charge) {
10
- let Creatable;
11
- (function (Creatable) {
12
- Creatable.type = isly_1.isly.object({
13
- destination: isly_1.isly.object({ account: isly_1.isly.string() }),
14
- rate: isly_1.isly.number(),
15
- applies: Applies_1.Applies.type,
16
- });
17
- })(Creatable = Charge.Creatable || (Charge.Creatable = {}));
18
- Charge.type = Creatable.type.extend({
19
- id: isly_1.isly.string(),
20
- });
21
- function fromCreatable(creatable) {
22
- return { ...creatable, id: cryptly_1.cryptly.Identifier.generate(4) };
23
- }
24
- Charge.fromCreatable = fromCreatable;
25
- function evaluate(charges = [], counterpart, currency, amount, preset, exchange) {
26
- const result = [];
27
- for (const charge of charges)
28
- if (Applies_1.Applies.evaluate(charge.applies, counterpart, preset, exchange))
29
- result.push(toTransactionAmountCharge(currency, amount, charge));
30
- return result;
31
- }
32
- Charge.evaluate = evaluate;
33
- function toTransactionAmountCharge(currency, amount, charge) {
9
+ Charge.Merchant = Merchant_1.Merchant;
10
+ Charge.Fx = Fx_1.Fx;
11
+ Charge.type = isly_1.isly.object({ merchant: Merchant_1.Merchant.type, fx: Fx_1.Fx.type });
12
+ function evaluate(counterpart, currency, amount, preset, charges, exchange) {
13
+ const merchant = charges?.merchant && Merchant_1.Merchant.evaluate(charges.merchant, currency, amount, counterpart, preset);
14
+ const fx = charges?.fx && Fx_1.Fx.evaluate(charges.fx, currency, amount, preset, exchange);
34
15
  return {
35
- amount: -isoly_1.isoly.Currency.multiply(currency, amount, charge.rate),
36
- charge,
16
+ ...(merchant && { merchant }),
17
+ ...(fx && { fx }),
37
18
  };
38
19
  }
39
- function sum(charges, currency) {
40
- return charges.reduce((sum, charge) => isoly_1.isoly.Currency.add(currency, sum, charge.amount), 0);
41
- }
42
- Charge.sum = sum;
20
+ Charge.evaluate = evaluate;
43
21
  })(Charge || (exports.Charge = Charge = {}));
44
22
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../Account/Charge/index.ts"],"names":[],"mappings":";;;AAAA,qCAAiC;AACjC,iCAA6B;AAC7B,+BAA2B;AAI3B,uCAAmC;AAKnC,IAAiB,MAAM,CA8CtB;AA9CD,WAAiB,MAAM;IAMtB,IAAiB,SAAS,CAMzB;IAND,WAAiB,SAAS;QACZ,cAAI,GAAG,WAAI,CAAC,MAAM,CAAY;YAC1C,WAAW,EAAE,WAAI,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,WAAI,CAAC,MAAM,EAAE,EAAE,CAAC;YACpD,IAAI,EAAE,WAAI,CAAC,MAAM,EAAE;YACnB,OAAO,EAAE,iBAAO,CAAC,IAAI;SACrB,CAAC,CAAA;IACH,CAAC,EANgB,SAAS,GAAT,gBAAS,KAAT,gBAAS,QAMzB;IACY,WAAI,GAAG,SAAS,CAAC,IAAI,CAAC,MAAM,CAAS;QACjD,EAAE,EAAE,WAAI,CAAC,MAAM,EAAE;KACjB,CAAC,CAAA;IACF,SAAgB,aAAa,CAAC,SAAoB;QACjD,OAAO,EAAE,GAAG,SAAS,EAAE,EAAE,EAAE,iBAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAA;IAC5D,CAAC;IAFe,oBAAa,gBAE5B,CAAA;IACD,SAAgB,QAAQ,CACvB,UAAoB,EAAE,EACtB,WAA0C,EAC1C,QAAwB,EACxB,MAAc,EACd,MAAoB,EACpB,QAA+B;QAE/B,MAAM,MAAM,GAAgC,EAAE,CAAA;QAC9C,KAAK,MAAM,MAAM,IAAI,OAAO;YAC3B,IAAI,iBAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,CAAC;gBAClE,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;QAClE,OAAO,MAAM,CAAA;IACd,CAAC;IAbe,eAAQ,WAavB,CAAA;IACD,SAAS,yBAAyB,CACjC,QAAwB,EACxB,MAAc,EACd,MAAc;QAEd,OAAO;YACN,MAAM,EAAE,CAAC,aAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,CAAC;YAC/D,MAAM;SACN,CAAA;IACF,CAAC;IACD,SAAgB,GAAG,CAAC,OAAoC,EAAE,QAAwB;QACjF,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC,aAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAA;IAC5F,CAAC;IAFe,UAAG,MAElB,CAAA;AACF,CAAC,EA9CgB,MAAM,sBAAN,MAAM,QA8CtB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../Account/Charge/index.ts"],"names":[],"mappings":";;;AACA,+BAA2B;AAI3B,6BAAqC;AACrC,yCAAuD;AAGvD,IAAiB,MAAM,CAqBtB;AArBD,WAAiB,MAAM;IACR,eAAQ,GAAG,mBAAc,CAAA;IACzB,SAAE,GAAG,OAAQ,CAAA;IACd,WAAI,GAAG,WAAI,CAAC,MAAM,CAAS,EAAE,QAAQ,EAAE,mBAAc,CAAC,IAAI,EAAE,EAAE,EAAE,OAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;IAC7F,SAAgB,QAAQ,CACvB,WAA0C,EAC1C,QAAwB,EACxB,MAAc,EACd,MAAoB,EACpB,OAAgB,EAChB,QAA+B;QAE/B,MAAM,QAAQ,GACb,OAAO,EAAE,QAAQ,IAAI,mBAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,CAAA;QACtG,MAAM,EAAE,GAAG,OAAO,EAAE,EAAE,IAAI,OAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAA;QAE3F,OAAO;YACN,GAAG,CAAC,QAAQ,IAAI,EAAE,QAAQ,EAAE,CAAC;YAC7B,GAAG,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;SACjB,CAAA;IACF,CAAC;IAhBe,eAAQ,WAgBvB,CAAA;AACF,CAAC,EArBgB,MAAM,sBAAN,MAAM,QAqBtB"}