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