Skip to content

Commit

Permalink
Create get_orderID.php
Browse files Browse the repository at this point in the history
this php file can be used to search for an orderID, to check a payment for example. The user can do this manually, in a form for example. This is because he or she has the orderID, and can therefore verify his or her purchase on a website.
  • Loading branch information
julienheinen authored Apr 2, 2024
1 parent 8b119a8 commit 76c1a66
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions examples/get_orderID.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
// OrderID verification
require __DIR__ . '/config/src/autoload.php';

use BTCPayServer\Client\Invoice;

function verifyOrderId($orderId) {
$apiKey = getenv('API_KEY'); //place your information here
$host = getenv('HOST');
$storeId = getenv('STORE_ID');

try {
$client = new Invoice($host, $apiKey);
$invoices = $client->getInvoicesByOrderIds($storeId, [$orderId]);

return !empty($invoices->getData()) ? $invoices->getData()[0] : null;
} catch (\Throwable $e) {
error_log($e->getMessage());
return null;
}
}
?>
// Filter and retain essential information. it uses the POST method, when sending a form for example
/* if (isset($_POST['order_id'])) {
$orderId = filter_var($_POST['order_id'], FILTER_SANITIZE_STRING);
$isValid = verifyOrderId($orderId);

if ($isValid) {
// Extraction des informations de paiement
$price = $isValid['amount'];
$currency = $isValid['currency'];
$buyerEmail = filter_var($isValid['metadata']['buyer_email'], FILTER_SANITIZE_EMAIL);
$buyerUsername = filter_var($isValid['metadata']['buyer_username'], FILTER_SANITIZE_STRING);
$paymentId = $isValid['id'];
$invoiceTime = $isValid['createdTime'];
$name = $isValid['metadata']['itemCode'];}} */

0 comments on commit 76c1a66

Please sign in to comment.