@paykit-sdk/comgate 1.0.0 → 1.0.4
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 +48 -41
- package/dist/comgate-provider.d.mts +1 -1
- package/dist/comgate-provider.d.ts +1 -1
- package/dist/comgate-provider.js +74 -28
- package/dist/comgate-provider.mjs +74 -28
- package/dist/index.js +74 -28
- package/dist/index.mjs +74 -28
- package/dist/utils/mapper.js +7 -3
- package/dist/utils/mapper.mjs +7 -3
- package/package.json +13 -11
package/README.md
CHANGED
|
@@ -28,7 +28,10 @@ export const endpoints = createEndpointHandlers(paykit);
|
|
|
28
28
|
import { paykit } from '@/lib/paykit';
|
|
29
29
|
import { EndpointPath } from '@paykit-sdk/core';
|
|
30
30
|
|
|
31
|
-
export async function POST(
|
|
31
|
+
export async function POST(
|
|
32
|
+
request: NextRequest,
|
|
33
|
+
{ params }: { params: { endpoint: string[] } },
|
|
34
|
+
) {
|
|
32
35
|
try {
|
|
33
36
|
// Construct the endpoint path with full type safety
|
|
34
37
|
const endpoint = ('/' + params.endpoint.join('/')) as EndpointPath;
|
|
@@ -101,46 +104,50 @@ const app = express();
|
|
|
101
104
|
|
|
102
105
|
// IMPORTANT: Webhook route must come BEFORE express.json() middleware
|
|
103
106
|
// This ensures we get the raw body for signature verification
|
|
104
|
-
app.post(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
107
|
+
app.post(
|
|
108
|
+
'/api/webhooks/comgate',
|
|
109
|
+
express.raw({ type: 'application/json' }),
|
|
110
|
+
async (req, res) => {
|
|
111
|
+
try {
|
|
112
|
+
const webhookSecret = process.env.COMGATE_SECRET;
|
|
113
|
+
|
|
114
|
+
if (!webhookSecret) {
|
|
115
|
+
return res.status(500).json({ error: 'Webhook secret not configured' });
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const webhook = paykit.webhooks
|
|
119
|
+
.setup({ webhookSecret })
|
|
120
|
+
.on('customer.created', async event => {
|
|
121
|
+
console.log('Customer created:', event.data);
|
|
122
|
+
})
|
|
123
|
+
.on('subscription.created', async event => {
|
|
124
|
+
console.log('Subscription created:', event.data);
|
|
125
|
+
})
|
|
126
|
+
.on('payment.created', async event => {
|
|
127
|
+
console.log('Payment created:', event.data);
|
|
128
|
+
})
|
|
129
|
+
.on('refund.created', async event => {
|
|
130
|
+
console.log('Refund created:', event.data);
|
|
131
|
+
})
|
|
132
|
+
.on('invoice.generated', async event => {
|
|
133
|
+
console.log('Invoice generated:', event.data);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const body = req.body; // Raw buffer from express.raw()
|
|
137
|
+
const headers = req.headers;
|
|
138
|
+
const url = request.url;
|
|
139
|
+
await webhook.handle({ body, headers, fullUrl: url });
|
|
140
|
+
|
|
141
|
+
// Return immediately, processing happens in background
|
|
142
|
+
res.json({ success: true });
|
|
143
|
+
} catch (error) {
|
|
144
|
+
console.error('Webhook error:', error);
|
|
145
|
+
res.status(500).json({
|
|
146
|
+
message: error instanceof Error ? error.message : 'Webhook processing failed',
|
|
128
147
|
});
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const url = request.url;
|
|
133
|
-
await webhook.handle({ body, headers, fullUrl: url });
|
|
134
|
-
|
|
135
|
-
// Return immediately, processing happens in background
|
|
136
|
-
res.json({ success: true });
|
|
137
|
-
} catch (error) {
|
|
138
|
-
console.error('Webhook error:', error);
|
|
139
|
-
res.status(500).json({
|
|
140
|
-
message: error instanceof Error ? error.message : 'Webhook processing failed',
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
});
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
);
|
|
144
151
|
|
|
145
152
|
// Regular API routes use JSON middleware
|
|
146
153
|
app.use(express.json());
|
|
@@ -196,4 +203,4 @@ COMGATE_SANDBOX=false
|
|
|
196
203
|
|
|
197
204
|
## License
|
|
198
205
|
|
|
199
|
-
|
|
206
|
+
ISC
|
|
@@ -44,7 +44,7 @@ declare class ComgateProvider extends AbstractPayKitProvider implements PayKitPr
|
|
|
44
44
|
updateSubscription: (id: string, params: UpdateSubscriptionSchema) => Promise<Subscription>;
|
|
45
45
|
retrieveSubscription: (id: string) => Promise<Subscription>;
|
|
46
46
|
cancelSubscription: (id: string) => Promise<Subscription>;
|
|
47
|
-
handleWebhook: ({ body: rawBody, headers }: HandleWebhookParams) => Promise<Array<WebhookEventPayload>>;
|
|
47
|
+
handleWebhook: ({ body: rawBody, headers, }: HandleWebhookParams) => Promise<Array<WebhookEventPayload>>;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
export { type ComgateOptions, ComgateProvider };
|
|
@@ -44,7 +44,7 @@ declare class ComgateProvider extends AbstractPayKitProvider implements PayKitPr
|
|
|
44
44
|
updateSubscription: (id: string, params: UpdateSubscriptionSchema) => Promise<Subscription>;
|
|
45
45
|
retrieveSubscription: (id: string) => Promise<Subscription>;
|
|
46
46
|
cancelSubscription: (id: string) => Promise<Subscription>;
|
|
47
|
-
handleWebhook: ({ body: rawBody, headers }: HandleWebhookParams) => Promise<Array<WebhookEventPayload>>;
|
|
47
|
+
handleWebhook: ({ body: rawBody, headers, }: HandleWebhookParams) => Promise<Array<WebhookEventPayload>>;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
export { type ComgateOptions, ComgateProvider };
|
package/dist/comgate-provider.js
CHANGED
|
@@ -4054,8 +4054,10 @@ var paykitPayment$InboundSchema = (webhookResponse, status) => {
|
|
|
4054
4054
|
currency: webhookResponse.curr,
|
|
4055
4055
|
customer: webhookResponse.payerId ?? { email: webhookResponse.email },
|
|
4056
4056
|
status,
|
|
4057
|
-
metadata: core.omitInternalMetadata(
|
|
4058
|
-
|
|
4057
|
+
metadata: core.omitInternalMetadata(
|
|
4058
|
+
JSON.parse(webhookResponse.refId)
|
|
4059
|
+
),
|
|
4060
|
+
item_id: null
|
|
4059
4061
|
};
|
|
4060
4062
|
};
|
|
4061
4063
|
var paykitInvoice$InboundSchema = (webhookResponse) => {
|
|
@@ -4075,7 +4077,9 @@ var paykitInvoice$InboundSchema = (webhookResponse) => {
|
|
|
4075
4077
|
billing_mode: "one_time",
|
|
4076
4078
|
// comgate does not support recurring payments
|
|
4077
4079
|
line_items: webhookResponse.name ? [{ id: webhookResponse.name, quantity: 1 }] : [],
|
|
4078
|
-
metadata: core.omitInternalMetadata(
|
|
4080
|
+
metadata: core.omitInternalMetadata(
|
|
4081
|
+
JSON.parse(webhookResponse.refId)
|
|
4082
|
+
)
|
|
4079
4083
|
};
|
|
4080
4084
|
};
|
|
4081
4085
|
|
|
@@ -4108,18 +4112,29 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4108
4112
|
baseUrl;
|
|
4109
4113
|
_client;
|
|
4110
4114
|
_throwOnError = (req, message) => {
|
|
4111
|
-
if (!req.ok)
|
|
4115
|
+
if (!req.ok)
|
|
4116
|
+
throw new core.OperationFailedError(message, this.providerName, {
|
|
4117
|
+
cause: new Error(req.error)
|
|
4118
|
+
});
|
|
4112
4119
|
if (req.value.code == 1100) {
|
|
4113
|
-
throw new core.OperationFailedError("Unknown error", this.providerName, {
|
|
4120
|
+
throw new core.OperationFailedError("Unknown error", this.providerName, {
|
|
4121
|
+
cause: new Error("Unknown error")
|
|
4122
|
+
});
|
|
4114
4123
|
}
|
|
4115
4124
|
if (req.value.code == 1200) {
|
|
4116
|
-
throw new core.OperationFailedError("Database error", this.providerName, {
|
|
4125
|
+
throw new core.OperationFailedError("Database error", this.providerName, {
|
|
4126
|
+
cause: new Error("Database error")
|
|
4127
|
+
});
|
|
4117
4128
|
}
|
|
4118
4129
|
if (req.value.code == 1400) {
|
|
4119
|
-
throw new core.OperationFailedError("Wrong query error", this.providerName, {
|
|
4130
|
+
throw new core.OperationFailedError("Wrong query error", this.providerName, {
|
|
4131
|
+
cause: new Error("Wrong query error")
|
|
4132
|
+
});
|
|
4120
4133
|
}
|
|
4121
4134
|
if (req.value.code == 1500) {
|
|
4122
|
-
throw new core.OperationFailedError("Unexpected error", this.providerName, {
|
|
4135
|
+
throw new core.OperationFailedError("Unexpected error", this.providerName, {
|
|
4136
|
+
cause: new Error("Unexpected error")
|
|
4137
|
+
});
|
|
4123
4138
|
}
|
|
4124
4139
|
return req.value;
|
|
4125
4140
|
};
|
|
@@ -4203,7 +4218,8 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4203
4218
|
};
|
|
4204
4219
|
createPayment = async (params) => {
|
|
4205
4220
|
const { error, data } = core.createPaymentSchema.safeParse(params);
|
|
4206
|
-
if (error)
|
|
4221
|
+
if (error)
|
|
4222
|
+
throw core.ValidationError.fromZodError(error, this.providerName, "createPayment");
|
|
4207
4223
|
const { customer } = data;
|
|
4208
4224
|
if (typeof customer === "object") {
|
|
4209
4225
|
throw new core.InvalidTypeError("customer", "string (customer ID)", "object", {
|
|
@@ -4229,18 +4245,23 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4229
4245
|
curr: String(data.currency),
|
|
4230
4246
|
label: String(paymentLabel)
|
|
4231
4247
|
});
|
|
4232
|
-
const response = await this._client.post(
|
|
4233
|
-
|
|
4234
|
-
|
|
4248
|
+
const response = await this._client.post(
|
|
4249
|
+
`/v2.0/payment`,
|
|
4250
|
+
{
|
|
4251
|
+
body: requestBody.toString()
|
|
4252
|
+
}
|
|
4253
|
+
);
|
|
4235
4254
|
this._throwOnError(response, "Failed to create payment");
|
|
4236
4255
|
const paymentObject = {
|
|
4237
4256
|
id: response.value.transId,
|
|
4238
4257
|
amount: data.amount,
|
|
4239
4258
|
currency: data.currency,
|
|
4240
4259
|
status: "pending",
|
|
4241
|
-
metadata:
|
|
4260
|
+
metadata: Object.fromEntries(
|
|
4261
|
+
Object.entries(data.metadata ?? {}).map(([key, value]) => [key, String(value)])
|
|
4262
|
+
),
|
|
4242
4263
|
customer,
|
|
4243
|
-
|
|
4264
|
+
item_id: data.item_id ?? null
|
|
4244
4265
|
};
|
|
4245
4266
|
return paymentObject;
|
|
4246
4267
|
};
|
|
@@ -4262,7 +4283,9 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4262
4283
|
retrievePayment = async (id) => {
|
|
4263
4284
|
const { error } = core.createPaymentSchema.safeParse({ id });
|
|
4264
4285
|
if (error) throw new Error(`Payment retrieval validation failed: ${error.message}`);
|
|
4265
|
-
const response = await this._client.get(
|
|
4286
|
+
const response = await this._client.get(
|
|
4287
|
+
`/v2.0/payment/${id}.json`
|
|
4288
|
+
);
|
|
4266
4289
|
if (!response.ok) {
|
|
4267
4290
|
throw new core.OperationFailedError(`Failed to retrieve payment`, this.providerName, {
|
|
4268
4291
|
cause: new Error("Unknown error")
|
|
@@ -4275,9 +4298,12 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4275
4298
|
if (error) {
|
|
4276
4299
|
throw core.ValidationError.fromZodError(error, this.providerName, "capturePayment");
|
|
4277
4300
|
}
|
|
4278
|
-
const response = await this._client.post(
|
|
4279
|
-
|
|
4280
|
-
|
|
4301
|
+
const response = await this._client.post(
|
|
4302
|
+
`/v2.0/preauth/${id}/confirm.json`,
|
|
4303
|
+
{
|
|
4304
|
+
body: new URLSearchParams({ amount: String(data.amount) }).toString()
|
|
4305
|
+
}
|
|
4306
|
+
);
|
|
4281
4307
|
this._throwOnError(response, "Failed to capture payment");
|
|
4282
4308
|
const paymentObject = {
|
|
4283
4309
|
id: response.value.transId,
|
|
@@ -4286,12 +4312,15 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4286
4312
|
status: "succeeded",
|
|
4287
4313
|
metadata: {},
|
|
4288
4314
|
customer: "",
|
|
4289
|
-
|
|
4315
|
+
item_id: null
|
|
4290
4316
|
};
|
|
4291
4317
|
return paymentObject;
|
|
4292
4318
|
};
|
|
4293
4319
|
cancelPayment = async (id) => {
|
|
4294
|
-
const response = await this._client.delete(
|
|
4320
|
+
const response = await this._client.delete(
|
|
4321
|
+
`/v2.0/payment/transId/${id}.json`,
|
|
4322
|
+
{}
|
|
4323
|
+
);
|
|
4295
4324
|
this._throwOnError(response, "Failed to cancel payment");
|
|
4296
4325
|
return response.value;
|
|
4297
4326
|
};
|
|
@@ -4316,7 +4345,9 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4316
4345
|
amount: data.amount,
|
|
4317
4346
|
currency: "CZK",
|
|
4318
4347
|
reason: data.reason,
|
|
4319
|
-
metadata:
|
|
4348
|
+
metadata: Object.fromEntries(
|
|
4349
|
+
Object.entries(data.metadata ?? {}).map(([key, value]) => [key, String(value)])
|
|
4350
|
+
)
|
|
4320
4351
|
};
|
|
4321
4352
|
return refundObject;
|
|
4322
4353
|
};
|
|
@@ -4350,9 +4381,12 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4350
4381
|
alternative: "Use the payment API instead and cancel the subscription manually"
|
|
4351
4382
|
});
|
|
4352
4383
|
};
|
|
4353
|
-
handleWebhook = async ({
|
|
4384
|
+
handleWebhook = async ({
|
|
4385
|
+
body: rawBody,
|
|
4386
|
+
headers
|
|
4387
|
+
}) => {
|
|
4354
4388
|
let body;
|
|
4355
|
-
const contentType = headers
|
|
4389
|
+
const contentType = headers.get("content-type");
|
|
4356
4390
|
if (contentType === "application/json") {
|
|
4357
4391
|
body = JSON.parse(rawBody);
|
|
4358
4392
|
} else {
|
|
@@ -4378,15 +4412,27 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4378
4412
|
throw new core.WebhookError("Webhook secret mismatch", { provider: this.providerName });
|
|
4379
4413
|
}
|
|
4380
4414
|
if (merchant !== this.opts.merchant) {
|
|
4381
|
-
throw new core.WebhookError("Webhook merchant mismatch", {
|
|
4415
|
+
throw new core.WebhookError("Webhook merchant mismatch", {
|
|
4416
|
+
provider: this.providerName
|
|
4417
|
+
});
|
|
4382
4418
|
}
|
|
4383
|
-
const verifyResponse = await this._client.post(
|
|
4384
|
-
|
|
4385
|
-
|
|
4419
|
+
const verifyResponse = await this._client.post(
|
|
4420
|
+
"/v1.0/status",
|
|
4421
|
+
{
|
|
4422
|
+
body: new URLSearchParams({
|
|
4423
|
+
merchant: this.opts.merchant,
|
|
4424
|
+
transId,
|
|
4425
|
+
secret: this.opts.secret
|
|
4426
|
+
}).toString()
|
|
4427
|
+
}
|
|
4428
|
+
);
|
|
4386
4429
|
this._throwOnError(verifyResponse, "Failed to verify webhook");
|
|
4387
4430
|
const comgateWebhookApiResponse = verifyResponse.value;
|
|
4388
4431
|
if (this.opts.debug) {
|
|
4389
|
-
console.info(
|
|
4432
|
+
console.info(
|
|
4433
|
+
"Webhook verified successfully, status:",
|
|
4434
|
+
comgateWebhookApiResponse.status
|
|
4435
|
+
);
|
|
4390
4436
|
}
|
|
4391
4437
|
if (!comgateWebhookApiResponse.status) {
|
|
4392
4438
|
throw new core.WebhookError("Failed to verify webhook: no status returned");
|
|
@@ -4052,8 +4052,10 @@ var paykitPayment$InboundSchema = (webhookResponse, status) => {
|
|
|
4052
4052
|
currency: webhookResponse.curr,
|
|
4053
4053
|
customer: webhookResponse.payerId ?? { email: webhookResponse.email },
|
|
4054
4054
|
status,
|
|
4055
|
-
metadata: omitInternalMetadata(
|
|
4056
|
-
|
|
4055
|
+
metadata: omitInternalMetadata(
|
|
4056
|
+
JSON.parse(webhookResponse.refId)
|
|
4057
|
+
),
|
|
4058
|
+
item_id: null
|
|
4057
4059
|
};
|
|
4058
4060
|
};
|
|
4059
4061
|
var paykitInvoice$InboundSchema = (webhookResponse) => {
|
|
@@ -4073,7 +4075,9 @@ var paykitInvoice$InboundSchema = (webhookResponse) => {
|
|
|
4073
4075
|
billing_mode: "one_time",
|
|
4074
4076
|
// comgate does not support recurring payments
|
|
4075
4077
|
line_items: webhookResponse.name ? [{ id: webhookResponse.name, quantity: 1 }] : [],
|
|
4076
|
-
metadata: omitInternalMetadata(
|
|
4078
|
+
metadata: omitInternalMetadata(
|
|
4079
|
+
JSON.parse(webhookResponse.refId)
|
|
4080
|
+
)
|
|
4077
4081
|
};
|
|
4078
4082
|
};
|
|
4079
4083
|
|
|
@@ -4106,18 +4110,29 @@ var ComgateProvider = class extends AbstractPayKitProvider {
|
|
|
4106
4110
|
baseUrl;
|
|
4107
4111
|
_client;
|
|
4108
4112
|
_throwOnError = (req, message) => {
|
|
4109
|
-
if (!req.ok)
|
|
4113
|
+
if (!req.ok)
|
|
4114
|
+
throw new OperationFailedError(message, this.providerName, {
|
|
4115
|
+
cause: new Error(req.error)
|
|
4116
|
+
});
|
|
4110
4117
|
if (req.value.code == 1100) {
|
|
4111
|
-
throw new OperationFailedError("Unknown error", this.providerName, {
|
|
4118
|
+
throw new OperationFailedError("Unknown error", this.providerName, {
|
|
4119
|
+
cause: new Error("Unknown error")
|
|
4120
|
+
});
|
|
4112
4121
|
}
|
|
4113
4122
|
if (req.value.code == 1200) {
|
|
4114
|
-
throw new OperationFailedError("Database error", this.providerName, {
|
|
4123
|
+
throw new OperationFailedError("Database error", this.providerName, {
|
|
4124
|
+
cause: new Error("Database error")
|
|
4125
|
+
});
|
|
4115
4126
|
}
|
|
4116
4127
|
if (req.value.code == 1400) {
|
|
4117
|
-
throw new OperationFailedError("Wrong query error", this.providerName, {
|
|
4128
|
+
throw new OperationFailedError("Wrong query error", this.providerName, {
|
|
4129
|
+
cause: new Error("Wrong query error")
|
|
4130
|
+
});
|
|
4118
4131
|
}
|
|
4119
4132
|
if (req.value.code == 1500) {
|
|
4120
|
-
throw new OperationFailedError("Unexpected error", this.providerName, {
|
|
4133
|
+
throw new OperationFailedError("Unexpected error", this.providerName, {
|
|
4134
|
+
cause: new Error("Unexpected error")
|
|
4135
|
+
});
|
|
4121
4136
|
}
|
|
4122
4137
|
return req.value;
|
|
4123
4138
|
};
|
|
@@ -4201,7 +4216,8 @@ var ComgateProvider = class extends AbstractPayKitProvider {
|
|
|
4201
4216
|
};
|
|
4202
4217
|
createPayment = async (params) => {
|
|
4203
4218
|
const { error, data } = createPaymentSchema.safeParse(params);
|
|
4204
|
-
if (error)
|
|
4219
|
+
if (error)
|
|
4220
|
+
throw ValidationError.fromZodError(error, this.providerName, "createPayment");
|
|
4205
4221
|
const { customer } = data;
|
|
4206
4222
|
if (typeof customer === "object") {
|
|
4207
4223
|
throw new InvalidTypeError("customer", "string (customer ID)", "object", {
|
|
@@ -4227,18 +4243,23 @@ var ComgateProvider = class extends AbstractPayKitProvider {
|
|
|
4227
4243
|
curr: String(data.currency),
|
|
4228
4244
|
label: String(paymentLabel)
|
|
4229
4245
|
});
|
|
4230
|
-
const response = await this._client.post(
|
|
4231
|
-
|
|
4232
|
-
|
|
4246
|
+
const response = await this._client.post(
|
|
4247
|
+
`/v2.0/payment`,
|
|
4248
|
+
{
|
|
4249
|
+
body: requestBody.toString()
|
|
4250
|
+
}
|
|
4251
|
+
);
|
|
4233
4252
|
this._throwOnError(response, "Failed to create payment");
|
|
4234
4253
|
const paymentObject = {
|
|
4235
4254
|
id: response.value.transId,
|
|
4236
4255
|
amount: data.amount,
|
|
4237
4256
|
currency: data.currency,
|
|
4238
4257
|
status: "pending",
|
|
4239
|
-
metadata:
|
|
4258
|
+
metadata: Object.fromEntries(
|
|
4259
|
+
Object.entries(data.metadata ?? {}).map(([key, value]) => [key, String(value)])
|
|
4260
|
+
),
|
|
4240
4261
|
customer,
|
|
4241
|
-
|
|
4262
|
+
item_id: data.item_id ?? null
|
|
4242
4263
|
};
|
|
4243
4264
|
return paymentObject;
|
|
4244
4265
|
};
|
|
@@ -4260,7 +4281,9 @@ var ComgateProvider = class extends AbstractPayKitProvider {
|
|
|
4260
4281
|
retrievePayment = async (id) => {
|
|
4261
4282
|
const { error } = createPaymentSchema.safeParse({ id });
|
|
4262
4283
|
if (error) throw new Error(`Payment retrieval validation failed: ${error.message}`);
|
|
4263
|
-
const response = await this._client.get(
|
|
4284
|
+
const response = await this._client.get(
|
|
4285
|
+
`/v2.0/payment/${id}.json`
|
|
4286
|
+
);
|
|
4264
4287
|
if (!response.ok) {
|
|
4265
4288
|
throw new OperationFailedError(`Failed to retrieve payment`, this.providerName, {
|
|
4266
4289
|
cause: new Error("Unknown error")
|
|
@@ -4273,9 +4296,12 @@ var ComgateProvider = class extends AbstractPayKitProvider {
|
|
|
4273
4296
|
if (error) {
|
|
4274
4297
|
throw ValidationError.fromZodError(error, this.providerName, "capturePayment");
|
|
4275
4298
|
}
|
|
4276
|
-
const response = await this._client.post(
|
|
4277
|
-
|
|
4278
|
-
|
|
4299
|
+
const response = await this._client.post(
|
|
4300
|
+
`/v2.0/preauth/${id}/confirm.json`,
|
|
4301
|
+
{
|
|
4302
|
+
body: new URLSearchParams({ amount: String(data.amount) }).toString()
|
|
4303
|
+
}
|
|
4304
|
+
);
|
|
4279
4305
|
this._throwOnError(response, "Failed to capture payment");
|
|
4280
4306
|
const paymentObject = {
|
|
4281
4307
|
id: response.value.transId,
|
|
@@ -4284,12 +4310,15 @@ var ComgateProvider = class extends AbstractPayKitProvider {
|
|
|
4284
4310
|
status: "succeeded",
|
|
4285
4311
|
metadata: {},
|
|
4286
4312
|
customer: "",
|
|
4287
|
-
|
|
4313
|
+
item_id: null
|
|
4288
4314
|
};
|
|
4289
4315
|
return paymentObject;
|
|
4290
4316
|
};
|
|
4291
4317
|
cancelPayment = async (id) => {
|
|
4292
|
-
const response = await this._client.delete(
|
|
4318
|
+
const response = await this._client.delete(
|
|
4319
|
+
`/v2.0/payment/transId/${id}.json`,
|
|
4320
|
+
{}
|
|
4321
|
+
);
|
|
4293
4322
|
this._throwOnError(response, "Failed to cancel payment");
|
|
4294
4323
|
return response.value;
|
|
4295
4324
|
};
|
|
@@ -4314,7 +4343,9 @@ var ComgateProvider = class extends AbstractPayKitProvider {
|
|
|
4314
4343
|
amount: data.amount,
|
|
4315
4344
|
currency: "CZK",
|
|
4316
4345
|
reason: data.reason,
|
|
4317
|
-
metadata:
|
|
4346
|
+
metadata: Object.fromEntries(
|
|
4347
|
+
Object.entries(data.metadata ?? {}).map(([key, value]) => [key, String(value)])
|
|
4348
|
+
)
|
|
4318
4349
|
};
|
|
4319
4350
|
return refundObject;
|
|
4320
4351
|
};
|
|
@@ -4348,9 +4379,12 @@ var ComgateProvider = class extends AbstractPayKitProvider {
|
|
|
4348
4379
|
alternative: "Use the payment API instead and cancel the subscription manually"
|
|
4349
4380
|
});
|
|
4350
4381
|
};
|
|
4351
|
-
handleWebhook = async ({
|
|
4382
|
+
handleWebhook = async ({
|
|
4383
|
+
body: rawBody,
|
|
4384
|
+
headers
|
|
4385
|
+
}) => {
|
|
4352
4386
|
let body;
|
|
4353
|
-
const contentType = headers
|
|
4387
|
+
const contentType = headers.get("content-type");
|
|
4354
4388
|
if (contentType === "application/json") {
|
|
4355
4389
|
body = JSON.parse(rawBody);
|
|
4356
4390
|
} else {
|
|
@@ -4376,15 +4410,27 @@ var ComgateProvider = class extends AbstractPayKitProvider {
|
|
|
4376
4410
|
throw new WebhookError("Webhook secret mismatch", { provider: this.providerName });
|
|
4377
4411
|
}
|
|
4378
4412
|
if (merchant !== this.opts.merchant) {
|
|
4379
|
-
throw new WebhookError("Webhook merchant mismatch", {
|
|
4413
|
+
throw new WebhookError("Webhook merchant mismatch", {
|
|
4414
|
+
provider: this.providerName
|
|
4415
|
+
});
|
|
4380
4416
|
}
|
|
4381
|
-
const verifyResponse = await this._client.post(
|
|
4382
|
-
|
|
4383
|
-
|
|
4417
|
+
const verifyResponse = await this._client.post(
|
|
4418
|
+
"/v1.0/status",
|
|
4419
|
+
{
|
|
4420
|
+
body: new URLSearchParams({
|
|
4421
|
+
merchant: this.opts.merchant,
|
|
4422
|
+
transId,
|
|
4423
|
+
secret: this.opts.secret
|
|
4424
|
+
}).toString()
|
|
4425
|
+
}
|
|
4426
|
+
);
|
|
4384
4427
|
this._throwOnError(verifyResponse, "Failed to verify webhook");
|
|
4385
4428
|
const comgateWebhookApiResponse = verifyResponse.value;
|
|
4386
4429
|
if (this.opts.debug) {
|
|
4387
|
-
console.info(
|
|
4430
|
+
console.info(
|
|
4431
|
+
"Webhook verified successfully, status:",
|
|
4432
|
+
comgateWebhookApiResponse.status
|
|
4433
|
+
);
|
|
4388
4434
|
}
|
|
4389
4435
|
if (!comgateWebhookApiResponse.status) {
|
|
4390
4436
|
throw new WebhookError("Failed to verify webhook: no status returned");
|
package/dist/index.js
CHANGED
|
@@ -4054,8 +4054,10 @@ var paykitPayment$InboundSchema = (webhookResponse, status) => {
|
|
|
4054
4054
|
currency: webhookResponse.curr,
|
|
4055
4055
|
customer: webhookResponse.payerId ?? { email: webhookResponse.email },
|
|
4056
4056
|
status,
|
|
4057
|
-
metadata: core.omitInternalMetadata(
|
|
4058
|
-
|
|
4057
|
+
metadata: core.omitInternalMetadata(
|
|
4058
|
+
JSON.parse(webhookResponse.refId)
|
|
4059
|
+
),
|
|
4060
|
+
item_id: null
|
|
4059
4061
|
};
|
|
4060
4062
|
};
|
|
4061
4063
|
var paykitInvoice$InboundSchema = (webhookResponse) => {
|
|
@@ -4075,7 +4077,9 @@ var paykitInvoice$InboundSchema = (webhookResponse) => {
|
|
|
4075
4077
|
billing_mode: "one_time",
|
|
4076
4078
|
// comgate does not support recurring payments
|
|
4077
4079
|
line_items: webhookResponse.name ? [{ id: webhookResponse.name, quantity: 1 }] : [],
|
|
4078
|
-
metadata: core.omitInternalMetadata(
|
|
4080
|
+
metadata: core.omitInternalMetadata(
|
|
4081
|
+
JSON.parse(webhookResponse.refId)
|
|
4082
|
+
)
|
|
4079
4083
|
};
|
|
4080
4084
|
};
|
|
4081
4085
|
|
|
@@ -4108,18 +4112,29 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4108
4112
|
baseUrl;
|
|
4109
4113
|
_client;
|
|
4110
4114
|
_throwOnError = (req, message) => {
|
|
4111
|
-
if (!req.ok)
|
|
4115
|
+
if (!req.ok)
|
|
4116
|
+
throw new core.OperationFailedError(message, this.providerName, {
|
|
4117
|
+
cause: new Error(req.error)
|
|
4118
|
+
});
|
|
4112
4119
|
if (req.value.code == 1100) {
|
|
4113
|
-
throw new core.OperationFailedError("Unknown error", this.providerName, {
|
|
4120
|
+
throw new core.OperationFailedError("Unknown error", this.providerName, {
|
|
4121
|
+
cause: new Error("Unknown error")
|
|
4122
|
+
});
|
|
4114
4123
|
}
|
|
4115
4124
|
if (req.value.code == 1200) {
|
|
4116
|
-
throw new core.OperationFailedError("Database error", this.providerName, {
|
|
4125
|
+
throw new core.OperationFailedError("Database error", this.providerName, {
|
|
4126
|
+
cause: new Error("Database error")
|
|
4127
|
+
});
|
|
4117
4128
|
}
|
|
4118
4129
|
if (req.value.code == 1400) {
|
|
4119
|
-
throw new core.OperationFailedError("Wrong query error", this.providerName, {
|
|
4130
|
+
throw new core.OperationFailedError("Wrong query error", this.providerName, {
|
|
4131
|
+
cause: new Error("Wrong query error")
|
|
4132
|
+
});
|
|
4120
4133
|
}
|
|
4121
4134
|
if (req.value.code == 1500) {
|
|
4122
|
-
throw new core.OperationFailedError("Unexpected error", this.providerName, {
|
|
4135
|
+
throw new core.OperationFailedError("Unexpected error", this.providerName, {
|
|
4136
|
+
cause: new Error("Unexpected error")
|
|
4137
|
+
});
|
|
4123
4138
|
}
|
|
4124
4139
|
return req.value;
|
|
4125
4140
|
};
|
|
@@ -4203,7 +4218,8 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4203
4218
|
};
|
|
4204
4219
|
createPayment = async (params) => {
|
|
4205
4220
|
const { error, data } = core.createPaymentSchema.safeParse(params);
|
|
4206
|
-
if (error)
|
|
4221
|
+
if (error)
|
|
4222
|
+
throw core.ValidationError.fromZodError(error, this.providerName, "createPayment");
|
|
4207
4223
|
const { customer } = data;
|
|
4208
4224
|
if (typeof customer === "object") {
|
|
4209
4225
|
throw new core.InvalidTypeError("customer", "string (customer ID)", "object", {
|
|
@@ -4229,18 +4245,23 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4229
4245
|
curr: String(data.currency),
|
|
4230
4246
|
label: String(paymentLabel)
|
|
4231
4247
|
});
|
|
4232
|
-
const response = await this._client.post(
|
|
4233
|
-
|
|
4234
|
-
|
|
4248
|
+
const response = await this._client.post(
|
|
4249
|
+
`/v2.0/payment`,
|
|
4250
|
+
{
|
|
4251
|
+
body: requestBody.toString()
|
|
4252
|
+
}
|
|
4253
|
+
);
|
|
4235
4254
|
this._throwOnError(response, "Failed to create payment");
|
|
4236
4255
|
const paymentObject = {
|
|
4237
4256
|
id: response.value.transId,
|
|
4238
4257
|
amount: data.amount,
|
|
4239
4258
|
currency: data.currency,
|
|
4240
4259
|
status: "pending",
|
|
4241
|
-
metadata:
|
|
4260
|
+
metadata: Object.fromEntries(
|
|
4261
|
+
Object.entries(data.metadata ?? {}).map(([key, value]) => [key, String(value)])
|
|
4262
|
+
),
|
|
4242
4263
|
customer,
|
|
4243
|
-
|
|
4264
|
+
item_id: data.item_id ?? null
|
|
4244
4265
|
};
|
|
4245
4266
|
return paymentObject;
|
|
4246
4267
|
};
|
|
@@ -4262,7 +4283,9 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4262
4283
|
retrievePayment = async (id) => {
|
|
4263
4284
|
const { error } = core.createPaymentSchema.safeParse({ id });
|
|
4264
4285
|
if (error) throw new Error(`Payment retrieval validation failed: ${error.message}`);
|
|
4265
|
-
const response = await this._client.get(
|
|
4286
|
+
const response = await this._client.get(
|
|
4287
|
+
`/v2.0/payment/${id}.json`
|
|
4288
|
+
);
|
|
4266
4289
|
if (!response.ok) {
|
|
4267
4290
|
throw new core.OperationFailedError(`Failed to retrieve payment`, this.providerName, {
|
|
4268
4291
|
cause: new Error("Unknown error")
|
|
@@ -4275,9 +4298,12 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4275
4298
|
if (error) {
|
|
4276
4299
|
throw core.ValidationError.fromZodError(error, this.providerName, "capturePayment");
|
|
4277
4300
|
}
|
|
4278
|
-
const response = await this._client.post(
|
|
4279
|
-
|
|
4280
|
-
|
|
4301
|
+
const response = await this._client.post(
|
|
4302
|
+
`/v2.0/preauth/${id}/confirm.json`,
|
|
4303
|
+
{
|
|
4304
|
+
body: new URLSearchParams({ amount: String(data.amount) }).toString()
|
|
4305
|
+
}
|
|
4306
|
+
);
|
|
4281
4307
|
this._throwOnError(response, "Failed to capture payment");
|
|
4282
4308
|
const paymentObject = {
|
|
4283
4309
|
id: response.value.transId,
|
|
@@ -4286,12 +4312,15 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4286
4312
|
status: "succeeded",
|
|
4287
4313
|
metadata: {},
|
|
4288
4314
|
customer: "",
|
|
4289
|
-
|
|
4315
|
+
item_id: null
|
|
4290
4316
|
};
|
|
4291
4317
|
return paymentObject;
|
|
4292
4318
|
};
|
|
4293
4319
|
cancelPayment = async (id) => {
|
|
4294
|
-
const response = await this._client.delete(
|
|
4320
|
+
const response = await this._client.delete(
|
|
4321
|
+
`/v2.0/payment/transId/${id}.json`,
|
|
4322
|
+
{}
|
|
4323
|
+
);
|
|
4295
4324
|
this._throwOnError(response, "Failed to cancel payment");
|
|
4296
4325
|
return response.value;
|
|
4297
4326
|
};
|
|
@@ -4316,7 +4345,9 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4316
4345
|
amount: data.amount,
|
|
4317
4346
|
currency: "CZK",
|
|
4318
4347
|
reason: data.reason,
|
|
4319
|
-
metadata:
|
|
4348
|
+
metadata: Object.fromEntries(
|
|
4349
|
+
Object.entries(data.metadata ?? {}).map(([key, value]) => [key, String(value)])
|
|
4350
|
+
)
|
|
4320
4351
|
};
|
|
4321
4352
|
return refundObject;
|
|
4322
4353
|
};
|
|
@@ -4350,9 +4381,12 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4350
4381
|
alternative: "Use the payment API instead and cancel the subscription manually"
|
|
4351
4382
|
});
|
|
4352
4383
|
};
|
|
4353
|
-
handleWebhook = async ({
|
|
4384
|
+
handleWebhook = async ({
|
|
4385
|
+
body: rawBody,
|
|
4386
|
+
headers
|
|
4387
|
+
}) => {
|
|
4354
4388
|
let body;
|
|
4355
|
-
const contentType = headers
|
|
4389
|
+
const contentType = headers.get("content-type");
|
|
4356
4390
|
if (contentType === "application/json") {
|
|
4357
4391
|
body = JSON.parse(rawBody);
|
|
4358
4392
|
} else {
|
|
@@ -4378,15 +4412,27 @@ var ComgateProvider = class extends core.AbstractPayKitProvider {
|
|
|
4378
4412
|
throw new core.WebhookError("Webhook secret mismatch", { provider: this.providerName });
|
|
4379
4413
|
}
|
|
4380
4414
|
if (merchant !== this.opts.merchant) {
|
|
4381
|
-
throw new core.WebhookError("Webhook merchant mismatch", {
|
|
4415
|
+
throw new core.WebhookError("Webhook merchant mismatch", {
|
|
4416
|
+
provider: this.providerName
|
|
4417
|
+
});
|
|
4382
4418
|
}
|
|
4383
|
-
const verifyResponse = await this._client.post(
|
|
4384
|
-
|
|
4385
|
-
|
|
4419
|
+
const verifyResponse = await this._client.post(
|
|
4420
|
+
"/v1.0/status",
|
|
4421
|
+
{
|
|
4422
|
+
body: new URLSearchParams({
|
|
4423
|
+
merchant: this.opts.merchant,
|
|
4424
|
+
transId,
|
|
4425
|
+
secret: this.opts.secret
|
|
4426
|
+
}).toString()
|
|
4427
|
+
}
|
|
4428
|
+
);
|
|
4386
4429
|
this._throwOnError(verifyResponse, "Failed to verify webhook");
|
|
4387
4430
|
const comgateWebhookApiResponse = verifyResponse.value;
|
|
4388
4431
|
if (this.opts.debug) {
|
|
4389
|
-
console.info(
|
|
4432
|
+
console.info(
|
|
4433
|
+
"Webhook verified successfully, status:",
|
|
4434
|
+
comgateWebhookApiResponse.status
|
|
4435
|
+
);
|
|
4390
4436
|
}
|
|
4391
4437
|
if (!comgateWebhookApiResponse.status) {
|
|
4392
4438
|
throw new core.WebhookError("Failed to verify webhook: no status returned");
|
package/dist/index.mjs
CHANGED
|
@@ -4052,8 +4052,10 @@ var paykitPayment$InboundSchema = (webhookResponse, status) => {
|
|
|
4052
4052
|
currency: webhookResponse.curr,
|
|
4053
4053
|
customer: webhookResponse.payerId ?? { email: webhookResponse.email },
|
|
4054
4054
|
status,
|
|
4055
|
-
metadata: omitInternalMetadata(
|
|
4056
|
-
|
|
4055
|
+
metadata: omitInternalMetadata(
|
|
4056
|
+
JSON.parse(webhookResponse.refId)
|
|
4057
|
+
),
|
|
4058
|
+
item_id: null
|
|
4057
4059
|
};
|
|
4058
4060
|
};
|
|
4059
4061
|
var paykitInvoice$InboundSchema = (webhookResponse) => {
|
|
@@ -4073,7 +4075,9 @@ var paykitInvoice$InboundSchema = (webhookResponse) => {
|
|
|
4073
4075
|
billing_mode: "one_time",
|
|
4074
4076
|
// comgate does not support recurring payments
|
|
4075
4077
|
line_items: webhookResponse.name ? [{ id: webhookResponse.name, quantity: 1 }] : [],
|
|
4076
|
-
metadata: omitInternalMetadata(
|
|
4078
|
+
metadata: omitInternalMetadata(
|
|
4079
|
+
JSON.parse(webhookResponse.refId)
|
|
4080
|
+
)
|
|
4077
4081
|
};
|
|
4078
4082
|
};
|
|
4079
4083
|
|
|
@@ -4106,18 +4110,29 @@ var ComgateProvider = class extends AbstractPayKitProvider {
|
|
|
4106
4110
|
baseUrl;
|
|
4107
4111
|
_client;
|
|
4108
4112
|
_throwOnError = (req, message) => {
|
|
4109
|
-
if (!req.ok)
|
|
4113
|
+
if (!req.ok)
|
|
4114
|
+
throw new OperationFailedError(message, this.providerName, {
|
|
4115
|
+
cause: new Error(req.error)
|
|
4116
|
+
});
|
|
4110
4117
|
if (req.value.code == 1100) {
|
|
4111
|
-
throw new OperationFailedError("Unknown error", this.providerName, {
|
|
4118
|
+
throw new OperationFailedError("Unknown error", this.providerName, {
|
|
4119
|
+
cause: new Error("Unknown error")
|
|
4120
|
+
});
|
|
4112
4121
|
}
|
|
4113
4122
|
if (req.value.code == 1200) {
|
|
4114
|
-
throw new OperationFailedError("Database error", this.providerName, {
|
|
4123
|
+
throw new OperationFailedError("Database error", this.providerName, {
|
|
4124
|
+
cause: new Error("Database error")
|
|
4125
|
+
});
|
|
4115
4126
|
}
|
|
4116
4127
|
if (req.value.code == 1400) {
|
|
4117
|
-
throw new OperationFailedError("Wrong query error", this.providerName, {
|
|
4128
|
+
throw new OperationFailedError("Wrong query error", this.providerName, {
|
|
4129
|
+
cause: new Error("Wrong query error")
|
|
4130
|
+
});
|
|
4118
4131
|
}
|
|
4119
4132
|
if (req.value.code == 1500) {
|
|
4120
|
-
throw new OperationFailedError("Unexpected error", this.providerName, {
|
|
4133
|
+
throw new OperationFailedError("Unexpected error", this.providerName, {
|
|
4134
|
+
cause: new Error("Unexpected error")
|
|
4135
|
+
});
|
|
4121
4136
|
}
|
|
4122
4137
|
return req.value;
|
|
4123
4138
|
};
|
|
@@ -4201,7 +4216,8 @@ var ComgateProvider = class extends AbstractPayKitProvider {
|
|
|
4201
4216
|
};
|
|
4202
4217
|
createPayment = async (params) => {
|
|
4203
4218
|
const { error, data } = createPaymentSchema.safeParse(params);
|
|
4204
|
-
if (error)
|
|
4219
|
+
if (error)
|
|
4220
|
+
throw ValidationError.fromZodError(error, this.providerName, "createPayment");
|
|
4205
4221
|
const { customer } = data;
|
|
4206
4222
|
if (typeof customer === "object") {
|
|
4207
4223
|
throw new InvalidTypeError("customer", "string (customer ID)", "object", {
|
|
@@ -4227,18 +4243,23 @@ var ComgateProvider = class extends AbstractPayKitProvider {
|
|
|
4227
4243
|
curr: String(data.currency),
|
|
4228
4244
|
label: String(paymentLabel)
|
|
4229
4245
|
});
|
|
4230
|
-
const response = await this._client.post(
|
|
4231
|
-
|
|
4232
|
-
|
|
4246
|
+
const response = await this._client.post(
|
|
4247
|
+
`/v2.0/payment`,
|
|
4248
|
+
{
|
|
4249
|
+
body: requestBody.toString()
|
|
4250
|
+
}
|
|
4251
|
+
);
|
|
4233
4252
|
this._throwOnError(response, "Failed to create payment");
|
|
4234
4253
|
const paymentObject = {
|
|
4235
4254
|
id: response.value.transId,
|
|
4236
4255
|
amount: data.amount,
|
|
4237
4256
|
currency: data.currency,
|
|
4238
4257
|
status: "pending",
|
|
4239
|
-
metadata:
|
|
4258
|
+
metadata: Object.fromEntries(
|
|
4259
|
+
Object.entries(data.metadata ?? {}).map(([key, value]) => [key, String(value)])
|
|
4260
|
+
),
|
|
4240
4261
|
customer,
|
|
4241
|
-
|
|
4262
|
+
item_id: data.item_id ?? null
|
|
4242
4263
|
};
|
|
4243
4264
|
return paymentObject;
|
|
4244
4265
|
};
|
|
@@ -4260,7 +4281,9 @@ var ComgateProvider = class extends AbstractPayKitProvider {
|
|
|
4260
4281
|
retrievePayment = async (id) => {
|
|
4261
4282
|
const { error } = createPaymentSchema.safeParse({ id });
|
|
4262
4283
|
if (error) throw new Error(`Payment retrieval validation failed: ${error.message}`);
|
|
4263
|
-
const response = await this._client.get(
|
|
4284
|
+
const response = await this._client.get(
|
|
4285
|
+
`/v2.0/payment/${id}.json`
|
|
4286
|
+
);
|
|
4264
4287
|
if (!response.ok) {
|
|
4265
4288
|
throw new OperationFailedError(`Failed to retrieve payment`, this.providerName, {
|
|
4266
4289
|
cause: new Error("Unknown error")
|
|
@@ -4273,9 +4296,12 @@ var ComgateProvider = class extends AbstractPayKitProvider {
|
|
|
4273
4296
|
if (error) {
|
|
4274
4297
|
throw ValidationError.fromZodError(error, this.providerName, "capturePayment");
|
|
4275
4298
|
}
|
|
4276
|
-
const response = await this._client.post(
|
|
4277
|
-
|
|
4278
|
-
|
|
4299
|
+
const response = await this._client.post(
|
|
4300
|
+
`/v2.0/preauth/${id}/confirm.json`,
|
|
4301
|
+
{
|
|
4302
|
+
body: new URLSearchParams({ amount: String(data.amount) }).toString()
|
|
4303
|
+
}
|
|
4304
|
+
);
|
|
4279
4305
|
this._throwOnError(response, "Failed to capture payment");
|
|
4280
4306
|
const paymentObject = {
|
|
4281
4307
|
id: response.value.transId,
|
|
@@ -4284,12 +4310,15 @@ var ComgateProvider = class extends AbstractPayKitProvider {
|
|
|
4284
4310
|
status: "succeeded",
|
|
4285
4311
|
metadata: {},
|
|
4286
4312
|
customer: "",
|
|
4287
|
-
|
|
4313
|
+
item_id: null
|
|
4288
4314
|
};
|
|
4289
4315
|
return paymentObject;
|
|
4290
4316
|
};
|
|
4291
4317
|
cancelPayment = async (id) => {
|
|
4292
|
-
const response = await this._client.delete(
|
|
4318
|
+
const response = await this._client.delete(
|
|
4319
|
+
`/v2.0/payment/transId/${id}.json`,
|
|
4320
|
+
{}
|
|
4321
|
+
);
|
|
4293
4322
|
this._throwOnError(response, "Failed to cancel payment");
|
|
4294
4323
|
return response.value;
|
|
4295
4324
|
};
|
|
@@ -4314,7 +4343,9 @@ var ComgateProvider = class extends AbstractPayKitProvider {
|
|
|
4314
4343
|
amount: data.amount,
|
|
4315
4344
|
currency: "CZK",
|
|
4316
4345
|
reason: data.reason,
|
|
4317
|
-
metadata:
|
|
4346
|
+
metadata: Object.fromEntries(
|
|
4347
|
+
Object.entries(data.metadata ?? {}).map(([key, value]) => [key, String(value)])
|
|
4348
|
+
)
|
|
4318
4349
|
};
|
|
4319
4350
|
return refundObject;
|
|
4320
4351
|
};
|
|
@@ -4348,9 +4379,12 @@ var ComgateProvider = class extends AbstractPayKitProvider {
|
|
|
4348
4379
|
alternative: "Use the payment API instead and cancel the subscription manually"
|
|
4349
4380
|
});
|
|
4350
4381
|
};
|
|
4351
|
-
handleWebhook = async ({
|
|
4382
|
+
handleWebhook = async ({
|
|
4383
|
+
body: rawBody,
|
|
4384
|
+
headers
|
|
4385
|
+
}) => {
|
|
4352
4386
|
let body;
|
|
4353
|
-
const contentType = headers
|
|
4387
|
+
const contentType = headers.get("content-type");
|
|
4354
4388
|
if (contentType === "application/json") {
|
|
4355
4389
|
body = JSON.parse(rawBody);
|
|
4356
4390
|
} else {
|
|
@@ -4376,15 +4410,27 @@ var ComgateProvider = class extends AbstractPayKitProvider {
|
|
|
4376
4410
|
throw new WebhookError("Webhook secret mismatch", { provider: this.providerName });
|
|
4377
4411
|
}
|
|
4378
4412
|
if (merchant !== this.opts.merchant) {
|
|
4379
|
-
throw new WebhookError("Webhook merchant mismatch", {
|
|
4413
|
+
throw new WebhookError("Webhook merchant mismatch", {
|
|
4414
|
+
provider: this.providerName
|
|
4415
|
+
});
|
|
4380
4416
|
}
|
|
4381
|
-
const verifyResponse = await this._client.post(
|
|
4382
|
-
|
|
4383
|
-
|
|
4417
|
+
const verifyResponse = await this._client.post(
|
|
4418
|
+
"/v1.0/status",
|
|
4419
|
+
{
|
|
4420
|
+
body: new URLSearchParams({
|
|
4421
|
+
merchant: this.opts.merchant,
|
|
4422
|
+
transId,
|
|
4423
|
+
secret: this.opts.secret
|
|
4424
|
+
}).toString()
|
|
4425
|
+
}
|
|
4426
|
+
);
|
|
4384
4427
|
this._throwOnError(verifyResponse, "Failed to verify webhook");
|
|
4385
4428
|
const comgateWebhookApiResponse = verifyResponse.value;
|
|
4386
4429
|
if (this.opts.debug) {
|
|
4387
|
-
console.info(
|
|
4430
|
+
console.info(
|
|
4431
|
+
"Webhook verified successfully, status:",
|
|
4432
|
+
comgateWebhookApiResponse.status
|
|
4433
|
+
);
|
|
4388
4434
|
}
|
|
4389
4435
|
if (!comgateWebhookApiResponse.status) {
|
|
4390
4436
|
throw new WebhookError("Failed to verify webhook: no status returned");
|
package/dist/utils/mapper.js
CHANGED
|
@@ -10,8 +10,10 @@ var paykitPayment$InboundSchema = (webhookResponse, status) => {
|
|
|
10
10
|
currency: webhookResponse.curr,
|
|
11
11
|
customer: webhookResponse.payerId ?? { email: webhookResponse.email },
|
|
12
12
|
status,
|
|
13
|
-
metadata: core.omitInternalMetadata(
|
|
14
|
-
|
|
13
|
+
metadata: core.omitInternalMetadata(
|
|
14
|
+
JSON.parse(webhookResponse.refId)
|
|
15
|
+
),
|
|
16
|
+
item_id: null
|
|
15
17
|
};
|
|
16
18
|
};
|
|
17
19
|
var paykitInvoice$InboundSchema = (webhookResponse) => {
|
|
@@ -31,7 +33,9 @@ var paykitInvoice$InboundSchema = (webhookResponse) => {
|
|
|
31
33
|
billing_mode: "one_time",
|
|
32
34
|
// comgate does not support recurring payments
|
|
33
35
|
line_items: webhookResponse.name ? [{ id: webhookResponse.name, quantity: 1 }] : [],
|
|
34
|
-
metadata: core.omitInternalMetadata(
|
|
36
|
+
metadata: core.omitInternalMetadata(
|
|
37
|
+
JSON.parse(webhookResponse.refId)
|
|
38
|
+
)
|
|
35
39
|
};
|
|
36
40
|
};
|
|
37
41
|
|
package/dist/utils/mapper.mjs
CHANGED
|
@@ -8,8 +8,10 @@ var paykitPayment$InboundSchema = (webhookResponse, status) => {
|
|
|
8
8
|
currency: webhookResponse.curr,
|
|
9
9
|
customer: webhookResponse.payerId ?? { email: webhookResponse.email },
|
|
10
10
|
status,
|
|
11
|
-
metadata: omitInternalMetadata(
|
|
12
|
-
|
|
11
|
+
metadata: omitInternalMetadata(
|
|
12
|
+
JSON.parse(webhookResponse.refId)
|
|
13
|
+
),
|
|
14
|
+
item_id: null
|
|
13
15
|
};
|
|
14
16
|
};
|
|
15
17
|
var paykitInvoice$InboundSchema = (webhookResponse) => {
|
|
@@ -29,7 +31,9 @@ var paykitInvoice$InboundSchema = (webhookResponse) => {
|
|
|
29
31
|
billing_mode: "one_time",
|
|
30
32
|
// comgate does not support recurring payments
|
|
31
33
|
line_items: webhookResponse.name ? [{ id: webhookResponse.name, quantity: 1 }] : [],
|
|
32
|
-
metadata: omitInternalMetadata(
|
|
34
|
+
metadata: omitInternalMetadata(
|
|
35
|
+
JSON.parse(webhookResponse.refId)
|
|
36
|
+
)
|
|
33
37
|
};
|
|
34
38
|
};
|
|
35
39
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paykit-sdk/comgate",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Comgate provider for PayKit",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
@@ -8,21 +8,20 @@
|
|
|
8
8
|
"files": [
|
|
9
9
|
"dist"
|
|
10
10
|
],
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
"
|
|
16
|
-
"author": "",
|
|
11
|
+
"keywords": [
|
|
12
|
+
"paykit",
|
|
13
|
+
"comgate"
|
|
14
|
+
],
|
|
15
|
+
"author": "Emmanuel Odii",
|
|
17
16
|
"license": "ISC",
|
|
18
17
|
"peerDependencies": {
|
|
19
|
-
"@paykit-sdk/core": ">=1.1.
|
|
18
|
+
"@paykit-sdk/core": ">=1.1.96"
|
|
20
19
|
},
|
|
21
20
|
"devDependencies": {
|
|
22
|
-
"@paykit-sdk/core": "workspace:*",
|
|
23
21
|
"tsup": "^8.5.0",
|
|
24
22
|
"typescript": "^5.9.2",
|
|
25
|
-
"zod": "^3.24.2"
|
|
23
|
+
"zod": "^3.24.2",
|
|
24
|
+
"@paykit-sdk/core": "1.1.96"
|
|
26
25
|
},
|
|
27
26
|
"publishConfig": {
|
|
28
27
|
"access": "public"
|
|
@@ -33,5 +32,8 @@
|
|
|
33
32
|
},
|
|
34
33
|
"bugs": {
|
|
35
34
|
"url": "https://github.com/usepaykit/paykit-sdk/issues"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsup"
|
|
36
38
|
}
|
|
37
|
-
}
|
|
39
|
+
}
|