Skip to content

Commit d5f68da

Browse files
committed
Updated with new parameters and new tokens
1 parent 328b3fb commit d5f68da

File tree

3 files changed

+38
-37
lines changed

3 files changed

+38
-37
lines changed

README.md

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Official PHP library of CryptAPI
66
## Requirements:
77

88
```
9-
PHP >= 5.5
9+
PHP >= 5.6
1010
ext-curl
1111
```
1212

@@ -30,21 +30,21 @@ composer require cryptapi/php-cryptapi
3030
<?php
3131
require 'vendor/autoload.php'; // Where your vendor directory is
3232

33-
$ca = new CryptAPI\CryptAPI($coin, $my_address, $callback_url, $parameters, $pending);
33+
$ca = new CryptAPI\CryptAPI($coin, $my_address, $callback_url, $parameters, $cryptapi_params);
3434
$payment_address = $ca->get_address();
3535
```
3636

3737
Where:
3838

39-
``$coin`` is the coin you wish to use, can be one of: ``['btc', 'eth', 'bch', 'ltc', 'iota', 'xmr']``
39+
``$coin`` is the coin you wish to use, from CryptAPI's supported currencies (e.g `'btc', 'eth', 'erc20_usdt', ...`)
4040

4141
``$my_address`` is your own crypto address, where your funds will be sent to
4242

4343
``$callback_url`` is the URL that will be called upon payment
4444

45-
``$parameters`` is any parameter you wish to send to identify the payment, such as ``['order_id' => 1234]``
45+
``$parameters`` is any parameter you wish to send to identify the payment, such as `['order_id' => 1234]`
4646

47-
``$pending`` if you want to be notified of pending transactions.
47+
``$cryptapi_params`` parameters that will be passed to CryptAPI _(check which extra parameters are available here: https://cryptapi.io/docs/#/Bitcoin/btccreate)_
4848

4949
``$payment_address`` is the newly generated address, that you will show your users
5050

@@ -58,15 +58,9 @@ The URL you provided earlier will be called when a user pays, for easier process
5858

5959
require 'vendor/autoload.php'; // Where your vendor directory is
6060

61-
$payment_data = CryptAPI\CryptAPI::process_callback($_GET, $convert);
61+
$payment_data = CryptAPI\CryptAPI::process_callback($_GET);
6262
```
6363

64-
Where:
65-
66-
`$convert` is a boolean to whether to convert to the main coin denomination.
67-
68-
&nbsp;
69-
7064
The `$payment_data` will be an array with the following keys:
7165

7266
`address_in` - the address generated by our service, where the funds were received
@@ -81,9 +75,13 @@ The `$payment_data` will be an array with the following keys:
8175

8276
`value` - the value that your customer paid
8377

78+
`value_coin` - the value that your customer paid, in the main coin denomination (e.g `BTC`)
79+
8480
`value_forwarded` - the value we forwarded to you, after our fee
8581

86-
`coin` - the coin the payment was made in, one of: ``['btc', 'eth', 'bch', 'ltc', 'iota', 'xmr']``
82+
`value_forwarded_coin` - the value we forwarded to you, after our fee, in the main coin denomination (e.g `BTC`)
83+
84+
`coin` - the coin the payment was made in (e.g: `'btc', 'eth', 'erc20_usdt', ...`)
8785

8886
`pending` - whether the transaction is pending, if `false` means it's confirmed
8987

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
"authors": [
99
{
1010
"name": "CryptAPI",
11-
"email": "cryptapi@protonmail.com",
11+
"email": "info@cryptapi.io",
1212
"homepage": "https://cryptapi.io",
1313
"role": "Developer"
1414
}
1515
],
1616
"support": {
17-
"email": "cryptapi@protonmail.com",
17+
"email": "info@cryptapi.io",
1818
"chat": "https://cryptapi.io",
1919
"docs": "https://cryptapi.io/docs/"
2020
},
2121
"require": {
22-
"php": ">=5.5.0",
22+
"php": ">=5.6.0",
2323
"ext-curl": "*",
2424
"ext-json": "*"
2525
},
@@ -28,5 +28,5 @@
2828
"CryptAPI\\": "cryptapi/"
2929
}
3030
},
31-
"version": "1.1.0"
31+
"version": "1.2.0"
3232
}

cryptapi/cryptapi.php

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,28 @@
55

66
class CryptAPI {
77
private static $base_url = "https://cryptapi.io/api";
8-
private $valid_coins = ['btc', 'bch', 'eth', 'ltc', 'xmr', 'iota'];
8+
private $valid_tokens = ['becaz', 'bnb', 'busd', 'cro', 'link', 'mkr', 'nexo', 'pax', 'tusd', 'usdc', 'usdt', ];
9+
private $valid_coins = ['btc', 'bch', 'eth', 'ltc', 'xmr', 'iota', ];
910
private $own_address = null;
1011
private $callback_url = null;
1112
private $coin = null;
12-
private $pending = false;
13+
private $ca_params = [];
1314
private $parameters = [];
1415

1516
public static $COIN_MULTIPLIERS = [
16-
'btc' => 100000000,
17-
'bch' => 100000000,
18-
'ltc' => 100000000,
19-
'eth' => 1000000000000000000,
20-
'iota' => 1000000,
21-
'xmr' => 1000000000000,
17+
'btc' => 10**8,
18+
'bch' => 10**8,
19+
'ltc' => 10**8,
20+
'eth' => 10**18,
21+
'iota' => 10**6,
22+
'xmr' => 10**12,
2223
];
2324

24-
public function __construct($coin, $own_address, $callback_url, $parameters=[], $pending=false) {
25+
public function __construct($coin, $own_address, $callback_url, $parameters=[], $ca_params=[]) {
26+
27+
foreach ($this->valid_tokens as $token) {
28+
$this->valid_coins[] = 'erc20_' . $token;
29+
}
2530

2631
if (!in_array($coin, $this->valid_coins)) {
2732
$vc = print_r($this->valid_coins, true);
@@ -31,7 +36,7 @@ public function __construct($coin, $own_address, $callback_url, $parameters=[],
3136
$this->own_address = $own_address;
3237
$this->callback_url = $callback_url;
3338
$this->coin = $coin;
34-
$this->pending = $pending ? 1 : 0;
39+
$this->ca_params = $ca_params;
3540
$this->parameters = $parameters;
3641

3742
}
@@ -46,11 +51,10 @@ public function get_address() {
4651
$callback_url = "{$this->callback_url}?{$req_parameters}";
4752
}
4853

49-
$ca_params = [
54+
$ca_params = array_merge([
5055
'callback' => $callback_url,
5156
'address' => $this->own_address,
52-
'pending' => $this->pending,
53-
];
57+
], $this->ca_params);
5458

5559
$response = CryptAPI::_request($this->coin, 'create', $ca_params);
5660

@@ -88,15 +92,17 @@ public static function get_info($coin) {
8892
return null;
8993
}
9094

91-
public static function process_callback($_get, $convert=false) {
95+
public static function process_callback($_get) {
9296
$params = [
9397
'address_in' => $_get['address_in'],
9498
'address_out' => $_get['address_out'],
9599
'txid_in' => $_get['txid_in'],
96100
'txid_out' => isset($_get['txid_out']) ? $_get['txid_out'] : null,
97101
'confirmations' => $_get['confirmations'],
98-
'value' => $convert ? Cryptapi::convert($_get['value'], $_get['coin']) : $_get['value'],
99-
'value_forwarded' => isset($_get['value_forwarded']) ? ($convert ? Cryptapi::convert($_get['value_forwarded'], $_get['coin']) : $_get['value_forwarded']) : null,
102+
'value' => $_get['value'],
103+
'value_coin' => $_get['value_coin'],
104+
'value_forwarded' => isset($_get['value_forwarded']) ? $_get['value_forwarded'] : null,
105+
'value_forwarded_coin' => isset($_get['value_forwarded_coin']) ? $_get['value_forwarded_coin'] : null,
100106
'coin' => $_get['coin'],
101107
'pending' => isset($_get['pending']) ? $_get['pending'] : false,
102108
];
@@ -109,13 +115,10 @@ public static function process_callback($_get, $convert=false) {
109115
return $params;
110116
}
111117

112-
public static function convert($val, $coin) {
113-
return $val / Cryptapi::$COIN_MULTIPLIERS[$coin];
114-
}
115-
116118
private static function _request($coin, $endpoint, $params=[]) {
117119

118120
$base_url = Cryptapi::$base_url;
121+
$coin = str_replace('_', '/', $coin);
119122

120123
if (!empty($params)) $data = http_build_query($params);
121124

0 commit comments

Comments
 (0)