@finteqhub/sdk-js 0.1.1
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 +18 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/src/processing.d.ts +11 -0
- package/dist/src/processing.js +83 -0
- package/dist/src/typings.d.ts +29 -0
- package/dist/src/typings.js +1 -0
- package/dist/src/utils.d.ts +1 -0
- package/dist/src/utils.js +11 -0
- package/package.json +21 -0
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# processing-sdk
|
|
2
|
+
|
|
3
|
+
Use `new FinteqHubProcessing(apiUrl: string, fingerprintVisitorId: string, merchantId: string, sessionId: string)` to create an instance of the FinteqHubProcessing object. The FinteqHubProcessing object is your entrypoint to FinteqHub processing SDK.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
const processing = new FinteqHubProcessing('api-url', 'fingerprint-visitor-id', 'merchant-id', 'session-id');
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
## processing.submitForm(data)
|
|
10
|
+
|
|
11
|
+
Use `processing.submitForm` to submit transaction. When called, `processing.submitForm` will attempt to complete any required actions to process transaction. This method returns a Promise which resolves with a string (redirect url) or Error that describes the failure.
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
processing
|
|
15
|
+
.submitForm(data)
|
|
16
|
+
.then(redirectUrl => window.location.replace(redirectUrl))
|
|
17
|
+
.catch(error => console.warn(error));
|
|
18
|
+
```
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SubmitData } from "./typings";
|
|
2
|
+
export declare class FinteqHubProcessing {
|
|
3
|
+
private apiUrl;
|
|
4
|
+
private fingerprintVisitorId;
|
|
5
|
+
private merchantId;
|
|
6
|
+
private sessionId;
|
|
7
|
+
constructor(apiUrl: string, fingerprintVisitorId: string, merchantId: string, sessionId: string);
|
|
8
|
+
submitForm(data: SubmitData): Promise<string>;
|
|
9
|
+
private processOperation;
|
|
10
|
+
private sendPost;
|
|
11
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { uuid } from "./utils";
|
|
2
|
+
export class FinteqHubProcessing {
|
|
3
|
+
constructor(apiUrl, fingerprintVisitorId, merchantId, sessionId) {
|
|
4
|
+
this.apiUrl = apiUrl;
|
|
5
|
+
this.fingerprintVisitorId = fingerprintVisitorId;
|
|
6
|
+
this.merchantId = merchantId;
|
|
7
|
+
this.sessionId = sessionId;
|
|
8
|
+
}
|
|
9
|
+
submitForm(data) {
|
|
10
|
+
const promise = new Promise((resolve, reject) => {
|
|
11
|
+
this.sendPost(`${this.apiUrl}/v2/transactions/submit-form`, data)
|
|
12
|
+
.then((response) => {
|
|
13
|
+
if (response.status === 200) {
|
|
14
|
+
response.json().then((result) => {
|
|
15
|
+
if (result.error) {
|
|
16
|
+
reject(new Error(result.error));
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
this.processOperation(`${this.apiUrl}/v1/operations/${result.operationId}`, resolve, reject);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
response
|
|
25
|
+
.json()
|
|
26
|
+
.then((result) => reject(new Error(result.error)))
|
|
27
|
+
.catch((error) => reject(error));
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
.catch((error) => reject(error));
|
|
31
|
+
});
|
|
32
|
+
return promise;
|
|
33
|
+
}
|
|
34
|
+
processOperation(url, resolve, reject) {
|
|
35
|
+
this.sendPost(url, {})
|
|
36
|
+
.then((response) => {
|
|
37
|
+
if (response.status === 200) {
|
|
38
|
+
response.json().then((result) => {
|
|
39
|
+
if (result.type === "redirect") {
|
|
40
|
+
resolve(result.redirectUrl);
|
|
41
|
+
}
|
|
42
|
+
else if (result.type === "submitForm") {
|
|
43
|
+
let iframe = document.createElement("iframe");
|
|
44
|
+
iframe.src = result.formUrl;
|
|
45
|
+
iframe.style.display = "none";
|
|
46
|
+
document.body.appendChild(iframe);
|
|
47
|
+
iframe.onload = () => {
|
|
48
|
+
this.processOperation(url, resolve, reject);
|
|
49
|
+
if (iframe) {
|
|
50
|
+
document.body.removeChild(iframe);
|
|
51
|
+
iframe = null;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
reject(new Error("unknown process operation type"));
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
else if (response.status === 400) {
|
|
61
|
+
response
|
|
62
|
+
.json()
|
|
63
|
+
.then((result) => reject(new Error(result.error)))
|
|
64
|
+
.catch((error) => reject(error));
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
.catch((error) => reject(error));
|
|
68
|
+
}
|
|
69
|
+
sendPost(url, data) {
|
|
70
|
+
return fetch(url, {
|
|
71
|
+
method: "POST",
|
|
72
|
+
headers: {
|
|
73
|
+
"Content-Type": "application/json;charset=UTF-8",
|
|
74
|
+
"x-merchant-id": this.merchantId,
|
|
75
|
+
"x-request-id": uuid(),
|
|
76
|
+
"x-fingerprint": this.fingerprintVisitorId,
|
|
77
|
+
"x-session-id": this.sessionId,
|
|
78
|
+
"x-project-id": "017cdbcb-ca22-68f1-95a9-edb698dd063c", // todo: fix it
|
|
79
|
+
},
|
|
80
|
+
body: JSON.stringify(data),
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export declare type Card = {
|
|
2
|
+
number: string;
|
|
3
|
+
holderName: string;
|
|
4
|
+
expiryMonth: number;
|
|
5
|
+
expiryYear: number;
|
|
6
|
+
CVV: string;
|
|
7
|
+
};
|
|
8
|
+
export declare type Payer = {
|
|
9
|
+
firstName: string;
|
|
10
|
+
lastName: string;
|
|
11
|
+
email: string;
|
|
12
|
+
country: string;
|
|
13
|
+
birthDate: string;
|
|
14
|
+
phoneNumber: string;
|
|
15
|
+
phoneCode: string;
|
|
16
|
+
};
|
|
17
|
+
export declare type BillingAddress = {
|
|
18
|
+
address: string;
|
|
19
|
+
city: string;
|
|
20
|
+
state: string;
|
|
21
|
+
country: string;
|
|
22
|
+
zipCode: string;
|
|
23
|
+
};
|
|
24
|
+
export declare type SubmitData = {
|
|
25
|
+
type: string;
|
|
26
|
+
card: Card;
|
|
27
|
+
billingAddress: BillingAddress;
|
|
28
|
+
payer: Payer;
|
|
29
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function uuid(): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function uuid() {
|
|
2
|
+
let seed = Date.now();
|
|
3
|
+
if (window.performance && typeof window.performance.now === "function") {
|
|
4
|
+
seed += performance.now();
|
|
5
|
+
}
|
|
6
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
7
|
+
const random = (seed + Math.random() * 16) % 16 | 0;
|
|
8
|
+
seed = Math.floor(seed / 16);
|
|
9
|
+
return (c === "x" ? random : random & (0x3 | 0x8)).toString(16);
|
|
10
|
+
});
|
|
11
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@finteqhub/sdk-js",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "SDK for interacting with FinteqHub processing API",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"repository": "https://github.com/finteqhub/sdk-js.git",
|
|
7
|
+
"typings": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist/*"
|
|
10
|
+
],
|
|
11
|
+
"author": "FinteqHub",
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"typescript": "^4.8.3"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc"
|
|
17
|
+
},
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"registry": "https://registry.npmjs.org"
|
|
20
|
+
}
|
|
21
|
+
}
|