### GET /reference/jwt-buy-crypto Source: https://integrations.simplex.com/reference/payments Initiates the purchase of cryptocurrency using JWT authentication. ```APIDOC ## GET /reference/jwt-buy-crypto ### Description Initiates the purchase of cryptocurrency using JWT authentication. ### Method GET ### Endpoint /reference/jwt-buy-crypto ### Parameters ### Request Body ### Request Example ### Response #### Success Response (200) #### Response Example ``` -------------------------------- ### Simplex Payment Refunded Event Example (JSON) Source: https://integrations.simplex.com/reference/get-events An example JSON structure representing a 'payment_simplexcc_refunded' event. This event includes details about the payment, such as its ID, status, amounts in fiat and crypto, and timestamps. It serves as a reference for how refund events are structured. ```JSON { "events": [{ "event_id": "6f8515ef-805a-41a3-80a5-76cd68315877", "name": "payment_simplexcc_refunded", "payment": { "id": "a7bc57ba-ed7c-40f4-9a13-2827ba018503", "status": "simplexcc_declined", "created_at": "2022-07-23T04:03:55.161Z", "partner_id": 720, "updated_at": "2022-07-24T07:14:03.782Z", "crypto_currency": "BTC", "fiat_total_amount": { "amount": 100, "currency": "USD" }, "crypto_total_amount": { "amount": 0.00376048, "currency": "BTC" }, "partner_end_user_id": "7936c0a4-7a5d-4257-a984-b37cca7be539" }, "timestamp": "2022-07-24T07:14:03.782Z" }] } ``` -------------------------------- ### GET /websites/integrations_simplex_reference Source: https://integrations.simplex.com/reference/transactions Retrieves reference information for Simplex integrations, including details about currency, fees, and payment parameters. ```APIDOC ## GET /websites/integrations_simplex_reference ### Description This endpoint provides reference data for Simplex integrations. It details the expected parameters for cryptocurrency transactions, including fee structures, payment amounts, and currency information. ### Method GET ### Endpoint /websites/integrations_simplex_reference ### Parameters #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **timestamp** (number) - The timestamp of the data. - **crypto_fee_currency** (string) - The currency in which the fee is denominated. - **payment_id** (string) - A unique identifier for the payment. - **fiat_total_amount** (number) - The total amount in fiat currency. - **original_http_ref_url** (string) - The original HTTP reference URL. - **currency** (string) - The fiat currency code. - **amount_crypto** (number) - The amount in cryptocurrency. - **amount_fee_in_crypto** (number) - The fee amount in cryptocurrency. - **order_id** (string) - A unique identifier for the order. - **request_id** (string) - A unique identifier for the request. - **next_page_cursor** (string) - A cursor for pagination. #### Response Example ```json { "timestamp": 1537078623.305, "crypto_fee_currency": "BTC", "payment_id": "85212121-93e3-4907-8530-37aa08446bf3", "fiat_total_amount": 1000.27, "original_http_ref_url": "http://demo-partner.com", "currency": "USD", "amount_crypto": 0.235, "amount_fee_in_crypto": 0.00062572, "order_id": "85444121-93e3-4917-8530-37aa08446bf3", "request_id": "85213321-93e3-4907-8530-37aa08446bf3", "next_page_cursor": "046b6c7f-0b8a-43b9-b35d-6489e6daee91" } ``` #### Error Response (400) - **description**: Bad Request - **content**: application/json - **schema**: {} #### Error Response Example ```json {} ``` ``` -------------------------------- ### GET /branches/1.0/reference/supported-crypto-currencies Source: https://integrations.simplex.com/reference/payments Retrieves a list of supported cryptocurrency currencies available through the Simplex API. ```APIDOC ## GET /branches/1.0/reference/supported-crypto-currencies ### Description Retrieves a list of supported cryptocurrency currencies available through the Simplex API. ### Method GET ### Endpoint /branches/1.0/reference/supported-crypto-currencies ### Parameters #### Query Parameters None ### Request Example (No request body for GET requests) ### Response #### Success Response (200) - **currencies** (array) - A list of supported cryptocurrency currencies. - **symbol** (string) - The symbol of the cryptocurrency. - **name** (string) - The full name of the cryptocurrency. #### Response Example ```json { "currencies": [ { "symbol": "BTC", "name": "Bitcoin" }, { "symbol": "ETH", "name": "Ethereum" } ] } ``` ``` -------------------------------- ### GET /branches/1.0/reference/supported-fiat-currencies Source: https://integrations.simplex.com/reference/payments Retrieves a list of supported fiat currencies available through the Simplex API. ```APIDOC ## GET /branches/1.0/reference/supported-fiat-currencies ### Description Retrieves a list of supported fiat currencies available through the Simplex API. ### Method GET ### Endpoint /branches/1.0/reference/supported-fiat-currencies ### Parameters #### Query Parameters None ### Request Example (No request body for GET requests) ### Response #### Success Response (200) - **currencies** (array) - A list of supported fiat currencies. - **code** (string) - The ISO 4217 currency code. - **name** (string) - The full name of the fiat currency. #### Response Example ```json { "currencies": [ { "code": "USD", "name": "United States Dollar" }, { "code": "EUR", "name": "Euro" } ] } ``` ``` -------------------------------- ### Initialize Simplex SDK with Public Key Source: https://integrations.simplex.com/reference/payments This script initializes the Simplex SDK with a provided public key. It ensures that the Simplex SDK is ready to be used for transactions. This script should be included in the HTML head. ```javascript window.simplexAsyncFunction = function () { Simplex.init({public_key: 'pk_test_6831b6e6-4c2c-462c-bcb7-dc98a13391f6'}) }; var script = document.createElement('script'); script.src = 'https://cdn.test-simplexcc.com/sdk/v1/js/sdk.js'; script.async = true; document.head.appendChild(script); ``` -------------------------------- ### Retrieve Transactions Data (Python) Source: https://integrations.simplex.com/reference/reporting This Python example shows how to retrieve transaction data from the Simplex API using the 'requests' library. It sends a GET request with the necessary headers and query parameters for filtering and pagination. ```python import requests url = "https://turnkey.api.simplex.com/transactions/" params = { "starting_at": "1658669633", "ending_at": "1658669633", "limit": "20" } headers = { "accept": "application/json", "x-api-key": "ApiKey XXXXXXXX" } response = requests.get(url, params=params, headers=headers) print(response.json()) ``` -------------------------------- ### Retrieve Transactions Data (Node.js) Source: https://integrations.simplex.com/reference/reporting This Node.js example shows how to fetch transaction data using the Simplex API. It utilizes the 'axios' library to make a GET request with specified headers and URL parameters for filtering and pagination. ```javascript const axios = require('axios'); const options = { method: 'GET', url: 'https://turnkey.api.simplex.com/transactions/', params: { starting_at: '1658669633', ending_at: '1658669633', limit: '20' }, headers: { 'accept': 'application/json', 'x-api-key': 'ApiKey XXXXXXXX' } }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### Initialize Simplex SDK with Custom HTML Source: https://integrations.simplex.com/reference/payments This snippet provides the custom HTML code required to initialize the Simplex SDK. It includes a public key for test environments and asynchronously loads the SDK script. Ensure the `public_key` is replaced with your actual public key for production environments. ```html ``` -------------------------------- ### Simplex API Endpoints Overview Source: https://integrations.simplex.com/reference/supported-by-simplex-api This section provides an overview of the Simplex API endpoints and their corresponding API hosts for different environments. ```APIDOC ## Simplex Buy API Endpoints ### Description These API endpoints provide up-to-date data on available fiat, crypto, and open countries for the Simplex Buy API. ### API Host The environments can be accessed via the API hosts below. #### Sandbox Environment **API Host:** `https://sandbox.test-simplexcc.com/v2` #### Production Environment **API Host:** `https://api.simplexcc.com/v2` ### Endpoints (Examples - actual endpoints not provided in source) #### GET /supported_fiat ##### Description Retrieves a list of supported fiat currencies. ##### Method GET ##### Endpoint `/supported_fiat` ##### Query Parameters None ##### Request Body None ##### Response ###### Success Response (200) - **currency** (string) - The fiat currency code (e.g., "USD") ###### Response Example ```json { "supported_fiat": [ {"currency": "USD"}, {"currency": "EUR"} ] } ``` #### GET /supported_crypto ##### Description Retrieves a list of supported cryptocurrencies. ##### Method GET ##### Endpoint `/supported_crypto` ##### Query Parameters None ##### Request Body None ##### Response ###### Success Response (200) - **currency** (string) - The cryptocurrency code (e.g., "BTC") ###### Response Example ```json { "supported_crypto": [ {"currency": "BTC"}, {"currency": "ETH"} ] } ``` #### GET /supported_countries ##### Description Retrieves a list of countries where Simplex services are available. ##### Method GET ##### Endpoint `/supported_countries` ##### Query Parameters - **type** (string) - Optional. Filter by type (e.g., "buy", "sell"). ##### Request Body None ##### Response ###### Success Response (200) - **country_code** (string) - The ISO 3166-1 alpha-2 country code (e.g., "US") - **country_name** (string) - The name of the country (e.g., "United States") ###### Response Example ```json { "supported_countries": [ {"country_code": "US", "country_name": "United States"}, {"country_code": "GB", "country_name": "United Kingdom"} ] } ``` ``` -------------------------------- ### Get Events API Request using Ruby Source: https://integrations.simplex.com/reference/events This Ruby code snippet illustrates how to make a GET request to the Simplex 'Get Events' endpoint using the 'httparty' gem. It includes the required API key for authentication in the request headers. The output will be the raw response from the API. ```ruby require 'httparty' url = 'https://sandbox.test-simplexcc.com/wallet/merchant/v2/events' response = HTTParty.get(url, headers: { 'Authorization' => 'ApiKey XXXXXXXX', 'accept' => 'application/json' } ) puts response ``` -------------------------------- ### Get Quote using PHP Source: https://integrations.simplex.com/reference/quote This PHP snippet shows how to get a cryptocurrency quote using cURL. It configures the cURL request to send a POST request with custom headers and a JSON payload to the Simplex API. ```php 'https://sandbox.test-simplexcc.com/wallet/merchant/v2/quote', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_HTTPHEADER => [ 'Authorization: ApiKey XXXXXXXX', 'accept: application/json', 'content-type: application/json' ], CURLOPT_POSTFIELDS => '{ "end_user_id": "string", "digital_currency": "string", "fiat_currency": "string", "requested_currency": "string", "requested_amount": 1.5, "wallet_id": "string", "client_ip": "string", "payment_methods": [ "string", "string" ] }' ]); $response = curl_exec($curl); cost_error(curl_error($curl), __FILE__, __LINE__); curl_close($curl); echo $response; ?> ``` -------------------------------- ### Simplex SDK Initialization and Table Update Service (JavaScript) Source: https://integrations.simplex.com/reference/payments This JavaScript code defines a service for managing Simplex SDK initialization and updating data tables with cryptocurrency information. It includes a mapping of ticker symbols to CoinGecko IDs for data retrieval. The `TableUpdateService` class handles initializing the table template and updating rows based on provided data. ```javascript class TableUpdateService { constructor() { this.tableTemplate = null; // Extended map of tickers to CoinGecko IDs this.coinGeckoIds = { '1EARTH': 'earthfund', '1INCH': '1inch', 'AAG-ERC20': 'aag-ventures', 'AAVE': 'aave', 'ACT': 'act-i-the-ai-prophecy', 'ADA': 'cardano', 'AERO': 'aerodrome-finance', 'AEVO': 'aevo-exchange', 'AGIX': 'singularitynet', 'AIOZ': 'aioz-network', 'ALGO': 'algorand', 'AKT': 'akash-network', 'APE': 'apecoin', 'APT': 'aptos', 'ARB': 'arbitrum', 'ARKM': 'arkham', 'ATOM': 'cosmos', 'AVAX': 'avalanche-2', 'AVAX-C': 'avalanche-2', 'AXS-ERC20': 'axie-infinity', 'BABYDOGE': 'baby-doge-coin', 'BCH': 'bitcoin-cash', 'BMX': 'bitmart-token', 'BNB': 'binancecoin', 'BNB-OPBNB': 'binancecoin', 'BNB-SC': 'binancecoin', 'BONK': 'bonk', 'BOME': 'book-of-meme', 'BRETT': 'based-brett', 'BSV': 'bitcoin-cash-sv', 'BTC': 'bitcoin', 'BTT': 'bittorrent', 'C98-SC': 'coin98', 'CAKE': 'pancakeswap-token', 'CARAT': 'diamond-standard-carat', 'CELO': 'celo', 'CEUR': 'celo-euro', 'CHZ': 'chiliz', 'COQ': 'coq-inu', 'CKB': 'nervos-network', 'COMP': 'compound-governance-token', 'COTI': 'coti', 'COTI-ERC20': 'coti', 'CRO-ERC20': 'crypto-com-chain', 'CSPR': 'casper-network', 'DAG': 'constellation-labs', 'DAI': 'dai', 'DEGEN': 'degen-base', 'DGB': 'digibyte', 'DIVI': 'divi', 'DOGE': 'dogecoin', 'DOT': 'polkadot', 'DRIFT': 'drift-protocol', 'EGC': 'evergrowcoin', 'EGLD': 'elrond-erd-2', 'ELON': 'dogelon-mars', 'ENA': 'ethena', 'ENS': 'ethereum-name-service', 'EOS': 'eos', 'EQX': 'eqifi', 'ETC': 'ethereum-classic', 'ETH': 'ethereum', 'ETH-ARBITRUM': ``` -------------------------------- ### GET /wallet/merchant/v2/events Source: https://integrations.simplex.com/reference/events This endpoint is used to track orders and retrieve all payment events associated with a merchant account. ```APIDOC ## GET /wallet/merchant/v2/events ### Description This endpoint is used to track orders. By calling this endpoint, you will receive all your payment events. ### Method GET ### Endpoint `https://sandbox.test-simplexcc.com/wallet/merchant/v2/events` ### Parameters #### Query Parameters None #### Request Body None ### Request Example ```curl curl --request GET \ --url https://sandbox.test-simplexcc.com/wallet/merchant/v2/events \ --header 'Authorization: ApiKey XXXXXXXX' \ --header 'accept: application/json' ``` ### Response #### Success Response (200) - **status** (string) - The current status of the payment. - **event_id** (string) - A unique identifier for the event. - **created_at** (string) - Timestamp when the event was created. Possible statuses include: - `payment_request_submitted`: User completed checkout, payment pending. - `payment_simplexcc_approved`: Simplex approved payment, funds to be transferred. - `payment_simplexcc_declined`: Payment declined by Simplex, bank, or card issuer. - `payment_simplexcc_crypto_sent`: Payment executed on blockchain, crypto sent to user. - `payment_simplexcc_refunded`: A refund has been issued. #### Response Example ```json { "status": "payment_simplexcc_approved", "event_id": "evt_12345abc", "created_at": "2023-10-27T10:00:00Z" } ``` ``` -------------------------------- ### Get Events API Request using PHP Source: https://integrations.simplex.com/reference/events This PHP code snippet shows how to fetch payment events from the Simplex API using cURL. It sets up the necessary cURL options, including the GET request method, URL, and required headers for authorization. The response is then printed. ```php ``` -------------------------------- ### Initialize Simplex Form with JavaScript Source: https://integrations.simplex.com/reference/payments This snippet demonstrates how to initialize a Simplex form on a webpage. It assumes the Simplex form SDK has been loaded. The `window.simplex.createForm()` function is called to render the form. ```javascript window.simplex.createForm(); ``` -------------------------------- ### Get Quote API Source: https://integrations.simplex.com/reference/quote This endpoint is used to quote a cryptocurrency price as per the payment method, fiat currency, and amount. ```APIDOC ## POST /wallet/merchant/v2/quote ### Description This endpoint retrieves a cryptocurrency price quote based on payment method, fiat currency, and amount. ### Method POST ### Endpoint https://sandbox.test-simplexcc.com/wallet/merchant/v2/quote ### Parameters #### Request Body - **end_user_id** (string) - Required - Unique identifier for a user on the partner's system. - **digital_currency** (string) - Required - The ticker symbol of requested crypto (BTC, ETH, etc.). - **fiat_currency** (string) - Required - The fiat currency code requested (USD, EUR, etc.). - **requested_currency** (string) - Required - The currency the user is asking a quote for. - **requested_amount** (float) - Required - The requested amount in the specified fiat currency. - **wallet_id** (string) - Optional - Partner name provided by Simplex. - **client_ip** (string) - Required - The end user's client IP address. - **payment_methods** (array of strings) - Optional - If omitted, all relevant payment methods are returned. Contact customer.success@simplex.com for specific method quotes. ### Request Example ```json { "end_user_id": "user123", "digital_currency": "BTC", "fiat_currency": "USD", "requested_currency": "USD", "requested_amount": 100.00, "wallet_id": "partnerName", "client_ip": "192.168.1.1", "payment_methods": ["credit_card"] } ``` ### Response #### Success Response (200) - **user_id** (string) - The unique identifier for a user. - **quote_id** (string) - Unique quote identifier in UUID format. - **wallet_id** (string) - Partner name provided by Simplex. - **digital_money.currency** (string) - The ticker symbol of the quoted crypto. - **digital_money.amount** (Number) - The crypto amount quoted for. - **fiat_money.currency** (string) - The fiat currency code quoted for. - **fiat_money.base_amount** (Number) - The fiat amount remaining without all fees. - **fiat_money.total_amount** (Number) - The total fiat amount the user will pay. - **valid_until** (string) - The expiration time for the quote. - **supported_digital_currencies** (Array of String) - The list of crypto enabled for a partner. - **fees.partner_fee.amount** (Number) - Partner fee amount. - **fees.partner_fee.currency** (string) - Partner fee currency. - **fees.payment_fee.amount** (Number) - Payment fee amount. - **fees.payment_fee.currency** (string) - Payment fee currency. - **fees.blockchain_fee.amount** (Number) - Blockchain fee amount. - **fees.blockchain_fee.currency** (string) - Blockchain fee currency. #### Response Example (200 - User asked in fiat) ```json { "user_id": "user123", "quote_id": "a1b2c3d4-e5f6-7890-1234-567890abcdef", "wallet_id": "partnerName", "digital_money": { "currency": "BTC", "amount": 0.00025 }, "fiat_money": { "currency": "USD", "base_amount": 100.00, "total_amount": 105.50 }, "valid_until": "2023-10-27T10:00:00Z", "supported_digital_currencies": ["BTC", "ETH", "USDC"], "fees": { "partner_fee": { "amount": 1.00, "currency": "USD" }, "payment_fee": { "amount": 2.50, "currency": "USD" }, "blockchain_fee": { "amount": 2.00, "currency": "USD" } } } ``` #### Error Response (500) ```json { "error": "Internal Server Error", "detailed_errors": { "errors": [ { "status": 500, "code": 1001, "title": "Internal processing error" } ] } } ``` #### Error Response (4XX) ```json { "status": "error", "error": "Bad Request", "errors": { "errors": [ { "code": "INVALID_PARAM", "params": ["end_user_id"], "message": "The provided end_user_id is invalid.", "path": "/wallet/merchant/v2/quote", "detailed_errors": { "errors": [ { "status": 400, "code": 1002, "title": "Invalid parameter value" } ] } } ] } } ``` ``` -------------------------------- ### cURL Payment Request Source: https://integrations.simplex.com/reference/payment Example of making a POST request to the Simplex Payment Request API using cURL. This demonstrates the required URL, headers (Authorization, accept, content-type), and method for initiating a payment request. ```shell curl --request POST \ --url https://sandbox.test-simplexcc.com/wallet/merchant/v2/payments/partner/data \ --header 'Authorization: ApiKey XXXXXXXX' \ --header 'accept: application/json' \ --header 'content-type: application/json' ``` -------------------------------- ### Simplex API Hosts Source: https://integrations.simplex.com/reference/index Access the Simplex API through the following hosts for sandbox and production environments. ```APIDOC ## API Host Information ### Description Details on the API hosts for accessing the Simplex API in different environments. ### Environment Details | Environment | API Host | |---------------|---------------------------| | Sandbox | https://sandbox.test-simplexcc.com/v2 | | Production | https://api.simplexcc.com/v2 | ``` -------------------------------- ### Get Events API Request using Python Source: https://integrations.simplex.com/reference/events This Python script demonstrates how to retrieve payment events from the Simplex API using the 'requests' library. It sends a GET request with the necessary API key in the headers. The script logs the response data, which contains the payment event details. ```python import requests url = "https://sandbox.test-simplexcc.com/wallet/merchant/v2/events" headers = { "Authorization": "ApiKey XXXXXXXX", "accept": "application/json" } response = requests.get(url, headers=headers) print(response.text) ``` -------------------------------- ### GET /websites/integrations_simplex_reference Source: https://integrations.simplex.com/reference/supported-crypto-currencies Retrieves a list of supported cryptocurrency integrations for Simplex. This includes details such as the cryptocurrency's name, ticker symbol, whether a memo or tag is required, and the compatible networks. ```APIDOC ## GET /websites/integrations_simplex_reference ### Description Retrieves a list of supported cryptocurrency integrations for Simplex. This includes details such as the cryptocurrency's name, ticker symbol, whether a memo or tag is required, and the compatible networks. ### Method GET ### Endpoint /websites/integrations_simplex_reference ### Parameters ### Request Example ```json { "example": "No request body for GET request." } ``` ### Response #### Success Response (200) - **response** (array) - An array of cryptocurrency integration objects. - **name** (string) - The name of the cryptocurrency. - **ticker_symbol** (string) - The ticker symbol of the cryptocurrency. - **memo/tag_field** (boolean) - Indicates if a memo or tag is required for transactions. - **fixed_min_amount** (any) - Minimum fixed amount, if applicable (can be null). - **networks** (array of strings) - A list of compatible blockchain networks for this cryptocurrency. #### Response Example ```json { "response": [ { "name": "1inch", "ticker_symbol": "1INCH", "memo/tag_field": false, "fixed_min_amount": null, "networks": [ "Ethereum", "Polygon", "Binance Smart Chain" ] }, { "name": "VeChain", "ticker_symbol": "VET", "memo/tag_field": false, "fixed_min_amount": null, "networks": [ "VeChain" ] } ] } ``` #### Error Response (400) - **description** (string) - Description of the error. #### Error Response Example ```json { "error": "Invalid request parameters" } ``` ``` -------------------------------- ### Get Events API Request using Node.js Source: https://integrations.simplex.com/reference/events This Node.js code snippet shows how to fetch payment events from the Simplex API. It utilizes the 'axios' library for making the HTTP GET request and includes the required authorization header. The response can be parsed to determine the status of payment orders. ```javascript const axios = require('axios'); const options = { method: 'GET', url: 'https://sandbox.test-simplexcc.com/wallet/merchant/v2/events', headers: { 'Authorization': 'ApiKey XXXXXXXX', 'accept': 'application/json' } }; axios.request(options).then(function (response) { console.log(response.data); }).catch(function (error) { console.error(error); }); ``` -------------------------------- ### Get Quote API Source: https://integrations.simplex.com/reference/jwt-quote Retrieve current rate quotes for fiat/crypto pairs. This endpoint requires a JWT token generated with specific payload parameters. ```APIDOC ## POST /quote ### Description Retrieves current rate quotes for fiat/crypto pairs. Requires a JWT token in the Authorization header. ### Method POST ### Endpoint /quote ### Parameters #### Query Parameters - **Authorization** (string) - Required - Bearer token: "Bearer YOUR_JWT_TOKEN" ### Request Body This endpoint does not have a request body. The necessary information is included in the JWT payload. ### Request Example ```json { "timestamp": 1539064222, "sourceAmount": 120, "sourceCurrency": "USD", "targetCurrency": "BNB-SC", "endUserID": "b175257e-1f30-49cc-84b7-0a7c8abc4526", "clientIP": "35.194.68.120" } ``` ### Response #### Success Response (200) - **digital_money** (object) - crypto response object - **currency** (string) - requested crypto currency - **amount** (number) - estimated crypto to receive - **fiat_money** (object) - fiat response object - **currency** (string) - fiat to pay with - **amount** (number) - fiat amount to pay #### Response Example ```json { "digital_money": { "currency": "BNB-SC", "amount": 0.54321 }, "fiat_money": { "currency": "USD", "amount": 120.00 } } ``` ``` -------------------------------- ### Node.js Payment Request Source: https://integrations.simplex.com/reference/payment Example of initiating a payment request using the Simplex API in Node.js. This snippet shows how to structure the POST request with appropriate headers and body parameters. ```javascript const url = 'https://sandbox.test-simplexcc.com/wallet/merchant/v2/payments/partner/data'; const apiKey = 'ApiKey XXXXXXXX'; const requestBody = { account_details: { // User's account details on the partner's service }, transaction_details: { // PaymentDetails - Details related to this payment only } }; fetch(url, { method: 'POST', headers: { 'Authorization': apiKey, 'accept': 'application/json', 'content-type': 'application/json' }, body: JSON.stringify(requestBody) }) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Error:', error)); ``` -------------------------------- ### Initialize Table Sorting on DOM Load Source: https://integrations.simplex.com/reference/payments Sets up the initial state for table sorting and fetches market data when the DOM is fully loaded. It then updates the table with the fetched data and ensures the sorting functionality is active. Handles potential errors during data fetching or table updates. ```javascript document.addEventListener('DOMContentLoaded', async () => { const tableService = new TableUpdateService(); try { const marketCaps = await tableService.getMarketData(); const updatedTable = tableService.updateTable('Market Cap', marketCaps, 'data-code'); document.getElementById('cryptoTable').innerHTML = updatedTable; } catch (error) { console.error('Error initializing table:', error); } }); class TableUpdateService { // ... (previous methods like sortTable, updateTable) // Placeholder for getMarketData method async getMarketData() { console.log('Fetching market data...'); // In a real application, this would fetch data from an API await new Promise(resolve => setTimeout(resolve, 1000)); // Simulate API call return { 'bitcoin': '$50000', 'ethereum': '$3000', 'ripple': '$1' }; } // Placeholder for addCoinGeckoUrls method addCoinGeckoUrls(html) { console.log('Adding CoinGecko URLs...'); // In a real application, this would parse HTML and add links return html; } // Placeholder for initializeSorting method initializeSorting() { console.log('Initializing sorting...'); // In a real application, this would set up event listeners for sorting const table = document.getElementById('cryptoTable'); if (table) { const headers = table.querySelectorAll('thead th'); headers.forEach((header, index) => { if (!header.querySelector('.sort-indicator')) { const indicator = document.createElement('span'); indicator.className = 'sort-indicator'; indicator.style.marginLeft = '5px'; header.appendChild(indicator); } header.style.cursor = 'pointer'; header.onclick = () => { // This is a simplified example; a real implementation would use the sortTable method correctly. console.log(`Simulating sort on column ${index}`); }; }); } } constructor() { this.currentSort = { column: -1, ascending: true }; } } ``` -------------------------------- ### GET /api/quote Source: https://integrations.simplex.com/reference/jwt-quote The GetQuote endpoint allows retrieving current rate quotes for fiat/crypto pairs. It requires a partner name and a JWT token, with an optional payment method parameter. ```APIDOC ## GET /api/quote ### Description Retrieves current rate quotes for fiat/crypto pairs. ### Method GET ### Endpoint https://partners.sandbox.test-simplexcc.com/api/quote ### Parameters #### Query Parameters - **partner** (string) - Required - your partner name on simplex end - **t** (string) - Required - The JWT token generated with quote parameters - **pyms** (string) - Optional - can query for a specific payment method (defaults to "credit_card") ### Request Example ``` GET /api/quote?partner=YOUR_PARTNER_NAME&t=YOUR_JWT_TOKEN&pyms=credit_card ``` ### Response #### Success Response (200) - **digital_money** (object) - Information about the digital currency. - **currency** (string) - The currency code (e.g., BTC). - **amount** (number) - The amount of digital currency. - **fiat_money** (object) - Information about the fiat currency. - **currency** (string) - The currency code (e.g., USD). - **amount** (integer) - The amount of fiat currency. #### Response Example ```json { "digital_money": { "currency": "BTC", "amount": 0.01520302 }, "fiat_money": { "currency": "USD", "amount": 100 } } ``` #### Error Response (400) - An empty JSON object is returned for errors. ``` -------------------------------- ### Get Quote using Ruby Source: https://integrations.simplex.com/reference/quote This Ruby snippet illustrates how to request a cryptocurrency quote using the 'httparty' gem. It constructs a POST request to the Simplex API with appropriate headers and JSON body. ```ruby require 'httparty' response = HTTParty.post 'https://sandbox.test-simplexcc.com/wallet/merchant/v2/quote', headers: { 'Authorization': 'ApiKey XXXXXXXX', 'accept': 'application/json', 'content-type': 'application/json' }, body: { end_user_id: 'string', digital_currency: 'string', fiat_currency: 'string', requested_currency: 'string', requested_amount: 1.5, wallet_id: 'string', client_ip: 'string', payment_methods: ['string', 'string'] }.to_json puts response.body ``` -------------------------------- ### Initialize Sortable Table - JavaScript Source: https://integrations.simplex.com/reference/payments This function sets up a table for interactive sorting. It attaches click event listeners to table headers, allowing users to sort the table by any column. It also adds visual indicators for sort direction and ensures that event listeners are correctly managed by replacing nodes. It relies on a `sortTable` method and expects a table with the ID 'cryptoTable'. ```javascript initializeSorting() { const table = document.getElementById('cryptoTable'); if (!table) return; const headers = table.querySelectorAll('thead th'); headers.forEach((header, index) => { header.style.cursor = 'pointer'; // Remove existing event listeners if any const newHeader = header.cloneNode(true); header.parentNode.replaceChild(newHeader, header); // Add new event listener newHeader.addEventListener('click', () => { this.sortTable(index); console.log('Sorting by column:', index); // Debug log }); // Add sort direction indicator if not exists if (!newHeader.querySelector('.sort-indicator')) { const indicator = document.createElement('span'); indicator.className = 'sort-indicator'; indicator.style.marginLeft = '5px'; newHeader.appendChild(indicator); } }); } ``` -------------------------------- ### JWT Payload Parameters for Buy Crypto Source: https://integrations.simplex.com/reference/jwt-buy-crypto Parameters required to construct the JWT token for initiating a cryptocurrency purchase. ```APIDOC ## JWT Payload Parameters ### Description These parameters are used to build the JWT token that authenticates and specifies the details of the cryptocurrency purchase. ### Parameters #### Request Body (Implicitly within JWT) - **timestamp** (Number) - Required - Unix timestamp of when “sig” was generated. - **fiatAmount** (Number) - Required - Amount of fiat currency to buy crypto with. - **fiatCurrency** (String) - Required - Fiat currency to pay with. - **cryptoCurrency** (String) - Required - Crypto currency for the transaction. - **cryptoAddress** (String) - Required - Crypto wallet address (must match cryptoCurrency). Can be shared via query params instead. - **destinationTag** (String) - Optional - Crypto wallet tag (if needed). Can be shared via query params. - **endUserID** (String) - Optional - UUID string to represent a user. ### Request Example ```javascript const paymentPayload = { "timestamp": 1531916946, "endUserID": "b175257e-1f30-49cc-84b7-0a7c8abc4526", "cryptoAddress": "3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy", "destinationTag": "werwe55", "cryptoCurrency": "BNB-SC", "fiatCurrency": "USD", "fiatAmount": 120 }; // Assuming 'jwt' library and 'API_SECRET_KEY' are defined elsewhere // const token = jwt.sign(paymentPayload, API_SECRET_KEY); ``` ``` -------------------------------- ### Get Quote using cURL Source: https://integrations.simplex.com/reference/quote This snippet demonstrates how to obtain a cryptocurrency quote using the cURL command-line tool. It specifies the POST request, URL, and necessary headers for authentication and content type. ```shell curl --request POST \ --url https://sandbox.test-simplexcc.com/wallet/merchant/v2/quote \ --header 'Authorization: ApiKey XXXXXXXX' \ --header 'accept: application/json' \ --header 'content-type: application/json' ``` -------------------------------- ### Fetch and Display Crypto Market Data using CoinGecko API (JavaScript) Source: https://integrations.simplex.com/reference/payments This JavaScript function `getMarketData` fetches cryptocurrency prices, market caps, and images from the CoinGecko API. It makes parallel API calls for efficiency and processes the data to update an HTML table dynamically. Error handling is included for API requests. Dependencies include the `fetch` API and standard JavaScript DOM manipulation. ```javascript async getMarketData() { try { console.log('Fetching market data...'); const ids = Object.values(this.coinGeckoIds).join(','); // Make a single bulk call for both price/mcap and coin data const [priceResponse, coinsResponse] = await Promise.all([ fetch(`https://api.coingecko.com/api/v3/simple/price?ids=${ids}&vs_currencies=usd&include_market_cap=true`), fetch(`https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=${ids}&order=market_cap_desc&per_page=250&page=1&sparkline=false`) ]); const priceData = await priceResponse.json(); const coinsData = await coinsResponse.json(); // Create lookup table for coin data const coinLookup = {}; coinsData.forEach(coin => { coinLookup[coin.id] = coin; }); // Create array for table data const tableData = []; // Process data and update logos for (const [ticker, geckoId] of Object.entries(this.coinGeckoIds)) { if (priceData[geckoId] && coinLookup[geckoId]) { const coin = coinLookup[geckoId]; // Update logo in the table const table = document.getElementById('cryptoTable'); const row = table.querySelector(`tr[data-code=\"${ticker}\"]`); if (row) { const imageCell = row.querySelector('td:first-child img'); if (imageCell && coin.image) { imageCell.src = coin.image; } } tableData.push({ Ticker: ticker, 'CoinGecko ID': geckoId, 'Price (USD)': `$${priceData[geckoId].usd.toLocaleString()}`, 'Market Cap (USD)': `$${priceData[geckoId].usd_market_cap.toLocaleString()}` }); } } // Print table to console console.table(tableData); // Process market caps for table display const marketCaps = {}; for (const [ticker, geckoId] of Object.entries(this.coinGeckoIds)) { if (priceData[geckoId]) { marketCaps[ticker] = `$${priceData[geckoId].usd_market_cap.toLocaleString()}`; } } return marketCaps; } catch (error) { console.error('Error fetching data:', error); return {}; } } ```