feat: add comment support for Lightning payments in BTCPay and Strike services
- Enhanced the sendPaymentWithAddress method in BTCPayService and StrikeService to accept an optional comment parameter. - Updated resolveLightningAddress to include the comment in the callback URL if supported by the LNURL-pay endpoint. - Modified PaymentService to construct a descriptive comment for Lightning invoices, improving clarity for users. These changes enhance the payment experience by allowing users to include contextual information with their transactions.
This commit is contained in:
@@ -345,12 +345,13 @@ export class BTCPayService implements LightningService {
|
||||
async sendPaymentWithAddress(
|
||||
address: string,
|
||||
payment: Payment,
|
||||
comment?: string,
|
||||
): Promise<LightningPaymentDTO> {
|
||||
try {
|
||||
const sats = Math.floor(payment.milisatsAmount / 1000);
|
||||
|
||||
// Resolve the Lightning address to a BOLT11 invoice
|
||||
const bolt11 = await this.resolveLightningAddress(address, sats);
|
||||
const bolt11 = await this.resolveLightningAddress(address, sats, comment);
|
||||
|
||||
// Pay the BOLT11 via BTCPay's internal Lightning node
|
||||
const payUrl = this.storeUrl('/lightning/BTC/invoices/pay');
|
||||
@@ -578,6 +579,7 @@ export class BTCPayService implements LightningService {
|
||||
private async resolveLightningAddress(
|
||||
address: string,
|
||||
amountSats: number,
|
||||
comment?: string,
|
||||
): Promise<string> {
|
||||
const [username, domain] = address.split('@');
|
||||
if (!username || !domain) {
|
||||
@@ -606,6 +608,16 @@ export class BTCPayService implements LightningService {
|
||||
const callbackUrl = new URL(lnurlData.callback);
|
||||
callbackUrl.searchParams.set('amount', amountMillisats.toString());
|
||||
|
||||
// Include a descriptive comment if the endpoint supports it.
|
||||
// LNURL-pay endpoints advertise commentAllowed (max char length).
|
||||
const commentAllowed = lnurlData.commentAllowed || 0;
|
||||
if (comment && commentAllowed > 0) {
|
||||
callbackUrl.searchParams.set(
|
||||
'comment',
|
||||
comment.slice(0, commentAllowed),
|
||||
);
|
||||
}
|
||||
|
||||
const { data: invoiceData } = await axios.get(callbackUrl.toString(), { timeout: 10_000 });
|
||||
|
||||
if (invoiceData.status === 'ERROR') {
|
||||
|
||||
@@ -5,6 +5,7 @@ export interface LightningService {
|
||||
sendPaymentWithAddress(
|
||||
address: string,
|
||||
payment: Payment,
|
||||
comment?: string,
|
||||
): Promise<LightningPaymentDTO>;
|
||||
|
||||
validateAddress(address: string): Promise<boolean>;
|
||||
|
||||
@@ -23,6 +23,7 @@ export class StrikeService implements LightningService {
|
||||
async sendPaymentWithAddress(
|
||||
address: string,
|
||||
payment: Payment,
|
||||
comment?: string,
|
||||
currency: 'USD' | 'BTC' = 'BTC',
|
||||
): Promise<LightningPaymentDTO> {
|
||||
try {
|
||||
@@ -39,7 +40,7 @@ export class StrikeService implements LightningService {
|
||||
: payment.usdAmount,
|
||||
currency,
|
||||
},
|
||||
description: isBlinkWallet ? undefined : 'Tip from IndeeHub',
|
||||
description: isBlinkWallet ? undefined : (comment || 'Tip from IndeeHub'),
|
||||
});
|
||||
|
||||
const createPaymentConfig = {
|
||||
|
||||
@@ -233,7 +233,7 @@ export class PaymentService {
|
||||
order: {
|
||||
[column]: 'DESC',
|
||||
},
|
||||
relations: ['filmmaker', 'filmmaker.paymentMethods'],
|
||||
relations: ['filmmaker', 'filmmaker.paymentMethods', 'content'],
|
||||
take: 5,
|
||||
};
|
||||
|
||||
@@ -347,10 +347,16 @@ export class PaymentService {
|
||||
}
|
||||
|
||||
try {
|
||||
// Build a descriptive comment for the Lightning invoice so the
|
||||
// creator's wallet shows what the payment is for.
|
||||
const contentTitle = shareholder.content?.title || 'content';
|
||||
const payoutComment = `IndeeHub ${type} payout - ${contentTitle}`;
|
||||
|
||||
this.logger.log(`[payout:${type}] Sending ${rounded} sats to ${selectedLightningAddress.lightningAddress}...`);
|
||||
const providerPayment = await this.provider.sendPaymentWithAddress(
|
||||
selectedLightningAddress.lightningAddress,
|
||||
payment,
|
||||
payoutComment,
|
||||
);
|
||||
|
||||
payment.providerId = providerPayment.id;
|
||||
|
||||
Reference in New Issue
Block a user