@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.js
CHANGED
|
@@ -350,7 +350,9 @@ class HttpClient {
|
|
|
350
350
|
* Builds the complete URL for the request
|
|
351
351
|
*/
|
|
352
352
|
buildUrl(url, customBaseURL, params) {
|
|
353
|
-
const baseURL = customBaseURL ||
|
|
353
|
+
const baseURL = customBaseURL ||
|
|
354
|
+
this.config.baseURL ||
|
|
355
|
+
"https://acquiring.tapsilat.dev/api/v1";
|
|
354
356
|
if (url.startsWith("http://") || url.startsWith("https://")) {
|
|
355
357
|
return url;
|
|
356
358
|
}
|
|
@@ -659,22 +661,62 @@ function sanitizeMetadata(metadata) {
|
|
|
659
661
|
return sanitized;
|
|
660
662
|
}
|
|
661
663
|
|
|
664
|
+
const isValidEmail = (email) => {
|
|
665
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
666
|
+
return emailRegex.test(email);
|
|
667
|
+
};
|
|
668
|
+
/**
|
|
669
|
+
* Generic response handler - consistent way to handle API responses
|
|
670
|
+
*
|
|
671
|
+
* @param response - The API response to process
|
|
672
|
+
* @param errorContext - Descriptive context for error messages
|
|
673
|
+
* @returns The data from a successful response
|
|
674
|
+
* @throws {TapsilatError} On any response error
|
|
675
|
+
*/
|
|
676
|
+
const handleResponse = (response, errorContext) => {
|
|
677
|
+
if (!response.success || !response.data) {
|
|
678
|
+
// Convert API errors to domain-specific errors
|
|
679
|
+
if (response.error) {
|
|
680
|
+
throw TapsilatError.fromAPIError(response.error);
|
|
681
|
+
}
|
|
682
|
+
throw new TapsilatError(`${errorContext} failed with no error details`, "UNKNOWN_ERROR");
|
|
683
|
+
}
|
|
684
|
+
return response.data;
|
|
685
|
+
};
|
|
686
|
+
/**
|
|
687
|
+
* Generic error handler - consistent way to handle errors
|
|
688
|
+
*
|
|
689
|
+
* @param error - The caught error to process
|
|
690
|
+
* @param errorContext - Descriptive context for error messages
|
|
691
|
+
* @throws {TapsilatError} Always throws an appropriate error type
|
|
692
|
+
*/
|
|
693
|
+
const handleError = (error, errorContext) => {
|
|
694
|
+
// Rethrow TapsilatErrors as-is
|
|
695
|
+
if (error instanceof TapsilatError) {
|
|
696
|
+
throw error;
|
|
697
|
+
}
|
|
698
|
+
// Convert generic errors to TapsilatNetworkError
|
|
699
|
+
throw new TapsilatNetworkError(error instanceof Error
|
|
700
|
+
? error.message
|
|
701
|
+
: `Unknown error during ${errorContext}`, "NETWORK_ERROR");
|
|
702
|
+
};
|
|
703
|
+
|
|
662
704
|
/**
|
|
663
705
|
* Main SDK class for Tapsilat payment operations
|
|
664
706
|
*
|
|
665
|
-
* @
|
|
666
|
-
*
|
|
667
|
-
*
|
|
668
|
-
*
|
|
669
|
-
*
|
|
670
|
-
*
|
|
707
|
+
* @summary Enterprise-grade TypeScript SDK for Tapsilat Payment Processing Platform
|
|
708
|
+
* @description
|
|
709
|
+
* The TapsilatSDK class provides a comprehensive interface for integrating with the Tapsilat payment platform.
|
|
710
|
+
* It offers secure, efficient, and type-safe methods for managing orders, payments, refunds, and other
|
|
711
|
+
* payment-related operations. The SDK includes built-in error handling, request validation, retry logic,
|
|
712
|
+
* and comprehensive logging capabilities.
|
|
671
713
|
*
|
|
672
|
-
*
|
|
673
|
-
*
|
|
674
|
-
*
|
|
675
|
-
*
|
|
676
|
-
*
|
|
677
|
-
*
|
|
714
|
+
* Key features:
|
|
715
|
+
* - Type-safe API with TypeScript support
|
|
716
|
+
* - Built-in error handling with custom error types
|
|
717
|
+
* - Automatic request/response validation
|
|
718
|
+
* - Configurable retry mechanism
|
|
719
|
+
* - Full compliance with Tapsilat API specifications
|
|
678
720
|
*/
|
|
679
721
|
class TapsilatSDK {
|
|
680
722
|
httpClient;
|
|
@@ -682,70 +724,105 @@ class TapsilatSDK {
|
|
|
682
724
|
/**
|
|
683
725
|
* Creates a new TapsilatSDK instance
|
|
684
726
|
*
|
|
685
|
-
* @
|
|
686
|
-
* @
|
|
727
|
+
* @summary Initializes the Tapsilat SDK with configuration options
|
|
728
|
+
* @description
|
|
729
|
+
* Creates and configures a new instance of the TapsilatSDK with the provided configuration.
|
|
730
|
+
* The constructor validates the bearer token, sets up the HTTP client with proper headers,
|
|
731
|
+
* configures retry mechanisms, and initializes internal state for API communication.
|
|
732
|
+
*
|
|
733
|
+
* The SDK instance is immutable after creation - configuration cannot be changed without
|
|
734
|
+
* creating a new instance. This ensures thread safety and predictable behavior.
|
|
735
|
+
*
|
|
736
|
+
* @param {TapsilatConfig} config - SDK configuration options
|
|
737
|
+
* @param {string} config.bearerToken - API authentication token (required)
|
|
738
|
+
* @param {string} [config.baseURL='https://api.tapsilat.com/v1'] - API base URL
|
|
739
|
+
* @param {number} [config.timeout=30000] - Request timeout in milliseconds
|
|
740
|
+
* @param {number} [config.maxRetries=3] - Maximum number of retry attempts
|
|
741
|
+
* @param {number} [config.retryDelay=1000] - Delay between retries in milliseconds
|
|
742
|
+
* @param {string} [config.version='v1'] - API version to use
|
|
743
|
+
* @param {boolean} [config.debug=false] - Enable debug logging
|
|
744
|
+
*
|
|
745
|
+
* @throws {TapsilatValidationError} When bearer token is invalid, missing, or malformed
|
|
746
|
+
* @throws {TypeError} When config parameter is not an object or missing required fields
|
|
687
747
|
*/
|
|
688
748
|
constructor(config) {
|
|
689
749
|
validateBearerToken(config.bearerToken);
|
|
690
750
|
this.config = config;
|
|
691
751
|
this.httpClient = new HttpClient(config);
|
|
692
752
|
}
|
|
693
|
-
//
|
|
753
|
+
// ORDER CREATION
|
|
754
|
+
// Summary: Create new payment order and get checkout URL
|
|
755
|
+
// Description: Initiates payment process with buyer info and returns secure checkout URL
|
|
694
756
|
/**
|
|
695
|
-
* Creates a new order and returns a checkout URL
|
|
757
|
+
* Creates a new order and returns a checkout URL
|
|
696
758
|
*
|
|
697
|
-
* @
|
|
698
|
-
* @
|
|
699
|
-
*
|
|
700
|
-
*
|
|
701
|
-
*
|
|
759
|
+
* @summary Initiates a new payment order with buyer information and generates checkout URL
|
|
760
|
+
* @description
|
|
761
|
+
* Creates a new payment order in the Tapsilat system with the provided order details.
|
|
762
|
+
* This method performs comprehensive validation of all input parameters, creates the order
|
|
763
|
+
* on the payment platform, and returns a checkout URL that customers can use to complete
|
|
764
|
+
* their payment. The method supports multiple currencies, locales, and comprehensive
|
|
765
|
+
* buyer information for compliance and fraud prevention.
|
|
766
|
+
*
|
|
767
|
+
* The returned checkout URL is valid for a limited time (typically 24 hours) and should
|
|
768
|
+
* be presented to the customer immediately. The order status can be tracked using the
|
|
769
|
+
* returned reference ID through the getOrderStatus method.
|
|
702
770
|
*
|
|
703
|
-
* @
|
|
704
|
-
*
|
|
705
|
-
*
|
|
706
|
-
*
|
|
707
|
-
*
|
|
708
|
-
*
|
|
709
|
-
*
|
|
710
|
-
*
|
|
711
|
-
*
|
|
712
|
-
*
|
|
713
|
-
*
|
|
714
|
-
*
|
|
715
|
-
*
|
|
716
|
-
*
|
|
717
|
-
* }
|
|
718
|
-
*
|
|
719
|
-
*
|
|
720
|
-
*
|
|
771
|
+
* @param {OrderCreateRequest} orderRequest - Complete order information
|
|
772
|
+
* @param {number} orderRequest.amount - Payment amount (must be positive, max 2 decimal places)
|
|
773
|
+
* @param {Currency} orderRequest.currency - Payment currency ('TRY', 'USD', 'EUR', 'GBP')
|
|
774
|
+
* @param {Locale} orderRequest.locale - Display language ('tr' for Turkish, 'en' for English)
|
|
775
|
+
* @param {Buyer} orderRequest.buyer - Customer information for payment processing
|
|
776
|
+
* @param {string} orderRequest.buyer.name - Customer's first name (required)
|
|
777
|
+
* @param {string} orderRequest.buyer.surname - Customer's last name (required)
|
|
778
|
+
* @param {string} orderRequest.buyer.email - Customer's email address (required, validated)
|
|
779
|
+
* @param {string} [orderRequest.buyer.phone] - Customer's phone number
|
|
780
|
+
* @param {string} [orderRequest.buyer.identityNumber] - National ID or tax number
|
|
781
|
+
* @param {Address} [orderRequest.buyer.shippingAddress] - Shipping address for physical goods
|
|
782
|
+
* @param {Address} [orderRequest.buyer.billingAddress] - Billing address for invoicing
|
|
783
|
+
* @param {string} [orderRequest.description] - Order description for customer reference
|
|
784
|
+
* @param {string} [orderRequest.callbackUrl] - URL to redirect after payment completion
|
|
785
|
+
* @param {string} [orderRequest.conversationId] - Custom tracking ID for your system
|
|
786
|
+
* @param {Record<string, unknown>} [orderRequest.metadata] - Additional custom data
|
|
787
|
+
*
|
|
788
|
+
* @returns {Promise<OrderCreateResponse>} Promise resolving to order creation response
|
|
789
|
+
* @returns {string} OrderCreateResponse.referenceId - Unique order identifier for tracking
|
|
790
|
+
* @returns {string} OrderCreateResponse.conversationId - Echo of provided conversation ID
|
|
791
|
+
* @returns {string} OrderCreateResponse.checkoutUrl - Payment page URL for customer
|
|
792
|
+
* @returns {string} OrderCreateResponse.status - Initial order status (typically 'CREATED')
|
|
793
|
+
* @returns {string} [OrderCreateResponse.qrCodeUrl] - QR code URL for mobile payments
|
|
794
|
+
*
|
|
795
|
+
* @throws {TapsilatValidationError} When input validation fails:
|
|
796
|
+
* - Amount is not positive or has more than 2 decimal places
|
|
797
|
+
* - Currency is not supported
|
|
798
|
+
* - Buyer information is incomplete or invalid
|
|
799
|
+
* - Email format is invalid
|
|
800
|
+
* - Required fields are missing
|
|
801
|
+
* @throws {TapsilatNetworkError} When network request fails:
|
|
802
|
+
* - Connection timeout
|
|
803
|
+
* - DNS resolution failure
|
|
804
|
+
* - Network connectivity issues
|
|
805
|
+
* @throws {TapsilatError} When API returns business logic errors:
|
|
806
|
+
* - Insufficient merchant balance
|
|
807
|
+
* - Currency not enabled for merchant
|
|
808
|
+
* - Buyer blocked due to fraud detection
|
|
809
|
+
* - Rate limiting exceeded
|
|
721
810
|
*/
|
|
722
811
|
async createOrder(orderRequest) {
|
|
723
|
-
// Validate the order request
|
|
724
|
-
this.validateOrderRequest(orderRequest);
|
|
725
|
-
try {
|
|
726
|
-
// Make the API request
|
|
727
|
-
const response = await this.httpClient.post("/order/create", orderRequest);
|
|
728
|
-
// Use our generic response handler
|
|
729
|
-
return this.handleResponse(response, "Order creation");
|
|
730
|
-
}
|
|
731
|
-
catch (error) {
|
|
732
|
-
// Use our generic error handler
|
|
733
|
-
this.handleError(error, "order creation");
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
/**
|
|
737
|
-
* Validates an order request object
|
|
738
|
-
* @private
|
|
739
|
-
*/
|
|
740
|
-
validateOrderRequest(orderRequest) {
|
|
812
|
+
// Validate the order request directly
|
|
741
813
|
// Check if request is null/undefined
|
|
742
814
|
if (!orderRequest) {
|
|
743
815
|
throw new TapsilatValidationError("Order request cannot be null or undefined");
|
|
744
816
|
}
|
|
745
|
-
// Validate amount
|
|
746
|
-
if (!isPositiveNumber(orderRequest.amount)
|
|
747
|
-
|
|
748
|
-
|
|
817
|
+
// Validate amount - check if positive
|
|
818
|
+
if (!isPositiveNumber(orderRequest.amount)) {
|
|
819
|
+
throw new TapsilatValidationError("Amount must be a positive number", {
|
|
820
|
+
provided: orderRequest.amount,
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
// Validate amount - check decimal places
|
|
824
|
+
if (!hasValidDecimalPlaces(orderRequest.amount)) {
|
|
825
|
+
throw new TapsilatValidationError("Amount must have maximum 2 decimal places", { provided: orderRequest.amount });
|
|
749
826
|
}
|
|
750
827
|
// Validate currency
|
|
751
828
|
if (!isNonEmptyString(orderRequest.currency)) {
|
|
@@ -762,73 +839,39 @@ class TapsilatSDK {
|
|
|
762
839
|
if (!isNonEmptyString(buyer.surname)) {
|
|
763
840
|
throw new TapsilatValidationError("Buyer surname is required and must be a non-empty string", { provided: buyer.surname });
|
|
764
841
|
}
|
|
765
|
-
|
|
766
|
-
|
|
842
|
+
// Validate buyer email - check if provided
|
|
843
|
+
if (!isNonEmptyString(buyer.email)) {
|
|
844
|
+
throw new TapsilatValidationError("Buyer email is required and must be a non-empty string", { provided: buyer.email });
|
|
767
845
|
}
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
* @private
|
|
772
|
-
*/
|
|
773
|
-
isValidEmail(email) {
|
|
774
|
-
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
775
|
-
return emailRegex.test(email);
|
|
776
|
-
}
|
|
777
|
-
/**
|
|
778
|
-
* Generic response handler - consistent way to handle API responses across SDK methods
|
|
779
|
-
* @private
|
|
780
|
-
*
|
|
781
|
-
* @param response - The API response to process
|
|
782
|
-
* @param errorContext - Descriptive context for error messages
|
|
783
|
-
* @returns The data from a successful response
|
|
784
|
-
* @throws {TapsilatError} On any response error
|
|
785
|
-
*/
|
|
786
|
-
handleResponse(response, errorContext) {
|
|
787
|
-
if (!response.success || !response.data) {
|
|
788
|
-
// Convert API errors to domain-specific errors
|
|
789
|
-
if (response.error) {
|
|
790
|
-
throw TapsilatError.fromAPIError(response.error);
|
|
791
|
-
}
|
|
792
|
-
throw new TapsilatError(`${errorContext} failed with no error details`, "UNKNOWN_ERROR");
|
|
846
|
+
// Validate buyer email - check format
|
|
847
|
+
if (!isValidEmail(buyer.email)) {
|
|
848
|
+
throw new TapsilatValidationError("Buyer email must be a valid email address", { provided: buyer.email });
|
|
793
849
|
}
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
*/
|
|
804
|
-
handleError(error, errorContext) {
|
|
805
|
-
// Rethrow TapsilatErrors as-is
|
|
806
|
-
if (error instanceof TapsilatError) {
|
|
807
|
-
throw error;
|
|
850
|
+
try {
|
|
851
|
+
// Make the API request
|
|
852
|
+
const response = await this.httpClient.post("/order/create", orderRequest);
|
|
853
|
+
// Use our generic response handler
|
|
854
|
+
return handleResponse(response, "Order creation");
|
|
855
|
+
}
|
|
856
|
+
catch (error) {
|
|
857
|
+
// Use our generic error handler
|
|
858
|
+
return handleError(error, "order creation");
|
|
808
859
|
}
|
|
809
|
-
// Convert generic errors to TapsilatNetworkError
|
|
810
|
-
throw new TapsilatNetworkError(error instanceof Error
|
|
811
|
-
? error.message
|
|
812
|
-
: `Unknown error during ${errorContext}`, "NETWORK_ERROR");
|
|
813
860
|
}
|
|
861
|
+
// ORDER RETRIEVAL BY REFERENCE ID
|
|
862
|
+
// Summary: Get complete order details and information
|
|
863
|
+
// Description: Retrieves full order data including buyer info, amounts, and current status
|
|
814
864
|
/**
|
|
815
865
|
* Gets an order by reference ID.
|
|
816
866
|
*
|
|
867
|
+
* @summary Retrieve complete order details and information
|
|
868
|
+
* @description Gets complete order data including buyer info, amounts, and current status using the unique reference ID.
|
|
869
|
+
*
|
|
817
870
|
* @param referenceId - The unique reference ID of the order
|
|
818
871
|
* @returns Promise resolving to the complete order details
|
|
819
872
|
* @throws {TapsilatValidationError} When referenceId is invalid
|
|
820
873
|
* @throws {TapsilatNetworkError} When API request fails due to network issues
|
|
821
874
|
* @throws {TapsilatError} When API returns an error response
|
|
822
|
-
*
|
|
823
|
-
* @example
|
|
824
|
-
* ```typescript
|
|
825
|
-
* try {
|
|
826
|
-
* const order = await tapsilat.getOrder("ord_123456789");
|
|
827
|
-
* console.log(`Order amount: ${order.amount} ${order.currency}`);
|
|
828
|
-
* } catch (error) {
|
|
829
|
-
* console.error(`Failed to get order: ${error.message}`);
|
|
830
|
-
* }
|
|
831
|
-
* ```
|
|
832
875
|
*/
|
|
833
876
|
async getOrder(referenceId) {
|
|
834
877
|
// Validate input
|
|
@@ -839,34 +882,26 @@ class TapsilatSDK {
|
|
|
839
882
|
// Make the API request
|
|
840
883
|
const response = await this.httpClient.get(`/order/${referenceId}`);
|
|
841
884
|
// Use our generic response handler
|
|
842
|
-
return
|
|
885
|
+
return handleResponse(response, "Order retrieval");
|
|
843
886
|
}
|
|
844
887
|
catch (error) {
|
|
845
888
|
// Use our generic error handler
|
|
846
|
-
|
|
889
|
+
return handleError(error, "order retrieval");
|
|
847
890
|
}
|
|
848
891
|
}
|
|
892
|
+
// ORDER LISTING WITH PAGINATION
|
|
893
|
+
// Summary: Retrieve paginated list of merchant orders
|
|
894
|
+
// Description: Gets orders with pagination support, filtering, and sorting options
|
|
849
895
|
/**
|
|
850
896
|
* Lists orders with pagination support.
|
|
851
897
|
*
|
|
898
|
+
* @summary Retrieve paginated list of merchant orders
|
|
899
|
+
* @description Gets orders with pagination support, filtering, and sorting options.
|
|
900
|
+
*
|
|
852
901
|
* @param params - Optional pagination parameters (page number and items per page)
|
|
853
902
|
* @returns Promise resolving to paginated list of orders
|
|
854
903
|
* @throws {TapsilatNetworkError} When API request fails due to network issues
|
|
855
904
|
* @throws {TapsilatError} When API returns an error response
|
|
856
|
-
*
|
|
857
|
-
* @example
|
|
858
|
-
* ```typescript
|
|
859
|
-
* try {
|
|
860
|
-
* // Get the second page with 20 items per page
|
|
861
|
-
* const orderList = await tapsilat.getOrders({ page: 2, per_page: 20 });
|
|
862
|
-
* console.log(`Total orders: ${orderList.total}`);
|
|
863
|
-
* orderList.rows.forEach(order => {
|
|
864
|
-
* console.log(`Order ${order.referenceId}: ${order.amount} ${order.currency}`);
|
|
865
|
-
* });
|
|
866
|
-
* } catch (error) {
|
|
867
|
-
* console.error(`Failed to list orders: ${error.message}`);
|
|
868
|
-
* }
|
|
869
|
-
* ```
|
|
870
905
|
*/
|
|
871
906
|
async getOrders(params = {}) {
|
|
872
907
|
try {
|
|
@@ -882,15 +917,21 @@ class TapsilatSDK {
|
|
|
882
917
|
// Make the API request
|
|
883
918
|
const response = await this.httpClient.get("/order/list", { params: params });
|
|
884
919
|
// Use our generic response handler
|
|
885
|
-
return
|
|
920
|
+
return handleResponse(response, "Order listing");
|
|
886
921
|
}
|
|
887
922
|
catch (error) {
|
|
888
923
|
// Use our generic error handler
|
|
889
|
-
|
|
924
|
+
return handleError(error, "order listing");
|
|
890
925
|
}
|
|
891
926
|
}
|
|
927
|
+
// ORDER CANCELLATION
|
|
928
|
+
// Summary: Cancel a pending order before payment completion
|
|
929
|
+
// Description: Cancels unpaid order and prevents further payment processing
|
|
892
930
|
/**
|
|
893
931
|
* Cancels an order by reference_id.
|
|
932
|
+
*
|
|
933
|
+
* @summary Cancel a pending order before payment completion
|
|
934
|
+
* @description Cancels unpaid order and prevents further payment processing.
|
|
894
935
|
*/
|
|
895
936
|
async cancelOrder(referenceId) {
|
|
896
937
|
if (!referenceId) {
|
|
@@ -905,27 +946,40 @@ class TapsilatSDK {
|
|
|
905
946
|
return response.data;
|
|
906
947
|
}
|
|
907
948
|
/**
|
|
908
|
-
* Gets the status of an order by reference ID
|
|
949
|
+
* Gets the current status of an order by reference ID
|
|
909
950
|
*
|
|
910
|
-
* @
|
|
911
|
-
* @
|
|
912
|
-
*
|
|
913
|
-
*
|
|
914
|
-
*
|
|
951
|
+
* @summary Retrieves real-time payment status and tracking information for a specific order
|
|
952
|
+
* @description
|
|
953
|
+
* Queries the Tapsilat payment platform to retrieve the current status of an order using its
|
|
954
|
+
* unique reference ID. This method provides real-time information about payment progress,
|
|
955
|
+
* completion status, and last update timestamp. It's essential for tracking payment flow
|
|
956
|
+
* and implementing proper order state management in your application.
|
|
915
957
|
*
|
|
916
|
-
*
|
|
917
|
-
*
|
|
918
|
-
*
|
|
919
|
-
*
|
|
920
|
-
*
|
|
921
|
-
*
|
|
922
|
-
*
|
|
923
|
-
*
|
|
924
|
-
*
|
|
925
|
-
*
|
|
926
|
-
*
|
|
927
|
-
* }
|
|
928
|
-
*
|
|
958
|
+
* The status information includes payment state (CREATED, PENDING_PAYMENT, COMPLETED, CANCELLED),
|
|
959
|
+
* last update timestamp, and any relevant status metadata. This method should be used to:
|
|
960
|
+
* - Check if a payment has been completed after redirecting from checkout
|
|
961
|
+
* - Monitor payment status for pending transactions
|
|
962
|
+
* - Verify order state before fulfilling goods/services
|
|
963
|
+
* - Implement webhook verification and status synchronization
|
|
964
|
+
*
|
|
965
|
+
* @param {string} referenceId - Unique order reference identifier from order creation
|
|
966
|
+
*
|
|
967
|
+
* @returns {Promise<OrderStatusResponse>} Promise resolving to current order status information
|
|
968
|
+
* @returns {string} OrderStatusResponse.referenceId - Echo of the provided reference ID
|
|
969
|
+
* @returns {string} OrderStatusResponse.status - Current payment status (CREATED, PENDING_PAYMENT, COMPLETED, CANCELLED, FAILED)
|
|
970
|
+
* @returns {string} OrderStatusResponse.lastUpdatedAt - ISO 8601 timestamp of last status change
|
|
971
|
+
*
|
|
972
|
+
* @throws {TapsilatValidationError} When input validation fails:
|
|
973
|
+
* - Reference ID is null, undefined, or empty string
|
|
974
|
+
* - Reference ID format is invalid (should match order ID pattern)
|
|
975
|
+
* @throws {TapsilatNetworkError} When network request fails:
|
|
976
|
+
* - Connection timeout during status check
|
|
977
|
+
* - DNS resolution failure
|
|
978
|
+
* - Network connectivity issues
|
|
979
|
+
* @throws {TapsilatError} When API returns business logic errors:
|
|
980
|
+
* - ORDER_NOT_FOUND: Order with given reference ID doesn't exist
|
|
981
|
+
* - ACCESS_DENIED: Order belongs to different merchant
|
|
982
|
+
* - RATE_LIMIT_EXCEEDED: Too many status check requests
|
|
929
983
|
*/
|
|
930
984
|
async getOrderStatus(referenceId) {
|
|
931
985
|
// Validate input using proper validation
|
|
@@ -936,17 +990,23 @@ class TapsilatSDK {
|
|
|
936
990
|
// Make the API request
|
|
937
991
|
const response = await this.httpClient.get(`/order/${referenceId}/status`);
|
|
938
992
|
// Use our generic response handler
|
|
939
|
-
return
|
|
993
|
+
return handleResponse(response, "Order status retrieval");
|
|
940
994
|
}
|
|
941
995
|
catch (error) {
|
|
942
996
|
// Use our generic error handler
|
|
943
|
-
|
|
997
|
+
return handleError(error, "order status retrieval");
|
|
944
998
|
}
|
|
945
999
|
}
|
|
1000
|
+
// ORDER REFUND OPERATIONS
|
|
1001
|
+
// Summary: Process partial refund for a completed order
|
|
1002
|
+
// Description: Refunds specified amount from a paid order and returns transaction details
|
|
946
1003
|
/**
|
|
947
1004
|
* Partially refunds an order.
|
|
948
1005
|
* Based on `refund_order` from the Python SDK.
|
|
949
1006
|
*
|
|
1007
|
+
* @summary Process partial refund for a completed order
|
|
1008
|
+
* @description Refunds specified amount from a paid order and returns transaction details.
|
|
1009
|
+
*
|
|
950
1010
|
* @param refundData - The refund details, including referenceId and amount.
|
|
951
1011
|
* @returns Promise resolving to the refund transaction details.
|
|
952
1012
|
*/
|
|
@@ -957,10 +1017,15 @@ class TapsilatSDK {
|
|
|
957
1017
|
}
|
|
958
1018
|
return response.data;
|
|
959
1019
|
}
|
|
1020
|
+
// Summary: Process full refund for a completed order
|
|
1021
|
+
// Description: Refunds entire order amount and returns transaction details
|
|
960
1022
|
/**
|
|
961
1023
|
* Fully refunds an order by its reference ID.
|
|
962
1024
|
* Based on `refund_all_order` from the Python SDK.
|
|
963
1025
|
*
|
|
1026
|
+
* @summary Process full refund for a completed order
|
|
1027
|
+
* @description Refunds entire order amount and returns transaction details.
|
|
1028
|
+
*
|
|
964
1029
|
* @param referenceId - The unique identifier of the order to fully refund.
|
|
965
1030
|
* @returns Promise resolving to the refund transaction details.
|
|
966
1031
|
*/
|
|
@@ -971,10 +1036,16 @@ class TapsilatSDK {
|
|
|
971
1036
|
}
|
|
972
1037
|
return response.data;
|
|
973
1038
|
}
|
|
1039
|
+
// ORDER PAYMENT DETAILS
|
|
1040
|
+
// Summary: Retrieve detailed payment transaction information for an order
|
|
1041
|
+
// Description: Gets payment method, amount, status, and card info for order transactions
|
|
974
1042
|
/**
|
|
975
1043
|
* Retrieves the payment details for an order.
|
|
976
1044
|
* Based on `get_order_payment_details` from the Python SDK.
|
|
977
1045
|
*
|
|
1046
|
+
* @summary Retrieve detailed payment transaction information for an order
|
|
1047
|
+
* @description Gets payment method, amount, status, and card info for order transactions.
|
|
1048
|
+
*
|
|
978
1049
|
* @param referenceId - The unique identifier of the order.
|
|
979
1050
|
* @param conversationId - Optional conversation ID for more specific querying.
|
|
980
1051
|
* @returns Promise resolving to a list of payment details.
|
|
@@ -997,9 +1068,15 @@ class TapsilatSDK {
|
|
|
997
1068
|
return response.data;
|
|
998
1069
|
}
|
|
999
1070
|
}
|
|
1071
|
+
// ORDER LOOKUP BY CONVERSATION ID
|
|
1072
|
+
// Summary: Find order using conversation ID instead of reference ID
|
|
1073
|
+
// Description: Alternative lookup method for orders using custom conversation identifier
|
|
1000
1074
|
/**
|
|
1001
1075
|
* Gets an order by conversation_id.
|
|
1002
1076
|
* Based on `get_order_by_conversation_id` from the Python SDK.
|
|
1077
|
+
*
|
|
1078
|
+
* @summary Find order using conversation ID instead of reference ID
|
|
1079
|
+
* @description Alternative lookup method for orders using custom conversation identifier.
|
|
1003
1080
|
*/
|
|
1004
1081
|
async getOrderByConversationId(conversationId) {
|
|
1005
1082
|
if (!conversationId) {
|
|
@@ -1014,6 +1091,9 @@ class TapsilatSDK {
|
|
|
1014
1091
|
/**
|
|
1015
1092
|
* Gets order transactions by reference_id.
|
|
1016
1093
|
* Based on `get_order_transactions` from the Python SDK.
|
|
1094
|
+
*
|
|
1095
|
+
* @summary Retrieve transaction history for an order
|
|
1096
|
+
* @description Gets detailed transaction records and payment attempts for a specific order.
|
|
1017
1097
|
*/
|
|
1018
1098
|
async getOrderTransactions(referenceId) {
|
|
1019
1099
|
if (!referenceId) {
|
|
@@ -1028,6 +1108,9 @@ class TapsilatSDK {
|
|
|
1028
1108
|
/**
|
|
1029
1109
|
* Gets order submerchants with pagination.
|
|
1030
1110
|
* Based on `get_order_submerchants` from the Python SDK.
|
|
1111
|
+
*
|
|
1112
|
+
* @summary Retrieve paginated list of submerchants for orders
|
|
1113
|
+
* @description Gets submerchant information with pagination support for order management.
|
|
1031
1114
|
*/
|
|
1032
1115
|
async getOrderSubmerchants(params = {}) {
|
|
1033
1116
|
const response = await this.httpClient.get("/order/submerchants", {
|
|
@@ -1041,6 +1124,9 @@ class TapsilatSDK {
|
|
|
1041
1124
|
/**
|
|
1042
1125
|
* Gets checkout URL for an order.
|
|
1043
1126
|
* Based on `get_checkout_url` from the Python SDK.
|
|
1127
|
+
*
|
|
1128
|
+
* @summary Retrieve checkout URL for existing order
|
|
1129
|
+
* @description Gets the payment checkout URL for an existing order using reference ID.
|
|
1044
1130
|
*/
|
|
1045
1131
|
async getCheckoutUrl(referenceId) {
|
|
1046
1132
|
const order = await this.getOrder(referenceId);
|
|
@@ -1053,19 +1139,13 @@ class TapsilatSDK {
|
|
|
1053
1139
|
/**
|
|
1054
1140
|
* Verifies webhook signature for security
|
|
1055
1141
|
*
|
|
1142
|
+
* @summary Validate webhook signature for security verification
|
|
1143
|
+
* @description Verifies the authenticity of webhook payloads using HMAC signature validation.
|
|
1144
|
+
*
|
|
1056
1145
|
* @param payload - Raw webhook payload string
|
|
1057
1146
|
* @param signature - Webhook signature from headers
|
|
1058
1147
|
* @param secret - Your webhook secret key
|
|
1059
1148
|
* @returns Promise resolving to true if signature is valid
|
|
1060
|
-
*
|
|
1061
|
-
* @example
|
|
1062
|
-
* ```typescript
|
|
1063
|
-
* const isValid = await sdk.verifyWebhook(
|
|
1064
|
-
* JSON.stringify(req.body),
|
|
1065
|
-
* req.headers['x-tapsilat-signature'],
|
|
1066
|
-
* 'your-webhook-secret'
|
|
1067
|
-
* );
|
|
1068
|
-
* ```
|
|
1069
1149
|
*/
|
|
1070
1150
|
async verifyWebhook(payload, signature, secret) {
|
|
1071
1151
|
// Implementation would depend on your webhook signature verification method
|
|
@@ -1080,6 +1160,9 @@ class TapsilatSDK {
|
|
|
1080
1160
|
/**
|
|
1081
1161
|
* Checks API service health and availability
|
|
1082
1162
|
*
|
|
1163
|
+
* @summary Check API service health and availability
|
|
1164
|
+
* @description Verifies that the Tapsilat API service is operational and accessible.
|
|
1165
|
+
*
|
|
1083
1166
|
* @returns Promise resolving to service status
|
|
1084
1167
|
*/
|
|
1085
1168
|
async healthCheck() {
|
|
@@ -1093,6 +1176,9 @@ class TapsilatSDK {
|
|
|
1093
1176
|
/**
|
|
1094
1177
|
* Gets current SDK configuration (without sensitive data)
|
|
1095
1178
|
*
|
|
1179
|
+
* @summary Get current SDK configuration without sensitive information
|
|
1180
|
+
* @description Returns a copy of the current configuration with sensitive data (like bearer token) excluded.
|
|
1181
|
+
*
|
|
1096
1182
|
* @returns Copy of current configuration
|
|
1097
1183
|
*/
|
|
1098
1184
|
getConfig() {
|
|
@@ -1105,6 +1191,9 @@ class TapsilatSDK {
|
|
|
1105
1191
|
/**
|
|
1106
1192
|
* Updates SDK configuration
|
|
1107
1193
|
*
|
|
1194
|
+
* @summary Update SDK configuration with new values
|
|
1195
|
+
* @description Updates the SDK configuration with provided values, validating bearer token if changed.
|
|
1196
|
+
*
|
|
1108
1197
|
* @param newConfig - Partial configuration to update
|
|
1109
1198
|
* @throws {TapsilatValidationError} When Bearer token is invalid
|
|
1110
1199
|
*/
|