@teamrepeat/card-token 1.0.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 +0 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/useCardToken.d.ts +23 -0
- package/dist/useCardToken.js +40 -0
- package/package.json +20 -0
package/README.md
ADDED
|
File without changes
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useCardToken, CardTokenIframe } from "./useCardToken";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
export interface CardTokenResult {
|
|
3
|
+
success: boolean;
|
|
4
|
+
token?: string;
|
|
5
|
+
error?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const useCardToken: () => {
|
|
8
|
+
loading: boolean;
|
|
9
|
+
result: CardTokenResult | null;
|
|
10
|
+
};
|
|
11
|
+
interface CardTokenIframeProps {
|
|
12
|
+
language: "is" | "en" | "de";
|
|
13
|
+
styles?: {
|
|
14
|
+
borderRadius?: number;
|
|
15
|
+
buttonBackground?: string;
|
|
16
|
+
buttonColor?: string;
|
|
17
|
+
color?: string;
|
|
18
|
+
errorColor?: string;
|
|
19
|
+
fontFamily?: string;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export declare const CardTokenIframe: React.FC<CardTokenIframeProps>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect } from "react";
|
|
3
|
+
export const useCardToken = () => {
|
|
4
|
+
const [loading, setLoading] = useState(false);
|
|
5
|
+
const [result, setResult] = useState(null);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const handleMessage = (event) => {
|
|
8
|
+
if ("repeatCardSaveSuccess" in event.data) {
|
|
9
|
+
const success = event.data.repeatCardSaveSuccess;
|
|
10
|
+
const token = event.data.cardToken;
|
|
11
|
+
setResult({ success, token });
|
|
12
|
+
setLoading(false);
|
|
13
|
+
}
|
|
14
|
+
else if (event.data.type === "cardSaveFailed") {
|
|
15
|
+
setResult({ success: false, error: "Card save failed" });
|
|
16
|
+
setLoading(false);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
window.addEventListener("message", handleMessage);
|
|
20
|
+
return () => window.removeEventListener("message", handleMessage);
|
|
21
|
+
}, []);
|
|
22
|
+
return { loading, result };
|
|
23
|
+
};
|
|
24
|
+
export const CardTokenIframe = ({ language, styles, }) => {
|
|
25
|
+
const { borderRadius, buttonBackground, buttonColor, color, errorColor, fontFamily, } = styles || {};
|
|
26
|
+
let url = `http://localhost:8000/get_card_token_iframe/06f8030a-bab8-45a8-b7bd-bc41fb0cf668/?language=${language || "is"}&languageSelector=false`;
|
|
27
|
+
if (borderRadius != null)
|
|
28
|
+
url += `&borderRadius=${borderRadius}`;
|
|
29
|
+
if (buttonBackground)
|
|
30
|
+
url += `&buttonBackground=${encodeURIComponent(buttonBackground)}`;
|
|
31
|
+
if (buttonColor)
|
|
32
|
+
url += `&buttonColor=${encodeURIComponent(buttonColor)}`;
|
|
33
|
+
if (color)
|
|
34
|
+
url += `&color=${encodeURIComponent(color)}`;
|
|
35
|
+
if (errorColor)
|
|
36
|
+
url += `&errorColor=${encodeURIComponent(errorColor)}`;
|
|
37
|
+
if (fontFamily)
|
|
38
|
+
url += `&fontFamily=${fontFamily}`;
|
|
39
|
+
return (_jsx("div", { style: { width: "100%", height: 600 }, children: _jsx("iframe", { src: url, style: { width: "100%", height: "100%", border: "none" }, title: "Kort" }) }));
|
|
40
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@teamrepeat/card-token",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "React hook and iframe component to fetch card tokens",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"prepublishOnly": "yarn build"
|
|
10
|
+
},
|
|
11
|
+
"author": "Repeat.is",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"react": "^17.0.0 || ^18.0.0"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"typescript": "^5.0.0",
|
|
18
|
+
"@types/react": "^18.0.0"
|
|
19
|
+
}
|
|
20
|
+
}
|