Prizm Integration
Prizm crypto-system integration guideline.

PRIZM payment system is the easiest way to receive and send crypto payments.

You can easily integrate PRIZM into your project, online store, exchanger and etc.

Prizm payment system integration

To begin working with PRIZM you will need to launch the network node (Node) and API_Servlet.

Network Node

The software can run on one server as well as on different servers. However it's better to launch it on the one for your convenience.
Firstly, you should launch the node and wait while it syncs. The next step is configuration of the PrizmAPIServlet module.

Configuration PrizmAPIServlet

File
Configuration
PrizmAPIServlet.properties
in the line passphrase: NONE
instead of NONE you should write the private key of the wallet that will be used by your project.
After you have filled in the fields, you should launch the servlet through
run-servlet.sh
in the line sendkey: NONE
instead of NONE you should write the password (it will be used by the function of coin sending as an additional protection from unauthorized transactions).

The example of implementation in PHP

The description of work with receiving and sending coins, with examples of ready-made functions and description of the principles of work. The Mysql database is used to store the transaction list, there is a dump of the storage table below, along with examples of code to work with the table (if you apply QueryBuilder, it won't be a problem).

The main principle of work

There is a script in the Cron-task that makes a request to the servlet every 2-5 minutes so it could receive new transactions on the wallet of the store. Having received the list of transactions, you should save them to the local database. If there are no operations in the database, you should run the command without any parameter. However if you wish to receive new transactions, you should send the number of the last transaction that you have as a parameter.

The example of the function:

1
<?php
2
function historyPZM($last_id = 0)
3
{
4
if ($last_id) {
5
$url = 'http://localhost:8888/history?fromid=' . $last_id;
6
} else {
7
$url = 'http://localhost:8888/history';
8
}
9
$page = '';
10
$result = get_web_page($url);
11
if (($result['errno'] != 0) || ($result['http_code'] != 200)) {
12
$error = $result['errmsg'];
13
} else {
14
$page = $result['content'];
15
}
16
$array_new = array();
17
$xcmorewrite = explode("\n", str_replace("\r", '', $page));
18
foreach ($xcmorewrite as $value) {
19
if ($value) {
20
$array_new[] = explode(";", $value);
21
}
22
}
23
return $array_new;
24
}
25
?>
Copied!

The function for retrieving page content:

1
<?php
2
3
function get_web_page($url)
4
{
5
$uagent = "Opera/9.80 (Windows NT 6.1; WOW64) Presto/2.12.388 Version/12.14";
6
$ch = curl_init($url);
7
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // recovers the web page
8
curl_setopt($ch, CURLOPT_HEADER, 0); // doesn’t recover headers
9
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // follows redirects
10
curl_setopt($ch, CURLOPT_ENCODING, ""); // handles all encodings
11
curl_setopt($ch, CURLOPT_USERAGENT, $uagent); // useragent
12
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20); // time-out of the connection
13
curl_setopt($ch, CURLOPT_TIMEOUT, 20); // time-out of the answer
14
curl_setopt($ch, CURLOPT_MAXREDIRS, 2); // stops after the 10th redirect
15
16
$content = curl_exec($ch);
17
$err = curl_errno($ch);
18
$errmsg = curl_error($ch);
19
$header = curl_getinfo($ch);
20
curl_close($ch);
21
22
$header['errno'] = $err;
23
$header['errmsg'] = $errmsg;
24
$header['content'] = $content;
25
return $header;
26
}
27
28
?>
29
30
You can test it through the console, for example: curl http://localhost:8888/history
31
32
The example of the Cron-task handler script for receiving new transactions and the table structure
33
34
CREATE TABLE `pzm_history` (
35
`id` bigint(20) NOT NULL,
36
`tarif_id` int(1) NOT NULL,
37
`tr_id` varchar(255) NOT NULL,
38
`tr_date` varchar(255) NOT NULL,
39
`tr_timestamp` int(11) NOT NULL,
40
`pzm` varchar(50) NOT NULL,
41
`summa` decimal(16,2) NOT NULL,
42
`mess` varchar(255) NOT NULL,
43
`status` int(1) NOT NULL
44
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
45
46
** All necessary keys and autoincrement for ID should be added to the table
Copied!

Handler:

In this example you receive the list of new transactions that should be saved to the local database.
Therefore, you keep a history of all transactions on the wallet and in the future you will search for them in our local database using key data.
1
<?php
2
$nomer = getLastPrmHistory();
3
$historys = historyPZM($nomer);
4
5
foreach ($historys as $item) {
6
if ($item['0'] != "No transactions!") {
7
8
// this line adds data to the ‘pzm_history’ table using INSERT IGNORE
9
10
PzmHistory::find()->insertIgnore([
11
'tr_id' => $item['0'],
12
'tr_date' => $item['1'],
13
'tr_timestamp' => $item['2'],
14
'pzm' => $item['3'],
15
'summa' => $item['4'],
16
'mess' => $item['5'],
17
'status' => 0
18
]);
19
}
20
}
21
22
function getLastPrmHistory()
23
{
24
// this line searches for the last row in the table to get the last ID of the transactions which are in the table
25
26
if (!empty($pzmHistory = PzmHistory::find()->orderBy('id', "DESC")->first())) {
27
return $pzmHistory->tr_id;
28
};
29
return 0;
30
}
31
32
?>
Copied!

Your project must work with the same Prizm Wallet, that is why all clients will be given the same requisites to replenish the internal account and the same hash ID of the operation. Be sure to inform the client that he must make a transaction strictly on the requisites indicating the hash identifier in the payment comment.

Thus, there should be another process that will analyze new incoming transactions and deposit coins to the internal account if the payment comment has a hash identifier of the client. Also you need to make a separate "I PAID" button for the client which could search and record new transactions for this user after making click on it.

Secondary functions and functions of coin sending

Getting public key for the wallet (works only for activated wallets having balance).
1
<?php
2
3
function destinationPZM($pzm)
4
{
5
$url = 'http://localhost:8888/publickey?destination=' . $pzm;
6
$page = '';
7
$result = get_web_page($url);
8
if (($result['errno'] != 0) || ($result['http_code'] != 200)) {
9
$error = $result['errmsg'];
10
return '';
11
} else {
12
$page = $result['content'];
13
$haystack = "Public key absent";
14
$haystack2 = "Send error!";
15
$pos = strripos($page, $haystack);
16
$pos2 = strripos($page, $haystack2);
17
if ($pos === false AND $pos2 === false) {
18
$xcmorewrite = explode(' ', $page);
19
$page = trim($xcmorewrite[0]);
20
return $page;
21
} else {
22
return '';
23
}
24
}
25
return $page;
26
}
27
28
?>
Copied!

Receiving current balance of the wallet:

1
<?php
2
3
function getBalancePZM($pzm)
4
{
5
$ip = '*******'; // пример 192.168.1.1:9976 with port
6
$url = 'http://'.$ip.'/prizm?requestType=getAccount&account=' . $pzm;
7
$page = '';
8
$result = get_web_page($url);
9
//print_r($result); die;
10
if (($result['errno'] != 0) || ($result['http_code'] != 200)) {
11
$error = $result['errmsg'];
12
return '';
13
} else {
14
$page = $result['content'];
15
$page = json_decode($page, true);
16
if ( isset($page['balanceNQT']) ) {
17
return $page['balanceNQT'] / 100;
18
} else {
19
return 0;
20
}
21
}
22
}
23
24
?>
Copied!

Method of coin sending:

1
<?php
2
3
public function payPZM($summa, $pzm, $public_key, $text)
4
{
5
$p2 = SENDKEY; // this is the password that you specified during setup
6
$return = false;
7
$url = 'http://localhost:8888/send?sendkey=' . $p2 . '&amount=' . $summa . '&comment=' . urlencode($text) . '&destination=' . $pzm . '&publickey=' . $public_key;
8
$page = '';
9
$result = get_web_page($url);
10
11
if (($result['errno'] != 0) || ($result['http_code'] != 200)) {
12
$error = $result['errmsg'];
13
} else {
14
$page = $result['content'];
15
}
16
17
if (preg_match('/^\+?\d+$/', $page)) {
18
$return = true;
19
} else {
20
$return = false;
21
}
22
return $return;
23
}
24
25
?>
Copied!
Last modified 9mo ago