@paykit-sdk/comgate 1.0.8 → 1.2.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/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 +195 -92
- package/dist/comgate-provider.mjs +196 -93
- package/dist/index.js +195 -92
- package/dist/index.mjs +196 -93
- 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 +5 -2
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 };
|
package/dist/comgate-provider.js
CHANGED
|
@@ -4047,12 +4047,12 @@ var coerce = {
|
|
|
4047
4047
|
date: ((arg) => ZodDate.create({ ...arg, coerce: true }))
|
|
4048
4048
|
};
|
|
4049
4049
|
var NEVER = INVALID;
|
|
4050
|
-
var
|
|
4050
|
+
var Payment$inboundSchema = (webhookResponse, status) => {
|
|
4051
4051
|
return {
|
|
4052
4052
|
id: webhookResponse.transId,
|
|
4053
4053
|
amount: webhookResponse.price,
|
|
4054
4054
|
currency: webhookResponse.curr,
|
|
4055
|
-
customer: webhookResponse.payerId
|
|
4055
|
+
customer: webhookResponse.payerId ? { id: webhookResponse.payerId } : { email: webhookResponse.email },
|
|
4056
4056
|
status,
|
|
4057
4057
|
metadata: core.omitInternalMetadata(
|
|
4058
4058
|
JSON.parse(webhookResponse.refId)
|
|
@@ -4062,7 +4062,7 @@ var paykitPayment$InboundSchema = (webhookResponse, status) => {
|
|
|
4062
4062
|
payment_url: ""
|
|
4063
4063
|
};
|
|
4064
4064
|
};
|
|
4065
|
-
var
|
|
4065
|
+
var Invoice$inboundSchema = (webhookResponse) => {
|
|
4066
4066
|
const status = (() => {
|
|
4067
4067
|
if (webhookResponse.status == "PAID") return "paid";
|
|
4068
4068
|
return "open";
|
|
@@ -4073,11 +4073,10 @@ var paykitInvoice$InboundSchema = (webhookResponse) => {
|
|
|
4073
4073
|
paid_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4074
4074
|
amount_paid: webhookResponse.price,
|
|
4075
4075
|
currency: webhookResponse.curr,
|
|
4076
|
-
customer: webhookResponse.payerId
|
|
4076
|
+
customer: webhookResponse.payerId ? { id: webhookResponse.payerId } : { email: webhookResponse.email },
|
|
4077
4077
|
custom_fields: null,
|
|
4078
4078
|
subscription_id: null,
|
|
4079
4079
|
billing_mode: "one_time",
|
|
4080
|
-
// comgate does not support recurring payments
|
|
4081
4080
|
line_items: webhookResponse.name ? [{ id: webhookResponse.name, quantity: 1 }] : [],
|
|
4082
4081
|
metadata: core.omitInternalMetadata(
|
|
4083
4082
|
JSON.parse(webhookResponse.refId)
|
|
@@ -4109,45 +4108,66 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4109
4108
|
},
|
|
4110
4109
|
retryOptions: { max: 3, baseDelay: 1e3, debug }
|
|
4111
4110
|
});
|
|
4111
|
+
this.isSandbox = opts.isSandbox;
|
|
4112
4112
|
}
|
|
4113
4113
|
providerName = providerName;
|
|
4114
4114
|
baseUrl;
|
|
4115
|
+
isSandbox;
|
|
4115
4116
|
_client;
|
|
4117
|
+
get _native() {
|
|
4118
|
+
return null;
|
|
4119
|
+
}
|
|
4116
4120
|
_throwOnError = (req, message) => {
|
|
4117
4121
|
if (!req.ok)
|
|
4118
4122
|
throw new core.OperationFailedError(message, this.providerName, {
|
|
4119
4123
|
cause: new Error(req.error)
|
|
4120
4124
|
});
|
|
4121
4125
|
if (req.value.code == 1100) {
|
|
4122
|
-
throw new core.OperationFailedError(
|
|
4123
|
-
|
|
4124
|
-
|
|
4126
|
+
throw new core.OperationFailedError(
|
|
4127
|
+
"Unknown error",
|
|
4128
|
+
this.providerName,
|
|
4129
|
+
{
|
|
4130
|
+
cause: new Error("Unknown error")
|
|
4131
|
+
}
|
|
4132
|
+
);
|
|
4125
4133
|
}
|
|
4126
4134
|
if (req.value.code == 1200) {
|
|
4127
|
-
throw new core.OperationFailedError(
|
|
4128
|
-
|
|
4129
|
-
|
|
4135
|
+
throw new core.OperationFailedError(
|
|
4136
|
+
"Database error",
|
|
4137
|
+
this.providerName,
|
|
4138
|
+
{
|
|
4139
|
+
cause: new Error("Database error")
|
|
4140
|
+
}
|
|
4141
|
+
);
|
|
4130
4142
|
}
|
|
4131
4143
|
if (req.value.code == 1400) {
|
|
4132
|
-
throw new core.OperationFailedError(
|
|
4133
|
-
|
|
4134
|
-
|
|
4144
|
+
throw new core.OperationFailedError(
|
|
4145
|
+
"Wrong query error",
|
|
4146
|
+
this.providerName,
|
|
4147
|
+
{
|
|
4148
|
+
cause: new Error("Wrong query error")
|
|
4149
|
+
}
|
|
4150
|
+
);
|
|
4135
4151
|
}
|
|
4136
4152
|
if (req.value.code == 1500) {
|
|
4137
|
-
throw new core.OperationFailedError(
|
|
4138
|
-
|
|
4139
|
-
|
|
4153
|
+
throw new core.OperationFailedError(
|
|
4154
|
+
"Unexpected error",
|
|
4155
|
+
this.providerName,
|
|
4156
|
+
{
|
|
4157
|
+
cause: new Error("Unexpected error")
|
|
4158
|
+
}
|
|
4159
|
+
);
|
|
4140
4160
|
}
|
|
4141
4161
|
return req.value;
|
|
4142
4162
|
};
|
|
4143
4163
|
createCheckout = async (params) => {
|
|
4144
4164
|
const { error, data } = core.createPaymentSchema.safeParse(params);
|
|
4145
4165
|
if (error) throw new Error(error.message.split("\n").join(" "));
|
|
4146
|
-
if (core.
|
|
4166
|
+
if (!core.isEmailCustomer(data.customer)) {
|
|
4147
4167
|
throw new core.InvalidTypeError(
|
|
4148
4168
|
"customer",
|
|
4149
|
-
"object
|
|
4150
|
-
"
|
|
4169
|
+
"object with email",
|
|
4170
|
+
data.customer === null ? "null" : "object with id",
|
|
4151
4171
|
{
|
|
4152
4172
|
provider: this.providerName,
|
|
4153
4173
|
method: "createCheckout"
|
|
@@ -4165,7 +4185,10 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4165
4185
|
label: data.provider_metadata?.label ? String(data.provider_metadata.label) : "Order from Eshop"
|
|
4166
4186
|
});
|
|
4167
4187
|
if (this.opts.debug) {
|
|
4168
|
-
console.log(
|
|
4188
|
+
console.log(
|
|
4189
|
+
"Creating payment with data:",
|
|
4190
|
+
requestBody.toString()
|
|
4191
|
+
);
|
|
4169
4192
|
}
|
|
4170
4193
|
const response = await this._client.post(
|
|
4171
4194
|
`/v2.0/paymentRedirect/merchant/${this.opts.merchant}`,
|
|
@@ -4174,9 +4197,13 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4174
4197
|
}
|
|
4175
4198
|
);
|
|
4176
4199
|
if (!response.ok) {
|
|
4177
|
-
throw new core.OperationFailedError(
|
|
4178
|
-
|
|
4179
|
-
|
|
4200
|
+
throw new core.OperationFailedError(
|
|
4201
|
+
`Failed to create payment`,
|
|
4202
|
+
this.providerName,
|
|
4203
|
+
{
|
|
4204
|
+
cause: new Error("Unknown error")
|
|
4205
|
+
}
|
|
4206
|
+
);
|
|
4180
4207
|
}
|
|
4181
4208
|
this._throwOnError(response, "Failed to create payment");
|
|
4182
4209
|
return null;
|
|
@@ -4194,10 +4221,14 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4194
4221
|
});
|
|
4195
4222
|
};
|
|
4196
4223
|
retrieveCheckout = async (id) => {
|
|
4197
|
-
throw new core.ProviderNotSupportedError(
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4224
|
+
throw new core.ProviderNotSupportedError(
|
|
4225
|
+
"retrieveCheckout",
|
|
4226
|
+
"Comgate",
|
|
4227
|
+
{
|
|
4228
|
+
reason: "Comgate does not support retrieving checkouts, use the payment API instead",
|
|
4229
|
+
alternative: "Use the payment API instead"
|
|
4230
|
+
}
|
|
4231
|
+
);
|
|
4201
4232
|
};
|
|
4202
4233
|
createCustomer = async (params) => {
|
|
4203
4234
|
throw new core.ProviderNotSupportedError("createCustomer", "Comgate", {
|
|
@@ -4206,10 +4237,14 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4206
4237
|
});
|
|
4207
4238
|
};
|
|
4208
4239
|
retrieveCustomer = async (id) => {
|
|
4209
|
-
throw new core.ProviderNotSupportedError(
|
|
4210
|
-
|
|
4211
|
-
|
|
4212
|
-
|
|
4240
|
+
throw new core.ProviderNotSupportedError(
|
|
4241
|
+
"retrieveCustomer",
|
|
4242
|
+
"Comgate",
|
|
4243
|
+
{
|
|
4244
|
+
reason: "Comgate does not support retrieving customers",
|
|
4245
|
+
alternative: "Use the payment API instead"
|
|
4246
|
+
}
|
|
4247
|
+
);
|
|
4213
4248
|
};
|
|
4214
4249
|
updateCustomer = async (id, params) => {
|
|
4215
4250
|
throw new core.ProviderNotSupportedError("updateCustomer", "Comgate", {
|
|
@@ -4226,28 +4261,41 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4226
4261
|
createPayment = async (params) => {
|
|
4227
4262
|
const { error, data } = core.createPaymentSchema.safeParse(params);
|
|
4228
4263
|
if (error) {
|
|
4229
|
-
throw core.ValidationError.fromZodError(
|
|
4264
|
+
throw core.ValidationError.fromZodError(
|
|
4265
|
+
error,
|
|
4266
|
+
this.providerName,
|
|
4267
|
+
"createPayment"
|
|
4268
|
+
);
|
|
4230
4269
|
}
|
|
4231
4270
|
const { customer } = data;
|
|
4232
|
-
if (
|
|
4233
|
-
throw new core.InvalidTypeError(
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4271
|
+
if (!core.isIdCustomer(customer)) {
|
|
4272
|
+
throw new core.InvalidTypeError(
|
|
4273
|
+
"customer",
|
|
4274
|
+
"object with id",
|
|
4275
|
+
customer === null ? "null" : "object with email",
|
|
4276
|
+
{
|
|
4277
|
+
provider: this.providerName,
|
|
4278
|
+
method: "createPayment"
|
|
4279
|
+
}
|
|
4280
|
+
);
|
|
4237
4281
|
}
|
|
4282
|
+
const payerId = String(customer.id);
|
|
4238
4283
|
const { email, paymentLabel = "Order from Eshop" } = core.validateRequiredKeys(
|
|
4239
4284
|
["email", "paymentLabel"],
|
|
4240
4285
|
data.provider_metadata ?? {},
|
|
4241
4286
|
"Missing required provider metadata: {keys}"
|
|
4242
4287
|
);
|
|
4243
4288
|
if (this.opts.debug) {
|
|
4244
|
-
console.log("Creating payment with metadata:", {
|
|
4289
|
+
console.log("Creating payment with metadata:", {
|
|
4290
|
+
email,
|
|
4291
|
+
paymentLabel
|
|
4292
|
+
});
|
|
4245
4293
|
}
|
|
4246
4294
|
const requestBody = new URLSearchParams({
|
|
4247
4295
|
code: "0",
|
|
4248
4296
|
test: this.opts.isSandbox ? "true" : "false",
|
|
4249
4297
|
refId: JSON.stringify(data.metadata ?? {}),
|
|
4250
|
-
payerId
|
|
4298
|
+
payerId,
|
|
4251
4299
|
price: String(data.amount),
|
|
4252
4300
|
email,
|
|
4253
4301
|
curr: String(data.currency),
|
|
@@ -4266,9 +4314,12 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4266
4314
|
currency: data.currency,
|
|
4267
4315
|
status: "pending",
|
|
4268
4316
|
metadata: Object.fromEntries(
|
|
4269
|
-
Object.entries(data.metadata ?? {}).map(([key, value]) => [
|
|
4317
|
+
Object.entries(data.metadata ?? {}).map(([key, value]) => [
|
|
4318
|
+
key,
|
|
4319
|
+
String(value)
|
|
4320
|
+
])
|
|
4270
4321
|
),
|
|
4271
|
-
customer,
|
|
4322
|
+
customer: core.isIdCustomer(customer) ? customer : null,
|
|
4272
4323
|
item_id: data.item_id ?? null,
|
|
4273
4324
|
requires_action: false,
|
|
4274
4325
|
payment_url: response.value.redirect ?? null
|
|
@@ -4282,36 +4333,55 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4282
4333
|
});
|
|
4283
4334
|
};
|
|
4284
4335
|
deletePayment = async (id) => {
|
|
4285
|
-
const response = await this._client.delete(
|
|
4336
|
+
const response = await this._client.delete(
|
|
4337
|
+
`/v2.0/payment/${id}.json`
|
|
4338
|
+
);
|
|
4286
4339
|
if (!response.ok) {
|
|
4287
|
-
throw new core.OperationFailedError(
|
|
4288
|
-
|
|
4289
|
-
|
|
4340
|
+
throw new core.OperationFailedError(
|
|
4341
|
+
`Failed to delete payment`,
|
|
4342
|
+
this.providerName,
|
|
4343
|
+
{
|
|
4344
|
+
cause: new Error("Unknown error")
|
|
4345
|
+
}
|
|
4346
|
+
);
|
|
4290
4347
|
}
|
|
4291
4348
|
return null;
|
|
4292
4349
|
};
|
|
4293
4350
|
retrievePayment = async (id) => {
|
|
4294
4351
|
const { error } = core.createPaymentSchema.safeParse({ id });
|
|
4295
|
-
if (error)
|
|
4352
|
+
if (error)
|
|
4353
|
+
throw new Error(
|
|
4354
|
+
`Payment retrieval validation failed: ${error.message}`
|
|
4355
|
+
);
|
|
4296
4356
|
const response = await this._client.get(
|
|
4297
4357
|
`/v2.0/payment/${id}.json`
|
|
4298
4358
|
);
|
|
4299
4359
|
if (!response.ok) {
|
|
4300
|
-
throw new core.OperationFailedError(
|
|
4301
|
-
|
|
4302
|
-
|
|
4360
|
+
throw new core.OperationFailedError(
|
|
4361
|
+
`Failed to retrieve payment`,
|
|
4362
|
+
this.providerName,
|
|
4363
|
+
{
|
|
4364
|
+
cause: new Error("Unknown error")
|
|
4365
|
+
}
|
|
4366
|
+
);
|
|
4303
4367
|
}
|
|
4304
4368
|
return response.value;
|
|
4305
4369
|
};
|
|
4306
4370
|
capturePayment = async (id, params) => {
|
|
4307
4371
|
const { error, data } = core.capturePaymentSchema.safeParse(params);
|
|
4308
4372
|
if (error) {
|
|
4309
|
-
throw core.ValidationError.fromZodError(
|
|
4373
|
+
throw core.ValidationError.fromZodError(
|
|
4374
|
+
error,
|
|
4375
|
+
this.providerName,
|
|
4376
|
+
"capturePayment"
|
|
4377
|
+
);
|
|
4310
4378
|
}
|
|
4311
4379
|
const response = await this._client.post(
|
|
4312
4380
|
`/v2.0/preauth/${id}/confirm.json`,
|
|
4313
4381
|
{
|
|
4314
|
-
body: new URLSearchParams({
|
|
4382
|
+
body: new URLSearchParams({
|
|
4383
|
+
amount: String(data.amount)
|
|
4384
|
+
}).toString()
|
|
4315
4385
|
}
|
|
4316
4386
|
);
|
|
4317
4387
|
this._throwOnError(response, "Failed to capture payment");
|
|
@@ -4321,7 +4391,7 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4321
4391
|
currency: "CZK",
|
|
4322
4392
|
status: "succeeded",
|
|
4323
4393
|
metadata: {},
|
|
4324
|
-
customer:
|
|
4394
|
+
customer: null,
|
|
4325
4395
|
item_id: null,
|
|
4326
4396
|
requires_action: false,
|
|
4327
4397
|
payment_url: response.value.redirect ?? null
|
|
@@ -4348,9 +4418,12 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4348
4418
|
test: this.opts.isSandbox ? "true" : "false",
|
|
4349
4419
|
refId: JSON.stringify(data.metadata ?? {})
|
|
4350
4420
|
});
|
|
4351
|
-
const response = await this._client.post(
|
|
4352
|
-
|
|
4353
|
-
|
|
4421
|
+
const response = await this._client.post(
|
|
4422
|
+
"/v2.0/refund.json",
|
|
4423
|
+
{
|
|
4424
|
+
body: requestBody.toString()
|
|
4425
|
+
}
|
|
4426
|
+
);
|
|
4354
4427
|
this._throwOnError(response, "Failed to create refund");
|
|
4355
4428
|
const refundObject = {
|
|
4356
4429
|
id: `paykit:refund:${Math.random().toString(36).substring(2, 15)}`,
|
|
@@ -4359,7 +4432,10 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4359
4432
|
reason: data.reason,
|
|
4360
4433
|
metadata: {
|
|
4361
4434
|
...Object.fromEntries(
|
|
4362
|
-
Object.entries(data.metadata ?? {}).map(([key, value]) => [
|
|
4435
|
+
Object.entries(data.metadata ?? {}).map(([key, value]) => [
|
|
4436
|
+
key,
|
|
4437
|
+
String(value)
|
|
4438
|
+
])
|
|
4363
4439
|
),
|
|
4364
4440
|
...response.value?.code ? { __comgate_refund_code: String(response.value.code) } : {},
|
|
4365
4441
|
...response.value?.message && {
|
|
@@ -4370,48 +4446,68 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4370
4446
|
return refundObject;
|
|
4371
4447
|
};
|
|
4372
4448
|
createSubscription = async (params) => {
|
|
4373
|
-
throw new core.ProviderNotSupportedError(
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4449
|
+
throw new core.ProviderNotSupportedError(
|
|
4450
|
+
"createSubscription",
|
|
4451
|
+
"Comgate",
|
|
4452
|
+
{
|
|
4453
|
+
reason: "Comgate does not support creating subscriptions",
|
|
4454
|
+
alternative: "Use the payment API instead and create a subscription manually"
|
|
4455
|
+
}
|
|
4456
|
+
);
|
|
4377
4457
|
};
|
|
4378
4458
|
deleteSubscription = async (id) => {
|
|
4379
|
-
throw new core.ProviderNotSupportedError(
|
|
4380
|
-
|
|
4381
|
-
|
|
4382
|
-
|
|
4459
|
+
throw new core.ProviderNotSupportedError(
|
|
4460
|
+
"deleteSubscription",
|
|
4461
|
+
"Comgate",
|
|
4462
|
+
{
|
|
4463
|
+
reason: "Comgate does not support deleting subscriptions",
|
|
4464
|
+
alternative: "Use the payment API instead and delete the subscription manually"
|
|
4465
|
+
}
|
|
4466
|
+
);
|
|
4383
4467
|
};
|
|
4384
4468
|
updateSubscription = async (id, params) => {
|
|
4385
|
-
throw new core.ProviderNotSupportedError(
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4469
|
+
throw new core.ProviderNotSupportedError(
|
|
4470
|
+
"updateSubscription",
|
|
4471
|
+
"Comgate",
|
|
4472
|
+
{
|
|
4473
|
+
reason: "Comgate does not support updating subscriptions",
|
|
4474
|
+
alternative: "Use the payment API instead and update the subscription manually"
|
|
4475
|
+
}
|
|
4476
|
+
);
|
|
4389
4477
|
};
|
|
4390
4478
|
retrieveSubscription = async (id) => {
|
|
4391
|
-
throw new core.ProviderNotSupportedError(
|
|
4392
|
-
|
|
4393
|
-
|
|
4394
|
-
|
|
4479
|
+
throw new core.ProviderNotSupportedError(
|
|
4480
|
+
"retrieveSubscription",
|
|
4481
|
+
"Comgate",
|
|
4482
|
+
{
|
|
4483
|
+
reason: "Comgate does not support retrieving subscriptions",
|
|
4484
|
+
alternative: "Use the payment API instead and retrieve the subscription manually"
|
|
4485
|
+
}
|
|
4486
|
+
);
|
|
4395
4487
|
};
|
|
4396
4488
|
cancelSubscription = async (id) => {
|
|
4397
|
-
throw new core.ProviderNotSupportedError(
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
4489
|
+
throw new core.ProviderNotSupportedError(
|
|
4490
|
+
"cancelSubscription",
|
|
4491
|
+
"Comgate",
|
|
4492
|
+
{
|
|
4493
|
+
reason: "Comgate does not support canceling subscriptions",
|
|
4494
|
+
alternative: "Use the payment API instead and cancel the subscription manually"
|
|
4495
|
+
}
|
|
4496
|
+
);
|
|
4401
4497
|
};
|
|
4402
|
-
handleWebhook = async ({
|
|
4403
|
-
body: rawBody,
|
|
4404
|
-
headers
|
|
4405
|
-
}) => {
|
|
4498
|
+
handleWebhook = async (payload, webhookSecret) => {
|
|
4499
|
+
const { body: rawBody, headersAsObject } = payload;
|
|
4406
4500
|
let body;
|
|
4407
|
-
const contentType =
|
|
4501
|
+
const contentType = headersAsObject["content-type"];
|
|
4408
4502
|
if (contentType === "application/json") {
|
|
4409
4503
|
body = JSON.parse(rawBody);
|
|
4410
4504
|
} else {
|
|
4411
4505
|
body = Object.fromEntries(new URLSearchParams(rawBody));
|
|
4412
4506
|
}
|
|
4413
4507
|
if (!body || typeof body !== "object") {
|
|
4414
|
-
throw new core.WebhookError("Invalid webhook payload", {
|
|
4508
|
+
throw new core.WebhookError("Invalid webhook payload", {
|
|
4509
|
+
provider: this.providerName
|
|
4510
|
+
});
|
|
4415
4511
|
}
|
|
4416
4512
|
if (this.opts.debug) {
|
|
4417
4513
|
console.info("Verifying webhook...");
|
|
@@ -4427,7 +4523,9 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4427
4523
|
"Missing required webhook parameters: {keys}"
|
|
4428
4524
|
);
|
|
4429
4525
|
if (secret !== this.opts.secret) {
|
|
4430
|
-
throw new core.WebhookError("Webhook secret mismatch", {
|
|
4526
|
+
throw new core.WebhookError("Webhook secret mismatch", {
|
|
4527
|
+
provider: this.providerName
|
|
4528
|
+
});
|
|
4431
4529
|
}
|
|
4432
4530
|
if (merchant !== this.opts.merchant) {
|
|
4433
4531
|
throw new core.WebhookError("Webhook merchant mismatch", {
|
|
@@ -4453,7 +4551,9 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4453
4551
|
);
|
|
4454
4552
|
}
|
|
4455
4553
|
if (!comgateWebhookApiResponse.status) {
|
|
4456
|
-
throw new core.WebhookError(
|
|
4554
|
+
throw new core.WebhookError(
|
|
4555
|
+
"Failed to verify webhook: no status returned"
|
|
4556
|
+
);
|
|
4457
4557
|
}
|
|
4458
4558
|
if (comgateWebhookApiResponse.status !== webhookStatusOut) {
|
|
4459
4559
|
throw new core.WebhookError(
|
|
@@ -4469,7 +4569,7 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4469
4569
|
const status = statusMap[comgateWebhookApiResponse.status];
|
|
4470
4570
|
const webhookHandlers = {
|
|
4471
4571
|
pending: (data) => {
|
|
4472
|
-
const payment =
|
|
4572
|
+
const payment = Payment$inboundSchema(data, "pending");
|
|
4473
4573
|
return [
|
|
4474
4574
|
core.paykitEvent$InboundSchema({
|
|
4475
4575
|
type: "payment.created",
|
|
@@ -4480,7 +4580,10 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4480
4580
|
];
|
|
4481
4581
|
},
|
|
4482
4582
|
requires_capture: (data) => {
|
|
4483
|
-
const payment =
|
|
4583
|
+
const payment = Payment$inboundSchema(
|
|
4584
|
+
data,
|
|
4585
|
+
"requires_capture"
|
|
4586
|
+
);
|
|
4484
4587
|
return [
|
|
4485
4588
|
core.paykitEvent$InboundSchema({
|
|
4486
4589
|
type: "payment.updated",
|
|
@@ -4491,10 +4594,10 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4491
4594
|
];
|
|
4492
4595
|
},
|
|
4493
4596
|
canceled: (data) => {
|
|
4494
|
-
const payment =
|
|
4597
|
+
const payment = Payment$inboundSchema(data, "canceled");
|
|
4495
4598
|
return [
|
|
4496
4599
|
core.paykitEvent$InboundSchema({
|
|
4497
|
-
type: "payment.
|
|
4600
|
+
type: "payment.failed",
|
|
4498
4601
|
created: (/* @__PURE__ */ new Date()).getTime(),
|
|
4499
4602
|
id: `paykit:payment:${Math.random().toString(36).substring(2, 15)}`,
|
|
4500
4603
|
data: payment
|
|
@@ -4502,11 +4605,11 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4502
4605
|
];
|
|
4503
4606
|
},
|
|
4504
4607
|
succeeded: (data) => {
|
|
4505
|
-
const invoice =
|
|
4506
|
-
const payment =
|
|
4608
|
+
const invoice = Invoice$inboundSchema(data);
|
|
4609
|
+
const payment = Payment$inboundSchema(data, "succeeded");
|
|
4507
4610
|
return [
|
|
4508
4611
|
core.paykitEvent$InboundSchema({
|
|
4509
|
-
type: "payment.
|
|
4612
|
+
type: "payment.succeeded",
|
|
4510
4613
|
created: (/* @__PURE__ */ new Date()).getTime(),
|
|
4511
4614
|
id: `paykit:payment:${Math.random().toString(36).substring(2, 15)}`,
|
|
4512
4615
|
data: payment
|