@fat-zebra/sdk 1.0.2 → 1.0.4
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/fat-zebra-sdk-1.0.2.tgz +0 -0
- package/package.json +1 -1
- package/src/index.ts +0 -9
- package/src/react/VerifyCard.tsx +0 -36
- package/src/react/index.ts +0 -3
- package/src/react/url.ts +0 -97
- package/src/react/useFatZebra.ts +0 -154
- package/src/sca/__tests__/eci-mappings.test.ts +0 -35
- package/src/sca/__tests__/index.test.ts +0 -514
- package/src/sca/cardinal.ts +0 -136
- package/src/sca/eci-mappings.ts +0 -63
- package/src/sca/index.ts +0 -329
- package/src/sca/scenarios/enrollment.ts +0 -164
- package/src/sca/scenarios/index.ts +0 -4
- package/src/sca/scenarios/validation.ts +0 -142
- package/src/sca/types.ts +0 -209
- package/src/shared/api-gateway-client.ts +0 -71
- package/src/shared/bridge-client.ts +0 -26
- package/src/shared/constants.ts +0 -19
- package/src/shared/event-manager.ts +0 -45
- package/src/shared/post-message-client.test.ts +0 -73
- package/src/shared/post-message-client.ts +0 -127
- package/src/shared/types.test.ts +0 -65
- package/src/shared/types.ts +0 -182
- package/src/shared/util.test.ts +0 -164
- package/src/shared/util.ts +0 -98
- package/tests/helpers/api-gateway-mock.ts +0 -46
|
Binary file
|
package/package.json
CHANGED
package/src/index.ts
DELETED
package/src/react/VerifyCard.tsx
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import useFatZebra from "./useFatZebra";
|
|
3
|
-
import * as FatZebra from "../shared/types";
|
|
4
|
-
|
|
5
|
-
type FrameProps = {
|
|
6
|
-
handlers: FatZebra.Handlers;
|
|
7
|
-
username: string;
|
|
8
|
-
accessToken: string;
|
|
9
|
-
config: FatZebra.VerificationConfig;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const Frame = ({ username, handlers, config }: FrameProps) => {
|
|
13
|
-
const bridgeRef = React.useRef<HTMLIFrameElement>(null);
|
|
14
|
-
|
|
15
|
-
const { url } = useFatZebra({
|
|
16
|
-
username: username,
|
|
17
|
-
config,
|
|
18
|
-
handlers: handlers,
|
|
19
|
-
bridge: bridgeRef,
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
return (
|
|
23
|
-
<div>
|
|
24
|
-
<iframe src={url} width="100%" height="700px" title="verification-form" />
|
|
25
|
-
<iframe
|
|
26
|
-
title="bridge-form"
|
|
27
|
-
src="http://paynow.test:3004/sdk/bridge"
|
|
28
|
-
width="100%"
|
|
29
|
-
height="700px"
|
|
30
|
-
ref={bridgeRef}
|
|
31
|
-
/>
|
|
32
|
-
</div>
|
|
33
|
-
);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export default Frame;
|
package/src/react/index.ts
DELETED
package/src/react/url.ts
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { parseTemplate } from 'url-template';
|
|
2
|
-
type RequiredURLValues = {
|
|
3
|
-
merchant: string;
|
|
4
|
-
hash: string;
|
|
5
|
-
reference: string;
|
|
6
|
-
amount: number;
|
|
7
|
-
currency: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
type VerificationURLValues = OptionalURLValues & {
|
|
11
|
-
merchant: string;
|
|
12
|
-
timestamp: string;
|
|
13
|
-
verification: string;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
type OptionalURLValues = Partial<{
|
|
17
|
-
hide_card_holder: string;
|
|
18
|
-
return_path: string
|
|
19
|
-
card_types: Array<string>;
|
|
20
|
-
surcharge_enabled: string;
|
|
21
|
-
sca_enabled: boolean;
|
|
22
|
-
css: string;
|
|
23
|
-
css_signature: string;
|
|
24
|
-
tokenize_only: boolean;
|
|
25
|
-
}>
|
|
26
|
-
|
|
27
|
-
type UrlValues = RequiredURLValues & OptionalURLValues
|
|
28
|
-
|
|
29
|
-
const generatePaymentURL = (values: UrlValues) => {
|
|
30
|
-
const queryParts = [
|
|
31
|
-
"tokenize_only",
|
|
32
|
-
"css",
|
|
33
|
-
"css_signature",
|
|
34
|
-
"iframe",
|
|
35
|
-
"postmessage",
|
|
36
|
-
"hide_card_holder",
|
|
37
|
-
"return_path",
|
|
38
|
-
"card_types",
|
|
39
|
-
"surcharge_enabled",
|
|
40
|
-
"sca_enabled",
|
|
41
|
-
]
|
|
42
|
-
|
|
43
|
-
const urlTemplate = parseTemplate(
|
|
44
|
-
`http://paynow.test:3004/sdk/v3/{merchant}/{reference}/{currency}/{amount}/{verification}{?${queryParts.join(",")}}`
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
const url = urlTemplate.expand({
|
|
48
|
-
merchant: values.merchant,
|
|
49
|
-
reference: values.reference,
|
|
50
|
-
currency: values.currency,
|
|
51
|
-
amount: values.amount,
|
|
52
|
-
verification: values.hash,
|
|
53
|
-
sca_enabled: values.sca_enabled,
|
|
54
|
-
css: values.css,
|
|
55
|
-
css_signature: values.css_signature,
|
|
56
|
-
iframe: true,
|
|
57
|
-
postmessage: true,
|
|
58
|
-
tokenize_only: values.tokenize_only,
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
return url;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const generateVerificationURL = (values: VerificationURLValues) => {
|
|
65
|
-
const queryParts = [
|
|
66
|
-
"tokenize_only",
|
|
67
|
-
"css",
|
|
68
|
-
"css_signature",
|
|
69
|
-
"iframe",
|
|
70
|
-
"postmessage",
|
|
71
|
-
"hide_card_holder",
|
|
72
|
-
"return_path",
|
|
73
|
-
"card_types",
|
|
74
|
-
"surcharge_enabled",
|
|
75
|
-
"sca_enabled",
|
|
76
|
-
]
|
|
77
|
-
|
|
78
|
-
const urlTemplate = parseTemplate(
|
|
79
|
-
`http://paynow.test:3004/sdk/v3/{merchant}/verification/{timestamp}/{verification}{?${queryParts.join(",")}}`
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
const url = urlTemplate.expand({
|
|
83
|
-
merchant: values.merchant,
|
|
84
|
-
timestamp: values.timestamp,
|
|
85
|
-
verification: values.verification,
|
|
86
|
-
sca_enabled: values.sca_enabled,
|
|
87
|
-
css: values.css,
|
|
88
|
-
css_signature: values.css_signature,
|
|
89
|
-
iframe: true,
|
|
90
|
-
postmessage: true,
|
|
91
|
-
tokenize_only: values.tokenize_only,
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
return url;
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
export { generatePaymentURL, generateVerificationURL };
|
package/src/react/useFatZebra.ts
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import { useEffect, useMemo } from "react";
|
|
2
|
-
import * as FatZebra from "../shared/types"
|
|
3
|
-
import { generatePaymentURL } from "./url";
|
|
4
|
-
import Sca from "../sca"
|
|
5
|
-
import GatewayClient from "../shared/api-gateway-client";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
interface SuccessEventDetail {
|
|
9
|
-
message: string;
|
|
10
|
-
data: any;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
interface ErrorEventDetail {
|
|
14
|
-
errors: string[];
|
|
15
|
-
data: any;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
type UseFatZebraProps = {
|
|
19
|
-
username: string,
|
|
20
|
-
handlers: FatZebra.Handlers,
|
|
21
|
-
config: FatZebra.VerificationConfig,
|
|
22
|
-
bridge: React.MutableRefObject<HTMLIFrameElement>,
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const useFatZebra = ({ username, config, handlers, bridge }: UseFatZebraProps) => {
|
|
27
|
-
const { options, accessToken, paymentIntent, verification } = config;
|
|
28
|
-
|
|
29
|
-
const sca = useMemo(() => {
|
|
30
|
-
const gatewayClient = new GatewayClient({ accessToken, username })
|
|
31
|
-
return new Sca({ gatewayClient })
|
|
32
|
-
}, [config, username])
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const emit = (
|
|
36
|
-
event: FatZebra.PublicEvent,
|
|
37
|
-
data: SuccessEventDetail | ErrorEventDetail
|
|
38
|
-
) => {
|
|
39
|
-
const handler = handlers[event]
|
|
40
|
-
if (handler) {
|
|
41
|
-
handler(new CustomEvent(event, { detail: data }))
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const handleCreatePaymentResponse = (data: FatZebra.CreatePaymentResponse) => {
|
|
46
|
-
const transactionPayload: FatZebra.TransactionPayload = {
|
|
47
|
-
transactionId: data.transaction_id,
|
|
48
|
-
responseCode: data.response_code,
|
|
49
|
-
message: data.message,
|
|
50
|
-
amount: data.amount,
|
|
51
|
-
currency: data.currency,
|
|
52
|
-
reference: data.reference,
|
|
53
|
-
cardNumber: data.card_number,
|
|
54
|
-
cardHolder: data.card_holder,
|
|
55
|
-
cardExpiry: data.card_expiry,
|
|
56
|
-
cardType: data.card_type,
|
|
57
|
-
verification: data.v,
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (data.errors) {
|
|
61
|
-
emit(FatZebra.PublicEvent.PAYMENT_ERROR, {
|
|
62
|
-
message: 'Payment failed.',
|
|
63
|
-
errors: data.errors,
|
|
64
|
-
data: transactionPayload,
|
|
65
|
-
})
|
|
66
|
-
} else {
|
|
67
|
-
emit(FatZebra.PublicEvent.PAYMENT_SUCCESS, {
|
|
68
|
-
message: 'Payment successful.',
|
|
69
|
-
data: transactionPayload,
|
|
70
|
-
})
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const handleTokenizeCardResponse = (data: FatZebra.TokenizeCardResponse) => {
|
|
75
|
-
if (data.errors) {
|
|
76
|
-
emit(FatZebra.PublicEvent.TOKENIZATION_ERROR, {
|
|
77
|
-
message: "Card tokenization failed.",
|
|
78
|
-
errors: data.errors,
|
|
79
|
-
data: null,
|
|
80
|
-
});
|
|
81
|
-
return;
|
|
82
|
-
} else {
|
|
83
|
-
emit(FatZebra.PublicEvent.TOKENIZATION_SUCCESS, {
|
|
84
|
-
message: "Card tokenization success.",
|
|
85
|
-
data: {
|
|
86
|
-
token: data.token,
|
|
87
|
-
},
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (options.tokenizeOnly) return
|
|
92
|
-
|
|
93
|
-
if (options.enableSca) {
|
|
94
|
-
sca.run({ paymentIntent, bin: data.bin, cardToken: data.token })
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const messageHandler = (event: any) => {
|
|
99
|
-
if (
|
|
100
|
-
event.data &&
|
|
101
|
-
event.data.source &&
|
|
102
|
-
event.data.source.includes("react-devtools")
|
|
103
|
-
)
|
|
104
|
-
return;
|
|
105
|
-
if (event.data.subject === FatZebra.BridgeEvent.BIN_LOOKUP) return;
|
|
106
|
-
|
|
107
|
-
if (event.data.subject === FatZebra.BridgeEvent.FORM_VALIDATION_ERROR) {
|
|
108
|
-
emit(FatZebra.PublicEvent.FORM_VALIDATION_ERROR, {
|
|
109
|
-
errors: event.data.data,
|
|
110
|
-
data: null,
|
|
111
|
-
});
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (event.data.subject === FatZebra.BridgeEvent.FORM_VALIDATION_SUCCESS) {
|
|
116
|
-
emit(FatZebra.PublicEvent.FORM_VALIDATION_SUCCESS, {
|
|
117
|
-
errors: event.data.data,
|
|
118
|
-
data: null,
|
|
119
|
-
});
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (event.data.subject === FatZebra.BridgeEvent.CREATE_PAYMENT_RESPONSE) {
|
|
124
|
-
handleCreatePaymentResponse(event.data.data)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (event.data.subject === FatZebra.BridgeEvent.TOKENIZE_CARD_RESPONSE) {
|
|
128
|
-
handleTokenizeCardResponse(event.data.data)
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
useEffect(() => {
|
|
133
|
-
window.addEventListener("message", messageHandler);
|
|
134
|
-
|
|
135
|
-
return () => {
|
|
136
|
-
window.removeEventListener("message", messageHandler);
|
|
137
|
-
};
|
|
138
|
-
}, []);
|
|
139
|
-
|
|
140
|
-
const payment = paymentIntent.payment
|
|
141
|
-
|
|
142
|
-
const url = generatePaymentURL({
|
|
143
|
-
...options,
|
|
144
|
-
merchant: username,
|
|
145
|
-
reference: payment.reference,
|
|
146
|
-
amount: payment.amount,
|
|
147
|
-
currency: payment.currency,
|
|
148
|
-
hash: verification,
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
return { url }
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
export default useFatZebra;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { eciMappings, toFzSli } from '../eci-mappings'
|
|
2
|
-
|
|
3
|
-
describe ('toFzSli', () => {
|
|
4
|
-
describe ('ECI mapping exists', () => {
|
|
5
|
-
it ('sli mapping => cardinal: 00, fz: 07', () => {
|
|
6
|
-
expect(toFzSli('00')).toEqual('07')
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
it ('sli mapping => cardinal: 01, fz: 06', () => {
|
|
10
|
-
expect(toFzSli('01')).toEqual('06')
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
it ('sli mapping => cardinal: 02, fz: 05', () => {
|
|
14
|
-
expect(toFzSli('02')).toEqual('05')
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
it ('sli mapping => cardinal: 05, fz: 05', () => {
|
|
18
|
-
expect(toFzSli('05')).toEqual('05')
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
it ('sli mapping => cardinal: 06, fz: 06', () => {
|
|
22
|
-
expect(toFzSli('06')).toEqual('06')
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
it ('sli mapping => cardinal: 07, fz: 07', () => {
|
|
26
|
-
expect(toFzSli('07')).toEqual('07')
|
|
27
|
-
})
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
describe ('ECI mapping does not exist', () => {
|
|
31
|
-
it ('sli mapping => cardinal: 09, fz: 09', () => {
|
|
32
|
-
expect(toFzSli('09')).toEqual('09')
|
|
33
|
-
})
|
|
34
|
-
})
|
|
35
|
-
})
|