PHP code example of pecunia-wallet / pecunia-sdk-php
1. Go to this page and download the library: Download pecunia-wallet/pecunia-sdk-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pecunia-wallet / pecunia-sdk-php example snippets
// Initialize client
$client = new \Pecunia\Client('your-api-token-here');
// Get all invoices
$invoices = $client->getAllInvoices();
foreach ($invoices as $invoice) {
echo "Invoice ID: {$invoice->id}, Requested Amount: {$invoice->amount->requested}\n";
}
// Create new invoice
$newInvoiceRef = $client->createInvoice([
'amount' => '10',
'sourceCurrency' => 'USD',
'lifeTime' => 'PT1H', // 1 hour
'availableCoins' => ['BTC', 'LTC']
]);
// Invoice details
$invoiceDetails = $client->getInvoice($newInvoiceRef->id);
// Get a payment link for the user
$paymentUrl = $newInvoiceRef->paymentUrl; // or $invoiceDetails->paymentUrl
// Verify callback signature
$payload = "request-body"; // Raw callback body
$header = "request-x-signature-header"; // X-Signature header
$secret = "your-callback-secret-here"; // Your callback secret
$ver = \Pecunia\Callback::verifySignature(
$payload,
$header,
currentSecret: $secret,
previousSecret: $secret // Previous secret is optional but supported for rotation
);
if ($ver) {
echo "Verified signature with " . ($ver == 'v0' ? 'previous' : 'current') . "secret";
} else {
echo "Failed to verify the signature.\n";
}
bash
$ composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.