-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
8b119a8
commit 76c1a66
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'];}} */ | ||
|