@finteqhub/sdk-js 0.2.0 → 0.4.0
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/README.md +36 -3
- package/dist/src/processing.d.ts +4 -2
- package/dist/src/processing.js +60 -34
- package/dist/src/typings.d.ts +81 -5
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -6,13 +6,46 @@ Use `new FinteqHubProcessing(apiUrl: string, fingerprintVisitorId: string, merch
|
|
|
6
6
|
const processing = new FinteqHubProcessing('api-url', 'fingerprint-visitor-id', 'merchant-id', 'session-id');
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## API
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
### processing.getSession()
|
|
12
|
+
|
|
13
|
+
Use `processing.getSession` to get session information.
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
processing
|
|
17
|
+
.getSession()
|
|
18
|
+
.then(result => console.log(result))
|
|
19
|
+
.catch(error => console.warn(error));
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### processing.submitForm(data)
|
|
23
|
+
|
|
24
|
+
Use `processing.submitForm` to submit transaction. When called, `processing.submitForm` will attempt to complete any required actions to process the transaction. This method returns promise which resolves with response (`{ "type": "redirect", "redirectUrl": string}`) or error that describes the failure.
|
|
12
25
|
|
|
13
26
|
```
|
|
14
27
|
processing
|
|
15
28
|
.submitForm(data)
|
|
16
|
-
.then(
|
|
29
|
+
.then(result => console.log(result))
|
|
30
|
+
.catch(error => console.warn(error));
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
import { FinteqHubProcessing } from "@finteqhub/sdk-js";
|
|
37
|
+
import FingerprintJS from "@fingerprintjs/fingerprintjs";
|
|
38
|
+
|
|
39
|
+
const fp = await FingerprintJS.load();
|
|
40
|
+
const result = await fp.get();
|
|
41
|
+
|
|
42
|
+
const processing = new FinteqHubProcessing(apiUrl, result.visitorId, merchantId, sessionId);
|
|
43
|
+
const session = await processing.getSession();
|
|
44
|
+
|
|
45
|
+
const data = {/** collect data from form and session **/}
|
|
46
|
+
|
|
47
|
+
processing
|
|
48
|
+
.submitForm(data)
|
|
49
|
+
.then(result => console.log(result))
|
|
17
50
|
.catch(error => console.warn(error));
|
|
18
51
|
```
|
package/dist/src/processing.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { SubmitData } from "./typings";
|
|
1
|
+
import { ProcessOperationRedirectResponse, SessionResponse, SubmitData } from "./typings";
|
|
2
2
|
export declare class FinteqHubProcessing {
|
|
3
3
|
private apiUrl;
|
|
4
4
|
private fingerprintVisitorId;
|
|
5
5
|
private merchantId;
|
|
6
6
|
private sessionId;
|
|
7
|
+
private projectId;
|
|
7
8
|
constructor(apiUrl: string, fingerprintVisitorId: string, merchantId: string, sessionId: string);
|
|
8
|
-
|
|
9
|
+
getSession(): Promise<SessionResponse>;
|
|
10
|
+
submitForm(data: SubmitData): Promise<ProcessOperationRedirectResponse>;
|
|
9
11
|
private processOperation;
|
|
10
12
|
private sendPost;
|
|
11
13
|
}
|
package/dist/src/processing.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import { uuid } from "./utils";
|
|
2
11
|
export class FinteqHubProcessing {
|
|
3
12
|
constructor(apiUrl, fingerprintVisitorId, merchantId, sessionId) {
|
|
@@ -6,38 +15,56 @@ export class FinteqHubProcessing {
|
|
|
6
15
|
this.merchantId = merchantId;
|
|
7
16
|
this.sessionId = sessionId;
|
|
8
17
|
}
|
|
18
|
+
getSession() {
|
|
19
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
var _a;
|
|
21
|
+
try {
|
|
22
|
+
const response = yield fetch(`${this.apiUrl}/v1/sessions/${this.sessionId}`, {
|
|
23
|
+
method: "GET",
|
|
24
|
+
headers: {
|
|
25
|
+
"Content-Type": "application/json;charset=UTF-8",
|
|
26
|
+
"x-merchant-id": this.merchantId,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
const result = yield response.json();
|
|
30
|
+
if (result.error || response.status !== 200) {
|
|
31
|
+
reject(new Error(result.error));
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
this.projectId = (_a = result.operation) === null || _a === void 0 ? void 0 : _a.projectId;
|
|
35
|
+
resolve(result);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (e) {
|
|
39
|
+
reject(e);
|
|
40
|
+
}
|
|
41
|
+
}));
|
|
42
|
+
}
|
|
9
43
|
submitForm(data) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
reject(new Error(result.error));
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
this.processOperation(`${this.apiUrl}/v1/operations/${result.operationId}`, resolve, reject);
|
|
20
|
-
}
|
|
21
|
-
});
|
|
44
|
+
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
try {
|
|
46
|
+
const response = yield this.sendPost(`${this.apiUrl}/v2/transactions/submit-form`, data);
|
|
47
|
+
const result = yield response.json();
|
|
48
|
+
if (result.error || response.status !== 200) {
|
|
49
|
+
reject(new Error(result.error));
|
|
22
50
|
}
|
|
23
51
|
else {
|
|
24
|
-
|
|
25
|
-
.json()
|
|
26
|
-
.then((result) => reject(new Error(result.error)))
|
|
27
|
-
.catch((error) => reject(error));
|
|
52
|
+
this.processOperation(`${this.apiUrl}/v1/operations/${result.operationId}`, resolve, reject);
|
|
28
53
|
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
reject(e);
|
|
57
|
+
}
|
|
58
|
+
}));
|
|
33
59
|
}
|
|
34
60
|
processOperation(url, resolve, reject) {
|
|
35
|
-
this
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
response.json()
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
try {
|
|
63
|
+
const response = yield this.sendPost(url, {});
|
|
64
|
+
const result = yield response.json();
|
|
65
|
+
if (response.status === 200) {
|
|
39
66
|
if (result.type === "redirect") {
|
|
40
|
-
resolve(result
|
|
67
|
+
resolve(result);
|
|
41
68
|
}
|
|
42
69
|
else if (result.type === "submitForm") {
|
|
43
70
|
let iframe = document.createElement("iframe");
|
|
@@ -55,16 +82,15 @@ export class FinteqHubProcessing {
|
|
|
55
82
|
else {
|
|
56
83
|
reject(new Error("unknown process operation type"));
|
|
57
84
|
}
|
|
58
|
-
}
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
reject(new Error(result.error));
|
|
88
|
+
}
|
|
59
89
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
.json()
|
|
63
|
-
.then((result) => reject(new Error(result.error)))
|
|
64
|
-
.catch((error) => reject(error));
|
|
90
|
+
catch (e) {
|
|
91
|
+
reject(e);
|
|
65
92
|
}
|
|
66
|
-
})
|
|
67
|
-
.catch((error) => reject(error));
|
|
93
|
+
});
|
|
68
94
|
}
|
|
69
95
|
sendPost(url, data) {
|
|
70
96
|
return fetch(url, {
|
|
@@ -75,7 +101,7 @@ export class FinteqHubProcessing {
|
|
|
75
101
|
"x-request-id": uuid(),
|
|
76
102
|
"x-fingerprint": this.fingerprintVisitorId,
|
|
77
103
|
"x-session-id": this.sessionId,
|
|
78
|
-
"x-project-id":
|
|
104
|
+
"x-project-id": this.projectId,
|
|
79
105
|
},
|
|
80
106
|
body: JSON.stringify(data),
|
|
81
107
|
});
|
package/dist/src/typings.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export declare type Card = {
|
|
2
2
|
number: string;
|
|
3
|
-
|
|
3
|
+
holder: string;
|
|
4
4
|
expiryMonth: number;
|
|
5
5
|
expiryYear: number;
|
|
6
6
|
CVV: string;
|
|
7
|
+
tokenize: boolean;
|
|
7
8
|
};
|
|
8
9
|
export declare type Payer = {
|
|
9
10
|
firstName: string;
|
|
@@ -12,18 +13,93 @@ export declare type Payer = {
|
|
|
12
13
|
country: string;
|
|
13
14
|
birthDate: string;
|
|
14
15
|
phoneNumber: string;
|
|
15
|
-
|
|
16
|
+
phoneCountryCode: string;
|
|
16
17
|
};
|
|
17
|
-
export declare type
|
|
18
|
+
export declare type Address = {
|
|
18
19
|
address: string;
|
|
19
20
|
city: string;
|
|
20
21
|
state: string;
|
|
21
22
|
country: string;
|
|
22
|
-
|
|
23
|
+
postalCode: string;
|
|
24
|
+
};
|
|
25
|
+
export declare type SessionResponse = {
|
|
26
|
+
customer?: Customer;
|
|
27
|
+
initCredentials: {
|
|
28
|
+
billingAddress?: Address;
|
|
29
|
+
card?: Card;
|
|
30
|
+
payer?: Payer;
|
|
31
|
+
shippingAddress: Address;
|
|
32
|
+
};
|
|
33
|
+
operation: OperationSession;
|
|
34
|
+
paymentMethods: PaymentMethods;
|
|
35
|
+
session: Session;
|
|
36
|
+
};
|
|
37
|
+
export interface Customer {
|
|
38
|
+
accounts?: CustomerAccount[];
|
|
39
|
+
country?: string;
|
|
40
|
+
id: string;
|
|
41
|
+
merchantCustomerId: string;
|
|
42
|
+
name?: string;
|
|
43
|
+
projectId: string;
|
|
44
|
+
}
|
|
45
|
+
export declare type CustomerAccount = {
|
|
46
|
+
id?: string;
|
|
47
|
+
integrationAccountId?: string;
|
|
48
|
+
paymentMethod?: string;
|
|
49
|
+
status?: string;
|
|
50
|
+
metadata?: any;
|
|
51
|
+
};
|
|
52
|
+
export declare type OperationSession = {
|
|
53
|
+
amount: string;
|
|
54
|
+
currencyCode: string;
|
|
55
|
+
failUrl: string;
|
|
56
|
+
operationId: string;
|
|
57
|
+
projectId: string;
|
|
58
|
+
successUrl: string;
|
|
59
|
+
transactionId: string;
|
|
60
|
+
transactionType: string;
|
|
61
|
+
};
|
|
62
|
+
export declare type PaymentMethods = {
|
|
63
|
+
credentials: {
|
|
64
|
+
[key: string]: {
|
|
65
|
+
fields?: {
|
|
66
|
+
[key: string]: FieldDetails;
|
|
67
|
+
};
|
|
68
|
+
required?: Array<string>;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
paymentMethods: {
|
|
72
|
+
[key: string]: {
|
|
73
|
+
friendlyName?: string;
|
|
74
|
+
logo?: string;
|
|
75
|
+
credentials?: string;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
export declare type Session = {
|
|
80
|
+
ttl: number;
|
|
81
|
+
createdAt: string;
|
|
82
|
+
};
|
|
83
|
+
export declare type FieldDetails = {
|
|
84
|
+
type?: string;
|
|
85
|
+
friendlyName?: string;
|
|
86
|
+
description?: string;
|
|
87
|
+
format?: string;
|
|
88
|
+
example?: string;
|
|
23
89
|
};
|
|
24
90
|
export declare type SubmitData = {
|
|
25
91
|
type: string;
|
|
26
92
|
card: Card;
|
|
27
|
-
billingAddress:
|
|
93
|
+
billingAddress: Address;
|
|
28
94
|
payer: Payer;
|
|
29
95
|
};
|
|
96
|
+
export declare type ProcessOperationRedirectResponse = {
|
|
97
|
+
type: "redirect";
|
|
98
|
+
redirectUrl: string;
|
|
99
|
+
metadata: unknown;
|
|
100
|
+
};
|
|
101
|
+
export declare type ProcessOperationResponse = {
|
|
102
|
+
type: "submitForm";
|
|
103
|
+
formUrl: string;
|
|
104
|
+
metadata: unknown;
|
|
105
|
+
} | ProcessOperationRedirectResponse;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@finteqhub/sdk-js",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "SDK for interacting with FinteqHub processing API",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"typings": "./dist/index.d.ts",
|
|
@@ -9,10 +9,16 @@
|
|
|
9
9
|
],
|
|
10
10
|
"author": "FinteqHub",
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"
|
|
12
|
+
"@types/jest": "^29.1.1",
|
|
13
|
+
"jest": "^29.1.2",
|
|
14
|
+
"jest-environment-jsdom": "^29.1.2",
|
|
15
|
+
"ts-jest": "^29.0.3",
|
|
16
|
+
"typescript": "^4.8.3",
|
|
17
|
+
"whatwg-fetch": "^3.6.2"
|
|
13
18
|
},
|
|
14
19
|
"scripts": {
|
|
15
|
-
"build": "tsc"
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"test": "jest"
|
|
16
22
|
},
|
|
17
23
|
"publishConfig": {
|
|
18
24
|
"registry": "https://registry.npmjs.org"
|