btcpayserver-greenfield-php/examples/payout_usage.php
ndeet 60e6be57f9
Some checks failed
Code Style / php-cs-fixer (push) Has been cancelled
Static analysis (Psalm) / Psalm (8.0) (push) Has been cancelled
Fixes #136 by adding BTCPay >=2.0 parameter. (#141)
2026-01-21 12:31:48 +01:00

209 lines
5.2 KiB
PHP

<?php
require __DIR__ . '/../vendor/autoload.php';
use BTCPayServer\Client\PullPayment;
use BTCPayServer\Util\PreciseNumber;
class PullPayments
{
public $apiKey;
public $host;
public $storeId;
public function __construct()
{
$this->apiKey = '';
$this->host = '';
$this->storeId = '';
}
public function getStorePullPayments()
{
$includeArchived = true;
try {
$client = new PullPayment($this->host, $this->apiKey);
var_dump($client->getStorePullPayments(
$this->storeId,
$includeArchived
));
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}
}
public function createPullPayment()
{
$paymentName = 'TestPayout-' . rand(0, 10000000);
$paymentAmount = PreciseNumber::parseString('0.000001');
$paymentCurrency = 'BTC';
$paymentPeriod = null;
$boltExpiration = 1;
$autoApproveClaims = false;
$startsAt = null;
$expiresAt = null;
$paymentMethods = ['BTC-CHAIN'];
try {
$client = new PullPayment($this->host, $this->apiKey);
var_dump(
$client->createPullPayment(
$this->storeId,
$paymentName,
$paymentAmount,
$paymentCurrency,
$paymentPeriod,
$boltExpiration,
$autoApproveClaims,
$startsAt,
$expiresAt,
$paymentMethods
)
);
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}
}
public function archivePullPayment()
{
$pullPaymentId = '';
try {
$client = new PullPayment($this->host, $this->apiKey);
var_dump($client->archivePullPayment(
$this->storeId,
$pullPaymentId
));
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}
}
public function cancelPayout()
{
$payoutId = '';
try {
$client = new PullPayment($this->host, $this->apiKey);
var_dump($client->cancelPayout(
$this->storeId,
$payoutId
));
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}
}
public function markPayoutAsPaid()
{
$payoutId = '';
try {
$client = new PullPayment($this->host, $this->apiKey);
var_dump($client->markPayoutAsPaid(
$this->storeId,
$payoutId
));
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}
}
public function approvePayout()
{
$payoutId = '';
try {
$client = new PullPayment($this->host, $this->apiKey);
var_dump($client->approvePayout(
$this->storeId,
$payoutId,
0,
null
));
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}
}
public function getPullPayment()
{
$pullPaymentId = '';
try {
$client = new PullPayment($this->host, $this->apiKey);
var_dump($client->getPullPayment(
$this->storeId,
$pullPaymentId
));
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}
}
public function getPayouts()
{
$pullPaymentId = '';
$includeCancelled = true;
try {
$client = new PullPayment($this->host, $this->apiKey);
var_dump($client->getPayouts(
$pullPaymentId,
$includeCancelled
));
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}
}
public function createPayout()
{
$pullPaymentId = '';
$destination = '';
$amount = PreciseNumber::parseString('0.000001');
$paymentMethod = 'BTC-CHAIN';
try {
$client = new PullPayment($this->host, $this->apiKey);
var_dump($client->createPayout(
$pullPaymentId,
$destination,
$amount,
$paymentMethod
));
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}
}
public function getPayout()
{
$pullPaymentId = '';
$payoutId = '';
try {
$client = new PullPayment($this->host, $this->apiKey);
var_dump($client->getPayout(
$pullPaymentId,
$payoutId
));
} catch (\Throwable $e) {
echo "Error: " . $e->getMessage();
}
}
}
$pp = new PullPayments();
//$pp->createPullPayment();
//$pp->getStorePullPayments();
//$pp->archivePullPayment();
//$pp->cancelPayout();
//$pp->markPayoutAsPaid();
//$pp->approvePayout();
//$pp->getPullPayment();
//$pp->getPayouts();
//$pp->createPayout();
//$pp->getPayout();