Skip to content

عميل DV-NET JS

هذا هو عميل JavaScript/TypeScript الرسمي للتكامل مع DV-NET Merchant API. يوفّر وصولاً سهلاً إلى جميع نقاط نهاية الـ API ويتولّى توقيع الطلبات. يعمل في بيئات Node.js والمتصفح.

المتطلبات

  • Node.js 18 أو أحدث (للاستخدام على الخادم)
  • متصفح حديث (للاستخدام على الواجهة العميل)

التثبيت

يمكنك تثبيت العميل عبر npm أو yarn:# باستخدام npm

npm install @dv-net/js-client

# Using yarn
yarn add @dv-net/js-client

البدء

تهيئة العميل الأساسية

لبدء استخدام العميل، ستحتاج إلى Merchant API Host و API Key الخاصين بك. يستخدم هذا المثال صياغة ES Modules (على سبيل المثال، في ملف TypeScript أو ملف .mjs).

js
// Import the client and exceptions
import { MerchantClient, DvNetException } from '@dv-net/js-client';

// Replace with your actual host and API key
const host = '[https://your-merchant-api.dv-net.com](https://your-merchant-api.dv-net.com)';
const apiKey = 'your_merchant_api_key_goes_here';

// --- Main function to run our async code ---
async function main() {
try {
// Initialize the client
const client = new MerchantClient(host, apiKey);

        // --- Example: Get available currencies ---
        const currenciesResponse = await client.getCurrencies();

        console.log(`Successfully fetched ${currenciesResponse.currencies.length} currencies:`);
        for (const currency of currenciesResponse.currencies) {
            console.log(`- ${currency.name} (${currency.ticker})`);
        }
        
        // --- Example: Get account balances ---
        const balancesResponse = await client.getProcessingWalletBalances();
        for (const walletBalance of balancesResponse.processingWallets) {
            console.log(`Balance for ${walletBalance.currencyShort.ticker}: ${walletBalance.asset.amount}`);
        }

    } catch (error) {
        // Catch base exception for all client errors
        if (error instanceof DvNetException) {
            console.error(`API Error: ${error.message}`);
            // You can also check for more specific errors:
            // if (error instanceof DvNetInvalidRequestException) { ... }
            // if (error instanceof DvNetServerException) { ... }
        } else {
            // Handle other unexpected errors
            console.error(`An unexpected error occurred: ${error.message}`);
        }
    }
}

// Run the main function
main();