@paykit-sdk/gopay 1.0.0 → 1.0.1
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 +41 -34
- package/dist/controllers/auth.js +21 -5
- package/dist/controllers/auth.mjs +21 -5
- package/dist/gopay-provider.js +116 -55
- package/dist/gopay-provider.mjs +116 -55
- package/dist/index.js +123 -56
- package/dist/index.mjs +123 -56
- package/dist/utils/mapper.js +13 -5
- package/dist/utils/mapper.mjs +13 -5
- package/package.json +8 -9
package/README.md
CHANGED
|
@@ -30,7 +30,10 @@ export const endpoints = createEndpointHandlers(paykit);
|
|
|
30
30
|
import { paykit } from '@/lib/paykit';
|
|
31
31
|
import { EndpointPath } from '@paykit-sdk/core';
|
|
32
32
|
|
|
33
|
-
export async function POST(
|
|
33
|
+
export async function POST(
|
|
34
|
+
request: NextRequest,
|
|
35
|
+
{ params }: { params: { endpoint: string[] } },
|
|
36
|
+
) {
|
|
34
37
|
try {
|
|
35
38
|
// Construct the endpoint path with full type safety
|
|
36
39
|
const endpoint = ('/' + params.endpoint.join('/')) as EndpointPath;
|
|
@@ -103,40 +106,44 @@ const app = express();
|
|
|
103
106
|
|
|
104
107
|
// IMPORTANT: Webhook route must come BEFORE express.json() middleware
|
|
105
108
|
// This ensures we get the raw body for signature verification
|
|
106
|
-
app.post(
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
109
|
+
app.post(
|
|
110
|
+
'/api/webhooks/gopay',
|
|
111
|
+
express.raw({ type: 'application/json' }),
|
|
112
|
+
async (req, res) => {
|
|
113
|
+
try {
|
|
114
|
+
const webhook = paykit.webhooks
|
|
115
|
+
.setup({ webhookSecret: '' })
|
|
116
|
+
.on('customer.created', async event => {
|
|
117
|
+
console.log('Customer created:', event.data);
|
|
118
|
+
})
|
|
119
|
+
.on('subscription.created', async event => {
|
|
120
|
+
console.log('Subscription created:', event.data);
|
|
121
|
+
})
|
|
122
|
+
.on('payment.created', async event => {
|
|
123
|
+
console.log('Payment created:', event.data);
|
|
124
|
+
})
|
|
125
|
+
.on('refund.created', async event => {
|
|
126
|
+
console.log('Refund created:', event.data);
|
|
127
|
+
})
|
|
128
|
+
.on('invoice.generated', async event => {
|
|
129
|
+
console.log('Invoice generated:', event.data);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const body = req.body; // Raw buffer from express.raw()
|
|
133
|
+
const headers = req.headers;
|
|
134
|
+
const url = request.url;
|
|
135
|
+
await webhook.handle({ body, headers, fullUrl: url });
|
|
136
|
+
|
|
137
|
+
// Return immediately, processing happens in background
|
|
138
|
+
res.json({ success: true });
|
|
139
|
+
} catch (error) {
|
|
140
|
+
console.error('Webhook error:', error);
|
|
141
|
+
res.status(500).json({
|
|
142
|
+
message: error instanceof Error ? error.message : 'Webhook processing failed',
|
|
124
143
|
});
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const url = request.url;
|
|
129
|
-
await webhook.handle({ body, headers, fullUrl: url });
|
|
130
|
-
|
|
131
|
-
// Return immediately, processing happens in background
|
|
132
|
-
res.json({ success: true });
|
|
133
|
-
} catch (error) {
|
|
134
|
-
console.error('Webhook error:', error);
|
|
135
|
-
res.status(500).json({
|
|
136
|
-
message: error instanceof Error ? error.message : 'Webhook processing failed',
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
});
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
);
|
|
140
147
|
|
|
141
148
|
// Regular API routes use JSON middleware
|
|
142
149
|
app.use(express.json());
|
package/dist/controllers/auth.js
CHANGED
|
@@ -7,7 +7,11 @@ var AuthController = class {
|
|
|
7
7
|
constructor(opts) {
|
|
8
8
|
this.opts = opts;
|
|
9
9
|
const debug = opts.debug ?? true;
|
|
10
|
-
this._client = new core.HTTPClient({
|
|
10
|
+
this._client = new core.HTTPClient({
|
|
11
|
+
baseUrl: this.opts.baseUrl,
|
|
12
|
+
headers: {},
|
|
13
|
+
retryOptions: { max: 3, baseDelay: 1e3, debug }
|
|
14
|
+
});
|
|
11
15
|
}
|
|
12
16
|
_client;
|
|
13
17
|
_accessToken = null;
|
|
@@ -17,10 +21,18 @@ var AuthController = class {
|
|
|
17
21
|
const expiry = parseInt(expiryStr || "0", 10);
|
|
18
22
|
if (expiry > Date.now()) return token;
|
|
19
23
|
}
|
|
20
|
-
const credentials = Buffer.from(
|
|
24
|
+
const credentials = Buffer.from(
|
|
25
|
+
`${this.opts.clientId}:${this.opts.clientSecret}`
|
|
26
|
+
).toString("base64");
|
|
21
27
|
const response = await this._client.post("/oauth2/token", {
|
|
22
|
-
headers: {
|
|
23
|
-
|
|
28
|
+
headers: {
|
|
29
|
+
Authorization: `Basic ${credentials}`,
|
|
30
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
31
|
+
},
|
|
32
|
+
body: new URLSearchParams({
|
|
33
|
+
grant_type: "client_credentials",
|
|
34
|
+
scope: "payment-all"
|
|
35
|
+
}).toString()
|
|
24
36
|
});
|
|
25
37
|
if (!response.ok || !response.value.access_token) {
|
|
26
38
|
throw new core.OperationFailedError("getAccessToken", "gopay", {
|
|
@@ -34,7 +46,11 @@ var AuthController = class {
|
|
|
34
46
|
};
|
|
35
47
|
getAuthHeaders = async () => {
|
|
36
48
|
const token = await this.getAccessToken();
|
|
37
|
-
return {
|
|
49
|
+
return {
|
|
50
|
+
Authorization: `Bearer ${token}`,
|
|
51
|
+
"Content-Type": "application/json",
|
|
52
|
+
Accept: "application/json"
|
|
53
|
+
};
|
|
38
54
|
};
|
|
39
55
|
};
|
|
40
56
|
|
|
@@ -5,7 +5,11 @@ var AuthController = class {
|
|
|
5
5
|
constructor(opts) {
|
|
6
6
|
this.opts = opts;
|
|
7
7
|
const debug = opts.debug ?? true;
|
|
8
|
-
this._client = new HTTPClient({
|
|
8
|
+
this._client = new HTTPClient({
|
|
9
|
+
baseUrl: this.opts.baseUrl,
|
|
10
|
+
headers: {},
|
|
11
|
+
retryOptions: { max: 3, baseDelay: 1e3, debug }
|
|
12
|
+
});
|
|
9
13
|
}
|
|
10
14
|
_client;
|
|
11
15
|
_accessToken = null;
|
|
@@ -15,10 +19,18 @@ var AuthController = class {
|
|
|
15
19
|
const expiry = parseInt(expiryStr || "0", 10);
|
|
16
20
|
if (expiry > Date.now()) return token;
|
|
17
21
|
}
|
|
18
|
-
const credentials = Buffer.from(
|
|
22
|
+
const credentials = Buffer.from(
|
|
23
|
+
`${this.opts.clientId}:${this.opts.clientSecret}`
|
|
24
|
+
).toString("base64");
|
|
19
25
|
const response = await this._client.post("/oauth2/token", {
|
|
20
|
-
headers: {
|
|
21
|
-
|
|
26
|
+
headers: {
|
|
27
|
+
Authorization: `Basic ${credentials}`,
|
|
28
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
29
|
+
},
|
|
30
|
+
body: new URLSearchParams({
|
|
31
|
+
grant_type: "client_credentials",
|
|
32
|
+
scope: "payment-all"
|
|
33
|
+
}).toString()
|
|
22
34
|
});
|
|
23
35
|
if (!response.ok || !response.value.access_token) {
|
|
24
36
|
throw new OperationFailedError("getAccessToken", "gopay", {
|
|
@@ -32,7 +44,11 @@ var AuthController = class {
|
|
|
32
44
|
};
|
|
33
45
|
getAuthHeaders = async () => {
|
|
34
46
|
const token = await this.getAccessToken();
|
|
35
|
-
return {
|
|
47
|
+
return {
|
|
48
|
+
Authorization: `Bearer ${token}`,
|
|
49
|
+
"Content-Type": "application/json",
|
|
50
|
+
Accept: "application/json"
|
|
51
|
+
};
|
|
36
52
|
};
|
|
37
53
|
};
|
|
38
54
|
|
package/dist/gopay-provider.js
CHANGED
|
@@ -4072,7 +4072,11 @@ var AuthController = class {
|
|
|
4072
4072
|
constructor(opts) {
|
|
4073
4073
|
this.opts = opts;
|
|
4074
4074
|
const debug = opts.debug ?? true;
|
|
4075
|
-
this._client = new core.HTTPClient({
|
|
4075
|
+
this._client = new core.HTTPClient({
|
|
4076
|
+
baseUrl: this.opts.baseUrl,
|
|
4077
|
+
headers: {},
|
|
4078
|
+
retryOptions: { max: 3, baseDelay: 1e3, debug }
|
|
4079
|
+
});
|
|
4076
4080
|
}
|
|
4077
4081
|
_client;
|
|
4078
4082
|
_accessToken = null;
|
|
@@ -4082,10 +4086,18 @@ var AuthController = class {
|
|
|
4082
4086
|
const expiry = parseInt(expiryStr || "0", 10);
|
|
4083
4087
|
if (expiry > Date.now()) return token;
|
|
4084
4088
|
}
|
|
4085
|
-
const credentials = Buffer.from(
|
|
4089
|
+
const credentials = Buffer.from(
|
|
4090
|
+
`${this.opts.clientId}:${this.opts.clientSecret}`
|
|
4091
|
+
).toString("base64");
|
|
4086
4092
|
const response = await this._client.post("/oauth2/token", {
|
|
4087
|
-
headers: {
|
|
4088
|
-
|
|
4093
|
+
headers: {
|
|
4094
|
+
Authorization: `Basic ${credentials}`,
|
|
4095
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
|
4096
|
+
},
|
|
4097
|
+
body: new URLSearchParams({
|
|
4098
|
+
grant_type: "client_credentials",
|
|
4099
|
+
scope: "payment-all"
|
|
4100
|
+
}).toString()
|
|
4089
4101
|
});
|
|
4090
4102
|
if (!response.ok || !response.value.access_token) {
|
|
4091
4103
|
throw new core.OperationFailedError("getAccessToken", "gopay", {
|
|
@@ -4099,11 +4111,17 @@ var AuthController = class {
|
|
|
4099
4111
|
};
|
|
4100
4112
|
getAuthHeaders = async () => {
|
|
4101
4113
|
const token = await this.getAccessToken();
|
|
4102
|
-
return {
|
|
4114
|
+
return {
|
|
4115
|
+
Authorization: `Bearer ${token}`,
|
|
4116
|
+
"Content-Type": "application/json",
|
|
4117
|
+
Accept: "application/json"
|
|
4118
|
+
};
|
|
4103
4119
|
};
|
|
4104
4120
|
};
|
|
4105
4121
|
var paykitPayment$InboundSchema = (data) => {
|
|
4106
|
-
const itemId = JSON.parse(
|
|
4122
|
+
const itemId = JSON.parse(
|
|
4123
|
+
data.additional_params?.find((param) => param.name === core.PAYKIT_METADATA_KEY)?.value ?? "{}"
|
|
4124
|
+
).itemId;
|
|
4107
4125
|
const metadata = core.omitInternalMetadata(
|
|
4108
4126
|
data.additional_params?.reduce(
|
|
4109
4127
|
(acc, param) => {
|
|
@@ -4119,13 +4137,17 @@ var paykitPayment$InboundSchema = (data) => {
|
|
|
4119
4137
|
currency: data.currency,
|
|
4120
4138
|
customer: data.payer ?? { email: data.payer?.email ?? "" },
|
|
4121
4139
|
status: data.state,
|
|
4122
|
-
|
|
4140
|
+
item_id: itemId,
|
|
4123
4141
|
metadata
|
|
4124
4142
|
};
|
|
4125
4143
|
};
|
|
4126
4144
|
var paykitInvoice$InboundSchema = (data, isSubscription) => {
|
|
4127
|
-
const quantity = JSON.parse(
|
|
4128
|
-
|
|
4145
|
+
const quantity = JSON.parse(
|
|
4146
|
+
data.additional_params?.find((param) => param.name === core.PAYKIT_METADATA_KEY)?.value ?? "{}"
|
|
4147
|
+
).qty;
|
|
4148
|
+
const itemId = JSON.parse(
|
|
4149
|
+
data.additional_params?.find((param) => param.name === core.PAYKIT_METADATA_KEY)?.value ?? "{}"
|
|
4150
|
+
).itemId;
|
|
4129
4151
|
const status = (() => {
|
|
4130
4152
|
if (data.state === "PAID") return "paid";
|
|
4131
4153
|
return "open";
|
|
@@ -4155,7 +4177,9 @@ var paykitInvoice$InboundSchema = (data, isSubscription) => {
|
|
|
4155
4177
|
};
|
|
4156
4178
|
};
|
|
4157
4179
|
var paykitSubscription$InboundSchema = (data) => {
|
|
4158
|
-
const itemId = JSON.parse(
|
|
4180
|
+
const itemId = JSON.parse(
|
|
4181
|
+
data.additional_params?.find((param) => param.name === core.PAYKIT_METADATA_KEY)?.value ?? "{}"
|
|
4182
|
+
).itemId;
|
|
4159
4183
|
const billingIntervalMap = {
|
|
4160
4184
|
DAY: "day",
|
|
4161
4185
|
WEEK: "week",
|
|
@@ -4236,12 +4260,8 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4236
4260
|
method: "createCheckout"
|
|
4237
4261
|
});
|
|
4238
4262
|
}
|
|
4239
|
-
const {
|
|
4240
|
-
amount,
|
|
4241
|
-
currency = "CZK",
|
|
4242
|
-
successUrl
|
|
4243
|
-
} = core.validateRequiredKeys(
|
|
4244
|
-
["amount", "currency", "successUrl"],
|
|
4263
|
+
const { amount, currency = "CZK" } = core.validateRequiredKeys(
|
|
4264
|
+
["amount", "currency"],
|
|
4245
4265
|
data.provider_metadata,
|
|
4246
4266
|
"The following fields must be present in the provider_metadata of createCheckout: {keys}"
|
|
4247
4267
|
);
|
|
@@ -4268,12 +4288,22 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4268
4288
|
currency,
|
|
4269
4289
|
order_number: crypto__namespace.randomBytes(8).toString("hex").slice(0, 15),
|
|
4270
4290
|
order_description: data.metadata?.description || "Checkout",
|
|
4271
|
-
items: [
|
|
4291
|
+
items: [
|
|
4292
|
+
{
|
|
4293
|
+
name: data.item_id,
|
|
4294
|
+
amount: Number(amount),
|
|
4295
|
+
count: data.quantity,
|
|
4296
|
+
type: "ITEM"
|
|
4297
|
+
}
|
|
4298
|
+
],
|
|
4272
4299
|
lang: data.provider_metadata?.lang ? data.provider_metadata.lang : "EN",
|
|
4273
|
-
callback: { return_url:
|
|
4300
|
+
callback: { return_url: data.success_url, notification_url: this.opts.webhookUrl },
|
|
4274
4301
|
additional_params: Object.entries({
|
|
4275
4302
|
...data.metadata,
|
|
4276
|
-
[core.PAYKIT_METADATA_KEY]: JSON.stringify({
|
|
4303
|
+
[core.PAYKIT_METADATA_KEY]: JSON.stringify({
|
|
4304
|
+
itemId: data.item_id,
|
|
4305
|
+
qty: data.quantity
|
|
4306
|
+
})
|
|
4277
4307
|
}).map(([name, value]) => ({
|
|
4278
4308
|
name,
|
|
4279
4309
|
value: String(value)
|
|
@@ -4287,9 +4317,12 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4287
4317
|
return response.value;
|
|
4288
4318
|
};
|
|
4289
4319
|
retrieveCheckout = async (id) => {
|
|
4290
|
-
const response = await this._client.get(
|
|
4291
|
-
|
|
4292
|
-
|
|
4320
|
+
const response = await this._client.get(
|
|
4321
|
+
`/payments/payment/${id}`,
|
|
4322
|
+
{
|
|
4323
|
+
headers: await this.authController.getAuthHeaders()
|
|
4324
|
+
}
|
|
4325
|
+
);
|
|
4293
4326
|
if (!response.ok) {
|
|
4294
4327
|
throw new core.OperationFailedError("retrieveCheckout", this.providerName, {
|
|
4295
4328
|
cause: new Error("Failed to retrieve checkout")
|
|
@@ -4340,8 +4373,8 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4340
4373
|
method: "createCheckout"
|
|
4341
4374
|
});
|
|
4342
4375
|
}
|
|
4343
|
-
const {
|
|
4344
|
-
["
|
|
4376
|
+
const { quantity, success_url } = core.validateRequiredKeys(
|
|
4377
|
+
["quantity", "success_url"],
|
|
4345
4378
|
data.provider_metadata,
|
|
4346
4379
|
"The following fields must be present in the provider_metadata of createCheckout: {keys}"
|
|
4347
4380
|
);
|
|
@@ -4351,6 +4384,18 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4351
4384
|
month: "MONTH",
|
|
4352
4385
|
year: "MONTH"
|
|
4353
4386
|
};
|
|
4387
|
+
const currentPeriodEnd = (() => {
|
|
4388
|
+
if (data.billing_interval === "day") {
|
|
4389
|
+
return new Date(Date.now() + 1 * 24 * 60 * 60 * 1e3).toISOString();
|
|
4390
|
+
}
|
|
4391
|
+
if (data.billing_interval === "week") {
|
|
4392
|
+
return new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3).toISOString();
|
|
4393
|
+
}
|
|
4394
|
+
if (data.billing_interval === "month") {
|
|
4395
|
+
return new Date(Date.now() + 30 * 24 * 60 * 60 * 1e3).toISOString();
|
|
4396
|
+
}
|
|
4397
|
+
return new Date(Date.now() + 365 * 24 * 60 * 60 * 1e3).toISOString();
|
|
4398
|
+
})();
|
|
4354
4399
|
const recurrenceCycle = intervalMap[data.billing_interval] ?? "ON_DEMAND";
|
|
4355
4400
|
const goPaySubscriptionOptions = {
|
|
4356
4401
|
payer: {
|
|
@@ -4363,13 +4408,15 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4363
4408
|
currency: data.currency ?? "CZK",
|
|
4364
4409
|
order_number: crypto__namespace.randomBytes(8).toString("hex").slice(0, 15),
|
|
4365
4410
|
order_description: data.metadata?.description || "Subscription",
|
|
4366
|
-
items: [
|
|
4411
|
+
items: [
|
|
4412
|
+
{ name: data.item_id, amount: Number(data.amount), count: parseInt(quantity) }
|
|
4413
|
+
],
|
|
4367
4414
|
recurrence: {
|
|
4368
4415
|
recurrence_cycle: recurrenceCycle,
|
|
4369
4416
|
recurrence_period: parseInt(quantity),
|
|
4370
|
-
recurrence_date_to:
|
|
4417
|
+
recurrence_date_to: currentPeriodEnd
|
|
4371
4418
|
},
|
|
4372
|
-
callback: { return_url:
|
|
4419
|
+
callback: { return_url: success_url, notification_url: this.opts.webhookUrl }
|
|
4373
4420
|
};
|
|
4374
4421
|
const response = await this._client.post("/payments/payment", {
|
|
4375
4422
|
body: JSON.stringify(goPaySubscriptionOptions),
|
|
@@ -4414,9 +4461,12 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4414
4461
|
return null;
|
|
4415
4462
|
};
|
|
4416
4463
|
retrieveSubscription = async (id) => {
|
|
4417
|
-
const response = await this._client.get(
|
|
4418
|
-
|
|
4419
|
-
|
|
4464
|
+
const response = await this._client.get(
|
|
4465
|
+
`/payments/payment/${id}`,
|
|
4466
|
+
{
|
|
4467
|
+
headers: await this.authController.getAuthHeaders()
|
|
4468
|
+
}
|
|
4469
|
+
);
|
|
4420
4470
|
if (!response.ok) {
|
|
4421
4471
|
throw new core.OperationFailedError("retrieveSubscription", this.providerName, {
|
|
4422
4472
|
cause: new Error("Failed to retrieve subscription")
|
|
@@ -4427,24 +4477,23 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4427
4477
|
};
|
|
4428
4478
|
createPayment = async (params) => {
|
|
4429
4479
|
const { error, data } = core.createPaymentSchema.safeParse(params);
|
|
4430
|
-
if (error)
|
|
4480
|
+
if (error)
|
|
4481
|
+
throw core.ValidationError.fromZodError(error, this.providerName, "createPayment");
|
|
4431
4482
|
if (typeof data.customer == "string" || typeof data.customer === "object" && !data.customer.email) {
|
|
4432
4483
|
throw new core.InvalidTypeError("customer", "object (customer) with email", "string", {
|
|
4433
4484
|
provider: this.providerName,
|
|
4434
4485
|
method: "createPayment"
|
|
4435
4486
|
});
|
|
4436
4487
|
}
|
|
4437
|
-
if (!data.
|
|
4438
|
-
throw new core.ConfigurationError(
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4488
|
+
if (!data.item_id) {
|
|
4489
|
+
throw new core.ConfigurationError(
|
|
4490
|
+
"item_id is required, this is the name of the item in GoPay",
|
|
4491
|
+
{
|
|
4492
|
+
provider: this.providerName,
|
|
4493
|
+
missingKeys: ["item_id"]
|
|
4494
|
+
}
|
|
4495
|
+
);
|
|
4442
4496
|
}
|
|
4443
|
-
const { quantity } = core.validateRequiredKeys(
|
|
4444
|
-
["quantity"],
|
|
4445
|
-
data.provider_metadata,
|
|
4446
|
-
"The following fields must be present in the provider_metadata of createPayment: {keys}"
|
|
4447
|
-
);
|
|
4448
4497
|
const goPayRequest = {
|
|
4449
4498
|
payer: {
|
|
4450
4499
|
allowed_payment_instruments: ["PAYMENT_CARD", "BANK_ACCOUNT"],
|
|
@@ -4455,13 +4504,13 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4455
4504
|
amount: data.amount,
|
|
4456
4505
|
currency: data.currency ?? "CZK",
|
|
4457
4506
|
order_number: crypto__namespace.randomBytes(8).toString("hex").slice(0, 15),
|
|
4458
|
-
order_description: data.
|
|
4459
|
-
items: [{ name: data.
|
|
4507
|
+
order_description: `Payment for ${data.item_id} by ${data.customer.email}`,
|
|
4508
|
+
items: [{ name: data.item_id, amount: data.amount, count: 1 }],
|
|
4460
4509
|
preauthorization: false,
|
|
4461
4510
|
// automatically captures the payment
|
|
4462
4511
|
additional_params: Object.entries({
|
|
4463
4512
|
...data.metadata,
|
|
4464
|
-
[core.PAYKIT_METADATA_KEY]: JSON.stringify({ itemId: data.
|
|
4513
|
+
[core.PAYKIT_METADATA_KEY]: JSON.stringify({ itemId: data.item_id, qty: 1 })
|
|
4465
4514
|
}).map(([name, value]) => ({
|
|
4466
4515
|
name,
|
|
4467
4516
|
value: String(value)
|
|
@@ -4480,9 +4529,12 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4480
4529
|
return response.value;
|
|
4481
4530
|
};
|
|
4482
4531
|
retrievePayment = async (id) => {
|
|
4483
|
-
const response = await this._client.get(
|
|
4484
|
-
|
|
4485
|
-
|
|
4532
|
+
const response = await this._client.get(
|
|
4533
|
+
`/payments/payment/${id}`,
|
|
4534
|
+
{
|
|
4535
|
+
headers: await this.authController.getAuthHeaders()
|
|
4536
|
+
}
|
|
4537
|
+
);
|
|
4486
4538
|
if (!response.ok) {
|
|
4487
4539
|
throw new core.OperationFailedError("retrievePayment", this.providerName, {
|
|
4488
4540
|
cause: new Error("Failed to retrieve payment")
|
|
@@ -4498,9 +4550,12 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4498
4550
|
});
|
|
4499
4551
|
};
|
|
4500
4552
|
capturePayment = async (id, params) => {
|
|
4501
|
-
const payment = await this._client.get(
|
|
4502
|
-
|
|
4503
|
-
|
|
4553
|
+
const payment = await this._client.get(
|
|
4554
|
+
`/payments/payment/${id}`,
|
|
4555
|
+
{
|
|
4556
|
+
headers: await this.authController.getAuthHeaders()
|
|
4557
|
+
}
|
|
4558
|
+
);
|
|
4504
4559
|
if (!payment.ok) {
|
|
4505
4560
|
throw new core.OperationFailedError("capturePayment", this.providerName, {
|
|
4506
4561
|
cause: new Error("Failed to retrieve payment")
|
|
@@ -4528,9 +4583,12 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4528
4583
|
return paykitPayment$InboundSchema(payment.value);
|
|
4529
4584
|
};
|
|
4530
4585
|
cancelPayment = async (id) => {
|
|
4531
|
-
const response = await this._client.post(
|
|
4532
|
-
|
|
4533
|
-
|
|
4586
|
+
const response = await this._client.post(
|
|
4587
|
+
`/payments/payment/${id}/void-authorization`,
|
|
4588
|
+
{
|
|
4589
|
+
headers: await this.authController.getAuthHeaders()
|
|
4590
|
+
}
|
|
4591
|
+
);
|
|
4534
4592
|
console.dir({ response }, { depth: 100 });
|
|
4535
4593
|
const payment = await this.retrievePayment(id);
|
|
4536
4594
|
if (!payment) {
|
|
@@ -4555,7 +4613,8 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4555
4613
|
};
|
|
4556
4614
|
async createRefund(params) {
|
|
4557
4615
|
const { error, data } = core.createRefundSchema.safeParse(params);
|
|
4558
|
-
if (error)
|
|
4616
|
+
if (error)
|
|
4617
|
+
throw core.ValidationError.fromZodError(error, this.providerName, "createRefund");
|
|
4559
4618
|
const payment = await this.retrievePayment(data.payment_id);
|
|
4560
4619
|
if (!payment) {
|
|
4561
4620
|
throw new core.OperationFailedError("createRefund", this.providerName, {
|
|
@@ -4601,7 +4660,9 @@ var GoPayProvider = class extends core.AbstractPayKitProvider {
|
|
|
4601
4660
|
})
|
|
4602
4661
|
);
|
|
4603
4662
|
if (error) {
|
|
4604
|
-
throw new core.WebhookError("Failed to retrieve payment", {
|
|
4663
|
+
throw new core.WebhookError("Failed to retrieve payment", {
|
|
4664
|
+
provider: this.providerName
|
|
4665
|
+
});
|
|
4605
4666
|
}
|
|
4606
4667
|
if (!payment.value) {
|
|
4607
4668
|
throw new core.WebhookError("Payment not found", { provider: this.providerName });
|