@paykit-sdk/react 1.1.81 → 1.1.92
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 +12 -67
- package/dist/index.d.ts +12 -67
- package/dist/index.js +101 -92
- package/dist/index.mjs +74 -52
- package/dist/resources/checkout.d.mts +22 -0
- package/dist/resources/checkout.d.ts +22 -0
- package/dist/resources/checkout.js +74 -0
- package/dist/resources/checkout.mjs +52 -0
- package/dist/resources/customer.d.mts +22 -0
- package/dist/resources/customer.d.ts +22 -0
- package/dist/resources/customer.js +74 -0
- package/dist/resources/customer.mjs +52 -0
- package/dist/resources/payment.d.mts +31 -0
- package/dist/resources/payment.d.ts +31 -0
- package/dist/resources/payment.js +80 -0
- package/dist/resources/payment.mjs +58 -0
- package/dist/resources/refund.d.mts +10 -0
- package/dist/resources/refund.d.ts +10 -0
- package/dist/resources/refund.js +71 -0
- package/dist/resources/refund.mjs +49 -0
- package/dist/resources/subscription.d.mts +26 -0
- package/dist/resources/subscription.d.ts +26 -0
- package/dist/resources/subscription.js +75 -0
- package/dist/resources/subscription.mjs +53 -0
- package/package.json +14 -15
package/dist/index.mjs
CHANGED
|
@@ -1,36 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
3
|
|
|
4
|
-
// src/
|
|
5
|
-
var parseElementContext = (ctx, name) => {
|
|
6
|
-
if (!ctx) throw new Error(`${name}Context must be used within the ${name}Provider`);
|
|
7
|
-
return ctx;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
// src/core.tsx
|
|
11
|
-
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
// src/context.tsx
|
|
12
5
|
var PaykitContext = React.createContext(void 0);
|
|
13
|
-
var PaykitProvider = ({
|
|
14
|
-
|
|
6
|
+
var PaykitProvider = ({ apiUrl, headers, children }) => {
|
|
7
|
+
const value = React.useMemo(() => ({ apiUrl, headers }), [apiUrl, headers]);
|
|
8
|
+
return /* @__PURE__ */ jsx(PaykitContext.Provider, { value, children });
|
|
15
9
|
};
|
|
16
|
-
var usePaykitContext = () =>
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const
|
|
10
|
+
var usePaykitContext = () => {
|
|
11
|
+
const ctx = React.useContext(PaykitContext);
|
|
12
|
+
if (!ctx)
|
|
13
|
+
throw new Error("Your app must be wrapped in PayKitProvider to use PayKit hooks.");
|
|
14
|
+
return ctx;
|
|
15
|
+
};
|
|
16
|
+
var useAsyncFn = (path, apiUrl, headersEsque) => {
|
|
17
|
+
const [loading, setLoading] = React.useState(false);
|
|
18
|
+
const run = React.useCallback(
|
|
24
19
|
async (...args) => {
|
|
25
20
|
setLoading(true);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
21
|
+
try {
|
|
22
|
+
const headers = typeof headersEsque === "function" ? headersEsque() : headersEsque != null ? headersEsque : {};
|
|
23
|
+
const response = await fetch(`${apiUrl}${path}`, {
|
|
24
|
+
method: "POST",
|
|
25
|
+
headers: { "Content-Type": "application/json", ...headers },
|
|
26
|
+
credentials: "include",
|
|
27
|
+
body: JSON.stringify({ args })
|
|
28
|
+
});
|
|
29
|
+
if (!response.ok) {
|
|
30
|
+
const errorData = await response.json().catch(() => ({ message: "Request failed" }));
|
|
31
|
+
throw new Error(errorData.message || `HTTP ${response.status}`);
|
|
32
|
+
}
|
|
33
|
+
const data = await response.json();
|
|
34
|
+
setLoading(false);
|
|
35
|
+
return [data.result, void 0];
|
|
36
|
+
} catch (error) {
|
|
37
|
+
setLoading(false);
|
|
38
|
+
return [void 0, error instanceof Error ? error : new Error(String(error))];
|
|
30
39
|
}
|
|
31
|
-
return [data, void 0];
|
|
32
40
|
},
|
|
33
|
-
[
|
|
41
|
+
[path, apiUrl, headersEsque]
|
|
34
42
|
);
|
|
35
43
|
return { run, loading };
|
|
36
44
|
};
|
|
@@ -38,41 +46,55 @@ var useAsyncFn = (fn) => {
|
|
|
38
46
|
// src/resources/customer.ts
|
|
39
47
|
var useCustomer = () => {
|
|
40
48
|
const ctx = usePaykitContext();
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
const update = useAsyncFn(ctx.provider.updateCustomer);
|
|
47
|
-
return { retrieve, create, update };
|
|
49
|
+
const retrieve = useAsyncFn("/customer/retrieve", ctx.apiUrl, ctx.headers);
|
|
50
|
+
const create = useAsyncFn("/customer/create", ctx.apiUrl, ctx.headers);
|
|
51
|
+
const update = useAsyncFn("/customer/update", ctx.apiUrl, ctx.headers);
|
|
52
|
+
const remove = useAsyncFn("/customer/delete", ctx.apiUrl, ctx.headers);
|
|
53
|
+
return { retrieve, create, update, remove };
|
|
48
54
|
};
|
|
49
55
|
|
|
50
56
|
// src/resources/subscription.ts
|
|
51
57
|
var useSubscription = () => {
|
|
52
58
|
const ctx = usePaykitContext();
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
return { retrieve, update, cancel };
|
|
59
|
+
const create = useAsyncFn("/subscription/create", ctx.apiUrl, ctx.headers);
|
|
60
|
+
const update = useAsyncFn("/subscription/update", ctx.apiUrl, ctx.headers);
|
|
61
|
+
const retrieve = useAsyncFn("/subscription/retrieve", ctx.apiUrl, ctx.headers);
|
|
62
|
+
const cancel = useAsyncFn("/subscription/cancel", ctx.apiUrl, ctx.headers);
|
|
63
|
+
const remove = useAsyncFn("/subscription/delete", ctx.apiUrl, ctx.headers);
|
|
64
|
+
return { create, update, retrieve, cancel, remove };
|
|
60
65
|
};
|
|
61
66
|
|
|
62
67
|
// src/resources/checkout.ts
|
|
63
68
|
var useCheckout = () => {
|
|
64
69
|
const ctx = usePaykitContext();
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
|
|
70
|
+
const create = useAsyncFn("/checkout/create", ctx.apiUrl, ctx.headers);
|
|
71
|
+
const retrieve = useAsyncFn("/checkout/retrieve", ctx.apiUrl, ctx.headers);
|
|
72
|
+
const update = useAsyncFn("/checkout/update", ctx.apiUrl, ctx.headers);
|
|
73
|
+
const remove = useAsyncFn("/checkout/delete", ctx.apiUrl, ctx.headers);
|
|
74
|
+
return { create, retrieve, update, remove };
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// src/resources/refund.ts
|
|
78
|
+
var useRefund = () => {
|
|
79
|
+
const ctx = usePaykitContext();
|
|
80
|
+
const create = useAsyncFn("/refund/create", ctx.apiUrl, ctx.headers);
|
|
81
|
+
return { create };
|
|
71
82
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
83
|
+
|
|
84
|
+
// src/resources/payment.ts
|
|
85
|
+
var usePayment = () => {
|
|
86
|
+
const ctx = usePaykitContext();
|
|
87
|
+
const create = useAsyncFn("/payment/create", ctx.apiUrl, ctx.headers);
|
|
88
|
+
const retrieve = useAsyncFn("/payment/retrieve", ctx.apiUrl, ctx.headers);
|
|
89
|
+
const update = useAsyncFn("/payment/update", ctx.apiUrl, ctx.headers);
|
|
90
|
+
const remove = useAsyncFn("/payment/delete", ctx.apiUrl, ctx.headers);
|
|
91
|
+
const capture = useAsyncFn("/payment/capture", ctx.apiUrl, ctx.headers);
|
|
92
|
+
const cancel = useAsyncFn(
|
|
93
|
+
"/payment/cancel",
|
|
94
|
+
ctx.apiUrl,
|
|
95
|
+
ctx.headers
|
|
96
|
+
);
|
|
97
|
+
return { create, retrieve, update, remove, capture, cancel };
|
|
78
98
|
};
|
|
99
|
+
|
|
100
|
+
export { PaykitProvider, useCheckout, useCustomer, usePaykitContext, usePayment, useRefund, useSubscription };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as _paykit_sdk_core from '@paykit-sdk/core';
|
|
2
|
+
|
|
3
|
+
declare const useCheckout: () => {
|
|
4
|
+
create: {
|
|
5
|
+
run: (params: _paykit_sdk_core.CreateCheckoutSchema) => Promise<[data: undefined, error: Error] | [data: _paykit_sdk_core.Checkout, error: undefined]>;
|
|
6
|
+
loading: boolean;
|
|
7
|
+
};
|
|
8
|
+
retrieve: {
|
|
9
|
+
run: (id: string) => Promise<[data: undefined, error: Error] | [data: _paykit_sdk_core.Checkout | null, error: undefined]>;
|
|
10
|
+
loading: boolean;
|
|
11
|
+
};
|
|
12
|
+
update: {
|
|
13
|
+
run: (id: string, params: _paykit_sdk_core.UpdateCheckoutSchema) => Promise<[data: undefined, error: Error] | [data: _paykit_sdk_core.Checkout, error: undefined]>;
|
|
14
|
+
loading: boolean;
|
|
15
|
+
};
|
|
16
|
+
remove: {
|
|
17
|
+
run: (id: string) => Promise<[data: undefined, error: Error] | [data: null, error: undefined]>;
|
|
18
|
+
loading: boolean;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { useCheckout };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as _paykit_sdk_core from '@paykit-sdk/core';
|
|
2
|
+
|
|
3
|
+
declare const useCheckout: () => {
|
|
4
|
+
create: {
|
|
5
|
+
run: (params: _paykit_sdk_core.CreateCheckoutSchema) => Promise<[data: undefined, error: Error] | [data: _paykit_sdk_core.Checkout, error: undefined]>;
|
|
6
|
+
loading: boolean;
|
|
7
|
+
};
|
|
8
|
+
retrieve: {
|
|
9
|
+
run: (id: string) => Promise<[data: undefined, error: Error] | [data: _paykit_sdk_core.Checkout | null, error: undefined]>;
|
|
10
|
+
loading: boolean;
|
|
11
|
+
};
|
|
12
|
+
update: {
|
|
13
|
+
run: (id: string, params: _paykit_sdk_core.UpdateCheckoutSchema) => Promise<[data: undefined, error: Error] | [data: _paykit_sdk_core.Checkout, error: undefined]>;
|
|
14
|
+
loading: boolean;
|
|
15
|
+
};
|
|
16
|
+
remove: {
|
|
17
|
+
run: (id: string) => Promise<[data: undefined, error: Error] | [data: null, error: undefined]>;
|
|
18
|
+
loading: boolean;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { useCheckout };
|
|
@@ -0,0 +1,74 @@
|
|
|
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)
|
|
31
|
+
throw new Error("Your app must be wrapped in PayKitProvider to use PayKit hooks.");
|
|
32
|
+
return ctx;
|
|
33
|
+
};
|
|
34
|
+
var useAsyncFn = (path, apiUrl, headersEsque) => {
|
|
35
|
+
const [loading, setLoading] = React__namespace.useState(false);
|
|
36
|
+
const run = React__namespace.useCallback(
|
|
37
|
+
async (...args) => {
|
|
38
|
+
setLoading(true);
|
|
39
|
+
try {
|
|
40
|
+
const headers = typeof headersEsque === "function" ? headersEsque() : headersEsque != null ? headersEsque : {};
|
|
41
|
+
const response = await fetch(`${apiUrl}${path}`, {
|
|
42
|
+
method: "POST",
|
|
43
|
+
headers: { "Content-Type": "application/json", ...headers },
|
|
44
|
+
credentials: "include",
|
|
45
|
+
body: JSON.stringify({ args })
|
|
46
|
+
});
|
|
47
|
+
if (!response.ok) {
|
|
48
|
+
const errorData = await response.json().catch(() => ({ message: "Request failed" }));
|
|
49
|
+
throw new Error(errorData.message || `HTTP ${response.status}`);
|
|
50
|
+
}
|
|
51
|
+
const data = await response.json();
|
|
52
|
+
setLoading(false);
|
|
53
|
+
return [data.result, void 0];
|
|
54
|
+
} catch (error) {
|
|
55
|
+
setLoading(false);
|
|
56
|
+
return [void 0, error instanceof Error ? error : new Error(String(error))];
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
[path, apiUrl, headersEsque]
|
|
60
|
+
);
|
|
61
|
+
return { run, loading };
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// src/resources/checkout.ts
|
|
65
|
+
var useCheckout = () => {
|
|
66
|
+
const ctx = usePaykitContext();
|
|
67
|
+
const create = useAsyncFn("/checkout/create", ctx.apiUrl, ctx.headers);
|
|
68
|
+
const retrieve = useAsyncFn("/checkout/retrieve", ctx.apiUrl, ctx.headers);
|
|
69
|
+
const update = useAsyncFn("/checkout/update", ctx.apiUrl, ctx.headers);
|
|
70
|
+
const remove = useAsyncFn("/checkout/delete", ctx.apiUrl, ctx.headers);
|
|
71
|
+
return { create, retrieve, update, remove };
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
exports.useCheckout = useCheckout;
|
|
@@ -0,0 +1,52 @@
|
|
|
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)
|
|
9
|
+
throw new Error("Your app must be wrapped in PayKitProvider to use PayKit hooks.");
|
|
10
|
+
return ctx;
|
|
11
|
+
};
|
|
12
|
+
var useAsyncFn = (path, apiUrl, headersEsque) => {
|
|
13
|
+
const [loading, setLoading] = React.useState(false);
|
|
14
|
+
const run = React.useCallback(
|
|
15
|
+
async (...args) => {
|
|
16
|
+
setLoading(true);
|
|
17
|
+
try {
|
|
18
|
+
const headers = typeof headersEsque === "function" ? headersEsque() : headersEsque != null ? headersEsque : {};
|
|
19
|
+
const response = await fetch(`${apiUrl}${path}`, {
|
|
20
|
+
method: "POST",
|
|
21
|
+
headers: { "Content-Type": "application/json", ...headers },
|
|
22
|
+
credentials: "include",
|
|
23
|
+
body: JSON.stringify({ args })
|
|
24
|
+
});
|
|
25
|
+
if (!response.ok) {
|
|
26
|
+
const errorData = await response.json().catch(() => ({ message: "Request failed" }));
|
|
27
|
+
throw new Error(errorData.message || `HTTP ${response.status}`);
|
|
28
|
+
}
|
|
29
|
+
const data = await response.json();
|
|
30
|
+
setLoading(false);
|
|
31
|
+
return [data.result, void 0];
|
|
32
|
+
} catch (error) {
|
|
33
|
+
setLoading(false);
|
|
34
|
+
return [void 0, error instanceof Error ? error : new Error(String(error))];
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
[path, apiUrl, headersEsque]
|
|
38
|
+
);
|
|
39
|
+
return { run, loading };
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// src/resources/checkout.ts
|
|
43
|
+
var useCheckout = () => {
|
|
44
|
+
const ctx = usePaykitContext();
|
|
45
|
+
const create = useAsyncFn("/checkout/create", ctx.apiUrl, ctx.headers);
|
|
46
|
+
const retrieve = useAsyncFn("/checkout/retrieve", ctx.apiUrl, ctx.headers);
|
|
47
|
+
const update = useAsyncFn("/checkout/update", ctx.apiUrl, ctx.headers);
|
|
48
|
+
const remove = useAsyncFn("/checkout/delete", ctx.apiUrl, ctx.headers);
|
|
49
|
+
return { create, retrieve, update, remove };
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export { useCheckout };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as _paykit_sdk_core from '@paykit-sdk/core';
|
|
2
|
+
|
|
3
|
+
declare const useCustomer: () => {
|
|
4
|
+
retrieve: {
|
|
5
|
+
run: (id: string) => Promise<[data: undefined, error: Error] | [data: _paykit_sdk_core.Customer | null, error: undefined]>;
|
|
6
|
+
loading: boolean;
|
|
7
|
+
};
|
|
8
|
+
create: {
|
|
9
|
+
run: (params: _paykit_sdk_core.CreateCustomerParams) => Promise<[data: undefined, error: Error] | [data: _paykit_sdk_core.Customer, error: undefined]>;
|
|
10
|
+
loading: boolean;
|
|
11
|
+
};
|
|
12
|
+
update: {
|
|
13
|
+
run: (id: string, params: _paykit_sdk_core.UpdateCustomerParams) => Promise<[data: undefined, error: Error] | [data: _paykit_sdk_core.Customer, error: undefined]>;
|
|
14
|
+
loading: boolean;
|
|
15
|
+
};
|
|
16
|
+
remove: {
|
|
17
|
+
run: (id: string) => Promise<[data: undefined, error: Error] | [data: null, error: undefined]>;
|
|
18
|
+
loading: boolean;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { useCustomer };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as _paykit_sdk_core from '@paykit-sdk/core';
|
|
2
|
+
|
|
3
|
+
declare const useCustomer: () => {
|
|
4
|
+
retrieve: {
|
|
5
|
+
run: (id: string) => Promise<[data: undefined, error: Error] | [data: _paykit_sdk_core.Customer | null, error: undefined]>;
|
|
6
|
+
loading: boolean;
|
|
7
|
+
};
|
|
8
|
+
create: {
|
|
9
|
+
run: (params: _paykit_sdk_core.CreateCustomerParams) => Promise<[data: undefined, error: Error] | [data: _paykit_sdk_core.Customer, error: undefined]>;
|
|
10
|
+
loading: boolean;
|
|
11
|
+
};
|
|
12
|
+
update: {
|
|
13
|
+
run: (id: string, params: _paykit_sdk_core.UpdateCustomerParams) => Promise<[data: undefined, error: Error] | [data: _paykit_sdk_core.Customer, error: undefined]>;
|
|
14
|
+
loading: boolean;
|
|
15
|
+
};
|
|
16
|
+
remove: {
|
|
17
|
+
run: (id: string) => Promise<[data: undefined, error: Error] | [data: null, error: undefined]>;
|
|
18
|
+
loading: boolean;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { useCustomer };
|
|
@@ -0,0 +1,74 @@
|
|
|
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)
|
|
31
|
+
throw new Error("Your app must be wrapped in PayKitProvider to use PayKit hooks.");
|
|
32
|
+
return ctx;
|
|
33
|
+
};
|
|
34
|
+
var useAsyncFn = (path, apiUrl, headersEsque) => {
|
|
35
|
+
const [loading, setLoading] = React__namespace.useState(false);
|
|
36
|
+
const run = React__namespace.useCallback(
|
|
37
|
+
async (...args) => {
|
|
38
|
+
setLoading(true);
|
|
39
|
+
try {
|
|
40
|
+
const headers = typeof headersEsque === "function" ? headersEsque() : headersEsque != null ? headersEsque : {};
|
|
41
|
+
const response = await fetch(`${apiUrl}${path}`, {
|
|
42
|
+
method: "POST",
|
|
43
|
+
headers: { "Content-Type": "application/json", ...headers },
|
|
44
|
+
credentials: "include",
|
|
45
|
+
body: JSON.stringify({ args })
|
|
46
|
+
});
|
|
47
|
+
if (!response.ok) {
|
|
48
|
+
const errorData = await response.json().catch(() => ({ message: "Request failed" }));
|
|
49
|
+
throw new Error(errorData.message || `HTTP ${response.status}`);
|
|
50
|
+
}
|
|
51
|
+
const data = await response.json();
|
|
52
|
+
setLoading(false);
|
|
53
|
+
return [data.result, void 0];
|
|
54
|
+
} catch (error) {
|
|
55
|
+
setLoading(false);
|
|
56
|
+
return [void 0, error instanceof Error ? error : new Error(String(error))];
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
[path, apiUrl, headersEsque]
|
|
60
|
+
);
|
|
61
|
+
return { run, loading };
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// src/resources/customer.ts
|
|
65
|
+
var useCustomer = () => {
|
|
66
|
+
const ctx = usePaykitContext();
|
|
67
|
+
const retrieve = useAsyncFn("/customer/retrieve", ctx.apiUrl, ctx.headers);
|
|
68
|
+
const create = useAsyncFn("/customer/create", ctx.apiUrl, ctx.headers);
|
|
69
|
+
const update = useAsyncFn("/customer/update", ctx.apiUrl, ctx.headers);
|
|
70
|
+
const remove = useAsyncFn("/customer/delete", ctx.apiUrl, ctx.headers);
|
|
71
|
+
return { retrieve, create, update, remove };
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
exports.useCustomer = useCustomer;
|
|
@@ -0,0 +1,52 @@
|
|
|
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)
|
|
9
|
+
throw new Error("Your app must be wrapped in PayKitProvider to use PayKit hooks.");
|
|
10
|
+
return ctx;
|
|
11
|
+
};
|
|
12
|
+
var useAsyncFn = (path, apiUrl, headersEsque) => {
|
|
13
|
+
const [loading, setLoading] = React.useState(false);
|
|
14
|
+
const run = React.useCallback(
|
|
15
|
+
async (...args) => {
|
|
16
|
+
setLoading(true);
|
|
17
|
+
try {
|
|
18
|
+
const headers = typeof headersEsque === "function" ? headersEsque() : headersEsque != null ? headersEsque : {};
|
|
19
|
+
const response = await fetch(`${apiUrl}${path}`, {
|
|
20
|
+
method: "POST",
|
|
21
|
+
headers: { "Content-Type": "application/json", ...headers },
|
|
22
|
+
credentials: "include",
|
|
23
|
+
body: JSON.stringify({ args })
|
|
24
|
+
});
|
|
25
|
+
if (!response.ok) {
|
|
26
|
+
const errorData = await response.json().catch(() => ({ message: "Request failed" }));
|
|
27
|
+
throw new Error(errorData.message || `HTTP ${response.status}`);
|
|
28
|
+
}
|
|
29
|
+
const data = await response.json();
|
|
30
|
+
setLoading(false);
|
|
31
|
+
return [data.result, void 0];
|
|
32
|
+
} catch (error) {
|
|
33
|
+
setLoading(false);
|
|
34
|
+
return [void 0, error instanceof Error ? error : new Error(String(error))];
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
[path, apiUrl, headersEsque]
|
|
38
|
+
);
|
|
39
|
+
return { run, loading };
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// src/resources/customer.ts
|
|
43
|
+
var useCustomer = () => {
|
|
44
|
+
const ctx = usePaykitContext();
|
|
45
|
+
const retrieve = useAsyncFn("/customer/retrieve", ctx.apiUrl, ctx.headers);
|
|
46
|
+
const create = useAsyncFn("/customer/create", ctx.apiUrl, ctx.headers);
|
|
47
|
+
const update = useAsyncFn("/customer/update", ctx.apiUrl, ctx.headers);
|
|
48
|
+
const remove = useAsyncFn("/customer/delete", ctx.apiUrl, ctx.headers);
|
|
49
|
+
return { retrieve, create, update, remove };
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export { useCustomer };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as _paykit_sdk_core from '@paykit-sdk/core';
|
|
2
|
+
import { Payment } from '@paykit-sdk/core';
|
|
3
|
+
|
|
4
|
+
declare const usePayment: () => {
|
|
5
|
+
create: {
|
|
6
|
+
run: (params: _paykit_sdk_core.CreatePaymentSchema) => Promise<[data: undefined, error: Error] | [data: Payment, error: undefined]>;
|
|
7
|
+
loading: boolean;
|
|
8
|
+
};
|
|
9
|
+
retrieve: {
|
|
10
|
+
run: (id: string) => Promise<[data: undefined, error: Error] | [data: Payment | null, error: undefined]>;
|
|
11
|
+
loading: boolean;
|
|
12
|
+
};
|
|
13
|
+
update: {
|
|
14
|
+
run: (id: string, params: _paykit_sdk_core.UpdatePaymentSchema) => Promise<[data: undefined, error: Error] | [data: Payment, error: undefined]>;
|
|
15
|
+
loading: boolean;
|
|
16
|
+
};
|
|
17
|
+
remove: {
|
|
18
|
+
run: (id: string) => Promise<[data: undefined, error: Error] | [data: null, error: undefined]>;
|
|
19
|
+
loading: boolean;
|
|
20
|
+
};
|
|
21
|
+
capture: {
|
|
22
|
+
run: (id: string, params: _paykit_sdk_core.CapturePaymentSchema) => Promise<[data: undefined, error: Error] | [data: Payment, error: undefined]>;
|
|
23
|
+
loading: boolean;
|
|
24
|
+
};
|
|
25
|
+
cancel: {
|
|
26
|
+
run: (args_0: string) => Promise<[data: undefined, error: Error] | [data: Payment, error: undefined]>;
|
|
27
|
+
loading: boolean;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { usePayment };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as _paykit_sdk_core from '@paykit-sdk/core';
|
|
2
|
+
import { Payment } from '@paykit-sdk/core';
|
|
3
|
+
|
|
4
|
+
declare const usePayment: () => {
|
|
5
|
+
create: {
|
|
6
|
+
run: (params: _paykit_sdk_core.CreatePaymentSchema) => Promise<[data: undefined, error: Error] | [data: Payment, error: undefined]>;
|
|
7
|
+
loading: boolean;
|
|
8
|
+
};
|
|
9
|
+
retrieve: {
|
|
10
|
+
run: (id: string) => Promise<[data: undefined, error: Error] | [data: Payment | null, error: undefined]>;
|
|
11
|
+
loading: boolean;
|
|
12
|
+
};
|
|
13
|
+
update: {
|
|
14
|
+
run: (id: string, params: _paykit_sdk_core.UpdatePaymentSchema) => Promise<[data: undefined, error: Error] | [data: Payment, error: undefined]>;
|
|
15
|
+
loading: boolean;
|
|
16
|
+
};
|
|
17
|
+
remove: {
|
|
18
|
+
run: (id: string) => Promise<[data: undefined, error: Error] | [data: null, error: undefined]>;
|
|
19
|
+
loading: boolean;
|
|
20
|
+
};
|
|
21
|
+
capture: {
|
|
22
|
+
run: (id: string, params: _paykit_sdk_core.CapturePaymentSchema) => Promise<[data: undefined, error: Error] | [data: Payment, error: undefined]>;
|
|
23
|
+
loading: boolean;
|
|
24
|
+
};
|
|
25
|
+
cancel: {
|
|
26
|
+
run: (args_0: string) => Promise<[data: undefined, error: Error] | [data: Payment, error: undefined]>;
|
|
27
|
+
loading: boolean;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { usePayment };
|
|
@@ -0,0 +1,80 @@
|
|
|
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)
|
|
31
|
+
throw new Error("Your app must be wrapped in PayKitProvider to use PayKit hooks.");
|
|
32
|
+
return ctx;
|
|
33
|
+
};
|
|
34
|
+
var useAsyncFn = (path, apiUrl, headersEsque) => {
|
|
35
|
+
const [loading, setLoading] = React__namespace.useState(false);
|
|
36
|
+
const run = React__namespace.useCallback(
|
|
37
|
+
async (...args) => {
|
|
38
|
+
setLoading(true);
|
|
39
|
+
try {
|
|
40
|
+
const headers = typeof headersEsque === "function" ? headersEsque() : headersEsque != null ? headersEsque : {};
|
|
41
|
+
const response = await fetch(`${apiUrl}${path}`, {
|
|
42
|
+
method: "POST",
|
|
43
|
+
headers: { "Content-Type": "application/json", ...headers },
|
|
44
|
+
credentials: "include",
|
|
45
|
+
body: JSON.stringify({ args })
|
|
46
|
+
});
|
|
47
|
+
if (!response.ok) {
|
|
48
|
+
const errorData = await response.json().catch(() => ({ message: "Request failed" }));
|
|
49
|
+
throw new Error(errorData.message || `HTTP ${response.status}`);
|
|
50
|
+
}
|
|
51
|
+
const data = await response.json();
|
|
52
|
+
setLoading(false);
|
|
53
|
+
return [data.result, void 0];
|
|
54
|
+
} catch (error) {
|
|
55
|
+
setLoading(false);
|
|
56
|
+
return [void 0, error instanceof Error ? error : new Error(String(error))];
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
[path, apiUrl, headersEsque]
|
|
60
|
+
);
|
|
61
|
+
return { run, loading };
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
// src/resources/payment.ts
|
|
65
|
+
var usePayment = () => {
|
|
66
|
+
const ctx = usePaykitContext();
|
|
67
|
+
const create = useAsyncFn("/payment/create", ctx.apiUrl, ctx.headers);
|
|
68
|
+
const retrieve = useAsyncFn("/payment/retrieve", ctx.apiUrl, ctx.headers);
|
|
69
|
+
const update = useAsyncFn("/payment/update", ctx.apiUrl, ctx.headers);
|
|
70
|
+
const remove = useAsyncFn("/payment/delete", ctx.apiUrl, ctx.headers);
|
|
71
|
+
const capture = useAsyncFn("/payment/capture", ctx.apiUrl, ctx.headers);
|
|
72
|
+
const cancel = useAsyncFn(
|
|
73
|
+
"/payment/cancel",
|
|
74
|
+
ctx.apiUrl,
|
|
75
|
+
ctx.headers
|
|
76
|
+
);
|
|
77
|
+
return { create, retrieve, update, remove, capture, cancel };
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
exports.usePayment = usePayment;
|