@paykit-sdk/comgate 1.0.7 → 1.0.9
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 +31 -8
- package/dist/comgate-provider.d.mts +9 -3
- package/dist/comgate-provider.d.ts +9 -3
- package/dist/comgate-provider.js +203 -94
- package/dist/comgate-provider.mjs +204 -95
- package/dist/index.js +203 -94
- package/dist/index.mjs +204 -95
- package/dist/utils/mapper.d.mts +9 -3
- package/dist/utils/mapper.d.ts +9 -3
- package/dist/utils/mapper.js +6 -7
- package/dist/utils/mapper.mjs +5 -6
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -34,11 +34,15 @@ export async function POST(
|
|
|
34
34
|
) {
|
|
35
35
|
try {
|
|
36
36
|
// Construct the endpoint path with full type safety
|
|
37
|
-
const endpoint = ('/' +
|
|
37
|
+
const endpoint = ('/' +
|
|
38
|
+
params.endpoint.join('/')) as EndpointPath;
|
|
38
39
|
const handler = endpoints[endpoint];
|
|
39
40
|
|
|
40
41
|
if (!handler) {
|
|
41
|
-
return NextResponse.json(
|
|
42
|
+
return NextResponse.json(
|
|
43
|
+
{ message: 'Endpoint not found' },
|
|
44
|
+
{ status: 404 },
|
|
45
|
+
);
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
// Parse request body
|
|
@@ -51,7 +55,12 @@ export async function POST(
|
|
|
51
55
|
} catch (error) {
|
|
52
56
|
console.error('PayKit API Error:', error);
|
|
53
57
|
return NextResponse.json(
|
|
54
|
-
{
|
|
58
|
+
{
|
|
59
|
+
message:
|
|
60
|
+
error instanceof Error
|
|
61
|
+
? error.message
|
|
62
|
+
: 'Internal server error',
|
|
63
|
+
},
|
|
55
64
|
{ status: 500 },
|
|
56
65
|
);
|
|
57
66
|
}
|
|
@@ -97,7 +106,10 @@ export async function POST(request: NextRequest) {
|
|
|
97
106
|
|
|
98
107
|
```typescript
|
|
99
108
|
import { paykit, endpoints } from '@/lib/paykit';
|
|
100
|
-
import {
|
|
109
|
+
import {
|
|
110
|
+
createEndpointHandlers,
|
|
111
|
+
EndpointPath,
|
|
112
|
+
} from '@paykit-sdk/core';
|
|
101
113
|
import express from 'express';
|
|
102
114
|
|
|
103
115
|
const app = express();
|
|
@@ -112,7 +124,9 @@ app.post(
|
|
|
112
124
|
const webhookSecret = process.env.COMGATE_SECRET;
|
|
113
125
|
|
|
114
126
|
if (!webhookSecret) {
|
|
115
|
-
return res
|
|
127
|
+
return res
|
|
128
|
+
.status(500)
|
|
129
|
+
.json({ error: 'Webhook secret not configured' });
|
|
116
130
|
}
|
|
117
131
|
|
|
118
132
|
const webhook = paykit.webhooks
|
|
@@ -143,7 +157,10 @@ app.post(
|
|
|
143
157
|
} catch (error) {
|
|
144
158
|
console.error('Webhook error:', error);
|
|
145
159
|
res.status(500).json({
|
|
146
|
-
message:
|
|
160
|
+
message:
|
|
161
|
+
error instanceof Error
|
|
162
|
+
? error.message
|
|
163
|
+
: 'Webhook processing failed',
|
|
147
164
|
});
|
|
148
165
|
}
|
|
149
166
|
},
|
|
@@ -154,7 +171,10 @@ app.use(express.json());
|
|
|
154
171
|
|
|
155
172
|
app.post('/api/paykit/*', async (req, res) => {
|
|
156
173
|
try {
|
|
157
|
-
const endpoint = req.path.replace(
|
|
174
|
+
const endpoint = req.path.replace(
|
|
175
|
+
'/api/paykit',
|
|
176
|
+
'',
|
|
177
|
+
) as EndpointPath;
|
|
158
178
|
const handler = endpoints[endpoint];
|
|
159
179
|
|
|
160
180
|
if (!handler) {
|
|
@@ -167,7 +187,10 @@ app.post('/api/paykit/*', async (req, res) => {
|
|
|
167
187
|
res.json({ result });
|
|
168
188
|
} catch (error) {
|
|
169
189
|
res.status(500).json({
|
|
170
|
-
message:
|
|
190
|
+
message:
|
|
191
|
+
error instanceof Error
|
|
192
|
+
? error.message
|
|
193
|
+
: 'Internal server error',
|
|
171
194
|
});
|
|
172
195
|
}
|
|
173
196
|
});
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { PaykitProviderOptions, AbstractPayKitProvider, PayKitProvider, CreateCheckoutSchema, Checkout, UpdateCheckoutSchema, CreateCustomerParams, Customer, UpdateCustomerParams, CreatePaymentSchema, Payment, UpdatePaymentSchema, CapturePaymentSchema, CreateRefundSchema, Refund, CreateSubscriptionSchema, Subscription, UpdateSubscriptionSchema,
|
|
1
|
+
import { PaykitProviderOptions, AbstractPayKitProvider, PayKitProvider, ProviderMetadataRegistry, CreateCheckoutSchema, Checkout, UpdateCheckoutSchema, CreateCustomerParams, Customer, UpdateCustomerParams, CreatePaymentSchema, Payment, UpdatePaymentSchema, CapturePaymentSchema, CreateRefundSchema, Refund, CreateSubscriptionSchema, Subscription, UpdateSubscriptionSchema, WebhookHandlerConfig, WebhookEventPayload } from '@paykit-sdk/core';
|
|
2
2
|
|
|
3
|
+
interface ComgateMetadata extends ProviderMetadataRegistry {
|
|
4
|
+
}
|
|
5
|
+
interface ComgateRawEvents extends Record<string, any> {
|
|
6
|
+
}
|
|
3
7
|
interface ComgateOptions extends PaykitProviderOptions {
|
|
4
8
|
/**
|
|
5
9
|
* The merchant ID
|
|
@@ -14,12 +18,14 @@ interface ComgateOptions extends PaykitProviderOptions {
|
|
|
14
18
|
*/
|
|
15
19
|
isSandbox: boolean;
|
|
16
20
|
}
|
|
17
|
-
declare class ComgateProvider extends AbstractPayKitProvider implements PayKitProvider {
|
|
21
|
+
declare class ComgateProvider extends AbstractPayKitProvider implements PayKitProvider<ComgateMetadata, null, ComgateRawEvents> {
|
|
18
22
|
private readonly opts;
|
|
19
23
|
readonly providerName = "comgate";
|
|
20
24
|
private baseUrl;
|
|
25
|
+
readonly isSandbox: boolean;
|
|
21
26
|
private _client;
|
|
22
27
|
constructor(opts: ComgateOptions);
|
|
28
|
+
get _native(): null;
|
|
23
29
|
private _throwOnError;
|
|
24
30
|
createCheckout: (params: CreateCheckoutSchema) => Promise<Checkout>;
|
|
25
31
|
updateCheckout: (id: string, params: UpdateCheckoutSchema) => Promise<Checkout>;
|
|
@@ -44,7 +50,7 @@ declare class ComgateProvider extends AbstractPayKitProvider implements PayKitPr
|
|
|
44
50
|
updateSubscription: (id: string, params: UpdateSubscriptionSchema) => Promise<Subscription>;
|
|
45
51
|
retrieveSubscription: (id: string) => Promise<Subscription>;
|
|
46
52
|
cancelSubscription: (id: string) => Promise<Subscription>;
|
|
47
|
-
handleWebhook: (
|
|
53
|
+
handleWebhook: (payload: WebhookHandlerConfig, webhookSecret: string | null) => Promise<Array<WebhookEventPayload<ComgateRawEvents>>>;
|
|
48
54
|
}
|
|
49
55
|
|
|
50
56
|
export { type ComgateOptions, ComgateProvider };
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { PaykitProviderOptions, AbstractPayKitProvider, PayKitProvider, CreateCheckoutSchema, Checkout, UpdateCheckoutSchema, CreateCustomerParams, Customer, UpdateCustomerParams, CreatePaymentSchema, Payment, UpdatePaymentSchema, CapturePaymentSchema, CreateRefundSchema, Refund, CreateSubscriptionSchema, Subscription, UpdateSubscriptionSchema,
|
|
1
|
+
import { PaykitProviderOptions, AbstractPayKitProvider, PayKitProvider, ProviderMetadataRegistry, CreateCheckoutSchema, Checkout, UpdateCheckoutSchema, CreateCustomerParams, Customer, UpdateCustomerParams, CreatePaymentSchema, Payment, UpdatePaymentSchema, CapturePaymentSchema, CreateRefundSchema, Refund, CreateSubscriptionSchema, Subscription, UpdateSubscriptionSchema, WebhookHandlerConfig, WebhookEventPayload } from '@paykit-sdk/core';
|
|
2
2
|
|
|
3
|
+
interface ComgateMetadata extends ProviderMetadataRegistry {
|
|
4
|
+
}
|
|
5
|
+
interface ComgateRawEvents extends Record<string, any> {
|
|
6
|
+
}
|
|
3
7
|
interface ComgateOptions extends PaykitProviderOptions {
|
|
4
8
|
/**
|
|
5
9
|
* The merchant ID
|
|
@@ -14,12 +18,14 @@ interface ComgateOptions extends PaykitProviderOptions {
|
|
|
14
18
|
*/
|
|
15
19
|
isSandbox: boolean;
|
|
16
20
|
}
|
|
17
|
-
declare class ComgateProvider extends AbstractPayKitProvider implements PayKitProvider {
|
|
21
|
+
declare class ComgateProvider extends AbstractPayKitProvider implements PayKitProvider<ComgateMetadata, null, ComgateRawEvents> {
|
|
18
22
|
private readonly opts;
|
|
19
23
|
readonly providerName = "comgate";
|
|
20
24
|
private baseUrl;
|
|
25
|
+
readonly isSandbox: boolean;
|
|
21
26
|
private _client;
|
|
22
27
|
constructor(opts: ComgateOptions);
|
|
28
|
+
get _native(): null;
|
|
23
29
|
private _throwOnError;
|
|
24
30
|
createCheckout: (params: CreateCheckoutSchema) => Promise<Checkout>;
|
|
25
31
|
updateCheckout: (id: string, params: UpdateCheckoutSchema) => Promise<Checkout>;
|
|
@@ -44,7 +50,7 @@ declare class ComgateProvider extends AbstractPayKitProvider implements PayKitPr
|
|
|
44
50
|
updateSubscription: (id: string, params: UpdateSubscriptionSchema) => Promise<Subscription>;
|
|
45
51
|
retrieveSubscription: (id: string) => Promise<Subscription>;
|
|
46
52
|
cancelSubscription: (id: string) => Promise<Subscription>;
|
|
47
|
-
handleWebhook: (
|
|
53
|
+
handleWebhook: (payload: WebhookHandlerConfig, webhookSecret: string | null) => Promise<Array<WebhookEventPayload<ComgateRawEvents>>>;
|
|
48
54
|
}
|
|
49
55
|
|
|
50
56
|
export { type ComgateOptions, ComgateProvider };
|