Skip to content

Commit 1e02522

Browse files
committed
update endpoint
1 parent a5f421e commit 1e02522

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

proxy/v1/ln/api/index.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
if (isset($pdat["add"])) {
8585
$result = api(null, json_encode($pdat), null, 0, "tx", null, null);
8686
// Add TOR support info
87-
$result["tor"] = has_tor();
87+
$result["tor"] = has_tor();
8888
echo json_encode(["ping" => $result]);
8989
return;
9090
}
@@ -526,8 +526,9 @@ function invoice_uniform($imp, $inv, $type) {
526526
}
527527

528528
if ($imp === "lnbits") {
529+
$bolt11 = isset($dat["bolt11"]) ? $dat["bolt11"] : $dat["payment_request"];
529530
return array_merge($result, [
530-
"bolt11" => $dat["payment_request"],
531+
"bolt11" => $bolt11,
531532
"hash" => $dat["payment_hash"]
532533
]);
533534
}
@@ -712,7 +713,7 @@ function get_lnd_status($dat, $base_result) {
712713
// Extract and normalize LNbits invoice status information
713714
function get_lnbits_status($dat, $base_result, $expiry) {
714715
$details = $dat["details"];
715-
$inv_txtime = isset($details["time"]) ? (int)$details["time"] : 0;
716+
$inv_txtime = isset($details["time"]) ? get_timestamp($details["time"]) : 0;
716717
$expired = ((time() - $inv_txtime) > $expiry);
717718
$br_state = "unknown";
718719
if ($details["pending"] == true) $br_state = "pending";
@@ -786,4 +787,28 @@ function r_err($dat, $code) {
786787
"code" => $code
787788
],
788789
];
790+
}
791+
792+
function get_timestamp($value) {
793+
if (is_numeric($value)) {
794+
$intValue = (int)$value;
795+
if ((string)$intValue === (string)$value && $intValue >= 0) {
796+
return $intValue;
797+
}
798+
}
799+
if (is_string($value)) {
800+
try {
801+
$dateTime = new DateTime($value);
802+
$timestamp = $dateTime->getTimestamp();
803+
if ($timestamp !== false) {
804+
return $timestamp;
805+
} else {
806+
return false;
807+
}
808+
809+
} catch (Exception $e) {
810+
return false;
811+
}
812+
}
813+
return false;
789814
}

0 commit comments

Comments
 (0)