@rubikpara/pf-sdk 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,844 @@
1
+ import { randomUUID, createHmac } from 'crypto';
2
+
3
+ // src/errors.ts
4
+ function errorCategory(errorCode) {
5
+ if (!errorCode) return "unknown";
6
+ const first = errorCode.trim().charAt(0);
7
+ if (first === "0") return "business";
8
+ if (first === "1") return "system";
9
+ if (first === "5") return "bank";
10
+ return "unknown";
11
+ }
12
+ var PfError = class extends Error {
13
+ constructor(message, options) {
14
+ super(message, options);
15
+ this.name = "PfError";
16
+ }
17
+ };
18
+ var PfConfigError = class extends PfError {
19
+ constructor(message) {
20
+ super(message);
21
+ this.name = "PfConfigError";
22
+ }
23
+ };
24
+ var PfApiError = class extends PfError {
25
+ errorCode;
26
+ errorMessage;
27
+ conversationId;
28
+ httpStatus;
29
+ category;
30
+ path;
31
+ /** Sunucudan dönen ham yanıt gövdesi. */
32
+ response;
33
+ constructor(init) {
34
+ const code = init.errorCode ?? null;
35
+ const msg = init.errorMessage ?? null;
36
+ super(
37
+ `PF Gateway hatas\u0131 [${code ?? "-"}] ${msg ?? "Bilinmeyen hata"} (${init.path})`
38
+ );
39
+ this.name = "PfApiError";
40
+ this.errorCode = code;
41
+ this.errorMessage = msg;
42
+ this.conversationId = init.conversationId ?? null;
43
+ this.httpStatus = init.httpStatus;
44
+ this.category = errorCategory(code);
45
+ this.path = init.path;
46
+ this.response = init.response;
47
+ }
48
+ };
49
+ var PfHttpError = class extends PfError {
50
+ status;
51
+ statusText;
52
+ body;
53
+ conversationId;
54
+ path;
55
+ constructor(init) {
56
+ super(
57
+ init.message ?? `PF Gateway HTTP ${init.status} ${init.statusText} (${init.path})`
58
+ );
59
+ this.name = "PfHttpError";
60
+ this.status = init.status;
61
+ this.statusText = init.statusText;
62
+ this.body = init.body;
63
+ this.conversationId = init.conversationId ?? null;
64
+ this.path = init.path;
65
+ }
66
+ };
67
+ var PfNetworkError = class extends PfError {
68
+ path;
69
+ constructor(path, cause) {
70
+ const detail = cause instanceof Error ? cause.message : String(cause);
71
+ super(`PF Gateway'e ula\u015F\u0131lamad\u0131 (${path}): ${detail}`, { cause });
72
+ this.name = "PfNetworkError";
73
+ this.path = path;
74
+ }
75
+ };
76
+ var PfTimeoutError = class extends PfError {
77
+ timeoutMs;
78
+ path;
79
+ constructor(path, timeoutMs) {
80
+ super(`PF Gateway iste\u011Fi ${timeoutMs} ms i\xE7inde yan\u0131t vermedi (${path})`);
81
+ this.name = "PfTimeoutError";
82
+ this.timeoutMs = timeoutMs;
83
+ this.path = path;
84
+ }
85
+ };
86
+ function generateNonce() {
87
+ return Date.now().toString();
88
+ }
89
+ function generateConversationId() {
90
+ return randomUUID().replace(/-/g, "").slice(0, 16);
91
+ }
92
+ function decodeSecretKey(secretKey) {
93
+ const bytes = Buffer.from(secretKey, "base64");
94
+ if (bytes.length === 0) {
95
+ throw new PfConfigError(
96
+ "secretKey Base64 olarak \xE7\xF6z\xFCmlenemedi. Size verilen SecretKey de\u011Ferini oldu\u011Fu gibi (Base64 kodlu) kullan\u0131n."
97
+ );
98
+ }
99
+ return bytes;
100
+ }
101
+ function computeHmacBase64(key, data) {
102
+ return createHmac("sha256", key).update(data, "utf8").digest("base64");
103
+ }
104
+ function createSignature(input) {
105
+ if (!input.publicKey) throw new PfConfigError("publicKey bo\u015F olamaz.");
106
+ if (!input.secretKey) throw new PfConfigError("secretKey bo\u015F olamaz.");
107
+ const nonce = input.nonce ?? generateNonce();
108
+ const conversationId = input.conversationId ?? generateConversationId();
109
+ const key = decodeSecretKey(input.secretKey);
110
+ const securityData = computeHmacBase64(key, input.publicKey + nonce);
111
+ const signature = computeHmacBase64(
112
+ key,
113
+ input.secretKey + conversationId + nonce + securityData
114
+ );
115
+ return {
116
+ publicKey: input.publicKey,
117
+ nonce,
118
+ signature,
119
+ conversationId,
120
+ securityData
121
+ };
122
+ }
123
+
124
+ // src/http.ts
125
+ function isRecord(value) {
126
+ return typeof value === "object" && value !== null && !Array.isArray(value);
127
+ }
128
+ function isFailedApiResponse(data) {
129
+ if (!isRecord(data)) return false;
130
+ return data.isSucceed === false || data.isSuccess === false;
131
+ }
132
+ function readString(record, key) {
133
+ const value = record[key];
134
+ return typeof value === "string" ? value : null;
135
+ }
136
+ function problemDetailsMessage(data) {
137
+ if (!isRecord(data)) return null;
138
+ const inner = isRecord(data.Value) ? data.Value : data;
139
+ const title = readString(inner, "Title") ?? readString(inner, "title");
140
+ const detail = readString(inner, "Detail") ?? readString(inner, "detail");
141
+ if (title && detail) return `${title}: ${detail}`;
142
+ return detail ?? title;
143
+ }
144
+ function createRequestSignal(userSignal, timeoutMs) {
145
+ const controller = new AbortController();
146
+ let timedOut = false;
147
+ const timer = setTimeout(() => {
148
+ timedOut = true;
149
+ controller.abort();
150
+ }, timeoutMs);
151
+ const onUserAbort = () => controller.abort(userSignal?.reason);
152
+ if (userSignal) {
153
+ if (userSignal.aborted) onUserAbort();
154
+ else userSignal.addEventListener("abort", onUserAbort, { once: true });
155
+ }
156
+ return {
157
+ signal: controller.signal,
158
+ timedOut: () => timedOut,
159
+ cleanup: () => {
160
+ clearTimeout(timer);
161
+ userSignal?.removeEventListener("abort", onUserAbort);
162
+ }
163
+ };
164
+ }
165
+ var Transport = class {
166
+ constructor(cfg) {
167
+ this.cfg = cfg;
168
+ }
169
+ cfg;
170
+ /** JSON gövdeli veya gövdesiz istek. Kimlik doğrulama bilgileri header olarak gider. */
171
+ async requestJson(method, path, init = {}) {
172
+ const auth = this.sign(init.options);
173
+ const headers = {
174
+ Accept: "application/json",
175
+ "User-Agent": this.cfg.userAgent,
176
+ PublicKey: auth.publicKey,
177
+ Nonce: auth.nonce,
178
+ Signature: auth.signature,
179
+ ConversationId: auth.conversationId,
180
+ MerchantNumber: this.cfg.merchantNumber
181
+ };
182
+ if (init.options?.clientIpAddress) {
183
+ headers.ClientIpAddress = init.options.clientIpAddress;
184
+ }
185
+ let body;
186
+ if (init.body !== void 0) {
187
+ headers["Content-Type"] = "application/json";
188
+ body = JSON.stringify(init.body);
189
+ }
190
+ return this.send(
191
+ { method, url: this.buildUrl(path, init.query), headers, body },
192
+ path,
193
+ auth.conversationId,
194
+ init.options
195
+ );
196
+ }
197
+ /**
198
+ * `multipart/form-data` istek. Kimlik doğrulama bilgileri header yerine
199
+ * form alanı olarak gönderilir (`/v1/Tokens`, `/v1/ThreeDS/init3ds`).
200
+ */
201
+ async requestForm(path, fields, options) {
202
+ const auth = this.sign(options);
203
+ const form = new FormData();
204
+ for (const [key, value] of Object.entries(fields)) {
205
+ if (value === void 0 || value === null) continue;
206
+ form.append(key, String(value));
207
+ }
208
+ form.append("PublicKey", auth.publicKey);
209
+ form.append("Nonce", auth.nonce);
210
+ form.append("Signature", auth.signature);
211
+ form.append("ConversationId", auth.conversationId);
212
+ form.append("MerchantNumber", this.cfg.merchantNumber);
213
+ const headers = {
214
+ Accept: "application/json",
215
+ "User-Agent": this.cfg.userAgent
216
+ };
217
+ return this.send(
218
+ { method: "POST", url: this.buildUrl(path), headers, body: form },
219
+ path,
220
+ auth.conversationId,
221
+ options
222
+ );
223
+ }
224
+ /** Kimlik doğrulaması gerektirmeyen düz metin GET (ör. /HealthCheck). */
225
+ async requestText(path, options) {
226
+ const handle = createRequestSignal(
227
+ options?.signal,
228
+ options?.timeoutMs ?? this.cfg.timeoutMs
229
+ );
230
+ try {
231
+ const res = await this.cfg.fetch(this.buildUrl(path), {
232
+ method: "GET",
233
+ headers: { Accept: "text/plain", "User-Agent": this.cfg.userAgent },
234
+ signal: handle.signal
235
+ });
236
+ const text = await res.text();
237
+ if (!res.ok) {
238
+ throw new PfHttpError({
239
+ status: res.status,
240
+ statusText: res.statusText,
241
+ body: text,
242
+ path
243
+ });
244
+ }
245
+ return text;
246
+ } catch (err) {
247
+ throw this.mapTransportError(err, path, handle, options);
248
+ } finally {
249
+ handle.cleanup();
250
+ }
251
+ }
252
+ sign(options) {
253
+ return createSignature({
254
+ publicKey: this.cfg.publicKey,
255
+ secretKey: this.cfg.secretKey,
256
+ conversationId: options?.conversationId ?? this.cfg.conversationIdFactory()
257
+ });
258
+ }
259
+ buildUrl(path, query) {
260
+ const url = new URL(path, this.cfg.baseUrl);
261
+ if (query) {
262
+ for (const [key, value] of Object.entries(query)) {
263
+ if (value === void 0 || value === null) continue;
264
+ url.searchParams.set(key, String(value));
265
+ }
266
+ }
267
+ return url.toString();
268
+ }
269
+ async send(req, path, conversationId, options) {
270
+ const handle = createRequestSignal(
271
+ options?.signal,
272
+ options?.timeoutMs ?? this.cfg.timeoutMs
273
+ );
274
+ let res;
275
+ let text;
276
+ try {
277
+ res = await this.cfg.fetch(req.url, {
278
+ method: req.method,
279
+ headers: req.headers,
280
+ body: req.body,
281
+ signal: handle.signal
282
+ });
283
+ text = await res.text();
284
+ } catch (err) {
285
+ throw this.mapTransportError(err, path, handle, options);
286
+ } finally {
287
+ handle.cleanup();
288
+ }
289
+ let data = null;
290
+ if (text.trim().length > 0) {
291
+ try {
292
+ data = JSON.parse(text);
293
+ } catch {
294
+ throw new PfHttpError({
295
+ status: res.status,
296
+ statusText: res.statusText,
297
+ body: text,
298
+ conversationId,
299
+ path,
300
+ message: `PF Gateway beklenmeyen (JSON olmayan) yan\u0131t d\xF6nd\xFC: HTTP ${res.status} (${path})`
301
+ });
302
+ }
303
+ }
304
+ if (!res.ok) {
305
+ if (isRecord(data) && (data.errorCode || data.errorMessage)) {
306
+ throw new PfApiError({
307
+ errorCode: readString(data, "errorCode"),
308
+ errorMessage: readString(data, "errorMessage"),
309
+ conversationId: readString(data, "conversationId") ?? conversationId,
310
+ httpStatus: res.status,
311
+ response: data,
312
+ path
313
+ });
314
+ }
315
+ const detail = problemDetailsMessage(data);
316
+ throw new PfHttpError({
317
+ status: res.status,
318
+ statusText: res.statusText,
319
+ body: text,
320
+ conversationId,
321
+ path,
322
+ message: detail ? `PF Gateway HTTP ${res.status} (${path}): ${detail}` : void 0
323
+ });
324
+ }
325
+ if (this.cfg.throwOnApiError && isFailedApiResponse(data)) {
326
+ const record = data;
327
+ throw new PfApiError({
328
+ errorCode: readString(record, "errorCode"),
329
+ errorMessage: readString(record, "errorMessage"),
330
+ conversationId: readString(record, "conversationId") ?? conversationId,
331
+ httpStatus: res.status,
332
+ response: data,
333
+ path
334
+ });
335
+ }
336
+ return data;
337
+ }
338
+ mapTransportError(err, path, handle, options) {
339
+ if (err instanceof PfError) return err;
340
+ if (handle.timedOut()) {
341
+ return new PfTimeoutError(path, options?.timeoutMs ?? this.cfg.timeoutMs);
342
+ }
343
+ if (options?.signal?.aborted) {
344
+ return err instanceof Error ? err : new Error(String(err));
345
+ }
346
+ return new PfNetworkError(path, err);
347
+ }
348
+ };
349
+
350
+ // src/resources/installments.ts
351
+ var InstallmentsResource = class {
352
+ constructor(transport) {
353
+ this.transport = transport;
354
+ }
355
+ transport;
356
+ /**
357
+ * BIN ve tutara göre kullanılabilir taksit seçeneklerini ve komisyon
358
+ * oranlarını döner. `GET /v1/Installment`
359
+ */
360
+ query(input, options) {
361
+ return this.transport.requestJson(
362
+ "GET",
363
+ "/v1/Installment",
364
+ {
365
+ query: {
366
+ BinNumber: input.binNumber,
367
+ Amount: input.amount,
368
+ CommissionFromCustomerSingleInstallment: input.commissionFromCustomerSingleInstallment
369
+ },
370
+ options
371
+ }
372
+ );
373
+ }
374
+ };
375
+
376
+ // src/resources/links.ts
377
+ var CURRENCY_TRY_NUMERIC = 949;
378
+ var LinksResource = class {
379
+ constructor(transport, defaults) {
380
+ this.transport = transport;
381
+ this.defaults = defaults;
382
+ }
383
+ transport;
384
+ defaults;
385
+ /**
386
+ * Ödeme linki oluşturur. Yanıttaki `id` değerini saklayın.
387
+ * `POST /v1/Payments/createLink`
388
+ */
389
+ create(input, options) {
390
+ return this.transport.requestJson(
391
+ "POST",
392
+ "/v1/Payments/createLink",
393
+ {
394
+ body: {
395
+ ...input,
396
+ maxUsageCount: input.maxUsageCount ?? (input.linkType === "SingleUse" ? 1 : void 0),
397
+ currency: input.currency ?? CURRENCY_TRY_NUMERIC,
398
+ notificationMethod: input.notificationMethod ?? "None"
399
+ },
400
+ options
401
+ }
402
+ );
403
+ }
404
+ /**
405
+ * Link durumu ve ödeme durumu.
406
+ * `POST /v1/Payments/link-status`
407
+ */
408
+ getStatus(input, options) {
409
+ return this.transport.requestJson(
410
+ "POST",
411
+ "/v1/Payments/link-status",
412
+ { body: { id: input.id }, options }
413
+ );
414
+ }
415
+ /**
416
+ * Linki siler / pasife alır. Başarılıysa `true` döner.
417
+ * `POST /v1/Payments/deleteLink`
418
+ */
419
+ delete(input, options) {
420
+ return this.transport.requestJson(
421
+ "POST",
422
+ "/v1/Payments/deleteLink",
423
+ { body: { id: input.id }, options }
424
+ );
425
+ }
426
+ /**
427
+ * Link üzerinden kart ile ödeme (provizyon).
428
+ * `POST /v1/Payments/linkProvision`
429
+ */
430
+ provision(input, options) {
431
+ return this.transport.requestJson(
432
+ "POST",
433
+ "/v1/Payments/linkProvision",
434
+ {
435
+ body: {
436
+ ...input,
437
+ pointAmount: input.pointAmount ?? 0,
438
+ paymentType: input.paymentType ?? "Auth",
439
+ integrationMode: input.integrationMode ?? "Api",
440
+ installmentCount: input.installmentCount ?? 1,
441
+ languageCode: input.languageCode ?? this.defaults.languageCode
442
+ },
443
+ options
444
+ }
445
+ );
446
+ }
447
+ };
448
+
449
+ // src/resources/payments.ts
450
+ var PaymentsResource = class {
451
+ constructor(transport, defaults) {
452
+ this.transport = transport;
453
+ this.defaults = defaults;
454
+ }
455
+ transport;
456
+ defaults;
457
+ /**
458
+ * Ödeme (provizyon). 3D Secure'lu akışta `threeDSessionId` verilir,
459
+ * 3DS'siz akışta verilmez. Yanıttaki `orderId` değerini saklayın.
460
+ * `POST /v1/Payments/provision`
461
+ */
462
+ provision(input, options) {
463
+ return this.transport.requestJson(
464
+ "POST",
465
+ "/v1/Payments/provision",
466
+ {
467
+ body: {
468
+ ...input,
469
+ pointAmount: input.pointAmount ?? 0,
470
+ currency: input.currency ?? this.defaults.currency,
471
+ paymentType: input.paymentType ?? "Auth",
472
+ integrationMode: input.integrationMode ?? "Api",
473
+ installmentCount: input.installmentCount ?? 1,
474
+ languageCode: input.languageCode ?? this.defaults.languageCode
475
+ },
476
+ options
477
+ }
478
+ );
479
+ }
480
+ /**
481
+ * İptal. Gün sonu yapılmamış işlemi tamamen iptal eder.
482
+ * `POST /v1/Payments/reverse`
483
+ */
484
+ reverse(input, options) {
485
+ return this.transport.requestJson(
486
+ "POST",
487
+ "/v1/Payments/reverse",
488
+ {
489
+ body: {
490
+ orderId: input.orderId,
491
+ languageCode: input.languageCode ?? this.defaults.languageCode
492
+ },
493
+ options
494
+ }
495
+ );
496
+ }
497
+ /**
498
+ * İade (Return). Gün sonu yapılmış işlemde kısmi veya tam iade.
499
+ * `POST /v1/Payments/return`
500
+ */
501
+ refund(input, options) {
502
+ return this.transport.requestJson(
503
+ "POST",
504
+ "/v1/Payments/return",
505
+ {
506
+ body: {
507
+ orderId: input.orderId,
508
+ amount: input.amount,
509
+ languageCode: input.languageCode ?? this.defaults.languageCode
510
+ },
511
+ options
512
+ }
513
+ );
514
+ }
515
+ /**
516
+ * İşlem sorgulama. `orderId` veya `paymentConversationId` ile.
517
+ * `POST /v1/Payments/inquire`
518
+ */
519
+ inquire(input, options) {
520
+ return this.transport.requestJson(
521
+ "POST",
522
+ "/v1/Payments/inquire",
523
+ {
524
+ body: {
525
+ orderId: input.orderId,
526
+ paymentConversationId: input.paymentConversationId,
527
+ languageCode: input.languageCode ?? this.defaults.languageCode
528
+ },
529
+ options
530
+ }
531
+ );
532
+ }
533
+ /**
534
+ * Kartın kullanılabilir puanını sorgular.
535
+ * `POST /v1/Payments/pointInquiry`
536
+ */
537
+ pointInquiry(input, options) {
538
+ return this.transport.requestJson(
539
+ "POST",
540
+ "/v1/Payments/pointInquiry",
541
+ {
542
+ body: {
543
+ cardToken: input.cardToken,
544
+ currency: input.currency ?? this.defaults.currency,
545
+ languageCode: input.languageCode ?? this.defaults.languageCode
546
+ },
547
+ options
548
+ }
549
+ );
550
+ }
551
+ /**
552
+ * BIN bilgisi (kart markası, banka, kart tipi).
553
+ * `POST /v1/Payments/bin-information`
554
+ */
555
+ binInformation(input, options) {
556
+ return this.transport.requestJson(
557
+ "POST",
558
+ "/v1/Payments/bin-information",
559
+ {
560
+ body: {
561
+ binNumber: input.binNumber,
562
+ cardToken: input.cardToken,
563
+ languageCode: input.languageCode ?? this.defaults.languageCode
564
+ },
565
+ options
566
+ }
567
+ );
568
+ }
569
+ };
570
+
571
+ // src/resources/soft-pos.ts
572
+ var SoftPosResource = class {
573
+ constructor(transport) {
574
+ this.transport = transport;
575
+ }
576
+ transport;
577
+ /**
578
+ * SoftPOS ödeme oturumu başlatır, `paymentSessionToken` döner.
579
+ * `POST /v1/PayneosPayment/create-payment-session`
580
+ */
581
+ createPaymentSession(input, options) {
582
+ return this.transport.requestJson(
583
+ "POST",
584
+ "/v1/PayneosPayment/create-payment-session",
585
+ { body: input, options }
586
+ );
587
+ }
588
+ /**
589
+ * Ödeme sonrası dönen callback verisini işler.
590
+ * `POST /v1/PayneosPayment/handle-callback-data`
591
+ *
592
+ * @experimental OpenAPI tanımında istek gövdesi belirtilmemiştir; `payload`
593
+ * verildiğinde JSON olarak gönderilir.
594
+ */
595
+ handleCallbackData(payload, options) {
596
+ return this.transport.requestJson(
597
+ "POST",
598
+ "/v1/PayneosPayment/handle-callback-data",
599
+ { body: payload, options }
600
+ );
601
+ }
602
+ /**
603
+ * SoftPOS işlem durumu sorgular.
604
+ * `POST /v1/PayneosPayment/soft-pos-transaction-inquiry`
605
+ */
606
+ transactionInquiry(input, options) {
607
+ return this.transport.requestJson(
608
+ "POST",
609
+ "/v1/PayneosPayment/soft-pos-transaction-inquiry",
610
+ { body: { orderId: input.orderId }, options }
611
+ );
612
+ }
613
+ };
614
+
615
+ // src/resources/three-ds.ts
616
+ function toRecord(source) {
617
+ const out = {};
618
+ const entries = source instanceof FormData || source instanceof URLSearchParams ? source.entries() : Symbol.iterator in source ? source : Object.entries(source);
619
+ for (const [key, value] of entries) {
620
+ if (value === void 0 || value === null) continue;
621
+ out[key] = typeof value === "string" ? value : Array.isArray(value) ? String(value[0] ?? "") : String(value);
622
+ }
623
+ return out;
624
+ }
625
+ function pick(record, name) {
626
+ const wanted = name.toLowerCase();
627
+ for (const [key, value] of Object.entries(record)) {
628
+ if (key.toLowerCase() === wanted) return value;
629
+ }
630
+ return "";
631
+ }
632
+ function parseThreeDSCallback(source) {
633
+ const raw = toRecord(source);
634
+ const mdStatus = pick(raw, "MdStatus");
635
+ const isSucceed = pick(raw, "IsSucceed").toLowerCase() === "true";
636
+ return {
637
+ mdStatus,
638
+ isSucceed,
639
+ errorCode: pick(raw, "ErrorCode"),
640
+ errorMessage: pick(raw, "ErrorMessage"),
641
+ threeDSessionId: pick(raw, "ThreeDSessionId"),
642
+ conversationId: pick(raw, "ConversationId"),
643
+ isVerified: mdStatus === "1" && isSucceed,
644
+ raw
645
+ };
646
+ }
647
+ var ThreeDSResource = class {
648
+ constructor(transport, defaults) {
649
+ this.transport = transport;
650
+ this.defaults = defaults;
651
+ }
652
+ transport;
653
+ defaults;
654
+ /**
655
+ * `cardToken` ile 3D Secure oturumu oluşturur ve `threeDSessionId` döner.
656
+ * `POST /v1/ThreeDS/getthreedsession`
657
+ */
658
+ createSession(input, options) {
659
+ return this.transport.requestJson(
660
+ "POST",
661
+ "/v1/ThreeDS/getthreedsession",
662
+ {
663
+ body: {
664
+ amount: input.amount,
665
+ pointAmount: input.pointAmount ?? 0,
666
+ cardToken: input.cardToken,
667
+ currency: input.currency ?? this.defaults.currency,
668
+ paymentType: input.paymentType ?? "Auth",
669
+ installmentCount: input.installmentCount ?? 1,
670
+ languageCode: input.languageCode ?? this.defaults.languageCode
671
+ },
672
+ options
673
+ }
674
+ );
675
+ }
676
+ /**
677
+ * Banka doğrulama sayfasının HTML içeriğini döner. Bu HTML'i kullanıcının
678
+ * tarayıcısında (iframe veya tam sayfa) render edin.
679
+ * `POST /v1/ThreeDS/init3ds` (multipart/form-data, kimlik doğrulama form alanı olarak).
680
+ */
681
+ init(input, options) {
682
+ return this.transport.requestForm(
683
+ "/v1/ThreeDS/init3ds",
684
+ {
685
+ ThreeDSessionId: input.threeDSessionId,
686
+ CallbackUrl: input.callbackUrl,
687
+ LanguageCode: input.languageCode ?? this.defaults.languageCode,
688
+ ClientIpAddress: input.clientIpAddress,
689
+ CardHolderName: input.cardHolderName
690
+ },
691
+ options
692
+ );
693
+ }
694
+ /**
695
+ * Callback sonrası 3DS doğrulama sonucunu sunucu tarafında sorgular.
696
+ * `mdStatus === "1"` ise ödeme adımına geçilebilir.
697
+ * `POST /v1/ThreeDS/getthreedsessionresult`
698
+ */
699
+ getResult(input, options) {
700
+ return this.transport.requestJson(
701
+ "POST",
702
+ "/v1/ThreeDS/getthreedsessionresult",
703
+ {
704
+ body: {
705
+ threeDSessionId: input.threeDSessionId,
706
+ languageCode: input.languageCode ?? this.defaults.languageCode
707
+ },
708
+ options
709
+ }
710
+ );
711
+ }
712
+ /** `parseThreeDSCallback` fonksiyonunun kısayolu. */
713
+ parseCallback(source) {
714
+ return parseThreeDSCallback(source);
715
+ }
716
+ };
717
+
718
+ // src/resources/tokens.ts
719
+ var TokensResource = class {
720
+ constructor(transport) {
721
+ this.transport = transport;
722
+ }
723
+ transport;
724
+ /**
725
+ * Kart bilgilerini güvenli bir `cardToken` değerine dönüştürür.
726
+ * `POST /v1/Tokens` (multipart/form-data, kimlik doğrulama form alanı olarak).
727
+ *
728
+ * Kart verisi yalnızca bu çağrıda sunucunuzdan geçer; sonraki tüm adımlar
729
+ * `cardToken` ile yapılır.
730
+ */
731
+ create(input, options) {
732
+ return this.transport.requestForm(
733
+ "/v1/Tokens",
734
+ {
735
+ CardNumber: input.cardNumber,
736
+ ExpireMonth: String(input.expireMonth),
737
+ ExpireYear: String(input.expireYear),
738
+ Cvv: input.cvv
739
+ },
740
+ options
741
+ );
742
+ }
743
+ };
744
+
745
+ // src/version.ts
746
+ var SDK_VERSION = "0.1.0";
747
+
748
+ // src/client.ts
749
+ var PF_BASE_URLS = {
750
+ test: "https://testpfapi.rubikpara.com"
751
+ };
752
+ var PfClient = class {
753
+ baseUrl;
754
+ tokens;
755
+ threeDS;
756
+ payments;
757
+ installments;
758
+ links;
759
+ softPos;
760
+ transport;
761
+ publicKey;
762
+ secretKey;
763
+ constructor(config) {
764
+ requireNonEmpty(config.publicKey, "publicKey");
765
+ requireNonEmpty(config.secretKey, "secretKey");
766
+ requireNonEmpty(config.merchantNumber, "merchantNumber");
767
+ const fetchImpl = config.fetch ?? globalThis.fetch;
768
+ if (typeof fetchImpl !== "function") {
769
+ throw new PfConfigError(
770
+ "Global fetch bulunamad\u0131. Node.js 18.17+ kullan\u0131n veya config.fetch ile bir fetch uygulamas\u0131 verin."
771
+ );
772
+ }
773
+ this.baseUrl = resolveBaseUrl(config);
774
+ this.publicKey = config.publicKey;
775
+ this.secretKey = config.secretKey;
776
+ const nodeVersion = typeof process !== "undefined" && process.version ? process.version : "";
777
+ this.transport = new Transport({
778
+ baseUrl: this.baseUrl,
779
+ publicKey: config.publicKey,
780
+ secretKey: config.secretKey,
781
+ merchantNumber: config.merchantNumber,
782
+ timeoutMs: config.timeoutMs ?? 3e4,
783
+ throwOnApiError: config.throwOnApiError ?? true,
784
+ fetch: fetchImpl,
785
+ conversationIdFactory: config.conversationIdFactory ?? generateConversationId,
786
+ userAgent: `rubikpara-pf-sdk/${SDK_VERSION} node/${nodeVersion}`.trim()
787
+ });
788
+ const defaults = {
789
+ languageCode: config.languageCode ?? "tr",
790
+ currency: config.currency ?? "TRY"
791
+ };
792
+ this.tokens = new TokensResource(this.transport);
793
+ this.threeDS = new ThreeDSResource(this.transport, defaults);
794
+ this.payments = new PaymentsResource(this.transport, defaults);
795
+ this.installments = new InstallmentsResource(this.transport);
796
+ this.links = new LinksResource(this.transport, defaults);
797
+ this.softPos = new SoftPosResource(this.transport);
798
+ }
799
+ /** `GET /HealthCheck`. Kimlik doğrulaması gerektirmez. */
800
+ healthCheck(options) {
801
+ return this.transport.requestText("/HealthCheck", options);
802
+ }
803
+ /**
804
+ * SDK dışında (ör. kendi HTTP istemcinizle) kullanmak üzere bu istemcinin
805
+ * anahtarlarıyla yeni bir imza üretir. Her istek için yeniden çağrılmalıdır.
806
+ */
807
+ createSignature(conversationId) {
808
+ return createSignature({
809
+ publicKey: this.publicKey,
810
+ secretKey: this.secretKey,
811
+ conversationId
812
+ });
813
+ }
814
+ };
815
+ function requireNonEmpty(value, name) {
816
+ if (typeof value !== "string" || value.trim().length === 0) {
817
+ throw new PfConfigError(`${name} zorunludur ve bo\u015F olamaz.`);
818
+ }
819
+ }
820
+ function resolveBaseUrl(config) {
821
+ if (config.baseUrl) {
822
+ try {
823
+ return new URL(config.baseUrl).toString().replace(/\/+$/, "");
824
+ } catch {
825
+ throw new PfConfigError(`baseUrl ge\xE7ersiz: ${config.baseUrl}`);
826
+ }
827
+ }
828
+ if (!config.environment) {
829
+ throw new PfConfigError(
830
+ 'Ortam belirtilmedi: test i\xE7in environment: "test", canl\u0131 ortam i\xE7in baseUrl verin. Canl\u0131 ortam adresi canl\u0131ya ge\xE7i\u015Fte entegrasyon@rubikpara.com taraf\u0131ndan iletilir.'
831
+ );
832
+ }
833
+ const url = PF_BASE_URLS[config.environment];
834
+ if (!url) {
835
+ throw new PfConfigError(
836
+ `environment ge\xE7ersiz: ${String(config.environment)}. Yaln\u0131zca "test" desteklenir; canl\u0131 ortam i\xE7in baseUrl verin.`
837
+ );
838
+ }
839
+ return url;
840
+ }
841
+
842
+ export { InstallmentsResource, LinksResource, PF_BASE_URLS, PaymentsResource, PfApiError, PfClient, PfConfigError, PfError, PfHttpError, PfNetworkError, PfTimeoutError, SDK_VERSION, SoftPosResource, ThreeDSResource, TokensResource, computeHmacBase64, createSignature, decodeSecretKey, errorCategory, generateConversationId, generateNonce, parseThreeDSCallback };
843
+ //# sourceMappingURL=index.js.map
844
+ //# sourceMappingURL=index.js.map