84
84
if (isset ($ pdat ["add " ])) {
85
85
$ result = api (null , json_encode ($ pdat ), null , 0 , "tx " , null , null );
86
86
// Add TOR support info
87
- $ result ["tor " ] = has_tor ();
87
+ $ result ["tor " ] = has_tor ();
88
88
echo json_encode (["ping " => $ result ]);
89
89
return ;
90
90
}
@@ -526,8 +526,9 @@ function invoice_uniform($imp, $inv, $type) {
526
526
}
527
527
528
528
if ($ imp === "lnbits " ) {
529
+ $ bolt11 = isset ($ dat ["bolt11 " ]) ? $ dat ["bolt11 " ] : $ dat ["payment_request " ];
529
530
return array_merge ($ result , [
530
- "bolt11 " => $ dat [ " payment_request " ] ,
531
+ "bolt11 " => $ bolt11 ,
531
532
"hash " => $ dat ["payment_hash " ]
532
533
]);
533
534
}
@@ -712,7 +713,7 @@ function get_lnd_status($dat, $base_result) {
712
713
// Extract and normalize LNbits invoice status information
713
714
function get_lnbits_status ($ dat , $ base_result , $ expiry ) {
714
715
$ details = $ dat ["details " ];
715
- $ inv_txtime = isset ($ details ["time " ]) ? ( int ) $ details ["time " ] : 0 ;
716
+ $ inv_txtime = isset ($ details ["time " ]) ? get_timestamp ( $ details ["time " ]) : 0 ;
716
717
$ expired = ((time () - $ inv_txtime ) > $ expiry );
717
718
$ br_state = "unknown " ;
718
719
if ($ details ["pending " ] == true ) $ br_state = "pending " ;
@@ -786,4 +787,28 @@ function r_err($dat, $code) {
786
787
"code " => $ code
787
788
],
788
789
];
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 ;
789
814
}
0 commit comments