zova-module-a-pay 5.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/cli/openapi.config.ts +9 -0
- package/dist/.metadata/component/paymentNextAction.d.ts +26 -0
- package/dist/.metadata/component/paymentNextAction.d.ts.map +1 -0
- package/dist/.metadata/index.d.ts +171 -0
- package/dist/.metadata/index.d.ts.map +1 -0
- package/dist/.metadata/this.d.ts +3 -0
- package/dist/.metadata/this.d.ts.map +1 -0
- package/dist/api/openapi/baseURL.d.ts +3 -0
- package/dist/api/openapi/baseURL.d.ts.map +1 -0
- package/dist/api/openapi/index.d.ts +4 -0
- package/dist/api/openapi/index.d.ts.map +1 -0
- package/dist/api/openapi/schemas.d.ts +328 -0
- package/dist/api/openapi/schemas.d.ts.map +1 -0
- package/dist/api/openapi/types.d.ts +9129 -0
- package/dist/api/openapi/types.d.ts.map +1 -0
- package/dist/api/paymentSession.d.ts +66 -0
- package/dist/api/paymentSession.d.ts.map +1 -0
- package/dist/apiSchema/paymentSession.d.ts +7 -0
- package/dist/apiSchema/paymentSession.d.ts.map +1 -0
- package/dist/component/paymentNextAction/controller.d.ts +15 -0
- package/dist/component/paymentNextAction/controller.d.ts.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +153 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/model/paymentSession.d.ts +549 -0
- package/dist/model/paymentSession.d.ts.map +1 -0
- package/dist/service/paymentCoordinator.d.ts +6 -0
- package/dist/service/paymentCoordinator.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/payment.d.ts +24 -0
- package/dist/types/payment.d.ts.map +1 -0
- package/package.json +34 -0
- package/src/.metadata/component/paymentNextAction.ts +31 -0
- package/src/.metadata/index.ts +217 -0
- package/src/.metadata/this.ts +2 -0
- package/src/api/openapi/baseURL.ts +5 -0
- package/src/api/openapi/index.ts +3 -0
- package/src/api/openapi/schemas.ts +584 -0
- package/src/api/openapi/types.ts +9324 -0
- package/src/api/paymentSession.ts +52 -0
- package/src/apiSchema/paymentSession.ts +20 -0
- package/src/component/paymentNextAction/controller.tsx +76 -0
- package/src/index.ts +3 -0
- package/src/lib/index.ts +1 -0
- package/src/model/paymentSession.ts +32 -0
- package/src/service/paymentCoordinator.ts +13 -0
- package/src/types/index.ts +1 -0
- package/src/types/payment.ts +25 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { IApiActionOptions } from 'zova-module-a-api';
|
|
2
|
+
|
|
3
|
+
import { Api, BeanApiBase } from 'zova-module-a-api';
|
|
4
|
+
|
|
5
|
+
import type { paths } from './openapi/index.js';
|
|
6
|
+
|
|
7
|
+
import { OpenApiBaseURL } from './openapi/index.js';
|
|
8
|
+
|
|
9
|
+
/** PaymentSession_start */
|
|
10
|
+
export const ApiApiPaymentSessionstartPath = '/api/payment-session/{id}/start';
|
|
11
|
+
export type ApiApiPaymentSessionstartPath = '/api/payment-session/{id}/start';
|
|
12
|
+
export type ApiApiPaymentSessionstartMethod = 'post';
|
|
13
|
+
export type ApiApiPaymentSessionstartRequestParams =
|
|
14
|
+
paths[ApiApiPaymentSessionstartPath][ApiApiPaymentSessionstartMethod]['parameters']['path'];
|
|
15
|
+
export type ApiApiPaymentSessionstartResponseBody =
|
|
16
|
+
paths[ApiApiPaymentSessionstartPath][ApiApiPaymentSessionstartMethod]['responses']['200']['content']['application/json']['data'];
|
|
17
|
+
|
|
18
|
+
/** PaymentSession_view */
|
|
19
|
+
export const ApiApiPaymentSessionviewPath = '/api/payment-session/{id}';
|
|
20
|
+
export type ApiApiPaymentSessionviewPath = '/api/payment-session/{id}';
|
|
21
|
+
export type ApiApiPaymentSessionviewMethod = 'get';
|
|
22
|
+
export type ApiApiPaymentSessionviewRequestParams =
|
|
23
|
+
paths[ApiApiPaymentSessionviewPath][ApiApiPaymentSessionviewMethod]['parameters']['path'];
|
|
24
|
+
export type ApiApiPaymentSessionviewResponseBody =
|
|
25
|
+
paths[ApiApiPaymentSessionviewPath][ApiApiPaymentSessionviewMethod]['responses']['200']['content']['application/json']['data'];
|
|
26
|
+
|
|
27
|
+
@Api()
|
|
28
|
+
export class ApiPaymentSession extends BeanApiBase {
|
|
29
|
+
start(
|
|
30
|
+
body: undefined,
|
|
31
|
+
options: {
|
|
32
|
+
params: ApiApiPaymentSessionstartRequestParams;
|
|
33
|
+
} & IApiActionOptions,
|
|
34
|
+
) {
|
|
35
|
+
return this.$fetch.post<any, ApiApiPaymentSessionstartResponseBody>(
|
|
36
|
+
this.$pathTranslate(ApiApiPaymentSessionstartPath, options.params),
|
|
37
|
+
body,
|
|
38
|
+
this.$configPrepare(OpenApiBaseURL(this.sys), options, true),
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
view(
|
|
43
|
+
options: {
|
|
44
|
+
params: ApiApiPaymentSessionviewRequestParams;
|
|
45
|
+
} & IApiActionOptions,
|
|
46
|
+
) {
|
|
47
|
+
return this.$fetch.get<any, ApiApiPaymentSessionviewResponseBody>(
|
|
48
|
+
this.$pathTranslate(ApiApiPaymentSessionviewPath, options.params),
|
|
49
|
+
this.$configPrepare(OpenApiBaseURL(this.sys), options, true),
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { IApiSchemaOptions } from 'zova-module-a-api';
|
|
2
|
+
|
|
3
|
+
import { BeanBase } from 'zova';
|
|
4
|
+
import { ApiSchema } from 'zova-module-a-api';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
ApiApiPaymentSessionstartPath,
|
|
8
|
+
ApiApiPaymentSessionviewPath,
|
|
9
|
+
} from '../api/paymentSession.js';
|
|
10
|
+
|
|
11
|
+
@ApiSchema()
|
|
12
|
+
export class ApiSchemaPaymentSession extends BeanBase {
|
|
13
|
+
start(options?: IApiSchemaOptions) {
|
|
14
|
+
return this.$sdk.createApiSchemas(ApiApiPaymentSessionstartPath, 'post', options);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
view(options?: IApiSchemaOptions) {
|
|
18
|
+
return this.$sdk.createApiSchemas(ApiApiPaymentSessionviewPath, 'get', options);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { BeanControllerBase, Use } from 'zova';
|
|
2
|
+
import { Controller } from 'zova-module-a-bean';
|
|
3
|
+
|
|
4
|
+
import type { ServicePaymentCoordinator } from '../../service/paymentCoordinator.js';
|
|
5
|
+
import type { TypePaymentNextAction } from '../../types/payment.js';
|
|
6
|
+
|
|
7
|
+
export interface ControllerPaymentNextActionProps {
|
|
8
|
+
action?: TypePaymentNextAction;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
onRefresh?: () => void | Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@Controller()
|
|
14
|
+
export class ControllerPaymentNextAction extends BeanControllerBase {
|
|
15
|
+
static $propsDefault = {};
|
|
16
|
+
|
|
17
|
+
@Use()
|
|
18
|
+
$$paymentCoordinator: ServicePaymentCoordinator;
|
|
19
|
+
|
|
20
|
+
async continueRedirect() {
|
|
21
|
+
const action = this.$props.action;
|
|
22
|
+
if (action?.kind !== 'redirect' || this.$props.disabled) return;
|
|
23
|
+
await this.$$paymentCoordinator.execute(action);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
protected render() {
|
|
27
|
+
const { action, disabled, onRefresh } = this.$props as ControllerPaymentNextActionProps;
|
|
28
|
+
if (!action) return null;
|
|
29
|
+
if (action.kind === 'redirect') {
|
|
30
|
+
return (
|
|
31
|
+
<div class="mt-6 space-y-3">
|
|
32
|
+
<p class="text-base-content/70">Continue to the payment provider to complete payment.</p>
|
|
33
|
+
<button
|
|
34
|
+
class="btn btn-primary"
|
|
35
|
+
disabled={disabled}
|
|
36
|
+
onClick={() => this.continueRedirect()}
|
|
37
|
+
>
|
|
38
|
+
Continue to payment
|
|
39
|
+
</button>
|
|
40
|
+
</div>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
if (action.kind === 'pending') {
|
|
44
|
+
return (
|
|
45
|
+
<div class="mt-6 space-y-3" aria-live="polite">
|
|
46
|
+
<p class="text-base-content/70">
|
|
47
|
+
Payment is being prepared
|
|
48
|
+
{action.retryAfterSeconds
|
|
49
|
+
? `; retrying in about ${action.retryAfterSeconds} seconds`
|
|
50
|
+
: ''}
|
|
51
|
+
.
|
|
52
|
+
</p>
|
|
53
|
+
{onRefresh && (
|
|
54
|
+
<button class="btn btn-outline" disabled={disabled} onClick={() => onRefresh()}>
|
|
55
|
+
Refresh payment status
|
|
56
|
+
</button>
|
|
57
|
+
)}
|
|
58
|
+
</div>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
if (action.kind === 'completed') {
|
|
62
|
+
return (
|
|
63
|
+
<p class="mt-6 text-base-content/70" aria-live="polite">
|
|
64
|
+
Payment is complete. Confirming the order…
|
|
65
|
+
</p>
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
return (
|
|
69
|
+
<div class="mt-6" aria-live="polite">
|
|
70
|
+
<p class="text-base-content/70">
|
|
71
|
+
Embedded checkout will be available when this payment provider is configured.
|
|
72
|
+
</p>
|
|
73
|
+
</div>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
}
|
package/src/index.ts
ADDED
package/src/lib/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { TableIdentity } from 'table-identity';
|
|
2
|
+
import type { IDecoratorModelOptions } from 'zova-module-a-model';
|
|
3
|
+
|
|
4
|
+
import { BeanModelBase, Model } from 'zova-module-a-model';
|
|
5
|
+
|
|
6
|
+
export interface IModelOptionsPaymentSession extends IDecoratorModelOptions {}
|
|
7
|
+
|
|
8
|
+
@Model<IModelOptionsPaymentSession>()
|
|
9
|
+
export class ModelPaymentSession extends BeanModelBase {
|
|
10
|
+
view(id: TableIdentity) {
|
|
11
|
+
if (!process.env.CLIENT || !this.$passport.isAuthenticated) return;
|
|
12
|
+
return this.$useStateData({
|
|
13
|
+
queryKey: ['view', id],
|
|
14
|
+
queryFn: async () => {
|
|
15
|
+
return await this.scope.api.paymentSession.view({ params: { id } });
|
|
16
|
+
},
|
|
17
|
+
meta: { disableSuspenseOnInit: true },
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
start(id: TableIdentity) {
|
|
22
|
+
return this.$useMutationData({
|
|
23
|
+
mutationKey: ['start', id],
|
|
24
|
+
mutationFn: async () => {
|
|
25
|
+
return await this.scope.api.paymentSession.start(undefined, { params: { id } });
|
|
26
|
+
},
|
|
27
|
+
onSuccess: async () => {
|
|
28
|
+
await this.$invalidateQueries({ queryKey: ['view', id] });
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BeanBase } from 'zova';
|
|
2
|
+
import { Service } from 'zova-module-a-bean';
|
|
3
|
+
|
|
4
|
+
import type { TypePaymentNextAction } from '../types/payment.js';
|
|
5
|
+
|
|
6
|
+
@Service()
|
|
7
|
+
export class ServicePaymentCoordinator extends BeanBase {
|
|
8
|
+
async execute(action: TypePaymentNextAction) {
|
|
9
|
+
if (action.kind !== 'redirect') return;
|
|
10
|
+
if (!process.env.CLIENT) return;
|
|
11
|
+
window.location.assign(action.url);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './payment.js';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export type TypePaymentNextAction =
|
|
2
|
+
| { kind: 'redirect'; url: string }
|
|
3
|
+
| { kind: 'embedded'; clientToken: string; publishableConfig?: Record<string, string> }
|
|
4
|
+
| { kind: 'pending'; retryAfterSeconds?: number }
|
|
5
|
+
| { kind: 'completed' };
|
|
6
|
+
|
|
7
|
+
export interface IPaymentSessionView {
|
|
8
|
+
id: string | number;
|
|
9
|
+
state:
|
|
10
|
+
| 'created'
|
|
11
|
+
| 'starting'
|
|
12
|
+
| 'requires_action'
|
|
13
|
+
| 'processing'
|
|
14
|
+
| 'succeeded'
|
|
15
|
+
| 'failed'
|
|
16
|
+
| 'cancelled'
|
|
17
|
+
| 'expired';
|
|
18
|
+
providerName: string;
|
|
19
|
+
nextAction?: TypePaymentNextAction;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface IPayUiProvider {
|
|
23
|
+
supports(action: TypePaymentNextAction): boolean;
|
|
24
|
+
execute(action: TypePaymentNextAction): Promise<void>;
|
|
25
|
+
}
|