Skip to content

Commit 2b977d8

Browse files
authored
Add files via upload
0 parents  commit 2b977d8

File tree

3 files changed

+165
-0
lines changed

3 files changed

+165
-0
lines changed

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
## Plisio PHP API library
2+
3+
To start using cryptocurrencies on your site you need to create an account on <https://plisio.net> and approve your domain under API setting page to get a **secret key**.
4+
5+
This secret key will be used for creating instance of the PlisioClient.
6+
7+
### Installation
8+
9+
**Composer**
10+
11+
You can install library via [Composer](http://getcomposer.org/). Run the following command in your terminal:
12+
13+
```bash
14+
composer require plisio/plisio-api-php
15+
```
16+
17+
Usage example:
18+
19+
```
20+
$secretKey = 'xxxxx';
21+
22+
$plisio = new \Plisio\ClientAPI($secretKey);
23+
$plisio->getBalances('BTC');
24+
```
25+
26+
New order:
27+
28+
```
29+
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
30+
31+
$secretKey = 'xxxxx';
32+
$request = [
33+
'amount' => float, // required Invoice amount in selected currency OR amount_usd can be used instead
34+
// 'amount_usd' => float, // required Invoice amoint in USD
35+
'currency' => string, // required (ETH, BTC, LTC, TZEC, DOGE, BCH, ...)
36+
'order_number' => string, // required Client's internal ID
37+
'order_name' => string, // required Client's internal name
38+
'description' => string, // optional any description
39+
'callback_url' => string, // optional Absolute URL where Plisio will send updates
40+
'success_url' => string, // optional Absolute URL of the final (success) invoice link
41+
42+
];
43+
44+
$plisio = new \Plisio\ClientAPI($secretKey);
45+
$invoice = $plisio->createTransaction($request);
46+
47+
if ($invoice && isset($invoice['status']) && $invoice['status'] == 'success') {
48+
header('Location: ' . $invoice['data']['invoice_url']);
49+
} else {
50+
print_r($invoice);
51+
}
52+
```

composer.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "payid19/payid19-api-php",
3+
"version": "1",
4+
"description": "Payid19 API library for PHP",
5+
"type": "library",
6+
"keywords": [
7+
"payid19",
8+
"merchant",
9+
"payment",
10+
"gateway",
11+
"bitcoin",
12+
"usdt",
13+
"tether",
14+
],
15+
"license": "MIT",
16+
"homepage": "https://payid19.com",
17+
"require": {
18+
"ext-curl": "*",
19+
"ext-json": "*"
20+
},
21+
"autoload": {
22+
"psr-4": {
23+
"Payid19\\": "src/"
24+
}
25+
}
26+
}

src/ClientAPI.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
namespace Payid19;
4+
5+
class ClientAPI
6+
{
7+
protected $public_key ='';
8+
protected $private_key = '';
9+
10+
public $apiEndPoint = 'https://payid19.com/api/v1';
11+
12+
13+
public function __construct($public_key,$private_key)
14+
{
15+
$this->public_key = $public_key;
16+
$this->private_key = $private_key;
17+
}
18+
19+
protected function getApiUrl($commandUrl)
20+
{
21+
return trim($this->apiEndPoint, '/') . '/' . $commandUrl;
22+
}
23+
24+
25+
public function create_invoice($req)
26+
{
27+
return $this->apiCall('create_invoice', $req);
28+
}
29+
30+
31+
private function isSetup()
32+
{
33+
if($this->public_key=='' or $this->private_key==''){
34+
return false;
35+
}
36+
}
37+
38+
39+
private function apiCall($cmd, $req = array())
40+
{
41+
if ($this->isSetup()==false) {
42+
return array('error' => 'You have not called the Setup function with your private and public keys!');
43+
}
44+
return $this->guestApiCall($cmd, $req);
45+
}
46+
47+
private function guestApiCall($cmd, $req = array())
48+
{
49+
try {
50+
$apiUrl = $this->getApiUrl($cmd);
51+
52+
$ch = curl_init();
53+
curl_setopt($ch, CURLOPT_URL, $apiUrl);
54+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
55+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
56+
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($req));
57+
$result = curl_exec($ch);
58+
curl_close($ch);
59+
60+
if($this->json_decode($result)->status=='error'){
61+
//error
62+
return $this->json_decode($result)->message[0];
63+
}else{
64+
//success
65+
return $this->json_decode($result)->message;
66+
}
67+
} catch (\Exception $e) {
68+
return array('status' => 'error', 'message' => 'Could not send request to API : ' . $apiUrl);
69+
}
70+
}
71+
72+
private function jsonDecode($data)
73+
{
74+
if (PHP_INT_SIZE < 8 && version_compare(PHP_VERSION, '5.4.0') >= 0) {
75+
// We are on 32-bit PHP, so use the bigint as string option. If you are using any API calls with Satoshis it is highly NOT recommended to use 32-bit PHP
76+
$dec = json_decode($data, TRUE, 512, JSON_BIGINT_AS_STRING);
77+
} else {
78+
$dec = json_decode($data, TRUE);
79+
}
80+
return $dec;
81+
}
82+
83+
public function verifyCallbackData($data, $secretKey)
84+
{
85+
86+
}
87+
}

0 commit comments

Comments
 (0)