@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/CHANGELOG.md ADDED
@@ -0,0 +1,28 @@
1
+ # Changelog
2
+
3
+ Bu dosya [Keep a Changelog](https://keepachangelog.com/tr/1.1.0/) biçimini,
4
+ sürümleme [Semantic Versioning](https://semver.org/lang/tr/) kurallarını izler.
5
+
6
+ ## [Unreleased]
7
+
8
+ ## [0.1.1] - 2026-11-16
9
+
10
+ ### Changed
11
+
12
+ - Paket bilgilerinden iç depo adresi kaldırıldı.
13
+ - README müşteri kullanımına odaklandı; geliştirme ve yayın notları paket dışındaki `CONTRIBUTING.md` dosyasına taşındı.
14
+
15
+ ## [0.1.0] - 2026-11-16
16
+
17
+ ### Added
18
+
19
+ - `PfClient`: test ortamı (`environment: "test"`) veya özel adres (`baseUrl`), zaman aşımı, özel `fetch`, varsayılan dil ve para birimi.
20
+ - Otomatik 2 aşamalı HMAC-SHA256 imzalama (`createSignature` ayrıca dışa açık).
21
+ - Kaynaklar: `tokens`, `threeDS`, `payments`, `installments`, `links`, `softPos`, `healthCheck`.
22
+ - Tipli hatalar: `PfApiError` (errorCode / category), `PfHttpError` (ProblemDetails mesajıyla), `PfNetworkError`, `PfTimeoutError`, `PfConfigError`.
23
+ - `parseThreeDSCallback` yardımcı fonksiyonu.
24
+ - ESM + CommonJS çıktı, TypeScript tip tanımları, sıfır çalışma zamanı bağımlılığı.
25
+
26
+ ### Security
27
+
28
+ - Canlı ortam adresi pakete gömülmez; canlıya geçişte iletilen adres `baseUrl` ile verilir.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rubik Para
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,260 @@
1
- # Temporary Holding Version
1
+ # @rubikpara/pf-sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Rubik Para **PF Gateway API** için resmi Node.js / TypeScript SDK'sı.
4
+
5
+ HMAC imzalama, kart tokenizasyon, 3D Secure, ödeme, iptal/iade, taksit sorgulama, link ile ödeme ve SoftPOS uç noktalarını tipli bir istemci arkasında toplar. Çalışma zamanı bağımlılığı yoktur.
6
+
7
+ - Node.js **18.17+** (global `fetch` ve `FormData` kullanır)
8
+ - ESM ve CommonJS
9
+ - TypeScript tip tanımları dahil
10
+ - Dokümantasyon: https://developer.rubikpara.com/docs/sdks/nodejs
11
+
12
+ ## Kurulum
13
+
14
+ ```bash
15
+ npm install @rubikpara/pf-sdk
16
+ # veya
17
+ pnpm add @rubikpara/pf-sdk
18
+ ```
19
+
20
+ ## Hızlı Başlangıç
21
+
22
+ ```ts
23
+ import { PfClient } from "@rubikpara/pf-sdk";
24
+
25
+ const pf = new PfClient({
26
+ publicKey: process.env.PF_PUBLIC_KEY!,
27
+ secretKey: process.env.PF_SECRET_KEY!, // Base64 kodlu, size verildiği gibi
28
+ merchantNumber: process.env.PF_MERCHANT_NUMBER!,
29
+ environment: "test",
30
+ });
31
+
32
+ // 1) Kart → token
33
+ const { cardToken } = await pf.tokens.create({
34
+ cardNumber: "6501700194147183",
35
+ expireMonth: "12",
36
+ expireYear: "2030",
37
+ cvv: "001",
38
+ });
39
+
40
+ // 2) Ödeme (3DS'siz; yetkili üye işyerleri için)
41
+ const payment = await pf.payments.provision(
42
+ { amount: 100, cardToken: cardToken!, cardHolderName: "Ad Soyad" },
43
+ { conversationId: "siparis-1001", clientIpAddress: "203.0.113.10" },
44
+ );
45
+
46
+ console.log(payment.orderId); // iptal / iade / sorgulama için saklayın
47
+ ```
48
+
49
+ SDK her çağrıda yeni bir `Nonce` ve `Signature` üretir; imza algoritmasıyla uğraşmanız gerekmez.
50
+
51
+ > **Önemli:** `secretKey` yalnızca sunucu tarafında kullanılmalıdır. Bu paketi tarayıcıda veya mobil uygulamada çalıştırmayın.
52
+
53
+ ## Canlı Ortama Geçiş
54
+
55
+ SDK yalnızca test ortamının adresini bilir. Canlı ortam adresi canlıya geçişte **entegrasyon@rubikpara.com** tarafından iletilir; `baseUrl` ile verin:
56
+
57
+ ```ts
58
+ const pf = new PfClient({
59
+ publicKey: process.env.PF_PUBLIC_KEY!,
60
+ secretKey: process.env.PF_SECRET_KEY!,
61
+ merchantNumber: process.env.PF_MERCHANT_NUMBER!,
62
+ baseUrl: process.env.PF_BASE_URL!, // size iletilen canlı ortam adresi
63
+ });
64
+ ```
65
+
66
+ `environment` ve `baseUrl` ikisi birden verilmezse istemci hata verir. Ortamın bilinçli olarak varsayılanı yoktur.
67
+
68
+ ## 3D Secure ile Ödeme
69
+
70
+ ```ts
71
+ // Sunucu: ödemeyi başlat
72
+ const { cardToken } = await pf.tokens.create(card);
73
+
74
+ const session = await pf.threeDS.createSession(
75
+ { amount: 100, cardToken: cardToken! },
76
+ { clientIpAddress: ip },
77
+ );
78
+
79
+ const init = await pf.threeDS.init({
80
+ threeDSessionId: session.threeDSessionId!,
81
+ callbackUrl: "https://siteniz.com/3ds-callback",
82
+ clientIpAddress: ip,
83
+ cardHolderName: "Ad Soyad",
84
+ });
85
+
86
+ // init.htmlContent → kullanıcının tarayıcısında render edin (iframe veya tam sayfa).
87
+ // Banka doğrulaması bitince kullanıcı callbackUrl'e form POST ile yönlendirilir.
88
+ ```
89
+
90
+ ```ts
91
+ // Sunucu: callback geldikten sonra
92
+ import { parseThreeDSCallback } from "@rubikpara/pf-sdk";
93
+
94
+ app.post(
95
+ "/3ds-callback",
96
+ express.urlencoded({ extended: false }),
97
+ async (req, res) => {
98
+ const cb = parseThreeDSCallback(req.body); // { mdStatus, isSucceed, threeDSessionId, isVerified, ... }
99
+
100
+ // Callback imzalı değildir: sonucu her zaman API'den doğrulayın.
101
+ const result = await pf.threeDS.getResult({
102
+ threeDSessionId: cb.threeDSessionId,
103
+ });
104
+ if (result.mdStatus !== "1") {
105
+ return res
106
+ .status(400)
107
+ .send(`3DS başarısız: ${result.mdErrorMessage ?? result.mdStatus}`);
108
+ }
109
+
110
+ const payment = await pf.payments.provision(
111
+ {
112
+ amount: 100,
113
+ cardToken, // 1. adımda sakladığınız token
114
+ threeDSessionId: cb.threeDSessionId,
115
+ cardHolderName: "Ad Soyad",
116
+ },
117
+ { conversationId: `siparis-${orderNo}`, clientIpAddress: req.ip },
118
+ );
119
+
120
+ res.redirect(`/siparis/${payment.orderId}`);
121
+ },
122
+ );
123
+ ```
124
+
125
+ Next.js route handler'da `parseThreeDSCallback(await req.formData())` aynı şekilde çalışır.
126
+
127
+ ## Hata Yönetimi
128
+
129
+ API, HTTP 200 dönse bile `isSucceed: false` ile iş mantığı hatası verebilir. SDK bu durumda **`PfApiError`** fırlatır; `isSucceed` kontrolünü unutma riski kalmaz.
130
+
131
+ ```ts
132
+ import { PfApiError, PfHttpError, PfNetworkError, PfTimeoutError } from "@rubikpara/pf-sdk";
133
+
134
+ try {
135
+ await pf.payments.provision(...);
136
+ } catch (err) {
137
+ if (err instanceof PfApiError) {
138
+ // err.errorCode → "0022"
139
+ // err.errorMessage → "Kart token zaman aşımına uğramıştır"
140
+ // err.category → "business" | "system" | "bank" | "unknown" (0xxx / 1xxx / 5xxx)
141
+ // err.conversationId, err.httpStatus, err.response (ham yanıt)
142
+ } else if (err instanceof PfTimeoutError) {
143
+ // timeoutMs içinde yanıt gelmedi; ödeme durumunu inquire ile doğrulayın
144
+ } else if (err instanceof PfHttpError) {
145
+ // 4xx/5xx veya JSON olmayan yanıt: err.status, err.body
146
+ // Yanlış anahtar: HTTP 401 "Unauthorized: Hmac Authentication Error"
147
+ } else if (err instanceof PfNetworkError) {
148
+ // DNS/TLS/bağlantı hatası: err.cause
149
+ }
150
+ }
151
+ ```
152
+
153
+ Hata fırlatmak yerine yanıtı olduğu gibi almak isterseniz:
154
+
155
+ ```ts
156
+ const pf = new PfClient({ ..., throwOnApiError: false });
157
+ const res = await pf.payments.inquire({ orderId });
158
+ if (!res.isSucceed) console.log(res.errorCode, res.errorMessage);
159
+ ```
160
+
161
+ ### Mükerrer işlem ve yeniden deneme
162
+
163
+ API, aynı `conversationId` ile gelen isteği idempotent kabul eder. Ödeme gibi kritik çağrılarda **kendi sipariş numaranızı** `conversationId` olarak verin; zaman aşımı veya ağ hatasında aynı değerle yeniden denemek mükerrer çekim oluşturmaz. SDK her denemede yeni imza üretir.
164
+
165
+ ## API Yüzeyi
166
+
167
+ | Kaynak | Metot | Uç nokta |
168
+ | ----------------- | ---------------------------------- | ------------------------------------------------------ |
169
+ | `pf.tokens` | `create(input)` | `POST /v1/Tokens` |
170
+ | `pf.threeDS` | `createSession(input)` | `POST /v1/ThreeDS/getthreedsession` |
171
+ | | `init(input)` | `POST /v1/ThreeDS/init3ds` |
172
+ | | `getResult(input)` | `POST /v1/ThreeDS/getthreedsessionresult` |
173
+ | | `parseCallback(form)` | yerel yardımcı |
174
+ | `pf.payments` | `provision(input)` | `POST /v1/Payments/provision` |
175
+ | | `reverse(input)` | `POST /v1/Payments/reverse` (iptal) |
176
+ | | `refund(input)` | `POST /v1/Payments/return` (iade) |
177
+ | | `inquire(input)` | `POST /v1/Payments/inquire` |
178
+ | | `pointInquiry(input)` | `POST /v1/Payments/pointInquiry` |
179
+ | | `binInformation(input)` | `POST /v1/Payments/bin-information` |
180
+ | `pf.installments` | `query(input)` | `GET /v1/Installment` |
181
+ | `pf.links` | `create(input)` | `POST /v1/Payments/createLink` |
182
+ | | `getStatus({ id })` | `POST /v1/Payments/link-status` |
183
+ | | `delete({ id })` | `POST /v1/Payments/deleteLink` |
184
+ | | `provision(input)` | `POST /v1/Payments/linkProvision` |
185
+ | `pf.softPos` | `createPaymentSession(input)` | `POST /v1/PayneosPayment/create-payment-session` |
186
+ | | `transactionInquiry(input)` | `POST /v1/PayneosPayment/soft-pos-transaction-inquiry` |
187
+ | | `handleCallbackData(payload?)` | `POST /v1/PayneosPayment/handle-callback-data` |
188
+ | `pf` | `healthCheck()` | `GET /HealthCheck` |
189
+ | `pf` | `createSignature(conversationId?)` | kendi HTTP istemciniz için imza |
190
+
191
+ Her metot ikinci parametre olarak `RequestOptions` alır:
192
+
193
+ ```ts
194
+ interface RequestOptions {
195
+ conversationId?: string; // verilmezse otomatik üretilir
196
+ clientIpAddress?: string; // son kullanıcının IP'si (ClientIpAddress header'ı)
197
+ signal?: AbortSignal;
198
+ timeoutMs?: number; // istemci genelindeki değeri ezer
199
+ }
200
+ ```
201
+
202
+ ### Uygulanan varsayılanlar
203
+
204
+ | Alan | Varsayılan | Nerede |
205
+ | -------------------- | ----------------------- | ------------------------------------- |
206
+ | `pointAmount` | `0` | provision, 3DS oturum, link provizyon |
207
+ | `currency` | `"TRY"` (istemci ayarı) | provision, 3DS oturum, puan sorgu |
208
+ | `paymentType` | `"Auth"` | provision, 3DS oturum, link provizyon |
209
+ | `integrationMode` | `"Api"` | provision, link provizyon |
210
+ | `installmentCount` | `1` | provision, 3DS oturum, link provizyon |
211
+ | `languageCode` | `"tr"` (istemci ayarı) | tüm JSON istekler ve init3ds |
212
+ | `currency` (link) | `949` (TRY, numerik) | `links.create` |
213
+ | `notificationMethod` | `"None"` | `links.create` |
214
+
215
+ İstek nesnesinde verdiğiniz değer her zaman varsayılanı ezer.
216
+
217
+ ## İstemci Seçenekleri
218
+
219
+ ```ts
220
+ new PfClient({
221
+ publicKey,
222
+ secretKey,
223
+ merchantNumber,
224
+ environment: "test", // ya da:
225
+ baseUrl: "https://...", // canlı ortam adresi (environment'ı ezer)
226
+ timeoutMs: 30_000, // varsayılan 30 sn
227
+ languageCode: "tr",
228
+ currency: "TRY",
229
+ throwOnApiError: true,
230
+ fetch: customFetch, // proxy, loglama, test
231
+ conversationIdFactory: () => myId(), // otomatik ConversationId üreteci
232
+ });
233
+ ```
234
+
235
+ ## Yalnızca İmza Üretmek
236
+
237
+ ```ts
238
+ import { createSignature } from "@rubikpara/pf-sdk";
239
+
240
+ const { nonce, signature, conversationId } = createSignature({
241
+ publicKey,
242
+ secretKey,
243
+ conversationId: "siparis-1001", // opsiyonel
244
+ });
245
+ // Header'lar: PublicKey, Nonce, Signature, ConversationId, MerchantNumber, ClientIpAddress
246
+ ```
247
+
248
+ ## CommonJS
249
+
250
+ ```js
251
+ const { PfClient } = require("@rubikpara/pf-sdk");
252
+ ```
253
+
254
+ ## Destek
255
+
256
+ Test ortamı bilgileri ve entegrasyon desteği için **entegrasyon@rubikpara.com**. Destek talebinde `conversationId` ve varsa `bankRrnNo` değerlerini paylaşmanız çözümü hızlandırır.
257
+
258
+ ## Lisans
259
+
260
+ MIT