Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions examples/lnbitsPayment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { convertMarkdownToPdf } from "@serendipityai/markdown2pdf-typescript";
import axios from "axios";

// Constants
const LN_BITS_URL = "https://demo.lnbits.com/api/v1/payments";
const ADMIN_KEY = process.env.LNBITS_ADMIN_KEY as string; // Set in your env

async function pay(offer: any) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we type this as OfferDetails🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah but I think all the other examples need the same doing, this one is at least consistent with the others!

console.log("Paying using lnbits:");

try {
const response = await axios.post(
LN_BITS_URL,
{
out: true,
bolt11: offer.payment_request
},
{
headers: {
"X-Api-Key": ADMIN_KEY,
"Content-Type": "application/json"
}
}
);

console.log("Payment successful:", response.data);
} catch (error) {
if (axios.isAxiosError(error)) {
console.error("Payment failed:", error.response?.data || error.message);
} else {
console.error("Unexpected error:", error);
}
}
}

async function main() {
const path = await convertMarkdownToPdf("# Save this one using LNbits", {
downloadPath: "output.pdf",
onPaymentRequest: pay
});
console.log("Saved PDF to:", path);
}

main().catch(console.error);