@paykit-sdk/gopay 1.1.2 → 1.1.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 +23 -6
- package/dist/gopay-provider.d.mts +24 -6
- package/dist/gopay-provider.d.ts +24 -6
- package/dist/gopay-provider.js +389 -196
- package/dist/gopay-provider.mjs +390 -197
- package/dist/index.js +391 -200
- package/dist/index.mjs +392 -201
- package/dist/utils/mapper.d.mts +19 -7
- package/dist/utils/mapper.d.ts +19 -7
- package/dist/utils/mapper.js +43 -31
- package/dist/utils/mapper.mjs +39 -27
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -4071,10 +4071,12 @@ var NEVER = INVALID;
|
|
|
4071
4071
|
var decodeHtmlEntities = (str) => {
|
|
4072
4072
|
return str.replace(/"/g, '"').replace(/'/g, "'").replace(/"/g, '"').replace(/'/g, "'");
|
|
4073
4073
|
};
|
|
4074
|
-
var
|
|
4074
|
+
var Payment$inboundSchema = (data) => {
|
|
4075
4075
|
const { item } = JSON.parse(
|
|
4076
4076
|
decodeHtmlEntities(
|
|
4077
|
-
data.additional_params?.find(
|
|
4077
|
+
data.additional_params?.find(
|
|
4078
|
+
(param) => param.name === core.PAYKIT_METADATA_KEY
|
|
4079
|
+
)?.value ?? "{}"
|
|
4078
4080
|
)
|
|
4079
4081
|
);
|
|
4080
4082
|
const metadata = core.omitInternalMetadata(
|
|
@@ -4101,7 +4103,7 @@ var paykitPayment$InboundSchema = (data) => {
|
|
|
4101
4103
|
id: data.id.toString(),
|
|
4102
4104
|
amount: data.amount,
|
|
4103
4105
|
currency: data.currency,
|
|
4104
|
-
customer: data.payer?.contact?.email ? { email: data.payer.contact.email } :
|
|
4106
|
+
customer: data.payer?.contact?.email ? { email: data.payer.contact.email } : null,
|
|
4105
4107
|
status: statusMap[data.state],
|
|
4106
4108
|
item_id: item,
|
|
4107
4109
|
metadata,
|
|
@@ -4109,10 +4111,12 @@ var paykitPayment$InboundSchema = (data) => {
|
|
|
4109
4111
|
payment_url: data.gw_url ?? null
|
|
4110
4112
|
};
|
|
4111
4113
|
};
|
|
4112
|
-
var
|
|
4114
|
+
var Checkout$inboundSchema = (data) => {
|
|
4113
4115
|
const { item, qty, type } = JSON.parse(
|
|
4114
4116
|
decodeHtmlEntities(
|
|
4115
|
-
data.additional_params?.find(
|
|
4117
|
+
data.additional_params?.find(
|
|
4118
|
+
(param) => param.name === core.PAYKIT_METADATA_KEY
|
|
4119
|
+
)?.value ?? "{}"
|
|
4116
4120
|
)
|
|
4117
4121
|
);
|
|
4118
4122
|
const metadata = core.omitInternalMetadata(
|
|
@@ -4128,24 +4132,28 @@ var paykitCheckout$InboundSchema = (data) => {
|
|
|
4128
4132
|
id: data.id.toString(),
|
|
4129
4133
|
amount: data.amount,
|
|
4130
4134
|
currency: data.currency,
|
|
4131
|
-
customer: data.payer?.contact?.email ? { email: data.payer.contact.email } :
|
|
4135
|
+
customer: data.payer?.contact?.email ? { email: data.payer.contact.email } : null,
|
|
4132
4136
|
payment_url: data.gw_url ?? "",
|
|
4133
4137
|
metadata,
|
|
4134
4138
|
session_type: type,
|
|
4135
4139
|
products: [{ id: item, quantity: parseInt(qty) }]
|
|
4136
4140
|
};
|
|
4137
4141
|
};
|
|
4138
|
-
var
|
|
4142
|
+
var Invoice$inboundSchema = (data, isSubscription) => {
|
|
4139
4143
|
const { item, qty } = JSON.parse(
|
|
4140
4144
|
decodeHtmlEntities(
|
|
4141
|
-
data.additional_params?.find(
|
|
4145
|
+
data.additional_params?.find(
|
|
4146
|
+
(param) => param.name === core.PAYKIT_METADATA_KEY
|
|
4147
|
+
)?.value ?? "{}"
|
|
4142
4148
|
)
|
|
4143
4149
|
);
|
|
4144
4150
|
const status = (() => {
|
|
4145
4151
|
if (data.state === "PAID") return "paid";
|
|
4146
4152
|
return "open";
|
|
4147
4153
|
})();
|
|
4148
|
-
const paidAt = isSubscription ? new Date(
|
|
4154
|
+
const paidAt = isSubscription ? new Date(
|
|
4155
|
+
data.recurrence?.recurrence_date_to ?? ""
|
|
4156
|
+
) : /* @__PURE__ */ new Date();
|
|
4149
4157
|
const metadata = core.omitInternalMetadata(
|
|
4150
4158
|
data.additional_params?.reduce(
|
|
4151
4159
|
(acc, param) => {
|
|
@@ -4159,7 +4167,7 @@ var paykitInvoice$InboundSchema = (data, isSubscription) => {
|
|
|
4159
4167
|
id: data.id.toString(),
|
|
4160
4168
|
amount_paid: data.amount,
|
|
4161
4169
|
currency: data.currency,
|
|
4162
|
-
customer: data.payer?.contact?.email ? { email: data.payer.contact.email } :
|
|
4170
|
+
customer: data.payer?.contact?.email ? { email: data.payer.contact.email } : null,
|
|
4163
4171
|
status,
|
|
4164
4172
|
paid_at: paidAt.toISOString(),
|
|
4165
4173
|
metadata: metadata ?? {},
|
|
@@ -4169,10 +4177,12 @@ var paykitInvoice$InboundSchema = (data, isSubscription) => {
|
|
|
4169
4177
|
line_items: [{ id: item, quantity: parseInt(qty) }]
|
|
4170
4178
|
};
|
|
4171
4179
|
};
|
|
4172
|
-
var
|
|
4180
|
+
var Subscription$inboundSchema = (data) => {
|
|
4173
4181
|
const { item } = JSON.parse(
|
|
4174
4182
|
decodeHtmlEntities(
|
|
4175
|
-
data.additional_params?.find(
|
|
4183
|
+
data.additional_params?.find(
|
|
4184
|
+
(param) => param.name === core.PAYKIT_METADATA_KEY
|
|
4185
|
+
)?.value ?? "{}"
|
|
4176
4186
|
)
|
|
4177
4187
|
);
|
|
4178
4188
|
const billingIntervalMap = {
|
|
@@ -4184,7 +4194,9 @@ var paykitSubscription$InboundSchema = (data) => {
|
|
|
4184
4194
|
const billingInterval = billingIntervalMap[data.recurrence?.recurrence_cycle ?? "ON_DEMAND"];
|
|
4185
4195
|
const recurrencePeriod = data.recurrence?.recurrence_period ?? 1;
|
|
4186
4196
|
const recurrenceCycle = data.recurrence?.recurrence_cycle;
|
|
4187
|
-
const currentPeriodEnd = new Date(
|
|
4197
|
+
const currentPeriodEnd = new Date(
|
|
4198
|
+
data.recurrence?.recurrence_date_to ?? ""
|
|
4199
|
+
);
|
|
4188
4200
|
const currentPeriodStart = (() => {
|
|
4189
4201
|
if (!currentPeriodEnd) return /* @__PURE__ */ new Date();
|
|
4190
4202
|
const endDate = new Date(currentPeriodEnd);
|
|
@@ -4214,21 +4226,21 @@ var paykitSubscription$InboundSchema = (data) => {
|
|
|
4214
4226
|
) ?? {}
|
|
4215
4227
|
);
|
|
4216
4228
|
const requiresAction = data.state === "CREATED" ? true : false;
|
|
4217
|
-
const
|
|
4218
|
-
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4229
|
+
const subscriptionStatusMap = {
|
|
4230
|
+
CREATED: "pending",
|
|
4231
|
+
PAID: "active",
|
|
4232
|
+
CANCELED: "canceled",
|
|
4233
|
+
TIMEOUTED: "canceled",
|
|
4234
|
+
REFUNDED: "canceled",
|
|
4235
|
+
PARTIALLY_REFUNDED: "canceled",
|
|
4236
|
+
AUTHORIZED: "active",
|
|
4237
|
+
PAYMENT_METHOD_CHOSEN: "active"
|
|
4238
|
+
};
|
|
4239
|
+
const status = subscriptionStatusMap[data.state] ?? "expired";
|
|
4228
4240
|
return {
|
|
4229
4241
|
id: data.id.toString(),
|
|
4230
4242
|
status,
|
|
4231
|
-
customer: data.payer?.contact?.email ? { email: data.payer.contact.email } :
|
|
4243
|
+
customer: data.payer?.contact?.email ? { email: data.payer.contact.email } : null,
|
|
4232
4244
|
item_id: item,
|
|
4233
4245
|
billing_interval: billingInterval,
|
|
4234
4246
|
currency: data.currency,
|
|
@@ -4241,7 +4253,7 @@ var paykitSubscription$InboundSchema = (data) => {
|
|
|
4241
4253
|
payment_url: requiresAction ? data.gw_url ?? null : null
|
|
4242
4254
|
};
|
|
4243
4255
|
};
|
|
4244
|
-
var
|
|
4256
|
+
var Refund$inboundSchema = (data) => {
|
|
4245
4257
|
return {
|
|
4246
4258
|
id: data.id.toString(),
|
|
4247
4259
|
amount: data.amount,
|
|
@@ -4267,6 +4279,7 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4267
4279
|
constructor(opts) {
|
|
4268
4280
|
super(gopayOptionsSchema, opts, providerName);
|
|
4269
4281
|
this.opts = opts;
|
|
4282
|
+
this.isSandbox = opts.isSandbox;
|
|
4270
4283
|
const debug = opts.debug ?? true;
|
|
4271
4284
|
this.baseUrl = opts.isSandbox ? "https://gw.sandbox.gopay.com/api" : "https://gate.gopay.cz/api";
|
|
4272
4285
|
this._client = new core.HTTPClient({
|
|
@@ -4278,7 +4291,10 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4278
4291
|
client: this._client,
|
|
4279
4292
|
provider: this.providerName,
|
|
4280
4293
|
tokenEndpoint: "/oauth2/token",
|
|
4281
|
-
credentials: {
|
|
4294
|
+
credentials: {
|
|
4295
|
+
username: opts.clientId,
|
|
4296
|
+
password: opts.clientSecret
|
|
4297
|
+
},
|
|
4282
4298
|
responseAdapter: (response) => ({
|
|
4283
4299
|
accessToken: response.access_token,
|
|
4284
4300
|
expiresIn: response.expires_in
|
|
@@ -4299,15 +4315,30 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4299
4315
|
providerName = providerName;
|
|
4300
4316
|
_client;
|
|
4301
4317
|
baseUrl;
|
|
4318
|
+
isSandbox;
|
|
4302
4319
|
tokenManager;
|
|
4320
|
+
get _native() {
|
|
4321
|
+
return null;
|
|
4322
|
+
}
|
|
4303
4323
|
createCheckout = async (params) => {
|
|
4304
4324
|
const { error, data } = core.createCheckoutSchema.safeParse(params);
|
|
4305
|
-
if (error)
|
|
4325
|
+
if (error) {
|
|
4326
|
+
throw core.ValidationError.fromZodError(
|
|
4327
|
+
error,
|
|
4328
|
+
"gopay",
|
|
4329
|
+
"createCheckout"
|
|
4330
|
+
);
|
|
4331
|
+
}
|
|
4306
4332
|
if (!core.isEmailCustomer(data.customer)) {
|
|
4307
|
-
throw new core.InvalidTypeError(
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4333
|
+
throw new core.InvalidTypeError(
|
|
4334
|
+
"customer",
|
|
4335
|
+
"object (customer) with email",
|
|
4336
|
+
"string",
|
|
4337
|
+
{
|
|
4338
|
+
provider: this.providerName,
|
|
4339
|
+
method: "createCheckout"
|
|
4340
|
+
}
|
|
4341
|
+
);
|
|
4311
4342
|
}
|
|
4312
4343
|
const { amount, currency = "CZK" } = core.validateRequiredKeys(
|
|
4313
4344
|
["amount", "currency"],
|
|
@@ -4334,9 +4365,9 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4334
4365
|
},
|
|
4335
4366
|
target: { type: "ACCOUNT", goid: parseInt(this.opts.goId) },
|
|
4336
4367
|
amount: Number(amount),
|
|
4337
|
-
currency,
|
|
4368
|
+
currency: currency.toUpperCase(),
|
|
4338
4369
|
order_number: crypto__namespace.randomBytes(8).toString("hex").slice(0, 15),
|
|
4339
|
-
order_description: data.
|
|
4370
|
+
order_description: `Payment for ${data.item_id} by ${data.customer.email}`,
|
|
4340
4371
|
items: [
|
|
4341
4372
|
{
|
|
4342
4373
|
name: data.item_id,
|
|
@@ -4346,7 +4377,10 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4346
4377
|
}
|
|
4347
4378
|
],
|
|
4348
4379
|
lang: data.provider_metadata?.language ? data.provider_metadata.language : "EN",
|
|
4349
|
-
callback: {
|
|
4380
|
+
callback: {
|
|
4381
|
+
return_url: data.success_url,
|
|
4382
|
+
notification_url: this.opts.webhookUrl
|
|
4383
|
+
},
|
|
4350
4384
|
additional_params: Object.entries({
|
|
4351
4385
|
...data.metadata,
|
|
4352
4386
|
[core.PAYKIT_METADATA_KEY]: JSON.stringify({
|
|
@@ -4367,11 +4401,15 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4367
4401
|
}
|
|
4368
4402
|
);
|
|
4369
4403
|
if (!response.ok) {
|
|
4370
|
-
throw new core.OperationFailedError(
|
|
4371
|
-
|
|
4372
|
-
|
|
4404
|
+
throw new core.OperationFailedError(
|
|
4405
|
+
"createCheckout",
|
|
4406
|
+
this.providerName,
|
|
4407
|
+
{
|
|
4408
|
+
cause: new Error("Failed to create checkout")
|
|
4409
|
+
}
|
|
4410
|
+
);
|
|
4373
4411
|
}
|
|
4374
|
-
return
|
|
4412
|
+
return Checkout$inboundSchema(response.value);
|
|
4375
4413
|
};
|
|
4376
4414
|
retrieveCheckout = async (id) => {
|
|
4377
4415
|
const response = await this._client.get(
|
|
@@ -4384,11 +4422,15 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4384
4422
|
}
|
|
4385
4423
|
);
|
|
4386
4424
|
if (!response.ok) {
|
|
4387
|
-
throw new core.OperationFailedError(
|
|
4388
|
-
|
|
4389
|
-
|
|
4425
|
+
throw new core.OperationFailedError(
|
|
4426
|
+
"retrieveCheckout",
|
|
4427
|
+
this.providerName,
|
|
4428
|
+
{
|
|
4429
|
+
cause: new Error("Failed to retrieve checkout")
|
|
4430
|
+
}
|
|
4431
|
+
);
|
|
4390
4432
|
}
|
|
4391
|
-
return
|
|
4433
|
+
return Checkout$inboundSchema(response.value);
|
|
4392
4434
|
};
|
|
4393
4435
|
updateCheckout = async (id, params) => {
|
|
4394
4436
|
if (this.opts.debug) {
|
|
@@ -4406,91 +4448,116 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4406
4448
|
});
|
|
4407
4449
|
};
|
|
4408
4450
|
createCustomer = async (params) => {
|
|
4409
|
-
if (this.cloudClient) {
|
|
4410
|
-
return this.cloudClient.customers.create(params);
|
|
4411
|
-
}
|
|
4412
4451
|
throw new core.ProviderNotSupportedError("createCustomer", "gopay", {
|
|
4413
|
-
reason: "Gopay doesn't support creating customers
|
|
4452
|
+
reason: "Gopay doesn't support creating customers"
|
|
4414
4453
|
});
|
|
4415
4454
|
};
|
|
4416
4455
|
updateCustomer = async (id, params) => {
|
|
4417
|
-
if (this.cloudClient) {
|
|
4418
|
-
return this.cloudClient.customers.update(id, params);
|
|
4419
|
-
}
|
|
4420
4456
|
throw new core.ProviderNotSupportedError("updateCustomer", "gopay", {
|
|
4421
|
-
reason: "Gopay doesn't support updating customers
|
|
4457
|
+
reason: "Gopay doesn't support updating customers"
|
|
4422
4458
|
});
|
|
4423
4459
|
};
|
|
4424
4460
|
deleteCustomer = async (id) => {
|
|
4425
|
-
if (this.cloudClient) {
|
|
4426
|
-
this.cloudClient.customers.delete(id);
|
|
4427
|
-
return null;
|
|
4428
|
-
}
|
|
4429
4461
|
throw new core.ProviderNotSupportedError("deleteCustomer", "gopay", {
|
|
4430
|
-
reason: "Gopay doesn't support deleting customers
|
|
4462
|
+
reason: "Gopay doesn't support deleting customers"
|
|
4431
4463
|
});
|
|
4432
4464
|
};
|
|
4433
4465
|
retrieveCustomer = async (id) => {
|
|
4434
|
-
if (this.cloudClient) {
|
|
4435
|
-
return this.cloudClient.customers.retrieve(id);
|
|
4436
|
-
}
|
|
4437
4466
|
throw new core.ProviderNotSupportedError("retrieveCustomer", "gopay", {
|
|
4438
|
-
reason: "Gopay doesn't support retrieving customers
|
|
4467
|
+
reason: "Gopay doesn't support retrieving customers"
|
|
4439
4468
|
});
|
|
4440
4469
|
};
|
|
4441
4470
|
createSubscription = async (params) => {
|
|
4442
4471
|
const { error, data } = core.createSubscriptionSchema.safeParse(params);
|
|
4443
|
-
if (error)
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4472
|
+
if (error)
|
|
4473
|
+
throw core.ValidationError.fromZodError(
|
|
4474
|
+
error,
|
|
4475
|
+
"gopay",
|
|
4476
|
+
"createSubscription"
|
|
4477
|
+
);
|
|
4478
|
+
if (!core.isEmailCustomer(data.customer)) {
|
|
4479
|
+
throw new core.InvalidTypeError(
|
|
4480
|
+
"customer",
|
|
4481
|
+
"object with email",
|
|
4482
|
+
core.isIdCustomer(data.customer) ? "object with id" : typeof data.customer,
|
|
4483
|
+
{
|
|
4484
|
+
provider: this.providerName,
|
|
4485
|
+
method: "createSubscription"
|
|
4486
|
+
}
|
|
4487
|
+
);
|
|
4449
4488
|
}
|
|
4450
4489
|
const { success_url } = core.validateRequiredKeys(
|
|
4451
4490
|
["success_url"],
|
|
4452
4491
|
data.provider_metadata,
|
|
4453
|
-
"The following fields must be present in the provider_metadata of
|
|
4492
|
+
"The following fields must be present in the provider_metadata of createSubscription: {keys}"
|
|
4454
4493
|
);
|
|
4494
|
+
const billingInterval = data.billing_interval;
|
|
4495
|
+
const isCustom = typeof billingInterval === "object" && billingInterval.type === "custom";
|
|
4496
|
+
const isYear = billingInterval === "year";
|
|
4497
|
+
const isOnDemand = isCustom || isYear;
|
|
4498
|
+
const intervalMap = {
|
|
4499
|
+
day: "DAY",
|
|
4500
|
+
week: "WEEK",
|
|
4501
|
+
month: "MONTH",
|
|
4502
|
+
year: "ON_DEMAND"
|
|
4503
|
+
};
|
|
4504
|
+
const recurrenceCycle = isCustom ? "ON_DEMAND" : intervalMap[billingInterval];
|
|
4455
4505
|
if (this.opts.debug) {
|
|
4456
|
-
if (
|
|
4506
|
+
if (isYear) {
|
|
4457
4507
|
console.info(
|
|
4458
|
-
"GoPay does not support yearly
|
|
4508
|
+
"[PayKit/GoPay] GoPay does not support yearly recurrence. Falling back to ON_DEMAND \u2014 you must trigger each charge manually via createRecurrence(parentPaymentId, ...). See: https://doc.gopay.com/#recurring-on-demand"
|
|
4509
|
+
);
|
|
4510
|
+
}
|
|
4511
|
+
if (isCustom) {
|
|
4512
|
+
const durationMs = billingInterval.durationMs;
|
|
4513
|
+
console.info(
|
|
4514
|
+
`[PayKit/GoPay] Custom interval (${durationMs}ms) is not supported by GoPay. Falling back to ON_DEMAND \u2014 trigger charges manually via createRecurrence(parentPaymentId, ...). See: https://doc.gopay.com/#recurring-on-demand`
|
|
4515
|
+
);
|
|
4516
|
+
}
|
|
4517
|
+
if (!isOnDemand) {
|
|
4518
|
+
console.info(
|
|
4519
|
+
`[PayKit/GoPay] AUTO recurrence (${recurrenceCycle}) \u2014 GoPay charges automatically each cycle. No createRecurrence() call is needed. Set provider_metadata.end_date (ISO string, e.g. "2027-01-01") to control when the subscription ends. Defaults to 1 year from today.`
|
|
4520
|
+
);
|
|
4521
|
+
} else {
|
|
4522
|
+
console.info(
|
|
4523
|
+
"[PayKit/GoPay] ON_DEMAND recurrence \u2014 you MUST call createRecurrence(parentPaymentId, ...) for each subsequent charge. GoPay will NOT charge automatically. Set provider_metadata.end_date (ISO string) to control the authorization window. Defaults to 1 year (custom interval) or 5 years (yearly interval)."
|
|
4459
4524
|
);
|
|
4460
4525
|
}
|
|
4461
4526
|
if (!data.provider_metadata?.description) {
|
|
4462
4527
|
console.info(
|
|
4463
|
-
`No
|
|
4528
|
+
`[PayKit/GoPay] No \`provider_metadata.description\` provided. Using default: "Subscription by ${data.customer.email}"`
|
|
4464
4529
|
);
|
|
4465
4530
|
}
|
|
4466
4531
|
}
|
|
4467
|
-
const
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
month: "MONTH",
|
|
4471
|
-
year: "ON_DEMAND"
|
|
4532
|
+
const toDateString = (ms) => {
|
|
4533
|
+
const d = new Date(ms);
|
|
4534
|
+
return d.toISOString().split("T")[0];
|
|
4472
4535
|
};
|
|
4473
|
-
const
|
|
4474
|
-
const
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
if (recurrenceCycle === "WEEK") {
|
|
4479
|
-
return new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3).toISOString();
|
|
4480
|
-
}
|
|
4481
|
-
if (recurrenceCycle === "MONTH") {
|
|
4482
|
-
return new Date(Date.now() + 30 * 24 * 60 * 60 * 1e3).toISOString();
|
|
4536
|
+
const GOPAY_MAX_DATE = "2099-12-30";
|
|
4537
|
+
const endDateOverride = data.provider_metadata?.end_date;
|
|
4538
|
+
const recurrenceDateTo = (() => {
|
|
4539
|
+
if (endDateOverride) {
|
|
4540
|
+
return endDateOverride < GOPAY_MAX_DATE ? endDateOverride : GOPAY_MAX_DATE;
|
|
4483
4541
|
}
|
|
4484
4542
|
if (recurrenceCycle === "ON_DEMAND") {
|
|
4485
|
-
|
|
4486
|
-
|
|
4487
|
-
|
|
4488
|
-
|
|
4489
|
-
|
|
4543
|
+
if (isCustom) {
|
|
4544
|
+
return toDateString(Date.now() + 365 * 24 * 60 * 60 * 1e3);
|
|
4545
|
+
}
|
|
4546
|
+
return toDateString(
|
|
4547
|
+
Date.now() + 5 * 365 * 24 * 60 * 60 * 1e3
|
|
4490
4548
|
);
|
|
4491
4549
|
}
|
|
4492
|
-
|
|
4550
|
+
return toDateString(Date.now() + 365 * 24 * 60 * 60 * 1e3);
|
|
4493
4551
|
})();
|
|
4552
|
+
const recurrencePeriod = data.provider_metadata?.recurrence_period ?? 1;
|
|
4553
|
+
const recurrence = isOnDemand ? {
|
|
4554
|
+
recurrence_cycle: recurrenceCycle,
|
|
4555
|
+
recurrence_date_to: recurrenceDateTo
|
|
4556
|
+
} : {
|
|
4557
|
+
recurrence_cycle: recurrenceCycle,
|
|
4558
|
+
recurrence_period: recurrencePeriod,
|
|
4559
|
+
recurrence_date_to: recurrenceDateTo
|
|
4560
|
+
};
|
|
4494
4561
|
const goPaySubscriptionOptions = {
|
|
4495
4562
|
payer: {
|
|
4496
4563
|
allowed_payment_instruments: ["PAYMENT_CARD"],
|
|
@@ -4501,24 +4568,28 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4501
4568
|
amount: Number(data.amount),
|
|
4502
4569
|
currency: data.currency ?? "CZK",
|
|
4503
4570
|
order_number: crypto__namespace.randomBytes(8).toString("hex").slice(0, 15),
|
|
4504
|
-
order_description: data.provider_metadata?.description ? data.provider_metadata.description :
|
|
4505
|
-
items: [
|
|
4506
|
-
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4571
|
+
order_description: data.provider_metadata?.description ? data.provider_metadata.description : `Subscription by ${data.customer.email}`,
|
|
4572
|
+
items: [
|
|
4573
|
+
{
|
|
4574
|
+
name: data.item_id,
|
|
4575
|
+
amount: Number(data.amount),
|
|
4576
|
+
count: data.quantity ?? 1
|
|
4577
|
+
}
|
|
4578
|
+
],
|
|
4579
|
+
recurrence,
|
|
4580
|
+
callback: {
|
|
4581
|
+
return_url: success_url,
|
|
4582
|
+
notification_url: this.opts.webhookUrl
|
|
4510
4583
|
},
|
|
4511
|
-
callback: { return_url: success_url, notification_url: this.opts.webhookUrl },
|
|
4512
4584
|
additional_params: Object.entries({
|
|
4513
4585
|
...data.metadata,
|
|
4514
4586
|
[core.PAYKIT_METADATA_KEY]: JSON.stringify({
|
|
4515
4587
|
item: data.item_id,
|
|
4516
|
-
qty: data.quantity
|
|
4588
|
+
qty: data.quantity,
|
|
4589
|
+
// Store the original interval so createRecurrence callers know the intended cadence
|
|
4590
|
+
billing_interval: isCustom ? `custom:${billingInterval.durationMs}ms` : billingInterval
|
|
4517
4591
|
})
|
|
4518
|
-
}).map(([name, value]) => ({
|
|
4519
|
-
name,
|
|
4520
|
-
value: String(value)
|
|
4521
|
-
}))
|
|
4592
|
+
}).map(([name, value]) => ({ name, value: String(value) }))
|
|
4522
4593
|
};
|
|
4523
4594
|
const response = await this._client.post(
|
|
4524
4595
|
"/payments/payment",
|
|
@@ -4528,28 +4599,42 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4528
4599
|
}
|
|
4529
4600
|
);
|
|
4530
4601
|
if (!response.ok) {
|
|
4531
|
-
throw new core.OperationFailedError(
|
|
4532
|
-
|
|
4533
|
-
|
|
4602
|
+
throw new core.OperationFailedError(
|
|
4603
|
+
"createSubscription",
|
|
4604
|
+
this.providerName,
|
|
4605
|
+
{
|
|
4606
|
+
cause: new Error(
|
|
4607
|
+
`[PayKit/GoPay] Failed to create subscription. Error: ${response.error}`
|
|
4608
|
+
)
|
|
4609
|
+
}
|
|
4610
|
+
);
|
|
4534
4611
|
}
|
|
4535
|
-
return
|
|
4612
|
+
return Subscription$inboundSchema(response.value);
|
|
4536
4613
|
};
|
|
4537
4614
|
updateSubscription = async (id, params) => {
|
|
4538
4615
|
const subscription = await this.retrieveSubscription(id);
|
|
4539
4616
|
if (!subscription) {
|
|
4540
|
-
throw new core.ProviderNotSupportedError(
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4617
|
+
throw new core.ProviderNotSupportedError(
|
|
4618
|
+
"updateSubscription",
|
|
4619
|
+
this.providerName,
|
|
4620
|
+
{
|
|
4621
|
+
reason: "Gopay doesn't support updating subscriptions",
|
|
4622
|
+
alternative: "Use the payment API instead and update the subscription manually"
|
|
4623
|
+
}
|
|
4624
|
+
);
|
|
4544
4625
|
}
|
|
4545
4626
|
return subscription;
|
|
4546
4627
|
};
|
|
4547
4628
|
cancelSubscription = async (id) => {
|
|
4548
4629
|
const existingSubscription = await this.retrieveSubscription(id);
|
|
4549
4630
|
if (!existingSubscription) {
|
|
4550
|
-
throw new core.OperationFailedError(
|
|
4551
|
-
|
|
4552
|
-
|
|
4631
|
+
throw new core.OperationFailedError(
|
|
4632
|
+
"cancelSubscription",
|
|
4633
|
+
this.providerName,
|
|
4634
|
+
{
|
|
4635
|
+
cause: new Error("Failed to retrieve subscription")
|
|
4636
|
+
}
|
|
4637
|
+
);
|
|
4553
4638
|
}
|
|
4554
4639
|
const response = await this._client.post(`/payments/payment/${id}/void-recurrence`, {
|
|
4555
4640
|
headers: {
|
|
@@ -4559,7 +4644,9 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4559
4644
|
});
|
|
4560
4645
|
return {
|
|
4561
4646
|
...existingSubscription,
|
|
4562
|
-
...response.value?.result == "FINISHED" && {
|
|
4647
|
+
...response.value?.result == "FINISHED" && {
|
|
4648
|
+
status: "canceled"
|
|
4649
|
+
}
|
|
4563
4650
|
};
|
|
4564
4651
|
};
|
|
4565
4652
|
deleteSubscription = async (id) => {
|
|
@@ -4574,21 +4661,35 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4574
4661
|
}
|
|
4575
4662
|
);
|
|
4576
4663
|
if (!response.ok) {
|
|
4577
|
-
throw new core.OperationFailedError(
|
|
4578
|
-
|
|
4579
|
-
|
|
4664
|
+
throw new core.OperationFailedError(
|
|
4665
|
+
"retrieveSubscription",
|
|
4666
|
+
this.providerName,
|
|
4667
|
+
{
|
|
4668
|
+
cause: new Error("Failed to retrieve subscription")
|
|
4669
|
+
}
|
|
4670
|
+
);
|
|
4580
4671
|
}
|
|
4581
|
-
return
|
|
4672
|
+
return Subscription$inboundSchema(response.value);
|
|
4582
4673
|
};
|
|
4583
4674
|
createPayment = async (params) => {
|
|
4584
4675
|
const { error, data } = core.createPaymentSchema.safeParse(params);
|
|
4585
|
-
if (error)
|
|
4586
|
-
throw core.ValidationError.fromZodError(
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4676
|
+
if (error) {
|
|
4677
|
+
throw core.ValidationError.fromZodError(
|
|
4678
|
+
error,
|
|
4679
|
+
this.providerName,
|
|
4680
|
+
"createPayment"
|
|
4681
|
+
);
|
|
4682
|
+
}
|
|
4683
|
+
if (!core.isEmailCustomer(data.customer)) {
|
|
4684
|
+
throw new core.InvalidTypeError(
|
|
4685
|
+
"customer",
|
|
4686
|
+
"object with email",
|
|
4687
|
+
core.isIdCustomer(data.customer) ? "object with id" : typeof data.customer,
|
|
4688
|
+
{
|
|
4689
|
+
provider: this.providerName,
|
|
4690
|
+
method: "createPayment"
|
|
4691
|
+
}
|
|
4692
|
+
);
|
|
4592
4693
|
}
|
|
4593
4694
|
if (!data.item_id) {
|
|
4594
4695
|
throw new core.ConfigurationError(
|
|
@@ -4599,23 +4700,54 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4599
4700
|
}
|
|
4600
4701
|
);
|
|
4601
4702
|
}
|
|
4703
|
+
const successUrl = data.provider_metadata?.success_url;
|
|
4704
|
+
if (!successUrl) {
|
|
4705
|
+
throw new core.ConfigurationError(
|
|
4706
|
+
"success_url is required, this is the URL to redirect the user to the success page after the payment is successful",
|
|
4707
|
+
{
|
|
4708
|
+
provider: this.providerName,
|
|
4709
|
+
missingKeys: ["success_url"]
|
|
4710
|
+
}
|
|
4711
|
+
);
|
|
4712
|
+
}
|
|
4602
4713
|
const goPayRequest = {
|
|
4603
4714
|
payer: {
|
|
4604
4715
|
allowed_payment_instruments: ["PAYMENT_CARD", "BANK_ACCOUNT"],
|
|
4605
4716
|
default_payment_instrument: "PAYMENT_CARD",
|
|
4606
|
-
contact: { email: data.customer.email }
|
|
4717
|
+
contact: { email: data.customer.email },
|
|
4718
|
+
...data.billing && {
|
|
4719
|
+
city: data.billing.address.city,
|
|
4720
|
+
postal_code: data.billing.address.postal_code,
|
|
4721
|
+
country_code: data.billing.address.country,
|
|
4722
|
+
phone_number: data.billing.address.phone
|
|
4723
|
+
}
|
|
4607
4724
|
},
|
|
4608
4725
|
target: { type: "ACCOUNT", goid: parseInt(this.opts.goId) },
|
|
4609
|
-
amount: data.amount,
|
|
4726
|
+
amount: Number(data.amount),
|
|
4610
4727
|
currency: data.currency ?? "CZK",
|
|
4611
4728
|
order_number: crypto__namespace.randomBytes(8).toString("hex").slice(0, 15),
|
|
4612
4729
|
order_description: `Payment for ${data.item_id} by ${data.customer.email}`,
|
|
4613
|
-
items: [
|
|
4730
|
+
items: [
|
|
4731
|
+
{
|
|
4732
|
+
name: data.item_id,
|
|
4733
|
+
amount: data.amount,
|
|
4734
|
+
count: 1,
|
|
4735
|
+
type: "ITEM"
|
|
4736
|
+
}
|
|
4737
|
+
],
|
|
4738
|
+
lang: data.provider_metadata?.language ? data.provider_metadata.language : "EN",
|
|
4739
|
+
callback: {
|
|
4740
|
+
return_url: successUrl,
|
|
4741
|
+
notification_url: this.opts.webhookUrl
|
|
4742
|
+
},
|
|
4614
4743
|
preauthorization: false,
|
|
4615
4744
|
// automatically captures the payment
|
|
4616
4745
|
additional_params: Object.entries({
|
|
4617
4746
|
...data.metadata,
|
|
4618
|
-
[core.PAYKIT_METADATA_KEY]: JSON.stringify({
|
|
4747
|
+
[core.PAYKIT_METADATA_KEY]: JSON.stringify({
|
|
4748
|
+
itemId: data.item_id,
|
|
4749
|
+
qty: 1
|
|
4750
|
+
})
|
|
4619
4751
|
}).map(([name, value]) => ({
|
|
4620
4752
|
name,
|
|
4621
4753
|
value: String(value)
|
|
@@ -4629,11 +4761,17 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4629
4761
|
}
|
|
4630
4762
|
);
|
|
4631
4763
|
if (!response.ok) {
|
|
4632
|
-
throw new core.OperationFailedError(
|
|
4633
|
-
|
|
4634
|
-
|
|
4764
|
+
throw new core.OperationFailedError(
|
|
4765
|
+
"createPayment",
|
|
4766
|
+
this.providerName,
|
|
4767
|
+
{
|
|
4768
|
+
cause: new Error(
|
|
4769
|
+
`Failed to create payment: ${JSON.stringify(response.error ?? response)}`
|
|
4770
|
+
)
|
|
4771
|
+
}
|
|
4772
|
+
);
|
|
4635
4773
|
}
|
|
4636
|
-
return
|
|
4774
|
+
return Payment$inboundSchema(response.value);
|
|
4637
4775
|
};
|
|
4638
4776
|
retrievePayment = async (id) => {
|
|
4639
4777
|
const response = await this._client.get(
|
|
@@ -4646,17 +4784,25 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4646
4784
|
}
|
|
4647
4785
|
);
|
|
4648
4786
|
if (!response.ok) {
|
|
4649
|
-
throw new core.OperationFailedError(
|
|
4650
|
-
|
|
4651
|
-
|
|
4787
|
+
throw new core.OperationFailedError(
|
|
4788
|
+
"retrievePayment",
|
|
4789
|
+
this.providerName,
|
|
4790
|
+
{
|
|
4791
|
+
cause: new Error("Failed to retrieve payment")
|
|
4792
|
+
}
|
|
4793
|
+
);
|
|
4652
4794
|
}
|
|
4653
|
-
return
|
|
4795
|
+
return Payment$inboundSchema(response.value);
|
|
4654
4796
|
};
|
|
4655
4797
|
deletePayment = async (id) => {
|
|
4656
|
-
throw new core.ProviderNotSupportedError(
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4798
|
+
throw new core.ProviderNotSupportedError(
|
|
4799
|
+
"deletePayment",
|
|
4800
|
+
this.providerName,
|
|
4801
|
+
{
|
|
4802
|
+
reason: "GoPay does not support deleting payments, use the",
|
|
4803
|
+
alternative: "Use createRefund() instead to refund payments"
|
|
4804
|
+
}
|
|
4805
|
+
);
|
|
4660
4806
|
};
|
|
4661
4807
|
capturePayment = async (id, params) => {
|
|
4662
4808
|
const payment = await this._client.get(
|
|
@@ -4664,32 +4810,39 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4664
4810
|
{ headers: await this.tokenManager.getAuthHeaders() }
|
|
4665
4811
|
);
|
|
4666
4812
|
if (!payment.ok) {
|
|
4667
|
-
throw new core.OperationFailedError(
|
|
4668
|
-
|
|
4669
|
-
|
|
4813
|
+
throw new core.OperationFailedError(
|
|
4814
|
+
"capturePayment",
|
|
4815
|
+
this.providerName,
|
|
4816
|
+
{
|
|
4817
|
+
cause: new Error("Failed to retrieve payment")
|
|
4818
|
+
}
|
|
4819
|
+
);
|
|
4670
4820
|
}
|
|
4671
4821
|
const { item, qty } = JSON.parse(
|
|
4672
4822
|
decodeHtmlEntities(
|
|
4673
|
-
payment.value.additional_params?.find(
|
|
4823
|
+
payment.value.additional_params?.find(
|
|
4824
|
+
(param) => param.name === core.PAYKIT_METADATA_KEY
|
|
4825
|
+
)?.value ?? "{}"
|
|
4674
4826
|
)
|
|
4675
4827
|
);
|
|
4676
4828
|
if (!payment) {
|
|
4677
|
-
throw new core.OperationFailedError(
|
|
4678
|
-
|
|
4679
|
-
|
|
4829
|
+
throw new core.OperationFailedError(
|
|
4830
|
+
"capturePayment",
|
|
4831
|
+
this.providerName,
|
|
4832
|
+
{
|
|
4833
|
+
cause: new Error("Payment not found after capture")
|
|
4834
|
+
}
|
|
4835
|
+
);
|
|
4680
4836
|
}
|
|
4681
4837
|
const captureBody = {
|
|
4682
4838
|
amount: params.amount,
|
|
4683
4839
|
items: [{ name: item, amount: params.amount, count: qty }]
|
|
4684
4840
|
};
|
|
4685
|
-
await this._client.post(
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
|
|
4689
|
-
|
|
4690
|
-
}
|
|
4691
|
-
);
|
|
4692
|
-
return paykitPayment$InboundSchema(payment.value);
|
|
4841
|
+
await this._client.post(`/payments/payment/${id}/capture`, {
|
|
4842
|
+
body: JSON.stringify(captureBody),
|
|
4843
|
+
headers: await this.tokenManager.getAuthHeaders()
|
|
4844
|
+
});
|
|
4845
|
+
return Payment$inboundSchema(payment.value);
|
|
4693
4846
|
};
|
|
4694
4847
|
cancelPayment = async (id) => {
|
|
4695
4848
|
await this._client.post(
|
|
@@ -4698,9 +4851,13 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4698
4851
|
);
|
|
4699
4852
|
const payment = await this.retrievePayment(id);
|
|
4700
4853
|
if (!payment) {
|
|
4701
|
-
throw new core.OperationFailedError(
|
|
4702
|
-
|
|
4703
|
-
|
|
4854
|
+
throw new core.OperationFailedError(
|
|
4855
|
+
"cancelPayment",
|
|
4856
|
+
this.providerName,
|
|
4857
|
+
{
|
|
4858
|
+
cause: new Error("Payment not found after cancellation")
|
|
4859
|
+
}
|
|
4860
|
+
);
|
|
4704
4861
|
}
|
|
4705
4862
|
return payment;
|
|
4706
4863
|
};
|
|
@@ -4711,34 +4868,52 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4711
4868
|
console.info("Gopay doesn't support updating payments");
|
|
4712
4869
|
const existing = await this.retrievePayment(id);
|
|
4713
4870
|
if (!existing) {
|
|
4714
|
-
throw new core.OperationFailedError(
|
|
4715
|
-
|
|
4716
|
-
|
|
4871
|
+
throw new core.OperationFailedError(
|
|
4872
|
+
"updatePayment",
|
|
4873
|
+
this.providerName,
|
|
4874
|
+
{
|
|
4875
|
+
cause: new Error("Failed to retrieve payment")
|
|
4876
|
+
}
|
|
4877
|
+
);
|
|
4717
4878
|
}
|
|
4718
4879
|
return existing;
|
|
4719
4880
|
};
|
|
4720
4881
|
async createRefund(params) {
|
|
4721
4882
|
const { error, data } = core.createRefundSchema.safeParse(params);
|
|
4722
4883
|
if (error) {
|
|
4723
|
-
throw core.ValidationError.fromZodError(
|
|
4884
|
+
throw core.ValidationError.fromZodError(
|
|
4885
|
+
error,
|
|
4886
|
+
this.providerName,
|
|
4887
|
+
"createRefund"
|
|
4888
|
+
);
|
|
4724
4889
|
}
|
|
4725
4890
|
const payment = await this.retrievePayment(data.payment_id);
|
|
4726
4891
|
if (!payment) {
|
|
4727
|
-
throw new core.OperationFailedError(
|
|
4728
|
-
|
|
4729
|
-
|
|
4892
|
+
throw new core.OperationFailedError(
|
|
4893
|
+
"createRefund",
|
|
4894
|
+
this.providerName,
|
|
4895
|
+
{
|
|
4896
|
+
cause: new Error("Failed to retrieve payment")
|
|
4897
|
+
}
|
|
4898
|
+
);
|
|
4730
4899
|
}
|
|
4731
4900
|
const response = await this._client.post(`/payments/payment/${data.payment_id}/refund`, {
|
|
4732
|
-
body: new URLSearchParams({
|
|
4901
|
+
body: new URLSearchParams({
|
|
4902
|
+
amount: String(data.amount)
|
|
4903
|
+
}).toString(),
|
|
4733
4904
|
headers: {
|
|
4734
4905
|
...await this.tokenManager.getAuthHeaders(),
|
|
4735
4906
|
"Content-Type": "application/x-www-form-urlencoded"
|
|
4736
4907
|
}
|
|
4737
4908
|
});
|
|
4738
4909
|
if (!response.ok) {
|
|
4739
|
-
throw new core.OperationFailedError(
|
|
4740
|
-
|
|
4741
|
-
|
|
4910
|
+
throw new core.OperationFailedError(
|
|
4911
|
+
"createRefund",
|
|
4912
|
+
this.providerName,
|
|
4913
|
+
{
|
|
4914
|
+
cause: new Error("Failed to create refund")
|
|
4915
|
+
}
|
|
4916
|
+
);
|
|
4742
4917
|
}
|
|
4743
4918
|
return {
|
|
4744
4919
|
id: crypto__namespace.randomBytes(8).toString("hex").slice(0, 15),
|
|
@@ -4748,23 +4923,28 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4748
4923
|
metadata: data.metadata
|
|
4749
4924
|
};
|
|
4750
4925
|
}
|
|
4751
|
-
handleWebhook = async (payload) => {
|
|
4926
|
+
handleWebhook = async (payload, webhookSecret) => {
|
|
4752
4927
|
const { fullUrl } = payload;
|
|
4753
4928
|
const paymentId = new URL(fullUrl).searchParams.get("id");
|
|
4754
4929
|
const parentId = new URL(fullUrl).searchParams.get("parent_id");
|
|
4755
4930
|
if (!paymentId) {
|
|
4756
|
-
throw new core.WebhookError("Payment ID is required", {
|
|
4931
|
+
throw new core.WebhookError("Payment ID is required", {
|
|
4932
|
+
provider: this.providerName
|
|
4933
|
+
});
|
|
4757
4934
|
}
|
|
4758
4935
|
if (this.opts.debug) {
|
|
4759
4936
|
console.info("Received GoPay webhook for payment:", paymentId);
|
|
4760
4937
|
}
|
|
4761
4938
|
const [payment, error] = await core.tryCatchAsync(
|
|
4762
|
-
this._client.get(
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
-
|
|
4939
|
+
this._client.get(
|
|
4940
|
+
`/payments/payment/${paymentId}`,
|
|
4941
|
+
{
|
|
4942
|
+
headers: {
|
|
4943
|
+
...await this.tokenManager.getAuthHeaders(),
|
|
4944
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
4945
|
+
}
|
|
4766
4946
|
}
|
|
4767
|
-
|
|
4947
|
+
)
|
|
4768
4948
|
);
|
|
4769
4949
|
if (error) {
|
|
4770
4950
|
throw new core.WebhookError("Failed to retrieve payment", {
|
|
@@ -4772,10 +4952,15 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4772
4952
|
});
|
|
4773
4953
|
}
|
|
4774
4954
|
if (!payment.value) {
|
|
4775
|
-
throw new core.WebhookError("Payment not found", {
|
|
4955
|
+
throw new core.WebhookError("Payment not found", {
|
|
4956
|
+
provider: this.providerName
|
|
4957
|
+
});
|
|
4776
4958
|
}
|
|
4777
4959
|
if (this.opts.debug) {
|
|
4778
|
-
console.info(
|
|
4960
|
+
console.info(
|
|
4961
|
+
"Webhook verified successfully, status:",
|
|
4962
|
+
payment.value.state
|
|
4963
|
+
);
|
|
4779
4964
|
}
|
|
4780
4965
|
const statusMap = {
|
|
4781
4966
|
CREATED: "pending",
|
|
@@ -4794,7 +4979,7 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4794
4979
|
__INDETERMINATE: (data) => {
|
|
4795
4980
|
const isRefundEvent = data.state === "REFUNDED" || data.state === "PARTIALLY_REFUNDED";
|
|
4796
4981
|
if (isRefundEvent) {
|
|
4797
|
-
const refund =
|
|
4982
|
+
const refund = Refund$inboundSchema(data);
|
|
4798
4983
|
return [
|
|
4799
4984
|
core.paykitEvent$InboundSchema({
|
|
4800
4985
|
type: "refund.created",
|
|
@@ -4807,7 +4992,7 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4807
4992
|
return [];
|
|
4808
4993
|
},
|
|
4809
4994
|
pending: (data) => {
|
|
4810
|
-
const payment2 =
|
|
4995
|
+
const payment2 = Payment$inboundSchema(data);
|
|
4811
4996
|
return [
|
|
4812
4997
|
core.paykitEvent$InboundSchema({
|
|
4813
4998
|
type: "payment.created",
|
|
@@ -4818,7 +5003,7 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4818
5003
|
];
|
|
4819
5004
|
},
|
|
4820
5005
|
processing: (data) => {
|
|
4821
|
-
const payment2 =
|
|
5006
|
+
const payment2 = Payment$inboundSchema(data);
|
|
4822
5007
|
return [
|
|
4823
5008
|
core.paykitEvent$InboundSchema({
|
|
4824
5009
|
type: "payment.updated",
|
|
@@ -4829,7 +5014,7 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4829
5014
|
];
|
|
4830
5015
|
},
|
|
4831
5016
|
requires_capture: (data) => {
|
|
4832
|
-
const payment2 =
|
|
5017
|
+
const payment2 = Payment$inboundSchema(data);
|
|
4833
5018
|
return [
|
|
4834
5019
|
core.paykitEvent$InboundSchema({
|
|
4835
5020
|
type: "payment.updated",
|
|
@@ -4840,9 +5025,9 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4840
5025
|
];
|
|
4841
5026
|
},
|
|
4842
5027
|
canceled: (data) => {
|
|
4843
|
-
const payment2 =
|
|
5028
|
+
const payment2 = Payment$inboundSchema(data);
|
|
4844
5029
|
const isCancellingSubscription = parentId && data.recurrence?.recurrence_state == "STOPPED";
|
|
4845
|
-
const subscription =
|
|
5030
|
+
const subscription = Subscription$inboundSchema(
|
|
4846
5031
|
data
|
|
4847
5032
|
);
|
|
4848
5033
|
const subscriptionCanceledWebhookEvent = {
|
|
@@ -4852,9 +5037,13 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4852
5037
|
data: subscription
|
|
4853
5038
|
};
|
|
4854
5039
|
return [
|
|
4855
|
-
...isCancellingSubscription ? [
|
|
5040
|
+
...isCancellingSubscription ? [
|
|
5041
|
+
core.paykitEvent$InboundSchema(
|
|
5042
|
+
subscriptionCanceledWebhookEvent
|
|
5043
|
+
)
|
|
5044
|
+
] : [],
|
|
4856
5045
|
core.paykitEvent$InboundSchema({
|
|
4857
|
-
type: "payment.
|
|
5046
|
+
type: "payment.failed",
|
|
4858
5047
|
created: (/* @__PURE__ */ new Date()).getTime(),
|
|
4859
5048
|
id: crypto__namespace.randomBytes(8).toString("hex").slice(0, 15),
|
|
4860
5049
|
data: payment2
|
|
@@ -4862,10 +5051,10 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4862
5051
|
];
|
|
4863
5052
|
},
|
|
4864
5053
|
failed: (data) => {
|
|
4865
|
-
const payment2 =
|
|
5054
|
+
const payment2 = Payment$inboundSchema(data);
|
|
4866
5055
|
return [
|
|
4867
5056
|
core.paykitEvent$InboundSchema({
|
|
4868
|
-
type: "payment.
|
|
5057
|
+
type: "payment.failed",
|
|
4869
5058
|
created: (/* @__PURE__ */ new Date()).getTime(),
|
|
4870
5059
|
id: crypto__namespace.randomBytes(8).toString("hex").slice(0, 15),
|
|
4871
5060
|
data: payment2
|
|
@@ -4873,9 +5062,9 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4873
5062
|
];
|
|
4874
5063
|
},
|
|
4875
5064
|
succeeded: (data) => {
|
|
4876
|
-
const payment2 =
|
|
4877
|
-
const invoice =
|
|
4878
|
-
const subscription =
|
|
5065
|
+
const payment2 = Payment$inboundSchema(data);
|
|
5066
|
+
const invoice = Invoice$inboundSchema(data, !!parentId);
|
|
5067
|
+
const subscription = Subscription$inboundSchema(
|
|
4879
5068
|
data
|
|
4880
5069
|
);
|
|
4881
5070
|
const subscriptionCreatedWebhookEvent = {
|
|
@@ -4885,7 +5074,11 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4885
5074
|
data: subscription
|
|
4886
5075
|
};
|
|
4887
5076
|
return [
|
|
4888
|
-
...parentId ? [
|
|
5077
|
+
...parentId ? [
|
|
5078
|
+
core.paykitEvent$InboundSchema(
|
|
5079
|
+
subscriptionCreatedWebhookEvent
|
|
5080
|
+
)
|
|
5081
|
+
] : [],
|
|
4889
5082
|
core.paykitEvent$InboundSchema({
|
|
4890
5083
|
type: "invoice.generated",
|
|
4891
5084
|
created: (/* @__PURE__ */ new Date()).getTime(),
|
|
@@ -4893,7 +5086,7 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4893
5086
|
data: invoice
|
|
4894
5087
|
}),
|
|
4895
5088
|
core.paykitEvent$InboundSchema({
|
|
4896
|
-
type: "payment.
|
|
5089
|
+
type: "payment.succeeded",
|
|
4897
5090
|
created: (/* @__PURE__ */ new Date()).getTime(),
|
|
4898
5091
|
id: crypto__namespace.randomBytes(8).toString("hex").slice(0, 15),
|
|
4899
5092
|
data: payment2
|
|
@@ -4901,7 +5094,7 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4901
5094
|
];
|
|
4902
5095
|
},
|
|
4903
5096
|
requires_action: (data) => {
|
|
4904
|
-
const payment2 =
|
|
5097
|
+
const payment2 = Payment$inboundSchema(data);
|
|
4905
5098
|
return [
|
|
4906
5099
|
core.paykitEvent$InboundSchema({
|
|
4907
5100
|
type: "payment.updated",
|
|
@@ -4937,10 +5130,9 @@ var gopay = () => {
|
|
|
4937
5130
|
"GOPAY_CLIENT_SECRET",
|
|
4938
5131
|
"GOPAY_GO_ID",
|
|
4939
5132
|
"GOPAY_SANDBOX",
|
|
4940
|
-
"GOPAY_WEBHOOK_URL"
|
|
4941
|
-
"PAYKIT_CLOUD_API_KEY"
|
|
5133
|
+
"GOPAY_WEBHOOK_URL"
|
|
4942
5134
|
],
|
|
4943
|
-
process.env ?? {
|
|
5135
|
+
process.env ?? {},
|
|
4944
5136
|
"Missing required environment variables: {keys}"
|
|
4945
5137
|
);
|
|
4946
5138
|
return createGopay({
|
|
@@ -4949,7 +5141,6 @@ var gopay = () => {
|
|
|
4949
5141
|
goId: envVars.GOPAY_GO_ID,
|
|
4950
5142
|
isSandbox: envVars.GOPAY_SANDBOX === "true",
|
|
4951
5143
|
webhookUrl: envVars.GOPAY_WEBHOOK_URL,
|
|
4952
|
-
cloudApiKey: envVars.PAYKIT_CLOUD_API_KEY,
|
|
4953
5144
|
debug: true
|
|
4954
5145
|
});
|
|
4955
5146
|
};
|