Getting started
Setup and usage

Setup and usage

The Web API supplies a collection of HTTP methods that underpin the majority of Boxcoin functionality. To start using the Web API follow the tutorial below.

Usage

Make a POST call to the file api.php of your Boxcoin installation. You can use the following PHP function to make the calls:


                                        function api($query) {
                                            $ch = curl_init('YOUR-DOMAIN/boxcoin/api.php');
                                            $parameters = [
                                                    CURLOPT_RETURNTRANSFER => true,
                                                    CURLOPT_SSL_VERIFYPEER => false,
                                                    CURLOPT_POST => true,
                                                    CURLOPT_CONNECTTIMEOUT => 5,
                                                    CURLOPT_POSTFIELDS => http_build_query(array_merge(['api-key' => 'YOUR-API-KEY'], $query))
                                            ];
                                            curl_setopt_array($ch, $parameters); 
                                            $response = curl_exec($ch);
                                            curl_close($ch);
                                            return $response, true;
                                        }
                                    

Usage example: api(['function' => 'get-user', 'user_id' => 123]).


Since client-side JavaScript files are accessible by anyone, your API key is also accessible by anyone and therefore this method is not secure.
                                        $.post('YOUR-DOMAIN/boxcoin/api.php', {
                                            api-key: 'YOUR-API-KEY',
                                            function: 'FUNCTION-NAME',
                                        }, function (response) {
                                            response = JSON.parse(response);
                                            if (response.success) {
                                                 
                                            }
                                        });
                                    

The variable $response will contains the JSON response. You can add new arguments in the query array: ['api=key' => '', 'function' => '', 'argument-name' => 'value', ...].


Replace the following strings with the correct values:

  • Replace YOUR-DOMAIN with your Boxcoin admin URL. Remove the /admin.php part from the URL. It should looks like this: https://YOUR-DOMAIN.com/boxcoin/api.php (if you're using the WordPress version: https://YOUR-DOMAIN.com/wp-content/plugins/boxcoin/api.php.
  • Replace YOUR-API-KEY with the API key available at Boxcoin > Settings > API key. If you are using the cloud version, get it from Boxcoin > Account > API key. You API key must be kept always secret.
  • Replace FUNCTION-NAME with the name of the API function you want to use. Get them from the methods listed below.

REST API
Transactions

Transactions


get-transactions

Returns all Boxcoin transactions.


Arguments

api-key
Your API key.
function
Enter get-transactions.
pagination
Set the pagination number from 0 to N. Returns only 100 results per page. Set it to -1 to get all results. Default: 0.
search
Returns only the transactions matching the specified search terms. Default: false.
status
Returns only the transactions with the given status. Accepted values: C(completed), P(pending), R(refunded), X(underpayment). Default: false.
cryptocurrency
Returns only the transactions in the given cryptocurrency. Default: false.
date_range
Returns only the transactions within the date range. Syntax: ['yyyy-mm-dd', 'yyyy-mm-dd']. Example: ['2022-08-02', '2022-08-03'].

Response

[
    {
	    "id": "433",
	    "title": "",
	    "description": "",
	    "from": "",
	    "to": "bc1qj2hafvdxnrt1pzyyhmp3z335kdxzuakqyynpuc",
	    "hash": "",
	    "amount": "0.00032102",
	    "amount_fiat": "10",
	    "cryptocurrency": "btc",
	    "currency": "usd",
	    "external_reference": "",
	    "creation_time": "2022-05-30 15:57:51",
	    "status": "P",
	    "webhook": "0"
    },
    ...
]  

create-transaction

Create a new transaction ready to be paid by the user.


Arguments

api-key
Your API key.
function
Enter create-transaction.
amount
The transaction amount in FIAT, e.g. 123.
cryptocurrency_code
The cryptocurrency code, e.g. btc.
currency_code
The currency code, e.g. usd. Default: Settings > Currency.
external_reference
Enter the string you want, it will be sent via webhook and as a redirect URL parameter.
title
Enter the string you want, it will be shown in the the admin area.
description
Enter the string you want, it will be shown in the the admin area.
billing
A JSON string containing billing details. Default empty string.
vat
A JSON string containing billing details. Default empty string.

Response

[433, '0.00032102', 'bc1rj7hascxdxnrt3pzyehmp3z221kdxzuakquunpwc']                                 

The alphanumeric string is the encrypted transaction.


update-transaction

Update a transaction.


Arguments

api-key
Your API key.
function
Enter update-transaction.
transaction_id
The transaction ID.
values
Array in JSON format, with the values to update. Syntax: ['key' => 'value', 'key' => 'value', ...]. Example: ['status' => 'C', 'title' => 'Example']. Allowed keys: title, description, from, to, hash, amount, amount_fiat, cryptocurrency, currency, external_reference, creation_time(2022-04-14 10:00:00), status (C for completed, P for pending, R for refunded, X for underpayment), billing, vat, vat_details (JSON array).

Response

true

check-transactions

Check the latest Blockchain transactions of the payment address and returns the Blockchain transaction details if the payment is detected.


Arguments

api-key
Your API key.
function
Enter check-transactions.
transaction_id
The transaction ID.

Response

Returns false if the payment is not found, or and encrypted string if the payment is detected. The encrypted string can be used as the value of the transaction attribute of the function check-transaction.


check-transaction

Returns the details of a Blockchain transaction.


Arguments

api-key
Your API key.
function
Enter check-transaction.
transaction
Enter the encrypted string returned by the function check-transactions.

Response

{
    "confirmed" => true,
    "confirmations" => 1155,
    "minimum_confirmations" => 3,
    "hash" => "8f50833a701b122698d56a4412d7c92bd56af97..."
}

download-transactions

Generate a CSV file with transaction details and returns the URL.


Arguments

api-key
Your API key.
function
Enter download-transactions.
search
Returns only the transactions matching the search.
status
Returns only the transactions with the provided status.
cryptocurrency
Returns only the transactions with the provided cryptocurrency.
date_range
Returns only the transactions within the date range. Syntax: ['yyyy-mm-dd', 'yyyy-mm-dd']. Example: ['2022-08-02', '2022-08-03'].

Response

http://boxcoin.dev/uploads/transactions-790419984.csv

invoice

Generate an invoice and return the URL to the invoice file.


Arguments

api-key
Your API key.
function
Enter invoice.
transaction_id
The transaction ID.

Response

http://boxcoin.dev/uploads/inv-5.pdf

REST API
Checkout

Checkout


get-checkouts

Returns the checkouts list, or a single checkout.


Arguments

api-key
Your API key.
function
Enter get-checkouts.
checkout_id
The checkout ID. Leave it empty to get all checkouts.

Response

[{
    "id": "2",
    "title": "Cloud Storage Premium",
    "description": "",
    "price": "99",
    "currency": "CNY",
    "type": "I",
    "redirect": "",
    "external_reference": "ABC",
    "creation_time": "2022-02-02 10:00:00"
}, {
    "id": "3",
    "title": "Cloud Storage Base",
    "description": "",
    "price": "99.5",
    "currency": "USD",
    "type": "P",
    "redirect": "",
    "external_reference": "",
    "creation_time": "2022-02-03 11:05:19"
},
...
]

save-checkout

Create a new checkout, or update an existing one..


Arguments

api-key
Your API key.
function
Enter save-checkout.
checkout
Pass the checkout array below in JSON format or get it from the function get-checkouts. Add the key id: CHECKOUT-ID to update an existing checkout.
{
    "title": "Cloud Storage Premium",
    "description": "",
    "price": "99",
    "currency": "CNY",
    "type": "I",
    "redirect": "",
    "external_reference": "ABC",
    "creation_time": "2022-02-02 10:00:00"
}

Response

Returns the checkout ID.


delete-checkout

Delete a checkout.


Arguments

api-key
Your API key.
function
Enter delete-checkout.
checkout_id
The checkout ID.

Response

true

REST API
Crypto

Crypto


get-balances

Returns the balances of the cryptocurrency addresses saved in the admin area.


Arguments

api-key
Your API key.
function
Enter get-balances.

Response

{
    "balances": {
        "btc": {
            "amount": 0.63521135,
            "fiat": 19563.05,
            "name": "Bitcoin"
        },
        "eth": {
            "amount": 0.001,
            "fiat": 1.92,
            "name": "Ethereum"
        },
        "doge": {
            "amount": 10,
            "fiat": 0.98,
            "name": "Dogecoin"
        }
    },
    "total": 18461.67,
    "currency": "USD"
}

REST API
FIAT

FIAT


get-fiat-value

Get the FIAT value of a cryptocurrency value.


Arguments

api-key
Your API key.
function
Enter get-fiat-value.
amount
The FIAT value.
cryptocurrency_code
The cryptocurrency code, e.g. btc.
currency_code
The currency code, e.g. usd.

Response

305126.4

REST API
Settings

Settings


get-settings

Returns all Boxcoin settings.


Arguments

api-key
Your API key.
function
Enter get-settings.

Response

{
    "address-btc": "",
    "address-eth": "",
    "address-doge": "",
    "refresh-interval": "5",
    "confirmations": "",
    "currency": "",
    "custom-explorer-active": false,
    "custom-explorer-divider": "",
    "custom-explorer-balance-url": "",
    "custom-explorer-balance-path": "",
    "custom-explorer-transaction-url": "",
    "custom-explorer-transaction-path": "",
    "custom-explorer-transactions-url": "",
    "custom-explorer-transactions-path": "",
    "custom-explorer-address": "",
    "custom-explorer-address-path": "",
    "webhook-url": "",
    ...
}

save-settings

Save all Boxcoin settings.


Arguments

api-key
Your API key.
function
Enter save-settings.
settings
Pass the array of all settings in JSON format. Get it with the function get-settings.

Response

true

REST API
Miscellaneous

Miscellaneous


cron

Run the Boxcoin cron jobs.


Arguments

api-key
Your API key.
function
Enter cron.

Response

true

update

Update Boxcoin to the latest version if available.


Arguments

api-key
Your API key.
function
Enter update.

Response

true

vat

Returns the VAT information of a given amount and country.


Arguments

api-key
Your API key.
function
Enter vat.
amount
The amount.
country_code
The country code of the VAT-registered country you want to apply. If not provided, the country is automatically retrieved from the user's IP. Default: false.
currency_code
The currency code of the provided amount. Default: false.

Response

[12.2,2.2,"IT","Italy","Including  2.2 for VAT in Italy",22]

vat-validation

Validate a VAT number.


Arguments

api-key
Your API key.
function
Enter vat-validation.
vat_number
The VAT number.

Response

{
  "success": true,
  "code": 200,
  "data": {
    "valid": true,
    "company": {
      "vat_number": "288305674",
      "country_code": "GB",
      "company_name": "WEIO LTD",
      "company_address": "142 CROMWELL ROAD\nLONDON\nGREATER LONDON\n\n\nSW7 4EF"
    }
  }
}