@pax2pay/model-paxgiro-card 0.0.17
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/.editorconfig +22 -0
- package/.eslintignore +4 -0
- package/.eslintrc +71 -0
- package/.github/workflows/bump.yml +30 -0
- package/.github/workflows/ci.yml +61 -0
- package/.github/workflows/publish.yml +34 -0
- package/.prettierrc +11 -0
- package/Authorization/Creatable.ts +23 -0
- package/Authorization/index.ts +56 -0
- package/Batch.ts +28 -0
- package/CODEOWNERS +1 -0
- package/Card/Creatable.ts +27 -0
- package/Card/index.ts +47 -0
- package/Clearing.ts +41 -0
- package/Confirm.ts +14 -0
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/Settlement/index.ts +38 -0
- package/dist/Authorization/Creatable.js +15 -0
- package/dist/Authorization/Creatable.js.map +1 -0
- package/dist/Authorization/index.js +47 -0
- package/dist/Authorization/index.js.map +1 -0
- package/dist/Batch.js +31 -0
- package/dist/Batch.js.map +1 -0
- package/dist/Card/Creatable.js +20 -0
- package/dist/Card/Creatable.js.map +1 -0
- package/dist/Card/index.js +37 -0
- package/dist/Card/index.js.map +1 -0
- package/dist/Clearing.js +24 -0
- package/dist/Clearing.js.map +1 -0
- package/dist/Confirm.js +10 -0
- package/dist/Confirm.js.map +1 -0
- package/dist/Settlement/index.js +30 -0
- package/dist/Settlement/index.js.map +1 -0
- package/dist/cjs/Authorization/Creatable.js +18 -0
- package/dist/cjs/Authorization/Creatable.js.map +1 -0
- package/dist/cjs/Authorization/index.js +50 -0
- package/dist/cjs/Authorization/index.js.map +1 -0
- package/dist/cjs/Batch.js +34 -0
- package/dist/cjs/Batch.js.map +1 -0
- package/dist/cjs/Card/Creatable.js +23 -0
- package/dist/cjs/Card/Creatable.js.map +1 -0
- package/dist/cjs/Card/index.js +40 -0
- package/dist/cjs/Card/index.js.map +1 -0
- package/dist/cjs/Clearing.js +27 -0
- package/dist/cjs/Clearing.js.map +1 -0
- package/dist/cjs/Confirm.js +13 -0
- package/dist/cjs/Confirm.js.map +1 -0
- package/dist/cjs/Settlement/index.js +33 -0
- package/dist/cjs/Settlement/index.js.map +1 -0
- package/dist/cjs/index.js +39 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/paxcard.js +16 -0
- package/dist/cjs/paxcard.js.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/paxcard.js +7 -0
- package/dist/paxcard.js.map +1 -0
- package/index.ts +2 -0
- package/package.json +62 -0
- package/paxcard.ts +6 -0
- package/tsconfig.cjs.json +13 -0
- package/tsconfig.json +34 -0
- package/tsconfig.mjs.json +9 -0
- package/vite.config.ts +17 -0
package/.editorconfig
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# http://editorconfig.org
|
|
2
|
+
|
|
3
|
+
root = true
|
|
4
|
+
|
|
5
|
+
[*]
|
|
6
|
+
charset = utf-8
|
|
7
|
+
indent_style = tab
|
|
8
|
+
indent_size = 2
|
|
9
|
+
end_of_line = lf
|
|
10
|
+
insert_final_newline = true
|
|
11
|
+
trim_trailing_whitespace = true
|
|
12
|
+
|
|
13
|
+
[{*.yml}]
|
|
14
|
+
indent_style = space
|
|
15
|
+
indent_size = 2
|
|
16
|
+
end_of_line = lf
|
|
17
|
+
insert_final_newline = true
|
|
18
|
+
trim_trailing_whitespace = true
|
|
19
|
+
|
|
20
|
+
[*.md]
|
|
21
|
+
insert_final_newline = true
|
|
22
|
+
trim_trailing_whitespace = false
|
package/.eslintignore
ADDED
package/.eslintrc
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"root": true,
|
|
3
|
+
"parser": "@typescript-eslint/parser",
|
|
4
|
+
"plugins": [
|
|
5
|
+
"@typescript-eslint",
|
|
6
|
+
"prettierx",
|
|
7
|
+
"simple-import-sort"
|
|
8
|
+
],
|
|
9
|
+
"extends": [
|
|
10
|
+
"eslint:recommended",
|
|
11
|
+
"plugin:@typescript-eslint/eslint-recommended",
|
|
12
|
+
"plugin:@typescript-eslint/recommended",
|
|
13
|
+
"plugin:prettierx/default"
|
|
14
|
+
],
|
|
15
|
+
"rules": {
|
|
16
|
+
"prettierx/options": [
|
|
17
|
+
1,
|
|
18
|
+
{
|
|
19
|
+
"singleQuote": false
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
23
|
+
"@typescript-eslint/no-namespace": "off",
|
|
24
|
+
"prefer-const": 1,
|
|
25
|
+
"@typescript-eslint/no-unused-vars": [
|
|
26
|
+
2,
|
|
27
|
+
{
|
|
28
|
+
"vars": "all",
|
|
29
|
+
"args": "none",
|
|
30
|
+
"varsIgnorePattern": "h"
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
"@typescript-eslint/explicit-module-boundary-types": "off",
|
|
34
|
+
"no-case-declarations": "off",
|
|
35
|
+
"no-inner-declarations": "off",
|
|
36
|
+
"sort-imports": "off",
|
|
37
|
+
"simple-import-sort/imports": [
|
|
38
|
+
"error",
|
|
39
|
+
{
|
|
40
|
+
"groups": [
|
|
41
|
+
[
|
|
42
|
+
"@stencil/core",
|
|
43
|
+
"cryptly",
|
|
44
|
+
"flagly",
|
|
45
|
+
"gracely",
|
|
46
|
+
"isoly",
|
|
47
|
+
"paramly",
|
|
48
|
+
"selectively",
|
|
49
|
+
"langly",
|
|
50
|
+
"tidily",
|
|
51
|
+
"uply",
|
|
52
|
+
"authly",
|
|
53
|
+
"persistly",
|
|
54
|
+
"servly",
|
|
55
|
+
"servly-azure",
|
|
56
|
+
"smoothly",
|
|
57
|
+
"^\\u0000",
|
|
58
|
+
"^@?\\w",
|
|
59
|
+
"^",
|
|
60
|
+
"^\\."
|
|
61
|
+
]
|
|
62
|
+
]
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
},
|
|
66
|
+
"settings": {
|
|
67
|
+
"prettierx": {
|
|
68
|
+
"usePrettierrc": true
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
name: "Bump"
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- "master"
|
|
7
|
+
jobs:
|
|
8
|
+
bump-version:
|
|
9
|
+
name: "Bump Version"
|
|
10
|
+
timeout-minutes: 60
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
if: "!contains(github.event.head_commit.message, 'ci: version bump to ')"
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- name: "Checkout source code"
|
|
16
|
+
uses: "actions/checkout@v3"
|
|
17
|
+
with:
|
|
18
|
+
token: ${{ secrets.ADMIN_TOKEN }}
|
|
19
|
+
- name: "Setup Node"
|
|
20
|
+
uses: "actions/setup-node@v3"
|
|
21
|
+
with:
|
|
22
|
+
node-version: current
|
|
23
|
+
cache: 'npm'
|
|
24
|
+
- name: "Version Bump"
|
|
25
|
+
id: version-bump
|
|
26
|
+
uses: "phips28/gh-action-bump-version@master"
|
|
27
|
+
with:
|
|
28
|
+
tag-prefix: 'release-'
|
|
29
|
+
env:
|
|
30
|
+
GITHUB_TOKEN: ${{ secrets.ADMIN_TOKEN }}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
|
|
6
|
+
jobs:
|
|
7
|
+
build:
|
|
8
|
+
name: Build
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
steps:
|
|
11
|
+
- uses: actions/checkout@v3
|
|
12
|
+
- uses: actions/setup-node@v3
|
|
13
|
+
with:
|
|
14
|
+
node-version: current
|
|
15
|
+
cache: 'npm'
|
|
16
|
+
- uses: actions/cache@v3
|
|
17
|
+
with:
|
|
18
|
+
path: '**/node_modules'
|
|
19
|
+
key: node_modules-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
|
|
20
|
+
- run: npm install
|
|
21
|
+
- run: npm run build
|
|
22
|
+
test:
|
|
23
|
+
name: Test
|
|
24
|
+
runs-on: ubuntu-latest
|
|
25
|
+
steps:
|
|
26
|
+
- uses: actions/checkout@v3
|
|
27
|
+
- uses: actions/setup-node@v3
|
|
28
|
+
with:
|
|
29
|
+
node-version: current
|
|
30
|
+
cache: 'npm'
|
|
31
|
+
- uses: actions/cache@v3
|
|
32
|
+
with:
|
|
33
|
+
path: '**/node_modules'
|
|
34
|
+
key: node_modules-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
|
|
35
|
+
- run: npm install
|
|
36
|
+
- run: npm run test
|
|
37
|
+
lint:
|
|
38
|
+
name: Lint
|
|
39
|
+
runs-on: ubuntu-latest
|
|
40
|
+
steps:
|
|
41
|
+
- uses: actions/checkout@v3
|
|
42
|
+
- uses: actions/setup-node@v3
|
|
43
|
+
with:
|
|
44
|
+
node-version: current
|
|
45
|
+
cache: 'npm'
|
|
46
|
+
- uses: actions/cache@v3
|
|
47
|
+
with:
|
|
48
|
+
path: '**/node_modules'
|
|
49
|
+
key: node_modules-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
|
|
50
|
+
- run: npm install
|
|
51
|
+
- run: npm run lint
|
|
52
|
+
audit:
|
|
53
|
+
name: Audit
|
|
54
|
+
runs-on: ubuntu-latest
|
|
55
|
+
steps:
|
|
56
|
+
- uses: actions/checkout@v3
|
|
57
|
+
- uses: actions/setup-node@v3
|
|
58
|
+
with:
|
|
59
|
+
node-version: current
|
|
60
|
+
cache: 'npm'
|
|
61
|
+
- run: npm audit --omit=dev
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
name: "Publish"
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "release-*"
|
|
7
|
+
jobs:
|
|
8
|
+
publish:
|
|
9
|
+
name: "Publish"
|
|
10
|
+
timeout-minutes: 60
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- name: "Checkout source code"
|
|
14
|
+
uses: "actions/checkout@v3"
|
|
15
|
+
- name: "Setup Node"
|
|
16
|
+
uses: "actions/setup-node@v3"
|
|
17
|
+
with:
|
|
18
|
+
node-version: current
|
|
19
|
+
cache: 'npm'
|
|
20
|
+
- uses: actions/cache@v3
|
|
21
|
+
with:
|
|
22
|
+
path: '**/node_modules'
|
|
23
|
+
key: node_modules-${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}
|
|
24
|
+
- name: Install
|
|
25
|
+
run: npm install
|
|
26
|
+
- name: Build
|
|
27
|
+
run: npm run build
|
|
28
|
+
- name: Publish
|
|
29
|
+
run: |
|
|
30
|
+
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc
|
|
31
|
+
npm publish --access public
|
|
32
|
+
shell: bash
|
|
33
|
+
env:
|
|
34
|
+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/.prettierrc
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { isoly } from "isoly"
|
|
2
|
+
import { pax2pay } from "@pax2pay/model-banking"
|
|
3
|
+
import { isly } from "isly"
|
|
4
|
+
import { Card } from "../Card"
|
|
5
|
+
|
|
6
|
+
export interface Creatable {
|
|
7
|
+
card: string
|
|
8
|
+
preset: Card.Creatable.Preset
|
|
9
|
+
amount: [isoly.Currency, number]
|
|
10
|
+
merchant: pax2pay.Merchant
|
|
11
|
+
acquirer: pax2pay.Acquirer
|
|
12
|
+
description: string
|
|
13
|
+
}
|
|
14
|
+
export namespace Creatable {
|
|
15
|
+
export const type = isly.object<Creatable>({
|
|
16
|
+
card: isly.string(),
|
|
17
|
+
preset: isly.string(),
|
|
18
|
+
amount: isly.tuple(isly.fromIs("isoly.Currency", isoly.Currency.is), isly.number()),
|
|
19
|
+
merchant: pax2pay.Merchant.type,
|
|
20
|
+
acquirer: pax2pay.Acquirer.type,
|
|
21
|
+
description: isly.string(),
|
|
22
|
+
})
|
|
23
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { cryptly } from "cryptly"
|
|
2
|
+
import { isoly } from "isoly"
|
|
3
|
+
import { pax2pay } from "@pax2pay/model-banking"
|
|
4
|
+
import { isly } from "isly"
|
|
5
|
+
import { Creatable as AuthorizationCreatable } from "./Creatable"
|
|
6
|
+
|
|
7
|
+
export interface Authorization {
|
|
8
|
+
id: cryptly.Identifier
|
|
9
|
+
number?: cryptly.Identifier
|
|
10
|
+
card: string
|
|
11
|
+
created: isoly.DateTime
|
|
12
|
+
amount: [isoly.Currency, number]
|
|
13
|
+
merchant: pax2pay.Merchant
|
|
14
|
+
acquirer: pax2pay.Acquirer
|
|
15
|
+
description: string
|
|
16
|
+
status?: "approved"
|
|
17
|
+
}
|
|
18
|
+
export namespace Authorization {
|
|
19
|
+
export import Creatable = AuthorizationCreatable
|
|
20
|
+
export function fromCreatable(authorization: Authorization.Creatable): Authorization {
|
|
21
|
+
return {
|
|
22
|
+
id: pax2pay.Identifier.generate(),
|
|
23
|
+
card: authorization.card,
|
|
24
|
+
created: isoly.DateTime.now(),
|
|
25
|
+
amount: authorization.amount,
|
|
26
|
+
merchant: authorization.merchant,
|
|
27
|
+
acquirer: authorization.acquirer,
|
|
28
|
+
description: authorization.description,
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export function from(id: cryptly.Identifier, authorization: pax2pay.Authorization): Authorization {
|
|
32
|
+
return {
|
|
33
|
+
id,
|
|
34
|
+
number: authorization.id,
|
|
35
|
+
status: authorization.status == "approved" ? "approved" : undefined,
|
|
36
|
+
card: authorization.card.id,
|
|
37
|
+
created: authorization.created,
|
|
38
|
+
amount: authorization.amount,
|
|
39
|
+
merchant: authorization.merchant,
|
|
40
|
+
acquirer: authorization.acquirer,
|
|
41
|
+
description: authorization.description,
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const type = isly.object<Authorization>({
|
|
46
|
+
id: isly.fromIs("Authorization.id", cryptly.Identifier.is),
|
|
47
|
+
number: isly.fromIs("Authorization.id", cryptly.Identifier.is).optional(),
|
|
48
|
+
card: isly.string(),
|
|
49
|
+
created: isly.fromIs("Authorization.created", isoly.DateTime.is),
|
|
50
|
+
amount: isly.tuple(isly.fromIs("isoly.Currency", isoly.Currency.is), isly.number()),
|
|
51
|
+
merchant: pax2pay.Merchant.type,
|
|
52
|
+
acquirer: pax2pay.Acquirer.type,
|
|
53
|
+
description: isly.string(),
|
|
54
|
+
status: isly.string("approved").optional(),
|
|
55
|
+
})
|
|
56
|
+
}
|
package/Batch.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { isoly } from "isoly"
|
|
2
|
+
|
|
3
|
+
export type Batch = string
|
|
4
|
+
export namespace Batch {
|
|
5
|
+
export function is(batch: any): batch is Batch {
|
|
6
|
+
return typeof batch == "string" && batch.length === 9 && /^\d{4}[0-3]\d{2}0[1-4]$/.test(batch)
|
|
7
|
+
}
|
|
8
|
+
export function from(time: isoly.DateTime): Batch {
|
|
9
|
+
return `${isoly.DateTime.getYear(time)}${dayOfYear(time)}0${cycle(time)}` as Batch
|
|
10
|
+
}
|
|
11
|
+
export function dayOfYear(time: isoly.DateTime): string {
|
|
12
|
+
const ms =
|
|
13
|
+
isoly.DateTime.epoch(time, "milliseconds") -
|
|
14
|
+
isoly.DateTime.epoch(`${Number.parseInt(time.slice(0, 4))}-01-01T00:00:00.000Z`, "milliseconds")
|
|
15
|
+
return (Math.floor(ms / 1000 / 60 / 60 / 24) + 1).toString().padStart(3, "0")
|
|
16
|
+
}
|
|
17
|
+
export function cycle(time: isoly.DateTime): number {
|
|
18
|
+
return Math.floor(isoly.DateTime.getHour(time) / 6) + 1
|
|
19
|
+
}
|
|
20
|
+
export function previous(time: isoly.DateTime = isoly.DateTime.now()): Batch {
|
|
21
|
+
return from(isoly.DateTime.previousHour(time, 6))
|
|
22
|
+
}
|
|
23
|
+
export function toPrefix(batch: Batch): string {
|
|
24
|
+
return `${isoly.Date.invert(
|
|
25
|
+
isoly.Date.next(`${batch.slice(0, 4)}-01-01`, Number.parseInt(batch.slice(4, 7)) - 1)
|
|
26
|
+
)}|${batch.slice(-1)}`
|
|
27
|
+
}
|
|
28
|
+
}
|
package/CODEOWNERS
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@EliasEriksson
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { pax2pay } from "@pax2pay/model-banking"
|
|
2
|
+
import { isly } from "isly"
|
|
3
|
+
|
|
4
|
+
export type Creatable = Omit<
|
|
5
|
+
pax2pay.Card.Creatable,
|
|
6
|
+
"account" | "realm" | "number" | "limit" | "rules" | "meta" | "key"
|
|
7
|
+
> & {
|
|
8
|
+
id: string
|
|
9
|
+
preset: Extract<pax2pay.Card.Preset, Creatable.Preset>
|
|
10
|
+
} & { details: Pick<pax2pay.Card.Creatable, "details">["details"] & { iin: string } }
|
|
11
|
+
export namespace Creatable {
|
|
12
|
+
export const presets: Extract<pax2pay.Card.Preset, "test-pg-200" | "test-pg-150" | "test-ta-pg-200">[] = [
|
|
13
|
+
"test-pg-200",
|
|
14
|
+
"test-ta-pg-200",
|
|
15
|
+
"test-pg-150",
|
|
16
|
+
]
|
|
17
|
+
export type Preset = typeof presets[number]
|
|
18
|
+
export const type = isly.object<Creatable>({
|
|
19
|
+
id: isly.string(),
|
|
20
|
+
preset: isly.string(presets),
|
|
21
|
+
details: isly.object({
|
|
22
|
+
iin: isly.string(),
|
|
23
|
+
expiry: pax2pay.Card.Expiry.type,
|
|
24
|
+
holder: isly.string(),
|
|
25
|
+
}),
|
|
26
|
+
})
|
|
27
|
+
}
|
package/Card/index.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { pax2pay } from "@pax2pay/model-banking"
|
|
2
|
+
import { isly } from "isly"
|
|
3
|
+
import { Creatable as CardCreatable } from "./Creatable"
|
|
4
|
+
|
|
5
|
+
export type Card = Omit<CardCreatable, "details"> & {
|
|
6
|
+
details: {
|
|
7
|
+
iin: string
|
|
8
|
+
last4: string
|
|
9
|
+
pan?: string
|
|
10
|
+
csc?: string
|
|
11
|
+
expiry: pax2pay.Card.Expiry
|
|
12
|
+
holder: string
|
|
13
|
+
token?: string
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export namespace Card {
|
|
18
|
+
export import Creatable = CardCreatable
|
|
19
|
+
export const type = isly.object<Card>({
|
|
20
|
+
id: isly.string(),
|
|
21
|
+
preset: isly.string(Creatable.presets),
|
|
22
|
+
details: isly.object({
|
|
23
|
+
iin: isly.string(),
|
|
24
|
+
pan: isly.string().optional(),
|
|
25
|
+
csc: isly.string().optional(),
|
|
26
|
+
last4: isly.string(),
|
|
27
|
+
token: isly.string().optional(),
|
|
28
|
+
expiry: pax2pay.Card.Expiry.type,
|
|
29
|
+
holder: isly.string(),
|
|
30
|
+
}),
|
|
31
|
+
})
|
|
32
|
+
export function fromCreatable(creatable: CardCreatable, options?: { cde?: boolean }): Card {
|
|
33
|
+
const last4 = `${(10000 * Math.random()).toFixed(0).padStart(4, "0")}`
|
|
34
|
+
const middle = creatable.preset.endsWith("150") ? "0000" : "000000"
|
|
35
|
+
const pan = `${creatable.details.iin}${middle}${last4}`
|
|
36
|
+
const token = `{"pan"="${pan}","csc"="000"}`
|
|
37
|
+
return {
|
|
38
|
+
...creatable,
|
|
39
|
+
details: {
|
|
40
|
+
...creatable.details,
|
|
41
|
+
token,
|
|
42
|
+
last4,
|
|
43
|
+
...(options?.cde && { pan, csc: "000" }),
|
|
44
|
+
},
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
package/Clearing.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { pax2pay } from "@pax2pay/model-banking"
|
|
2
|
+
import { isly } from "isly"
|
|
3
|
+
|
|
4
|
+
export type Clearing = Clearing.Capture | Clearing.Refund
|
|
5
|
+
export namespace Clearing {
|
|
6
|
+
export interface Capture {
|
|
7
|
+
type: "capture"
|
|
8
|
+
authorization: string
|
|
9
|
+
batch: string
|
|
10
|
+
amount: pax2pay.Amount
|
|
11
|
+
fee: pax2pay.Amount
|
|
12
|
+
}
|
|
13
|
+
export interface Refund {
|
|
14
|
+
type: "refund"
|
|
15
|
+
id: string
|
|
16
|
+
batch: string
|
|
17
|
+
card: string
|
|
18
|
+
merchant: pax2pay.Merchant
|
|
19
|
+
acquirer: pax2pay.Acquirer
|
|
20
|
+
fee: pax2pay.Amount
|
|
21
|
+
amount: pax2pay.Amount
|
|
22
|
+
}
|
|
23
|
+
export const Capture = isly.object<Capture>({
|
|
24
|
+
type: isly.string("capture"),
|
|
25
|
+
authorization: isly.string(),
|
|
26
|
+
batch: isly.string(),
|
|
27
|
+
amount: pax2pay.Amount.type,
|
|
28
|
+
fee: pax2pay.Amount.type,
|
|
29
|
+
})
|
|
30
|
+
export const Refund = isly.object<Refund>({
|
|
31
|
+
type: isly.string("refund"),
|
|
32
|
+
batch: isly.string(),
|
|
33
|
+
acquirer: pax2pay.Acquirer.type,
|
|
34
|
+
merchant: pax2pay.Merchant.type,
|
|
35
|
+
card: isly.string(),
|
|
36
|
+
id: isly.string(),
|
|
37
|
+
amount: pax2pay.Amount.type,
|
|
38
|
+
fee: pax2pay.Amount.type,
|
|
39
|
+
})
|
|
40
|
+
export const type = isly.union<Clearing, Capture, Refund>(Capture, Refund)
|
|
41
|
+
}
|
package/Confirm.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { isly } from "isly"
|
|
2
|
+
|
|
3
|
+
export type Confirm = {
|
|
4
|
+
reference: string
|
|
5
|
+
card: string
|
|
6
|
+
approvalCode: string
|
|
7
|
+
}
|
|
8
|
+
export namespace Confirm {
|
|
9
|
+
export const type = isly.object<Confirm>({
|
|
10
|
+
reference: isly.string(),
|
|
11
|
+
card: isly.string(),
|
|
12
|
+
approvalCode: isly.string(),
|
|
13
|
+
})
|
|
14
|
+
}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 utily
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { isoly } from "isoly"
|
|
2
|
+
import { pax2pay } from "@pax2pay/model-banking"
|
|
3
|
+
import { isly } from "isly"
|
|
4
|
+
import { Authorization } from "../Authorization"
|
|
5
|
+
|
|
6
|
+
export interface Settlement {
|
|
7
|
+
created: isoly.DateTime
|
|
8
|
+
batch: pax2pay.Settlement.Batch
|
|
9
|
+
totals: Settlement.Totals
|
|
10
|
+
}
|
|
11
|
+
export namespace Settlement {
|
|
12
|
+
export type Totals = Partial<Record<isoly.Currency, Record<"amount" | "interchange", number>>>
|
|
13
|
+
export namespace Totals {
|
|
14
|
+
export const type = isly.record<Totals>(
|
|
15
|
+
isly.fromIs("isoly.Currency", isoly.Currency.is),
|
|
16
|
+
isly.object<Record<"amount" | "interchange", number>>({
|
|
17
|
+
amount: isly.number(),
|
|
18
|
+
interchange: isly.number(),
|
|
19
|
+
})
|
|
20
|
+
)
|
|
21
|
+
export function from(authorizations: Authorization[]): Totals {
|
|
22
|
+
return authorizations.reduce((totals, authorization) => {
|
|
23
|
+
totals[authorization.amount[0]] = {
|
|
24
|
+
amount: (totals[authorization.amount[0]]?.amount ?? 0) + authorization.amount[1],
|
|
25
|
+
interchange:
|
|
26
|
+
(totals[authorization.amount[0]]?.interchange ?? 0) +
|
|
27
|
+
isoly.Currency.multiply(authorization.amount[0], authorization.amount[1], 0.02),
|
|
28
|
+
}
|
|
29
|
+
return totals
|
|
30
|
+
}, {} as Totals)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export const type = isly.object<Settlement>({
|
|
34
|
+
created: isly.fromIs("isoly.DateTime", isoly.DateTime.is),
|
|
35
|
+
batch: pax2pay.Settlement.Batch.type,
|
|
36
|
+
totals: Totals.type,
|
|
37
|
+
})
|
|
38
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { isoly } from "isoly";
|
|
2
|
+
import { pax2pay } from "@pax2pay/model-banking";
|
|
3
|
+
import { isly } from "isly";
|
|
4
|
+
export var Creatable;
|
|
5
|
+
(function (Creatable) {
|
|
6
|
+
Creatable.type = isly.object({
|
|
7
|
+
card: isly.string(),
|
|
8
|
+
preset: isly.string(),
|
|
9
|
+
amount: isly.tuple(isly.fromIs("isoly.Currency", isoly.Currency.is), isly.number()),
|
|
10
|
+
merchant: pax2pay.Merchant.type,
|
|
11
|
+
acquirer: pax2pay.Acquirer.type,
|
|
12
|
+
description: isly.string(),
|
|
13
|
+
});
|
|
14
|
+
})(Creatable || (Creatable = {}));
|
|
15
|
+
//# sourceMappingURL=Creatable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Creatable.js","sourceRoot":"","sources":["../../Authorization/Creatable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAW3B,MAAM,KAAW,SAAS,CASzB;AATD,WAAiB,SAAS;IACZ,cAAI,GAAG,IAAI,CAAC,MAAM,CAAY;QAC1C,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE;QACnB,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE;QACrB,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;QACnF,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI;QAC/B,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI;QAC/B,WAAW,EAAE,IAAI,CAAC,MAAM,EAAE;KAC1B,CAAC,CAAA;AACH,CAAC,EATgB,SAAS,KAAT,SAAS,QASzB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { cryptly } from "cryptly";
|
|
2
|
+
import { isoly } from "isoly";
|
|
3
|
+
import { pax2pay } from "@pax2pay/model-banking";
|
|
4
|
+
import { isly } from "isly";
|
|
5
|
+
import { Creatable as AuthorizationCreatable } from "./Creatable";
|
|
6
|
+
export var Authorization;
|
|
7
|
+
(function (Authorization) {
|
|
8
|
+
Authorization.Creatable = AuthorizationCreatable;
|
|
9
|
+
function fromCreatable(authorization) {
|
|
10
|
+
return {
|
|
11
|
+
id: pax2pay.Identifier.generate(),
|
|
12
|
+
card: authorization.card,
|
|
13
|
+
created: isoly.DateTime.now(),
|
|
14
|
+
amount: authorization.amount,
|
|
15
|
+
merchant: authorization.merchant,
|
|
16
|
+
acquirer: authorization.acquirer,
|
|
17
|
+
description: authorization.description,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
Authorization.fromCreatable = fromCreatable;
|
|
21
|
+
function from(id, authorization) {
|
|
22
|
+
return {
|
|
23
|
+
id,
|
|
24
|
+
number: authorization.id,
|
|
25
|
+
status: authorization.status == "approved" ? "approved" : undefined,
|
|
26
|
+
card: authorization.card.id,
|
|
27
|
+
created: authorization.created,
|
|
28
|
+
amount: authorization.amount,
|
|
29
|
+
merchant: authorization.merchant,
|
|
30
|
+
acquirer: authorization.acquirer,
|
|
31
|
+
description: authorization.description,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
Authorization.from = from;
|
|
35
|
+
Authorization.type = isly.object({
|
|
36
|
+
id: isly.fromIs("Authorization.id", cryptly.Identifier.is),
|
|
37
|
+
number: isly.fromIs("Authorization.id", cryptly.Identifier.is).optional(),
|
|
38
|
+
card: isly.string(),
|
|
39
|
+
created: isly.fromIs("Authorization.created", isoly.DateTime.is),
|
|
40
|
+
amount: isly.tuple(isly.fromIs("isoly.Currency", isoly.Currency.is), isly.number()),
|
|
41
|
+
merchant: pax2pay.Merchant.type,
|
|
42
|
+
acquirer: pax2pay.Acquirer.type,
|
|
43
|
+
description: isly.string(),
|
|
44
|
+
status: isly.string("approved").optional(),
|
|
45
|
+
});
|
|
46
|
+
})(Authorization || (Authorization = {}));
|
|
47
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../Authorization/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AAChD,OAAO,EAAE,IAAI,EAAE,MAAM,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E,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE;QACzE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE;QACnB,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,uBAAuB,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;QAChE,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,gBAAgB,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;QACnF,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI;QAC/B,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,IAAI;QAC/B,WAAW,EAAE,IAAI,CAAC,MAAM,EAAE;QAC1B,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,QAAQ,EAAE;KAC1C,CAAC,CAAA;AACH,CAAC,EAtCgB,aAAa,KAAb,aAAa,QAsC7B"}
|
package/dist/Batch.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { isoly } from "isoly";
|
|
2
|
+
export var Batch;
|
|
3
|
+
(function (Batch) {
|
|
4
|
+
function is(batch) {
|
|
5
|
+
return typeof batch == "string" && batch.length === 9 && /^\d{4}[0-3]\d{2}0[1-4]$/.test(batch);
|
|
6
|
+
}
|
|
7
|
+
Batch.is = is;
|
|
8
|
+
function from(time) {
|
|
9
|
+
return `${isoly.DateTime.getYear(time)}${dayOfYear(time)}0${cycle(time)}`;
|
|
10
|
+
}
|
|
11
|
+
Batch.from = from;
|
|
12
|
+
function dayOfYear(time) {
|
|
13
|
+
const ms = isoly.DateTime.epoch(time, "milliseconds") -
|
|
14
|
+
isoly.DateTime.epoch(`${Number.parseInt(time.slice(0, 4))}-01-01T00:00:00.000Z`, "milliseconds");
|
|
15
|
+
return (Math.floor(ms / 1000 / 60 / 60 / 24) + 1).toString().padStart(3, "0");
|
|
16
|
+
}
|
|
17
|
+
Batch.dayOfYear = dayOfYear;
|
|
18
|
+
function cycle(time) {
|
|
19
|
+
return Math.floor(isoly.DateTime.getHour(time) / 6) + 1;
|
|
20
|
+
}
|
|
21
|
+
Batch.cycle = cycle;
|
|
22
|
+
function previous(time = isoly.DateTime.now()) {
|
|
23
|
+
return from(isoly.DateTime.previousHour(time, 6));
|
|
24
|
+
}
|
|
25
|
+
Batch.previous = previous;
|
|
26
|
+
function toPrefix(batch) {
|
|
27
|
+
return `${isoly.Date.invert(isoly.Date.next(`${batch.slice(0, 4)}-01-01`, Number.parseInt(batch.slice(4, 7)) - 1))}|${batch.slice(-1)}`;
|
|
28
|
+
}
|
|
29
|
+
Batch.toPrefix = toPrefix;
|
|
30
|
+
})(Batch || (Batch = {}));
|
|
31
|
+
//# sourceMappingURL=Batch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Batch.js","sourceRoot":"","sources":["../Batch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AAG7B,MAAM,KAAW,KAAK,CAwBrB;AAxBD,WAAiB,KAAK;IACrB,SAAgB,EAAE,CAAC,KAAU;QAC5B,OAAO,OAAO,KAAK,IAAI,QAAQ,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,yBAAyB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC/F,CAAC;IAFe,QAAE,KAEjB,CAAA;IACD,SAAgB,IAAI,CAAC,IAAoB;QACxC,OAAO,GAAG,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,EAAW,CAAA;IACnF,CAAC;IAFe,UAAI,OAEnB,CAAA;IACD,SAAgB,SAAS,CAAC,IAAoB;QAC7C,MAAM,EAAE,GACP,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,cAAc,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