@paykit-sdk/react 1.1.9 → 1.1.91
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 +2 -2
- package/dist/hooks/use-async-fn.d.mts +9 -0
- package/dist/hooks/use-async-fn.d.ts +9 -0
- package/dist/hooks/use-async-fn.js +56 -0
- package/dist/hooks/use-async-fn.mjs +34 -0
- package/dist/index.d.mts +11 -148
- package/dist/index.d.ts +11 -148
- package/dist/index.js +139 -92
- package/dist/index.mjs +113 -52
- package/dist/resources/checkout.d.mts +22 -0
- package/dist/resources/checkout.d.ts +22 -0
- package/dist/resources/checkout.js +89 -0
- package/dist/resources/checkout.mjs +67 -0
- package/dist/resources/customer.d.mts +22 -0
- package/dist/resources/customer.d.ts +22 -0
- package/dist/resources/customer.js +89 -0
- package/dist/resources/customer.mjs +67 -0
- package/dist/resources/payment.d.mts +31 -0
- package/dist/resources/payment.d.ts +31 -0
- package/dist/resources/payment.js +95 -0
- package/dist/resources/payment.mjs +73 -0
- package/dist/resources/refund.d.mts +10 -0
- package/dist/resources/refund.d.ts +10 -0
- package/dist/resources/refund.js +74 -0
- package/dist/resources/refund.mjs +52 -0
- package/dist/resources/subscription.d.mts +26 -0
- package/dist/resources/subscription.d.ts +26 -0
- package/dist/resources/subscription.js +94 -0
- package/dist/resources/subscription.mjs +72 -0
- package/package.json +3 -3
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
require('react/jsx-runtime');
|
|
5
|
+
|
|
6
|
+
function _interopNamespace(e) {
|
|
7
|
+
if (e && e.__esModule) return e;
|
|
8
|
+
var n = Object.create(null);
|
|
9
|
+
if (e) {
|
|
10
|
+
Object.keys(e).forEach(function (k) {
|
|
11
|
+
if (k !== 'default') {
|
|
12
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return e[k]; }
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
n.default = e;
|
|
21
|
+
return Object.freeze(n);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
25
|
+
|
|
26
|
+
// src/context.tsx
|
|
27
|
+
var PaykitContext = React__namespace.createContext(void 0);
|
|
28
|
+
var usePaykitContext = () => {
|
|
29
|
+
const ctx = React__namespace.useContext(PaykitContext);
|
|
30
|
+
if (!ctx) throw new Error("Your app must be wrapped in PayKitProvider to use PayKit hooks.");
|
|
31
|
+
return ctx;
|
|
32
|
+
};
|
|
33
|
+
var useAsyncFn = (path, apiUrl, headersEsque) => {
|
|
34
|
+
const [loading, setLoading] = React__namespace.useState(false);
|
|
35
|
+
const run = React__namespace.useCallback(
|
|
36
|
+
async (...args) => {
|
|
37
|
+
setLoading(true);
|
|
38
|
+
try {
|
|
39
|
+
const headers = typeof headersEsque === "function" ? headersEsque() : headersEsque != null ? headersEsque : {};
|
|
40
|
+
const response = await fetch(`${apiUrl}${path}`, {
|
|
41
|
+
method: "POST",
|
|
42
|
+
headers: { "Content-Type": "application/json", ...headers },
|
|
43
|
+
credentials: "include",
|
|
44
|
+
body: JSON.stringify({ args })
|
|
45
|
+
});
|
|
46
|
+
if (!response.ok) {
|
|
47
|
+
const errorData = await response.json().catch(() => ({ message: "Request failed" }));
|
|
48
|
+
throw new Error(errorData.message || `HTTP ${response.status}`);
|
|
49
|
+
}
|
|
50
|
+
const data = await response.json();
|
|
51
|
+
setLoading(false);
|
|
52
|
+
return [data.result, void 0];
|
|
53
|
+
} catch (error) {
|
|
54
|
+
setLoading(false);
|
|
55
|
+
return [void 0, error instanceof Error ? error : new Error(String(error))];
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
[path, apiUrl, headersEsque]
|
|
59
|
+
);
|
|
60
|
+
return { run, loading };
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// src/resources/subscription.ts
|
|
64
|
+
var useSubscription = () => {
|
|
65
|
+
const ctx = usePaykitContext();
|
|
66
|
+
const create = useAsyncFn(
|
|
67
|
+
"/subscription/create",
|
|
68
|
+
ctx.apiUrl,
|
|
69
|
+
ctx.headers
|
|
70
|
+
);
|
|
71
|
+
const update = useAsyncFn(
|
|
72
|
+
"/subscription/update",
|
|
73
|
+
ctx.apiUrl,
|
|
74
|
+
ctx.headers
|
|
75
|
+
);
|
|
76
|
+
const retrieve = useAsyncFn(
|
|
77
|
+
"/subscription/retrieve",
|
|
78
|
+
ctx.apiUrl,
|
|
79
|
+
ctx.headers
|
|
80
|
+
);
|
|
81
|
+
const cancel = useAsyncFn(
|
|
82
|
+
"/subscription/cancel",
|
|
83
|
+
ctx.apiUrl,
|
|
84
|
+
ctx.headers
|
|
85
|
+
);
|
|
86
|
+
const remove = useAsyncFn(
|
|
87
|
+
"/subscription/delete",
|
|
88
|
+
ctx.apiUrl,
|
|
89
|
+
ctx.headers
|
|
90
|
+
);
|
|
91
|
+
return { create, update, retrieve, cancel, remove };
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
exports.useSubscription = useSubscription;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import 'react/jsx-runtime';
|
|
3
|
+
|
|
4
|
+
// src/context.tsx
|
|
5
|
+
var PaykitContext = React.createContext(void 0);
|
|
6
|
+
var usePaykitContext = () => {
|
|
7
|
+
const ctx = React.useContext(PaykitContext);
|
|
8
|
+
if (!ctx) throw new Error("Your app must be wrapped in PayKitProvider to use PayKit hooks.");
|
|
9
|
+
return ctx;
|
|
10
|
+
};
|
|
11
|
+
var useAsyncFn = (path, apiUrl, headersEsque) => {
|
|
12
|
+
const [loading, setLoading] = React.useState(false);
|
|
13
|
+
const run = React.useCallback(
|
|
14
|
+
async (...args) => {
|
|
15
|
+
setLoading(true);
|
|
16
|
+
try {
|
|
17
|
+
const headers = typeof headersEsque === "function" ? headersEsque() : headersEsque != null ? headersEsque : {};
|
|
18
|
+
const response = await fetch(`${apiUrl}${path}`, {
|
|
19
|
+
method: "POST",
|
|
20
|
+
headers: { "Content-Type": "application/json", ...headers },
|
|
21
|
+
credentials: "include",
|
|
22
|
+
body: JSON.stringify({ args })
|
|
23
|
+
});
|
|
24
|
+
if (!response.ok) {
|
|
25
|
+
const errorData = await response.json().catch(() => ({ message: "Request failed" }));
|
|
26
|
+
throw new Error(errorData.message || `HTTP ${response.status}`);
|
|
27
|
+
}
|
|
28
|
+
const data = await response.json();
|
|
29
|
+
setLoading(false);
|
|
30
|
+
return [data.result, void 0];
|
|
31
|
+
} catch (error) {
|
|
32
|
+
setLoading(false);
|
|
33
|
+
return [void 0, error instanceof Error ? error : new Error(String(error))];
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
[path, apiUrl, headersEsque]
|
|
37
|
+
);
|
|
38
|
+
return { run, loading };
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// src/resources/subscription.ts
|
|
42
|
+
var useSubscription = () => {
|
|
43
|
+
const ctx = usePaykitContext();
|
|
44
|
+
const create = useAsyncFn(
|
|
45
|
+
"/subscription/create",
|
|
46
|
+
ctx.apiUrl,
|
|
47
|
+
ctx.headers
|
|
48
|
+
);
|
|
49
|
+
const update = useAsyncFn(
|
|
50
|
+
"/subscription/update",
|
|
51
|
+
ctx.apiUrl,
|
|
52
|
+
ctx.headers
|
|
53
|
+
);
|
|
54
|
+
const retrieve = useAsyncFn(
|
|
55
|
+
"/subscription/retrieve",
|
|
56
|
+
ctx.apiUrl,
|
|
57
|
+
ctx.headers
|
|
58
|
+
);
|
|
59
|
+
const cancel = useAsyncFn(
|
|
60
|
+
"/subscription/cancel",
|
|
61
|
+
ctx.apiUrl,
|
|
62
|
+
ctx.headers
|
|
63
|
+
);
|
|
64
|
+
const remove = useAsyncFn(
|
|
65
|
+
"/subscription/delete",
|
|
66
|
+
ctx.apiUrl,
|
|
67
|
+
ctx.headers
|
|
68
|
+
);
|
|
69
|
+
return { create, update, retrieve, cancel, remove };
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export { useSubscription };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paykit-sdk/react",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.91",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"dist"
|
|
16
16
|
],
|
|
17
17
|
"scripts": {
|
|
18
|
-
"build": "tsup
|
|
18
|
+
"build": "tsup",
|
|
19
19
|
"dev": "tsup src/index.ts --format cjs,esm --dts --watch",
|
|
20
20
|
"prepublishOnly": "rm -rf dist && npm run build",
|
|
21
21
|
"typecheck": "tsc --noEmit"
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"react": ">=16.8.0",
|
|
28
28
|
"react-dom": ">=16.8.0",
|
|
29
|
-
"@paykit-sdk/core": ">=1.1.
|
|
29
|
+
"@paykit-sdk/core": ">=1.1.9"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@swc/core": "^1.12.9",
|