@tapsilat/tapsilat-js 1.0.2 → 1.0.3
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 +3 -9
- package/dist/TapsilatSDK.d.ts +156 -118
- package/dist/TapsilatSDK.d.ts.map +1 -1
- package/dist/http/HttpClient.d.ts.map +1 -1
- package/dist/index.d.ts +156 -118
- package/dist/index.esm.js +254 -165
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +254 -165
- package/dist/index.js.map +1 -1
- package/dist/types/index.d.ts +6 -6
- package/dist/utils/index.d.ts +20 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -231,19 +231,19 @@ interface OrderCreateResponse {
|
|
|
231
231
|
/**
|
|
232
232
|
* Main SDK class for Tapsilat payment operations
|
|
233
233
|
*
|
|
234
|
-
* @
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
234
|
+
* @summary Enterprise-grade TypeScript SDK for Tapsilat Payment Processing Platform
|
|
235
|
+
* @description
|
|
236
|
+
* The TapsilatSDK class provides a comprehensive interface for integrating with the Tapsilat payment platform.
|
|
237
|
+
* It offers secure, efficient, and type-safe methods for managing orders, payments, refunds, and other
|
|
238
|
+
* payment-related operations. The SDK includes built-in error handling, request validation, retry logic,
|
|
239
|
+
* and comprehensive logging capabilities.
|
|
240
240
|
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
241
|
+
* Key features:
|
|
242
|
+
* - Type-safe API with TypeScript support
|
|
243
|
+
* - Built-in error handling with custom error types
|
|
244
|
+
* - Automatic request/response validation
|
|
245
|
+
* - Configurable retry mechanism
|
|
246
|
+
* - Full compliance with Tapsilat API specifications
|
|
247
247
|
*/
|
|
248
248
|
declare class TapsilatSDK {
|
|
249
249
|
private readonly httpClient;
|
|
@@ -251,109 +251,107 @@ declare class TapsilatSDK {
|
|
|
251
251
|
/**
|
|
252
252
|
* Creates a new TapsilatSDK instance
|
|
253
253
|
*
|
|
254
|
-
* @
|
|
255
|
-
* @
|
|
254
|
+
* @summary Initializes the Tapsilat SDK with configuration options
|
|
255
|
+
* @description
|
|
256
|
+
* Creates and configures a new instance of the TapsilatSDK with the provided configuration.
|
|
257
|
+
* The constructor validates the bearer token, sets up the HTTP client with proper headers,
|
|
258
|
+
* configures retry mechanisms, and initializes internal state for API communication.
|
|
259
|
+
*
|
|
260
|
+
* The SDK instance is immutable after creation - configuration cannot be changed without
|
|
261
|
+
* creating a new instance. This ensures thread safety and predictable behavior.
|
|
262
|
+
*
|
|
263
|
+
* @param {TapsilatConfig} config - SDK configuration options
|
|
264
|
+
* @param {string} config.bearerToken - API authentication token (required)
|
|
265
|
+
* @param {string} [config.baseURL='https://api.tapsilat.com/v1'] - API base URL
|
|
266
|
+
* @param {number} [config.timeout=30000] - Request timeout in milliseconds
|
|
267
|
+
* @param {number} [config.maxRetries=3] - Maximum number of retry attempts
|
|
268
|
+
* @param {number} [config.retryDelay=1000] - Delay between retries in milliseconds
|
|
269
|
+
* @param {string} [config.version='v1'] - API version to use
|
|
270
|
+
* @param {boolean} [config.debug=false] - Enable debug logging
|
|
271
|
+
*
|
|
272
|
+
* @throws {TapsilatValidationError} When bearer token is invalid, missing, or malformed
|
|
273
|
+
* @throws {TypeError} When config parameter is not an object or missing required fields
|
|
256
274
|
*/
|
|
257
275
|
constructor(config: TapsilatConfig);
|
|
258
276
|
/**
|
|
259
|
-
* Creates a new order and returns a checkout URL
|
|
277
|
+
* Creates a new order and returns a checkout URL
|
|
260
278
|
*
|
|
261
|
-
* @
|
|
262
|
-
* @
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
279
|
+
* @summary Initiates a new payment order with buyer information and generates checkout URL
|
|
280
|
+
* @description
|
|
281
|
+
* Creates a new payment order in the Tapsilat system with the provided order details.
|
|
282
|
+
* This method performs comprehensive validation of all input parameters, creates the order
|
|
283
|
+
* on the payment platform, and returns a checkout URL that customers can use to complete
|
|
284
|
+
* their payment. The method supports multiple currencies, locales, and comprehensive
|
|
285
|
+
* buyer information for compliance and fraud prevention.
|
|
266
286
|
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
* const orderResponse = await tapsilat.createOrder({
|
|
271
|
-
* amount: 100.50,
|
|
272
|
-
* currency: 'TRY',
|
|
273
|
-
* locale: 'en',
|
|
274
|
-
* buyer: {
|
|
275
|
-
* name: 'John',
|
|
276
|
-
* surname: 'Doe',
|
|
277
|
-
* email: 'john.doe@example.com'
|
|
278
|
-
* }
|
|
279
|
-
* });
|
|
280
|
-
* console.log(`Checkout URL: ${orderResponse.checkoutUrl}`);
|
|
281
|
-
* } catch (error) {
|
|
282
|
-
* console.error(`Order creation failed: ${error.message}`);
|
|
283
|
-
* }
|
|
284
|
-
* ```
|
|
285
|
-
*/
|
|
286
|
-
createOrder(orderRequest: OrderCreateRequest): Promise<OrderCreateResponse>;
|
|
287
|
-
/**
|
|
288
|
-
* Validates an order request object
|
|
289
|
-
* @private
|
|
290
|
-
*/
|
|
291
|
-
private validateOrderRequest;
|
|
292
|
-
/**
|
|
293
|
-
* Basic email validation
|
|
294
|
-
* @private
|
|
295
|
-
*/
|
|
296
|
-
private isValidEmail;
|
|
297
|
-
/**
|
|
298
|
-
* Generic response handler - consistent way to handle API responses across SDK methods
|
|
299
|
-
* @private
|
|
287
|
+
* The returned checkout URL is valid for a limited time (typically 24 hours) and should
|
|
288
|
+
* be presented to the customer immediately. The order status can be tracked using the
|
|
289
|
+
* returned reference ID through the getOrderStatus method.
|
|
300
290
|
*
|
|
301
|
-
* @param
|
|
302
|
-
* @param
|
|
303
|
-
* @
|
|
304
|
-
* @
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
*
|
|
309
|
-
* @
|
|
291
|
+
* @param {OrderCreateRequest} orderRequest - Complete order information
|
|
292
|
+
* @param {number} orderRequest.amount - Payment amount (must be positive, max 2 decimal places)
|
|
293
|
+
* @param {Currency} orderRequest.currency - Payment currency ('TRY', 'USD', 'EUR', 'GBP')
|
|
294
|
+
* @param {Locale} orderRequest.locale - Display language ('tr' for Turkish, 'en' for English)
|
|
295
|
+
* @param {Buyer} orderRequest.buyer - Customer information for payment processing
|
|
296
|
+
* @param {string} orderRequest.buyer.name - Customer's first name (required)
|
|
297
|
+
* @param {string} orderRequest.buyer.surname - Customer's last name (required)
|
|
298
|
+
* @param {string} orderRequest.buyer.email - Customer's email address (required, validated)
|
|
299
|
+
* @param {string} [orderRequest.buyer.phone] - Customer's phone number
|
|
300
|
+
* @param {string} [orderRequest.buyer.identityNumber] - National ID or tax number
|
|
301
|
+
* @param {Address} [orderRequest.buyer.shippingAddress] - Shipping address for physical goods
|
|
302
|
+
* @param {Address} [orderRequest.buyer.billingAddress] - Billing address for invoicing
|
|
303
|
+
* @param {string} [orderRequest.description] - Order description for customer reference
|
|
304
|
+
* @param {string} [orderRequest.callbackUrl] - URL to redirect after payment completion
|
|
305
|
+
* @param {string} [orderRequest.conversationId] - Custom tracking ID for your system
|
|
306
|
+
* @param {Record<string, unknown>} [orderRequest.metadata] - Additional custom data
|
|
307
|
+
*
|
|
308
|
+
* @returns {Promise<OrderCreateResponse>} Promise resolving to order creation response
|
|
309
|
+
* @returns {string} OrderCreateResponse.referenceId - Unique order identifier for tracking
|
|
310
|
+
* @returns {string} OrderCreateResponse.conversationId - Echo of provided conversation ID
|
|
311
|
+
* @returns {string} OrderCreateResponse.checkoutUrl - Payment page URL for customer
|
|
312
|
+
* @returns {string} OrderCreateResponse.status - Initial order status (typically 'CREATED')
|
|
313
|
+
* @returns {string} [OrderCreateResponse.qrCodeUrl] - QR code URL for mobile payments
|
|
310
314
|
*
|
|
311
|
-
* @
|
|
312
|
-
*
|
|
313
|
-
*
|
|
315
|
+
* @throws {TapsilatValidationError} When input validation fails:
|
|
316
|
+
* - Amount is not positive or has more than 2 decimal places
|
|
317
|
+
* - Currency is not supported
|
|
318
|
+
* - Buyer information is incomplete or invalid
|
|
319
|
+
* - Email format is invalid
|
|
320
|
+
* - Required fields are missing
|
|
321
|
+
* @throws {TapsilatNetworkError} When network request fails:
|
|
322
|
+
* - Connection timeout
|
|
323
|
+
* - DNS resolution failure
|
|
324
|
+
* - Network connectivity issues
|
|
325
|
+
* @throws {TapsilatError} When API returns business logic errors:
|
|
326
|
+
* - Insufficient merchant balance
|
|
327
|
+
* - Currency not enabled for merchant
|
|
328
|
+
* - Buyer blocked due to fraud detection
|
|
329
|
+
* - Rate limiting exceeded
|
|
314
330
|
*/
|
|
315
|
-
|
|
331
|
+
createOrder(orderRequest: OrderCreateRequest): Promise<OrderCreateResponse>;
|
|
316
332
|
/**
|
|
317
333
|
* Gets an order by reference ID.
|
|
318
334
|
*
|
|
335
|
+
* @summary Retrieve complete order details and information
|
|
336
|
+
* @description Gets complete order data including buyer info, amounts, and current status using the unique reference ID.
|
|
337
|
+
*
|
|
319
338
|
* @param referenceId - The unique reference ID of the order
|
|
320
339
|
* @returns Promise resolving to the complete order details
|
|
321
340
|
* @throws {TapsilatValidationError} When referenceId is invalid
|
|
322
341
|
* @throws {TapsilatNetworkError} When API request fails due to network issues
|
|
323
342
|
* @throws {TapsilatError} When API returns an error response
|
|
324
|
-
*
|
|
325
|
-
* @example
|
|
326
|
-
* ```typescript
|
|
327
|
-
* try {
|
|
328
|
-
* const order = await tapsilat.getOrder("ord_123456789");
|
|
329
|
-
* console.log(`Order amount: ${order.amount} ${order.currency}`);
|
|
330
|
-
* } catch (error) {
|
|
331
|
-
* console.error(`Failed to get order: ${error.message}`);
|
|
332
|
-
* }
|
|
333
|
-
* ```
|
|
334
343
|
*/
|
|
335
344
|
getOrder(referenceId: string): Promise<Order>;
|
|
336
345
|
/**
|
|
337
346
|
* Lists orders with pagination support.
|
|
338
347
|
*
|
|
348
|
+
* @summary Retrieve paginated list of merchant orders
|
|
349
|
+
* @description Gets orders with pagination support, filtering, and sorting options.
|
|
350
|
+
*
|
|
339
351
|
* @param params - Optional pagination parameters (page number and items per page)
|
|
340
352
|
* @returns Promise resolving to paginated list of orders
|
|
341
353
|
* @throws {TapsilatNetworkError} When API request fails due to network issues
|
|
342
354
|
* @throws {TapsilatError} When API returns an error response
|
|
343
|
-
*
|
|
344
|
-
* @example
|
|
345
|
-
* ```typescript
|
|
346
|
-
* try {
|
|
347
|
-
* // Get the second page with 20 items per page
|
|
348
|
-
* const orderList = await tapsilat.getOrders({ page: 2, per_page: 20 });
|
|
349
|
-
* console.log(`Total orders: ${orderList.total}`);
|
|
350
|
-
* orderList.rows.forEach(order => {
|
|
351
|
-
* console.log(`Order ${order.referenceId}: ${order.amount} ${order.currency}`);
|
|
352
|
-
* });
|
|
353
|
-
* } catch (error) {
|
|
354
|
-
* console.error(`Failed to list orders: ${error.message}`);
|
|
355
|
-
* }
|
|
356
|
-
* ```
|
|
357
355
|
*/
|
|
358
356
|
getOrders(params?: {
|
|
359
357
|
page?: number;
|
|
@@ -361,36 +359,55 @@ declare class TapsilatSDK {
|
|
|
361
359
|
}): Promise<PaginatedResponse<Order>>;
|
|
362
360
|
/**
|
|
363
361
|
* Cancels an order by reference_id.
|
|
362
|
+
*
|
|
363
|
+
* @summary Cancel a pending order before payment completion
|
|
364
|
+
* @description Cancels unpaid order and prevents further payment processing.
|
|
364
365
|
*/
|
|
365
366
|
cancelOrder(referenceId: string): Promise<Order>;
|
|
366
367
|
/**
|
|
367
|
-
* Gets the status of an order by reference ID
|
|
368
|
+
* Gets the current status of an order by reference ID
|
|
368
369
|
*
|
|
369
|
-
* @
|
|
370
|
-
* @
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
370
|
+
* @summary Retrieves real-time payment status and tracking information for a specific order
|
|
371
|
+
* @description
|
|
372
|
+
* Queries the Tapsilat payment platform to retrieve the current status of an order using its
|
|
373
|
+
* unique reference ID. This method provides real-time information about payment progress,
|
|
374
|
+
* completion status, and last update timestamp. It's essential for tracking payment flow
|
|
375
|
+
* and implementing proper order state management in your application.
|
|
374
376
|
*
|
|
375
|
-
*
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
*
|
|
385
|
-
*
|
|
386
|
-
* }
|
|
387
|
-
*
|
|
377
|
+
* The status information includes payment state (CREATED, PENDING_PAYMENT, COMPLETED, CANCELLED),
|
|
378
|
+
* last update timestamp, and any relevant status metadata. This method should be used to:
|
|
379
|
+
* - Check if a payment has been completed after redirecting from checkout
|
|
380
|
+
* - Monitor payment status for pending transactions
|
|
381
|
+
* - Verify order state before fulfilling goods/services
|
|
382
|
+
* - Implement webhook verification and status synchronization
|
|
383
|
+
*
|
|
384
|
+
* @param {string} referenceId - Unique order reference identifier from order creation
|
|
385
|
+
*
|
|
386
|
+
* @returns {Promise<OrderStatusResponse>} Promise resolving to current order status information
|
|
387
|
+
* @returns {string} OrderStatusResponse.referenceId - Echo of the provided reference ID
|
|
388
|
+
* @returns {string} OrderStatusResponse.status - Current payment status (CREATED, PENDING_PAYMENT, COMPLETED, CANCELLED, FAILED)
|
|
389
|
+
* @returns {string} OrderStatusResponse.lastUpdatedAt - ISO 8601 timestamp of last status change
|
|
390
|
+
*
|
|
391
|
+
* @throws {TapsilatValidationError} When input validation fails:
|
|
392
|
+
* - Reference ID is null, undefined, or empty string
|
|
393
|
+
* - Reference ID format is invalid (should match order ID pattern)
|
|
394
|
+
* @throws {TapsilatNetworkError} When network request fails:
|
|
395
|
+
* - Connection timeout during status check
|
|
396
|
+
* - DNS resolution failure
|
|
397
|
+
* - Network connectivity issues
|
|
398
|
+
* @throws {TapsilatError} When API returns business logic errors:
|
|
399
|
+
* - ORDER_NOT_FOUND: Order with given reference ID doesn't exist
|
|
400
|
+
* - ACCESS_DENIED: Order belongs to different merchant
|
|
401
|
+
* - RATE_LIMIT_EXCEEDED: Too many status check requests
|
|
388
402
|
*/
|
|
389
403
|
getOrderStatus(referenceId: string): Promise<OrderStatusResponse>;
|
|
390
404
|
/**
|
|
391
405
|
* Partially refunds an order.
|
|
392
406
|
* Based on `refund_order` from the Python SDK.
|
|
393
407
|
*
|
|
408
|
+
* @summary Process partial refund for a completed order
|
|
409
|
+
* @description Refunds specified amount from a paid order and returns transaction details.
|
|
410
|
+
*
|
|
394
411
|
* @param refundData - The refund details, including referenceId and amount.
|
|
395
412
|
* @returns Promise resolving to the refund transaction details.
|
|
396
413
|
*/
|
|
@@ -399,6 +416,9 @@ declare class TapsilatSDK {
|
|
|
399
416
|
* Fully refunds an order by its reference ID.
|
|
400
417
|
* Based on `refund_all_order` from the Python SDK.
|
|
401
418
|
*
|
|
419
|
+
* @summary Process full refund for a completed order
|
|
420
|
+
* @description Refunds entire order amount and returns transaction details.
|
|
421
|
+
*
|
|
402
422
|
* @param referenceId - The unique identifier of the order to fully refund.
|
|
403
423
|
* @returns Promise resolving to the refund transaction details.
|
|
404
424
|
*/
|
|
@@ -407,6 +427,9 @@ declare class TapsilatSDK {
|
|
|
407
427
|
* Retrieves the payment details for an order.
|
|
408
428
|
* Based on `get_order_payment_details` from the Python SDK.
|
|
409
429
|
*
|
|
430
|
+
* @summary Retrieve detailed payment transaction information for an order
|
|
431
|
+
* @description Gets payment method, amount, status, and card info for order transactions.
|
|
432
|
+
*
|
|
410
433
|
* @param referenceId - The unique identifier of the order.
|
|
411
434
|
* @param conversationId - Optional conversation ID for more specific querying.
|
|
412
435
|
* @returns Promise resolving to a list of payment details.
|
|
@@ -415,16 +438,25 @@ declare class TapsilatSDK {
|
|
|
415
438
|
/**
|
|
416
439
|
* Gets an order by conversation_id.
|
|
417
440
|
* Based on `get_order_by_conversation_id` from the Python SDK.
|
|
441
|
+
*
|
|
442
|
+
* @summary Find order using conversation ID instead of reference ID
|
|
443
|
+
* @description Alternative lookup method for orders using custom conversation identifier.
|
|
418
444
|
*/
|
|
419
445
|
getOrderByConversationId(conversationId: string): Promise<Order>;
|
|
420
446
|
/**
|
|
421
447
|
* Gets order transactions by reference_id.
|
|
422
448
|
* Based on `get_order_transactions` from the Python SDK.
|
|
449
|
+
*
|
|
450
|
+
* @summary Retrieve transaction history for an order
|
|
451
|
+
* @description Gets detailed transaction records and payment attempts for a specific order.
|
|
423
452
|
*/
|
|
424
453
|
getOrderTransactions(referenceId: string): Promise<any[]>;
|
|
425
454
|
/**
|
|
426
455
|
* Gets order submerchants with pagination.
|
|
427
456
|
* Based on `get_order_submerchants` from the Python SDK.
|
|
457
|
+
*
|
|
458
|
+
* @summary Retrieve paginated list of submerchants for orders
|
|
459
|
+
* @description Gets submerchant information with pagination support for order management.
|
|
428
460
|
*/
|
|
429
461
|
getOrderSubmerchants(params?: {
|
|
430
462
|
page?: number;
|
|
@@ -433,29 +465,29 @@ declare class TapsilatSDK {
|
|
|
433
465
|
/**
|
|
434
466
|
* Gets checkout URL for an order.
|
|
435
467
|
* Based on `get_checkout_url` from the Python SDK.
|
|
468
|
+
*
|
|
469
|
+
* @summary Retrieve checkout URL for existing order
|
|
470
|
+
* @description Gets the payment checkout URL for an existing order using reference ID.
|
|
436
471
|
*/
|
|
437
472
|
getCheckoutUrl(referenceId: string): Promise<string>;
|
|
438
473
|
/**
|
|
439
474
|
* Verifies webhook signature for security
|
|
440
475
|
*
|
|
476
|
+
* @summary Validate webhook signature for security verification
|
|
477
|
+
* @description Verifies the authenticity of webhook payloads using HMAC signature validation.
|
|
478
|
+
*
|
|
441
479
|
* @param payload - Raw webhook payload string
|
|
442
480
|
* @param signature - Webhook signature from headers
|
|
443
481
|
* @param secret - Your webhook secret key
|
|
444
482
|
* @returns Promise resolving to true if signature is valid
|
|
445
|
-
*
|
|
446
|
-
* @example
|
|
447
|
-
* ```typescript
|
|
448
|
-
* const isValid = await sdk.verifyWebhook(
|
|
449
|
-
* JSON.stringify(req.body),
|
|
450
|
-
* req.headers['x-tapsilat-signature'],
|
|
451
|
-
* 'your-webhook-secret'
|
|
452
|
-
* );
|
|
453
|
-
* ```
|
|
454
483
|
*/
|
|
455
484
|
verifyWebhook(payload: string, signature: string, secret: string): Promise<boolean>;
|
|
456
485
|
/**
|
|
457
486
|
* Checks API service health and availability
|
|
458
487
|
*
|
|
488
|
+
* @summary Check API service health and availability
|
|
489
|
+
* @description Verifies that the Tapsilat API service is operational and accessible.
|
|
490
|
+
*
|
|
459
491
|
* @returns Promise resolving to service status
|
|
460
492
|
*/
|
|
461
493
|
healthCheck(): Promise<{
|
|
@@ -465,6 +497,9 @@ declare class TapsilatSDK {
|
|
|
465
497
|
/**
|
|
466
498
|
* Gets current SDK configuration (without sensitive data)
|
|
467
499
|
*
|
|
500
|
+
* @summary Get current SDK configuration without sensitive information
|
|
501
|
+
* @description Returns a copy of the current configuration with sensitive data (like bearer token) excluded.
|
|
502
|
+
*
|
|
468
503
|
* @returns Copy of current configuration
|
|
469
504
|
*/
|
|
470
505
|
getConfig(): Omit<TapsilatConfig, "bearerToken"> & {
|
|
@@ -473,6 +508,9 @@ declare class TapsilatSDK {
|
|
|
473
508
|
/**
|
|
474
509
|
* Updates SDK configuration
|
|
475
510
|
*
|
|
511
|
+
* @summary Update SDK configuration with new values
|
|
512
|
+
* @description Updates the SDK configuration with provided values, validating bearer token if changed.
|
|
513
|
+
*
|
|
476
514
|
* @param newConfig - Partial configuration to update
|
|
477
515
|
* @throws {TapsilatValidationError} When Bearer token is invalid
|
|
478
516
|
*/
|