@paykit-sdk/react 1.1.81 → 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 -67
- package/dist/index.d.ts +11 -67
- 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 +4 -4
package/README.md
CHANGED
|
@@ -14,9 +14,9 @@ npm install @paykit-sdk/react
|
|
|
14
14
|
|
|
15
15
|
```tsx
|
|
16
16
|
import { PayKit } from '@paykit-sdk/core';
|
|
17
|
-
import {
|
|
17
|
+
import { paypal } from '@paykit-sdk/paypal';
|
|
18
18
|
|
|
19
|
-
const provider =
|
|
19
|
+
const provider = paypal();
|
|
20
20
|
const paykit = new PayKit(provider);
|
|
21
21
|
|
|
22
22
|
export { provider, paykit };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EndpointPath } from '@paykit-sdk/core';
|
|
2
|
+
|
|
3
|
+
type AsyncResult<T> = [data: T, error: undefined] | [data: undefined, error: Error];
|
|
4
|
+
declare const useAsyncFn: <Args extends unknown[], Response>(path: EndpointPath, apiUrl: string, headersEsque: Record<string, string> | (() => Record<string, string>)) => {
|
|
5
|
+
run: (...args: Args) => Promise<AsyncResult<Response>>;
|
|
6
|
+
loading: boolean;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export { useAsyncFn };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { EndpointPath } from '@paykit-sdk/core';
|
|
2
|
+
|
|
3
|
+
type AsyncResult<T> = [data: T, error: undefined] | [data: undefined, error: Error];
|
|
4
|
+
declare const useAsyncFn: <Args extends unknown[], Response>(path: EndpointPath, apiUrl: string, headersEsque: Record<string, string> | (() => Record<string, string>)) => {
|
|
5
|
+
run: (...args: Args) => Promise<AsyncResult<Response>>;
|
|
6
|
+
loading: boolean;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export { useAsyncFn };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
|
|
5
|
+
function _interopNamespace(e) {
|
|
6
|
+
if (e && e.__esModule) return e;
|
|
7
|
+
var n = Object.create(null);
|
|
8
|
+
if (e) {
|
|
9
|
+
Object.keys(e).forEach(function (k) {
|
|
10
|
+
if (k !== 'default') {
|
|
11
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return e[k]; }
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
n.default = e;
|
|
20
|
+
return Object.freeze(n);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
24
|
+
|
|
25
|
+
// src/hooks/use-async-fn.ts
|
|
26
|
+
var useAsyncFn = (path, apiUrl, headersEsque) => {
|
|
27
|
+
const [loading, setLoading] = React__namespace.useState(false);
|
|
28
|
+
const run = React__namespace.useCallback(
|
|
29
|
+
async (...args) => {
|
|
30
|
+
setLoading(true);
|
|
31
|
+
try {
|
|
32
|
+
const headers = typeof headersEsque === "function" ? headersEsque() : headersEsque != null ? headersEsque : {};
|
|
33
|
+
const response = await fetch(`${apiUrl}${path}`, {
|
|
34
|
+
method: "POST",
|
|
35
|
+
headers: { "Content-Type": "application/json", ...headers },
|
|
36
|
+
credentials: "include",
|
|
37
|
+
body: JSON.stringify({ args })
|
|
38
|
+
});
|
|
39
|
+
if (!response.ok) {
|
|
40
|
+
const errorData = await response.json().catch(() => ({ message: "Request failed" }));
|
|
41
|
+
throw new Error(errorData.message || `HTTP ${response.status}`);
|
|
42
|
+
}
|
|
43
|
+
const data = await response.json();
|
|
44
|
+
setLoading(false);
|
|
45
|
+
return [data.result, void 0];
|
|
46
|
+
} catch (error) {
|
|
47
|
+
setLoading(false);
|
|
48
|
+
return [void 0, error instanceof Error ? error : new Error(String(error))];
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
[path, apiUrl, headersEsque]
|
|
52
|
+
);
|
|
53
|
+
return { run, loading };
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
exports.useAsyncFn = useAsyncFn;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
// src/hooks/use-async-fn.ts
|
|
4
|
+
var useAsyncFn = (path, apiUrl, headersEsque) => {
|
|
5
|
+
const [loading, setLoading] = React.useState(false);
|
|
6
|
+
const run = React.useCallback(
|
|
7
|
+
async (...args) => {
|
|
8
|
+
setLoading(true);
|
|
9
|
+
try {
|
|
10
|
+
const headers = typeof headersEsque === "function" ? headersEsque() : headersEsque != null ? headersEsque : {};
|
|
11
|
+
const response = await fetch(`${apiUrl}${path}`, {
|
|
12
|
+
method: "POST",
|
|
13
|
+
headers: { "Content-Type": "application/json", ...headers },
|
|
14
|
+
credentials: "include",
|
|
15
|
+
body: JSON.stringify({ args })
|
|
16
|
+
});
|
|
17
|
+
if (!response.ok) {
|
|
18
|
+
const errorData = await response.json().catch(() => ({ message: "Request failed" }));
|
|
19
|
+
throw new Error(errorData.message || `HTTP ${response.status}`);
|
|
20
|
+
}
|
|
21
|
+
const data = await response.json();
|
|
22
|
+
setLoading(false);
|
|
23
|
+
return [data.result, void 0];
|
|
24
|
+
} catch (error) {
|
|
25
|
+
setLoading(false);
|
|
26
|
+
return [void 0, error instanceof Error ? error : new Error(String(error))];
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
[path, apiUrl, headersEsque]
|
|
30
|
+
);
|
|
31
|
+
return { run, loading };
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export { useAsyncFn };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,72 +1,16 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
export { useCustomer } from './resources/customer.mjs';
|
|
4
|
+
export { useSubscription } from './resources/subscription.mjs';
|
|
5
|
+
export { useCheckout } from './resources/checkout.mjs';
|
|
6
|
+
export { useRefund } from './resources/refund.mjs';
|
|
7
|
+
import '@paykit-sdk/core';
|
|
5
8
|
|
|
6
|
-
interface PaykitProviderProps {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
interface PaykitProviderProps extends React.PropsWithChildren {
|
|
10
|
+
apiUrl: string;
|
|
11
|
+
headers: Record<string, string> | (() => Record<string, string>);
|
|
9
12
|
}
|
|
10
|
-
declare const PaykitProvider: ({
|
|
11
|
-
declare const usePaykitContext: () =>
|
|
12
|
-
provider: PayKitProvider;
|
|
13
|
-
} | undefined;
|
|
13
|
+
declare const PaykitProvider: ({ apiUrl, headers, children }: PaykitProviderProps) => react_jsx_runtime.JSX.Element;
|
|
14
|
+
declare const usePaykitContext: () => PaykitProviderProps;
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
retrieve: {
|
|
17
|
-
run: (id: string) => Promise<[data: undefined, error: Error] | [data: _paykit_sdk_core.Customer | null, error: undefined]>;
|
|
18
|
-
loading: boolean;
|
|
19
|
-
};
|
|
20
|
-
create: {
|
|
21
|
-
run: (params: {
|
|
22
|
-
email: string;
|
|
23
|
-
metadata?: Record<string, string> | undefined;
|
|
24
|
-
name?: string | undefined;
|
|
25
|
-
}) => Promise<[data: undefined, error: Error] | [data: _paykit_sdk_core.Customer, error: undefined]>;
|
|
26
|
-
loading: boolean;
|
|
27
|
-
};
|
|
28
|
-
update: {
|
|
29
|
-
run: (id: string, params: {
|
|
30
|
-
email?: string | undefined;
|
|
31
|
-
metadata?: Record<string, string> | undefined;
|
|
32
|
-
name?: string | undefined;
|
|
33
|
-
}) => Promise<[data: undefined, error: Error] | [data: _paykit_sdk_core.Customer, error: undefined]>;
|
|
34
|
-
loading: boolean;
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
declare const useSubscription: () => {
|
|
39
|
-
retrieve: {
|
|
40
|
-
run: (id: string) => Promise<[data: undefined, error: Error] | [data: _paykit_sdk_core.Subscription | null, error: undefined]>;
|
|
41
|
-
loading: boolean;
|
|
42
|
-
};
|
|
43
|
-
update: {
|
|
44
|
-
run: (id: string, params: {
|
|
45
|
-
metadata?: Record<string, string> | undefined;
|
|
46
|
-
}) => Promise<[data: undefined, error: Error] | [data: _paykit_sdk_core.Subscription, error: undefined]>;
|
|
47
|
-
loading: boolean;
|
|
48
|
-
};
|
|
49
|
-
cancel: {
|
|
50
|
-
run: (id: string) => Promise<[data: undefined, error: Error] | [data: null, error: undefined]>;
|
|
51
|
-
loading: boolean;
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
declare const useCheckout: () => {
|
|
56
|
-
create: {
|
|
57
|
-
run: (params: {
|
|
58
|
-
customer_id: string;
|
|
59
|
-
metadata: Record<string, string>;
|
|
60
|
-
session_type: "one_time" | "recurring";
|
|
61
|
-
item_id: string;
|
|
62
|
-
provider_metadata?: Record<string, unknown> | undefined;
|
|
63
|
-
}) => Promise<[data: undefined, error: Error] | [data: _paykit_sdk_core.Checkout, error: undefined]>;
|
|
64
|
-
loading: boolean;
|
|
65
|
-
};
|
|
66
|
-
retrieve: {
|
|
67
|
-
run: (id: string) => Promise<[data: undefined, error: Error] | [data: _paykit_sdk_core.Checkout | null, error: undefined]>;
|
|
68
|
-
loading: boolean;
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
export { PaykitProvider, useCheckout, useCustomer, usePaykitContext, useSubscription };
|
|
16
|
+
export { PaykitProvider, usePaykitContext };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,72 +1,16 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
export { useCustomer } from './resources/customer.js';
|
|
4
|
+
export { useSubscription } from './resources/subscription.js';
|
|
5
|
+
export { useCheckout } from './resources/checkout.js';
|
|
6
|
+
export { useRefund } from './resources/refund.js';
|
|
7
|
+
import '@paykit-sdk/core';
|
|
5
8
|
|
|
6
|
-
interface PaykitProviderProps {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
interface PaykitProviderProps extends React.PropsWithChildren {
|
|
10
|
+
apiUrl: string;
|
|
11
|
+
headers: Record<string, string> | (() => Record<string, string>);
|
|
9
12
|
}
|
|
10
|
-
declare const PaykitProvider: ({
|
|
11
|
-
declare const usePaykitContext: () =>
|
|
12
|
-
provider: PayKitProvider;
|
|
13
|
-
} | undefined;
|
|
13
|
+
declare const PaykitProvider: ({ apiUrl, headers, children }: PaykitProviderProps) => react_jsx_runtime.JSX.Element;
|
|
14
|
+
declare const usePaykitContext: () => PaykitProviderProps;
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
retrieve: {
|
|
17
|
-
run: (id: string) => Promise<[data: undefined, error: Error] | [data: _paykit_sdk_core.Customer | null, error: undefined]>;
|
|
18
|
-
loading: boolean;
|
|
19
|
-
};
|
|
20
|
-
create: {
|
|
21
|
-
run: (params: {
|
|
22
|
-
email: string;
|
|
23
|
-
metadata?: Record<string, string> | undefined;
|
|
24
|
-
name?: string | undefined;
|
|
25
|
-
}) => Promise<[data: undefined, error: Error] | [data: _paykit_sdk_core.Customer, error: undefined]>;
|
|
26
|
-
loading: boolean;
|
|
27
|
-
};
|
|
28
|
-
update: {
|
|
29
|
-
run: (id: string, params: {
|
|
30
|
-
email?: string | undefined;
|
|
31
|
-
metadata?: Record<string, string> | undefined;
|
|
32
|
-
name?: string | undefined;
|
|
33
|
-
}) => Promise<[data: undefined, error: Error] | [data: _paykit_sdk_core.Customer, error: undefined]>;
|
|
34
|
-
loading: boolean;
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
declare const useSubscription: () => {
|
|
39
|
-
retrieve: {
|
|
40
|
-
run: (id: string) => Promise<[data: undefined, error: Error] | [data: _paykit_sdk_core.Subscription | null, error: undefined]>;
|
|
41
|
-
loading: boolean;
|
|
42
|
-
};
|
|
43
|
-
update: {
|
|
44
|
-
run: (id: string, params: {
|
|
45
|
-
metadata?: Record<string, string> | undefined;
|
|
46
|
-
}) => Promise<[data: undefined, error: Error] | [data: _paykit_sdk_core.Subscription, error: undefined]>;
|
|
47
|
-
loading: boolean;
|
|
48
|
-
};
|
|
49
|
-
cancel: {
|
|
50
|
-
run: (id: string) => Promise<[data: undefined, error: Error] | [data: null, error: undefined]>;
|
|
51
|
-
loading: boolean;
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
declare const useCheckout: () => {
|
|
56
|
-
create: {
|
|
57
|
-
run: (params: {
|
|
58
|
-
customer_id: string;
|
|
59
|
-
metadata: Record<string, string>;
|
|
60
|
-
session_type: "one_time" | "recurring";
|
|
61
|
-
item_id: string;
|
|
62
|
-
provider_metadata?: Record<string, unknown> | undefined;
|
|
63
|
-
}) => Promise<[data: undefined, error: Error] | [data: _paykit_sdk_core.Checkout, error: undefined]>;
|
|
64
|
-
loading: boolean;
|
|
65
|
-
};
|
|
66
|
-
retrieve: {
|
|
67
|
-
run: (id: string) => Promise<[data: undefined, error: Error] | [data: _paykit_sdk_core.Checkout | null, error: undefined]>;
|
|
68
|
-
loading: boolean;
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
export { PaykitProvider, useCheckout, useCustomer, usePaykitContext, useSubscription };
|
|
16
|
+
export { PaykitProvider, usePaykitContext };
|
package/dist/index.js
CHANGED
|
@@ -1,76 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
'use strict';
|
|
29
2
|
|
|
30
|
-
|
|
31
|
-
var
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
PaykitProvider: () => PaykitProvider,
|
|
34
|
-
useCheckout: () => useCheckout,
|
|
35
|
-
useCustomer: () => useCustomer,
|
|
36
|
-
usePaykitContext: () => usePaykitContext,
|
|
37
|
-
useSubscription: () => useSubscription
|
|
38
|
-
});
|
|
39
|
-
module.exports = __toCommonJS(index_exports);
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
40
5
|
|
|
41
|
-
|
|
42
|
-
|
|
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
|
+
}
|
|
43
23
|
|
|
44
|
-
|
|
45
|
-
var parseElementContext = (ctx, name) => {
|
|
46
|
-
if (!ctx) throw new Error(`${name}Context must be used within the ${name}Provider`);
|
|
47
|
-
return ctx;
|
|
48
|
-
};
|
|
24
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
49
25
|
|
|
50
|
-
// src/
|
|
51
|
-
var
|
|
52
|
-
var
|
|
53
|
-
|
|
54
|
-
return /* @__PURE__ */
|
|
26
|
+
// src/context.tsx
|
|
27
|
+
var PaykitContext = React__namespace.createContext(void 0);
|
|
28
|
+
var PaykitProvider = ({ apiUrl, headers, children }) => {
|
|
29
|
+
const value = React__namespace.useMemo(() => ({ apiUrl, headers }), [apiUrl, headers]);
|
|
30
|
+
return /* @__PURE__ */ jsxRuntime.jsx(PaykitContext.Provider, { value, children });
|
|
55
31
|
};
|
|
56
|
-
var usePaykitContext = () =>
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
var useAsyncFn = (
|
|
62
|
-
const [loading, setLoading] =
|
|
63
|
-
const run =
|
|
32
|
+
var usePaykitContext = () => {
|
|
33
|
+
const ctx = React__namespace.useContext(PaykitContext);
|
|
34
|
+
if (!ctx) throw new Error("Your app must be wrapped in PayKitProvider to use PayKit hooks.");
|
|
35
|
+
return ctx;
|
|
36
|
+
};
|
|
37
|
+
var useAsyncFn = (path, apiUrl, headersEsque) => {
|
|
38
|
+
const [loading, setLoading] = React__namespace.useState(false);
|
|
39
|
+
const run = React__namespace.useCallback(
|
|
64
40
|
async (...args) => {
|
|
65
41
|
setLoading(true);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
42
|
+
try {
|
|
43
|
+
const headers = typeof headersEsque === "function" ? headersEsque() : headersEsque != null ? headersEsque : {};
|
|
44
|
+
const response = await fetch(`${apiUrl}${path}`, {
|
|
45
|
+
method: "POST",
|
|
46
|
+
headers: { "Content-Type": "application/json", ...headers },
|
|
47
|
+
credentials: "include",
|
|
48
|
+
body: JSON.stringify({ args })
|
|
49
|
+
});
|
|
50
|
+
if (!response.ok) {
|
|
51
|
+
const errorData = await response.json().catch(() => ({ message: "Request failed" }));
|
|
52
|
+
throw new Error(errorData.message || `HTTP ${response.status}`);
|
|
53
|
+
}
|
|
54
|
+
const data = await response.json();
|
|
55
|
+
setLoading(false);
|
|
56
|
+
return [data.result, void 0];
|
|
57
|
+
} catch (error) {
|
|
58
|
+
setLoading(false);
|
|
59
|
+
return [void 0, error instanceof Error ? error : new Error(String(error))];
|
|
70
60
|
}
|
|
71
|
-
return [data, void 0];
|
|
72
61
|
},
|
|
73
|
-
[
|
|
62
|
+
[path, apiUrl, headersEsque]
|
|
74
63
|
);
|
|
75
64
|
return { run, loading };
|
|
76
65
|
};
|
|
@@ -78,42 +67,100 @@ var useAsyncFn = (fn) => {
|
|
|
78
67
|
// src/resources/customer.ts
|
|
79
68
|
var useCustomer = () => {
|
|
80
69
|
const ctx = usePaykitContext();
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
|
|
70
|
+
const retrieve = useAsyncFn(
|
|
71
|
+
"/customer/retrieve",
|
|
72
|
+
ctx.apiUrl,
|
|
73
|
+
ctx.headers
|
|
74
|
+
);
|
|
75
|
+
const create = useAsyncFn(
|
|
76
|
+
"/customer/create",
|
|
77
|
+
ctx.apiUrl,
|
|
78
|
+
ctx.headers
|
|
79
|
+
);
|
|
80
|
+
const update = useAsyncFn(
|
|
81
|
+
"/customer/update",
|
|
82
|
+
ctx.apiUrl,
|
|
83
|
+
ctx.headers
|
|
84
|
+
);
|
|
85
|
+
const remove = useAsyncFn(
|
|
86
|
+
"/customer/delete",
|
|
87
|
+
ctx.apiUrl,
|
|
88
|
+
ctx.headers
|
|
89
|
+
);
|
|
90
|
+
return { retrieve, create, update, remove };
|
|
88
91
|
};
|
|
89
92
|
|
|
90
93
|
// src/resources/subscription.ts
|
|
91
94
|
var useSubscription = () => {
|
|
92
95
|
const ctx = usePaykitContext();
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
|
|
96
|
+
const create = useAsyncFn(
|
|
97
|
+
"/subscription/create",
|
|
98
|
+
ctx.apiUrl,
|
|
99
|
+
ctx.headers
|
|
100
|
+
);
|
|
101
|
+
const update = useAsyncFn(
|
|
102
|
+
"/subscription/update",
|
|
103
|
+
ctx.apiUrl,
|
|
104
|
+
ctx.headers
|
|
105
|
+
);
|
|
106
|
+
const retrieve = useAsyncFn(
|
|
107
|
+
"/subscription/retrieve",
|
|
108
|
+
ctx.apiUrl,
|
|
109
|
+
ctx.headers
|
|
110
|
+
);
|
|
111
|
+
const cancel = useAsyncFn(
|
|
112
|
+
"/subscription/cancel",
|
|
113
|
+
ctx.apiUrl,
|
|
114
|
+
ctx.headers
|
|
115
|
+
);
|
|
116
|
+
const remove = useAsyncFn(
|
|
117
|
+
"/subscription/delete",
|
|
118
|
+
ctx.apiUrl,
|
|
119
|
+
ctx.headers
|
|
120
|
+
);
|
|
121
|
+
return { create, update, retrieve, cancel, remove };
|
|
100
122
|
};
|
|
101
123
|
|
|
102
124
|
// src/resources/checkout.ts
|
|
103
125
|
var useCheckout = () => {
|
|
104
126
|
const ctx = usePaykitContext();
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
127
|
+
const create = useAsyncFn(
|
|
128
|
+
"/checkout/create",
|
|
129
|
+
ctx.apiUrl,
|
|
130
|
+
ctx.headers
|
|
131
|
+
);
|
|
132
|
+
const retrieve = useAsyncFn(
|
|
133
|
+
"/checkout/retrieve",
|
|
134
|
+
ctx.apiUrl,
|
|
135
|
+
ctx.headers
|
|
136
|
+
);
|
|
137
|
+
const update = useAsyncFn(
|
|
138
|
+
"/checkout/update",
|
|
139
|
+
ctx.apiUrl,
|
|
140
|
+
ctx.headers
|
|
141
|
+
);
|
|
142
|
+
const remove = useAsyncFn(
|
|
143
|
+
"/checkout/delete",
|
|
144
|
+
ctx.apiUrl,
|
|
145
|
+
ctx.headers
|
|
146
|
+
);
|
|
147
|
+
return { create, retrieve, update, remove };
|
|
111
148
|
};
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
149
|
+
|
|
150
|
+
// src/resources/refund.ts
|
|
151
|
+
var useRefund = () => {
|
|
152
|
+
const ctx = usePaykitContext();
|
|
153
|
+
const create = useAsyncFn(
|
|
154
|
+
"/refund/create",
|
|
155
|
+
ctx.apiUrl,
|
|
156
|
+
ctx.headers
|
|
157
|
+
);
|
|
158
|
+
return { create };
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
exports.PaykitProvider = PaykitProvider;
|
|
162
|
+
exports.useCheckout = useCheckout;
|
|
163
|
+
exports.useCustomer = useCustomer;
|
|
164
|
+
exports.usePaykitContext = usePaykitContext;
|
|
165
|
+
exports.useRefund = useRefund;
|
|
166
|
+
exports.useSubscription = useSubscription;
|