-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreturnurl.php
56 lines (48 loc) · 1.28 KB
/
returnurl.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
* @var string $btcpay_url
* @var string $storeid
* @var string $apikey
* @var string $lbapikey
* @var string $resellerid
* @var string $checksum_secret
* @var string $reseller_base_url
*/
// Include autoload file.
require __DIR__ . '/vendor/autoload.php';
// redirect user to setup.php if DB doesn't exist
if (!file_exists(__DIR__ . '/private/config.inc.php')) {
header('Location: setup.php');
exit(0);
}
if (!isset($_GET['invoice_id'])) die("We need an invoice_id!");
require __DIR__ . '/private/config.inc.php';
// Import Invoice client class.
use BTCPayServer\Client\Invoice;
// Get information about a specific invoice.
try {
$client = new Invoice($btcpay_url, $apikey);
$invoice = $client->getInvoice($storeid, $_GET['invoice_id']);
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
exit(1);
}
$state = $invoice->getData()['status'];
$return_urls = $invoice->getData()['metadata']['posData'];
if ($state == "Expired" || $state == "Invalid") {
header('Location: ' . $return_urls['n_url']);
exit(0);
}
elseif ($state == "Settled") {
header('Location: ' . $return_urls['y_url']);
exit(0);
}
elseif ($state == "Processing") {
header('Location: ' . $return_urls['p_url']);
exit(0);
}
else {
echo "unknown invoice status: " . $state;
exit(0);
}
?>