Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacquesvw committed Jun 8, 2024
1 parent c468c72 commit 922de18
Show file tree
Hide file tree
Showing 22 changed files with 1,883 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

require __DIR__ . '/../vendor/autoload.php';

use BTCPayServer\Client\ApiKey;

// Fill in with your BTCPay Server data.
$apiKey = '';
$host = ''; // e.g. https://your.btcpay-server.tld
$userEmail = '';
$userId = '';

// Get information about store on BTCPay Server.
try {
$client = new ApiKey($host, $apiKey);
var_dump($client->getCurrent());
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}
/*
print("\nCreate a new api key (needs server modify permission of used api).\n");
try {
$client = new Apikey($host, $apiKey);
var_dump($client->createApiKey('api generated', ['btcpay.store.canmodifystoresettings']));
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}
*/
print("\nCreate a new api key for different user. Needs unrestricted access\n");

try {
$client = new Apikey($host, $apiKey);
$uKey = $client->createApiKeyForUser($userEmail, 'api generated to be deleted', ['btcpay.store.canmodifystoresettings']);
var_dump($uKey);
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}


print("\nRevoke api key for different user.\n");

try {
$client = new Apikey($host, $apiKey);
$uKey = $client->revokeApiKeyForUser($userEmail, $uKey->getData()['apiKey']);
var_dump($uKey);
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

// Include autoload file.
require __DIR__ . '/../vendor/autoload.php';

// Import Invoice client class.
use BTCPayServer\Client\Invoice;
use BTCPayServer\Client\InvoiceCheckoutOptions;
use BTCPayServer\Util\PreciseNumber;

// Fill in with your BTCPay Server data.
$apiKey = '';
$host = '';
$storeId = '';
$amount = 5.15 + mt_rand(0, 20);
$currency = 'USD';
$orderId = 'Test39939' . mt_rand(0, 1000);
$buyerEmail = 'john@example.com';

// Create a basic invoice.
try {
$client = new Invoice($host, $apiKey);
var_dump(
$client->createInvoice(
$storeId,
$currency,
PreciseNumber::parseString($amount),
$orderId,
$buyerEmail
)
);
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}

// Create a more complex invoice with redirect url and metadata.
try {
$client = new Invoice($host, $apiKey);

// Setup custom metadata. This will be visible in the invoice and can include
// arbitrary data. Example below will show up on the invoice details page on
// BTCPay Server.
$metaData = [
'buyerName' => 'John Doe',
'buyerAddress1' => '43 South Beech Rd.',
'buyerAddress2' => 'Door 3',
'buyerCity' => 'Mount Prospect',
'buyerState' => 'IL',
'buyerZip' => '60056',
'buyerCountry' => 'USA',
'buyerPhone' => '001555664123456',
'posData' => 'Data shown on the invoice details go here. Can be JSON encoded string',
'itemDesc' => 'Can be a description of the purchased item.',
'itemCode' => 'Can be SKU or item number',
'physical' => false, // indicates if physical product
'taxIncluded' => 2.15, // tax amount (included in the total amount).
];

// Setup custom checkout options, defaults get picked from store config.
$checkoutOptions = new InvoiceCheckoutOptions();
$checkoutOptions
->setSpeedPolicy($checkoutOptions::SPEED_HIGH)
->setPaymentMethods(['BTC'])
->setRedirectURL('https://shop.yourdomain.tld?order=38338');

var_dump(
$client->createInvoice(
$storeId,
$currency,
PreciseNumber::parseString($amount),
$orderId,
$buyerEmail,
$metaData,
$checkoutOptions
)
);
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}

// Create a top-up (0 initial amount) invoice.
try {
$client = new Invoice($host, $apiKey);
var_dump(
$client->createInvoice(
$storeId,
$currency,
null,
$orderId,
$buyerEmail
)
);
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

// Include autoload file.
require __DIR__ . '/../vendor/autoload.php';

// Import Invoice client class.
use BTCPayServer\Client\Invoice;

// Fill in with your BTCPay Server data.
$apiKey = '';
$host = ''; // e.g. https://your.btcpay-server.tld
$storeId = '';
$invoiceId = '';

// Get information about a specific invoice.
try {
echo 'Get invoice data:' . PHP_EOL;
$client = new Invoice($host, $apiKey);
var_dump($client->getInvoice($storeId, $invoiceId));
echo 'Get invoice payment methods:' . PHP_EOL;
var_dump($client->getPaymentMethods($storeId, $invoiceId));
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

require __DIR__ . '/../vendor/autoload.php';

use BTCPayServer\Client\Health;

class HealthClass
{
public $apiKey;
public $host;

public function __construct()
{
$this->apiKey = '';
$this->host = '';
}

public function getHealthStatus()
{
try {
$client = new Health($this->host, $this->apiKey);
var_dump($client->getHealthStatus());
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}
}
}

$health = new HealthClass();
$health->getHealthStatus();
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?php

require __DIR__ . '/../vendor/autoload.php';

use BTCPayServer\Client\LightningInternalNode;

class LightningInternalNodes
{
public $apiKey;
public $host;
public $cryptoCode;

public function __construct()
{
$this->apiKey = '';
$this->host = '';
$this->cryptoCode = 'BTC';
}

public function getNodeInformation()
{
try {
$client = new LightningInternalNode($this->host, $this->apiKey);
var_dump($client->getNodeInformation(
$this->cryptoCode
));
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}
}

public function connectToLightningNode()
{
$nodeURI = null;

try {
$client = new LightningInternalNode($this->host, $this->apiKey);
var_dump($client->connectToLightningNode(
$this->cryptoCode,
$nodeURI
));
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}
}

public function getChannels()
{
try {
$client = new LightningInternalNode($this->host, $this->apiKey);
var_dump($client->getChannels(
$this->cryptoCode
));
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}
}

public function openChannel()
{
$nodeURI = '';
$channelAmount = '100';
$feeRate = '1';

try {
$client = new LightningInternalNode($this->host, $this->apiKey);
var_dump($client->openChannel(
$this->cryptoCode,
$nodeURI,
$channelAmount,
$feeRate
));
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}
}

public function getDepositAddress()
{
try {
$client = new LightningInternalNode($this->host, $this->apiKey);
var_dump($client->getDepositAddress(
$this->cryptoCode
));
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}
}

public function getInvoice()
{
$id = '';

try {
$client = new LightningInternalNode($this->host, $this->apiKey);
var_dump($client->getInvoice(
$this->cryptoCode,
$id
));
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}
}

public function payLightningInvoice()
{
$BOLT11 = '';

try {
$client = new LightningInternalNode($this->host, $this->apiKey);
var_dump($client->payLightningInvoice(
$this->cryptoCode,
$BOLT11
));
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}
}

public function createLightningInvoice()
{
$amount = '1000000';
$description = 'test';
$expiry = 600;
$privateRouteHints = false;

try {
$client = new LightningInternalNode($this->host, $this->apiKey);
var_dump($client->createLightningInvoice(
$this->cryptoCode,
$amount,
$expiry,
$description,
$privateRouteHints
));
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}
}
}

$node = new LightningInternalNodes();
//$node->getNodeInformation();
//$node->connectToLightningNode();
//$node->getChannels();
//$node->openChannel();
//$node->getDepositAddress();
//$node->getInvoice();
//$node->payLightningInvoice();
//$node->createLightningInvoice();
Loading

0 comments on commit 922de18

Please sign in to comment.