diff --git a/bot/commands.js b/bot/commands.js index 98d09b65..44fcd44a 100644 --- a/bot/commands.js +++ b/bot/commands.js @@ -18,6 +18,7 @@ const { } = require('../util'); const ordersActions = require('./ordersActions'); const OrderEvents = require('./modules/events/orders'); +const { removeLightningPrefix } = require('../util'); const { resolvLightningAddress } = require('../lnurl/lnurl-pay'); const { logger } = require('../logger'); @@ -32,7 +33,7 @@ const waitPayment = async (ctx, bot, buyer, seller, order, buyerInvoice) => { return; } - order.buyer_invoice = buyerInvoice; + order.buyer_invoice = removeLightningPrefix(buyerInvoice); // We need the i18n context to send the message with the correct language const i18nCtx = await getUserI18nContext(seller); // If the buyer is the creator, at this moment the seller already paid the hold invoice diff --git a/bot/validations.js b/bot/validations.js index 781622b9..356d5447 100644 --- a/bot/validations.js +++ b/bot/validations.js @@ -2,7 +2,11 @@ const { parsePaymentRequest } = require('invoices'); const { ObjectId } = require('mongoose').Types; const messages = require('./messages'); const { Order, User, Community } = require('../models'); -const { isIso4217, isDisputeSolver } = require('../util'); +const { + isIso4217, + isDisputeSolver, + removeLightningPrefix, +} = require('../util'); const { existLightningAddress } = require('../lnurl/lnurl-pay'); const { logger } = require('../logger'); @@ -305,7 +309,8 @@ const validateLightningAddress = async lightningAddress => { const validateInvoice = async (ctx, lnInvoice) => { try { - const invoice = parsePaymentRequest({ request: lnInvoice }); + const checkedPrefixlnInvoice = removeLightningPrefix(lnInvoice); + const invoice = parsePaymentRequest({ request: checkedPrefixlnInvoice }); const latestDate = new Date( Date.now() + parseInt(process.env.INVOICE_EXPIRATION_WINDOW) ).toISOString(); @@ -344,7 +349,8 @@ const validateInvoice = async (ctx, lnInvoice) => { const isValidInvoice = async (ctx, lnInvoice) => { try { - const invoice = parsePaymentRequest({ request: lnInvoice }); + const checkedPrefixlnInvoice = removeLightningPrefix(lnInvoice); + const invoice = parsePaymentRequest({ request: checkedPrefixlnInvoice }); const latestDate = new Date( Date.now() + parseInt(process.env.INVOICE_EXPIRATION_WINDOW) ).toISOString(); diff --git a/util/index.js b/util/index.js index 628b2117..0960768e 100644 --- a/util/index.js +++ b/util/index.js @@ -504,3 +504,15 @@ exports.getStars = (rate, totalReviews) => { exports.removeAtSymbol = text => { return text[0] === '@' ? text.slice(1) : text; }; + +exports.removeLightningPrefix = invoice => { + const prefix = 'lightning:'; + + // Check if the invoice starts with the prefix + if (invoice.startsWith(prefix)) { + return invoice.substring(prefix.length); + } + + // Return the invoice as is if no prefix is found + return invoice; +};