Skip to content

Commit 5ebee6a

Browse files
authored
feat: rename composite functionality to recurrence (#35)
1 parent 306ecbb commit 5ebee6a

File tree

13 files changed

+92
-105
lines changed

13 files changed

+92
-105
lines changed

src/assembler.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,11 @@ export function generatePixObject<T extends PixElementType>(
3434
? {
3535
fetchPayload: ({ DPP, codMun }) =>
3636
fetchPayload({ url: elements.url, DPP, codMun }),
37+
fetchRecPayload: () => fetchRecPayload({ url: elements.urlRec }),
3738
}
3839
: {}),
39-
...(elements.type === PixElementType.COMPOSITE
40+
...(elements.type === PixElementType.RECURRENCE
4041
? {
41-
fetchPayload: elements.url
42-
? ({ DPP, codMun }) =>
43-
fetchPayload({ url: elements.url, DPP, codMun })
44-
: undefined,
4542
fetchRecPayload: () => fetchRecPayload({ url: elements.urlRec }),
4643
}
4744
: {}),

src/create.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { generatePixObject } from './assembler';
22
import {
3-
CreateCompositePixParams,
43
CreateDynamicPixParams,
4+
CreateRecurrencePixParams,
55
CreateStaticPixParams,
66
} from './types/pixCreate';
77
import {
8-
CompositePixEmvElements,
98
DynamicPixEmvElements,
10-
PixCompositeObject,
9+
PixRecurrenceObject,
1110
PixDynamicObject,
1211
PixElementType,
1312
PixStaticObject,
1413
StaticPixEmvElements,
14+
RecurrencePixEmvElements,
1515
} from './types/pixElements';
1616
import { PixError } from './types/pixError';
1717
import { generateErrorObject } from './utils/generateErrorObject';
@@ -66,17 +66,16 @@ export function createDynamicPix(
6666

6767
const elements = {
6868
type: PixElementType.DYNAMIC,
69-
urlRec: undefined,
7069
...defaultStaticFields,
7170
...params,
7271
} as DynamicPixEmvElements;
7372

7473
return generatePixObject(elements) as PixDynamicObject;
7574
}
7675

77-
export function createCompositePix(
78-
params: CreateCompositePixParams
79-
): PixCompositeObject | PixError {
76+
export function createRecurrencePix(
77+
params: CreateRecurrencePixParams
78+
): PixRecurrenceObject | PixError {
8079
if (params.merchantName.length > 25)
8180
return generateErrorObject('merchantName character limit exceeded (> 25)');
8281

@@ -87,10 +86,11 @@ export function createCompositePix(
8786
return generateErrorObject('merchantCity character limit exceeded (> 15)');
8887

8988
const elements = {
90-
type: PixElementType.COMPOSITE,
89+
type: PixElementType.RECURRENCE,
9190
...defaultStaticFields,
9291
...params,
93-
} as CompositePixEmvElements;
92+
url: undefined,
93+
} as RecurrencePixEmvElements;
9494

95-
return generatePixObject(elements) as PixCompositeObject;
95+
return generatePixObject(elements) as PixRecurrenceObject;
9696
}

src/emvHandler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function generateMAI(elements: PixElements): string {
2727
].join('');
2828
} else if (
2929
elements.type === PixElementType.DYNAMIC ||
30-
elements.type === PixElementType.COMPOSITE
30+
elements.type === PixElementType.RECURRENCE
3131
) {
3232
return [
3333
generateEmvElement(EmvMaiSchema.TAG_MAI_GUI, EmvMaiSchema.BC_GUI),
@@ -46,7 +46,7 @@ export function createEmv(elements: PixElements): string {
4646
![
4747
PixElementType.STATIC,
4848
PixElementType.DYNAMIC,
49-
PixElementType.COMPOSITE,
49+
PixElementType.RECURRENCE,
5050
].includes(elements.type)
5151
)
5252
return 'INVALID';

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
export {
22
createDynamicPix,
33
createStaticPix,
4-
createCompositePix,
4+
createRecurrencePix,
55
} from './create';
66
export { parsePix } from './parser';
77
export {
88
hasError,
99
isStaticPix,
1010
isDynamicPix,
11-
isCompositePix,
11+
isRecurrencePix,
1212
} from './validate';
1313
export { PixError } from './types/pixError';
1414
export * from './types/pixElements';

src/parser.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function extractElements(
5151
emvElements: ValidTags
5252
): PixElements | PixError {
5353
const basicElements = extractMandatoryElements(emvElements);
54-
const isComposite = isPix(emvElements, 'composite');
54+
const isRecurrence = isPix(emvElements, 'recurrence');
5555
if (isPix(emvElements, 'static')) {
5656
const amountNumber = +emvElements.getTag(EmvSchema.TAG_TRANSACTION_AMOUNT);
5757
const transactionAmount = !isNaN(amountNumber) ? amountNumber : 0;
@@ -72,7 +72,7 @@ export function extractElements(
7272
EmvSchema.TAG_ADDITIONAL_DATA
7373
),
7474
fss: emvElements.getSubTag(EmvMaiSchema.TAG_MAI_FSS, EmvSchema.TAG_MAI),
75-
urlRec: isComposite
75+
urlRec: isRecurrence
7676
? emvElements.getSubTag(
7777
EmvMaiSchema.TAG_MAI_URL,
7878
EmvSchema.TAG_UNRESERVED_TEMPLATE
@@ -82,30 +82,24 @@ export function extractElements(
8282
}
8383

8484
if (isPix(emvElements, 'dynamic')) {
85-
if (isComposite) {
86-
return {
87-
type: PixElementType.COMPOSITE,
88-
...basicElements,
89-
url: emvElements.getSubTag(EmvMaiSchema.TAG_MAI_URL, EmvSchema.TAG_MAI),
90-
urlRec: emvElements.getSubTag(
91-
EmvMaiSchema.TAG_MAI_URL,
92-
EmvSchema.TAG_UNRESERVED_TEMPLATE
93-
),
94-
};
95-
}
96-
9785
return {
9886
type: PixElementType.DYNAMIC,
9987
...basicElements,
10088
url: emvElements.getSubTag(EmvMaiSchema.TAG_MAI_URL, EmvSchema.TAG_MAI),
101-
urlRec: undefined,
89+
urlRec: isRecurrence
90+
? emvElements.getSubTag(
91+
EmvMaiSchema.TAG_MAI_URL,
92+
EmvSchema.TAG_UNRESERVED_TEMPLATE
93+
)
94+
: undefined,
10295
};
10396
}
10497

105-
if (isComposite) {
98+
if (isRecurrence) {
10699
return {
107-
type: PixElementType.COMPOSITE,
100+
type: PixElementType.RECURRENCE,
108101
...basicElements,
102+
url: undefined,
109103
urlRec: emvElements.getSubTag(
110104
EmvMaiSchema.TAG_MAI_URL,
111105
EmvSchema.TAG_UNRESERVED_TEMPLATE

src/types/pixCreate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ export type CreateDynamicPixParams = {
1515
merchantName: string;
1616
merchantCity: string;
1717
url: string;
18+
urlRec?: string;
1819
oneTime?: boolean;
1920
};
2021

21-
export type CreateCompositePixParams = {
22+
export type CreateRecurrencePixParams = {
2223
merchantName: string;
2324
merchantCity: string;
2425
oneTime?: boolean;
25-
url?: string;
2626
urlRec: string;
2727
};

src/types/pixElements.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ValueOf } from './helpers';
2-
import { PixCompositeFn, PixDynamicFn, PixStaticFn } from './pixFunctions';
2+
import { PixDynamicFn, PixRecurrenceFn, PixStaticFn } from './pixFunctions';
33

44
export interface PixEmvMandatoryElements {
55
readonly merchantCategoryCode: string; // EL52
@@ -15,20 +15,20 @@ export interface PixEmvBasicElements extends PixEmvMandatoryElements {
1515

1616
export enum PixElementType {
1717
DYNAMIC = 'DYNAMIC',
18-
COMPOSITE = 'COMPOSITE',
1918
STATIC = 'STATIC',
19+
RECURRENCE = 'RECURRENCE',
2020
INVALID = 'INVALID',
2121
}
2222

2323
export interface DynamicPixEmvElements extends PixEmvBasicElements {
2424
readonly type: PixElementType.DYNAMIC;
2525
readonly url: string;
26-
readonly urlRec: undefined;
26+
readonly urlRec?: string;
2727
}
2828

29-
export interface CompositePixEmvElements extends PixEmvBasicElements {
30-
readonly type: PixElementType.COMPOSITE;
31-
readonly url?: string;
29+
export interface RecurrencePixEmvElements extends PixEmvBasicElements {
30+
readonly type: PixElementType.RECURRENCE;
31+
readonly url: undefined;
3232
readonly urlRec: string;
3333
}
3434

@@ -51,18 +51,18 @@ export type PixElement = {
5151
[PixElementType.DYNAMIC]: DynamicPixEmvElements;
5252
[PixElementType.STATIC]: StaticPixEmvElements;
5353
[PixElementType.INVALID]: InvalidPixEmvElements;
54-
[PixElementType.COMPOSITE]: CompositePixEmvElements;
54+
[PixElementType.RECURRENCE]: RecurrencePixEmvElements;
5555
};
5656
export type PixElements =
5757
| StaticPixEmvElements
5858
| DynamicPixEmvElements
59-
| CompositePixEmvElements;
59+
| RecurrencePixEmvElements;
6060

6161
export type PixObject = {
6262
[PixElementType.DYNAMIC]: DynamicPixEmvElements;
6363
[PixElementType.STATIC]: StaticPixEmvElements;
6464
[PixElementType.INVALID]: InvalidPixEmvElements;
65-
[PixElementType.COMPOSITE]: CompositePixEmvElements;
65+
[PixElementType.RECURRENCE]: RecurrencePixEmvElements;
6666
};
6767

6868
export type PixObjects = ValueOf<PixObject>;
@@ -71,4 +71,4 @@ export type PixStaticObject = StaticPixEmvElements & PixStaticFn;
7171

7272
export type PixDynamicObject = DynamicPixEmvElements & PixDynamicFn;
7373

74-
export type PixCompositeObject = CompositePixEmvElements & PixCompositeFn;
74+
export type PixRecurrenceObject = RecurrencePixEmvElements & PixRecurrenceFn;

src/types/pixFunctions.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { PIXFetchResults } from '../dynamicPayload';
22
import {
3-
PixCompositeObject,
43
PixDynamicObject,
4+
PixRecurrenceObject,
55
PixStaticObject,
66
} from './pixElements';
77
import { PixError } from './pixError';
@@ -25,13 +25,11 @@ export interface PixDynamicFn extends PixFnDefault {
2525
readonly fetchPayload: (
2626
params: FetchPayloadParams
2727
) => Promise<PIXFetchResults | PixError>;
28+
readonly fetchRecPayload?: () => Promise<PIXFetchResults | PixError>;
2829
readonly throwIfError: () => PixDynamicObject;
2930
}
3031

31-
export interface PixCompositeFn extends PixFnDefault {
32-
readonly fetchPayload?: (
33-
params: FetchPayloadParams
34-
) => Promise<PIXFetchResults | PixError>;
32+
export interface PixRecurrenceFn extends PixFnDefault {
3533
readonly fetchRecPayload: () => Promise<PIXFetchResults | PixError>;
36-
readonly throwIfError: () => PixCompositeObject;
34+
readonly throwIfError: () => PixRecurrenceObject;
3735
}

src/validate.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import {
2-
PixCompositeObject,
32
PixDynamicObject,
43
PixElements,
54
PixElementType,
65
PixObjects,
6+
PixRecurrenceObject,
77
PixStaticObject,
88
} from './types/pixElements';
99
import { EmvMaiSchema, EmvSchema, ValidTags } from './types/pixEmvSchema';
1010
import { PixError } from './types/pixError';
1111

1212
export function isPix(
1313
emvElements: ValidTags,
14-
test: 'pix' | 'valid' | 'static' | 'dynamic' | 'composite'
14+
test: 'pix' | 'valid' | 'static' | 'dynamic' | 'recurrence'
1515
): boolean {
1616
if (!emvElements.getTag(EmvSchema.TAG_MAI)) return false;
1717

@@ -24,7 +24,7 @@ export function isPix(
2424
EmvSchema.TAG_MAI
2525
);
2626

27-
const isComposite = emvElements.getSubTag(
27+
const isRecurrence = emvElements.getSubTag(
2828
EmvMaiSchema.TAG_MAI_URL,
2929
EmvSchema.TAG_UNRESERVED_TEMPLATE
3030
);
@@ -33,13 +33,13 @@ export function isPix(
3333
case 'pix':
3434
return true;
3535
case 'valid':
36-
return !!isStatic || !!isDynamic || !!isComposite;
36+
return !!isStatic || !!isDynamic || !!isRecurrence;
3737
case 'static':
3838
return !!isStatic;
3939
case 'dynamic':
4040
return !!isDynamic;
41-
case 'composite':
42-
return !!isComposite;
41+
case 'recurrence':
42+
return !!isRecurrence;
4343
default:
4444
return false;
4545
}
@@ -69,8 +69,8 @@ export function isDynamicPix(
6969
return pixElement && pixElement.type === PixElementType.DYNAMIC;
7070
}
7171

72-
export function isCompositePix(
72+
export function isRecurrencePix(
7373
pixElement: PixObjects
74-
): pixElement is PixCompositeObject {
75-
return pixElement && pixElement.type === PixElementType.COMPOSITE;
74+
): pixElement is PixRecurrenceObject {
75+
return pixElement && pixElement.type === PixElementType.RECURRENCE;
7676
}

0 commit comments

Comments
 (0)