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