commit
34ce95881a
3 changed files with 19 additions and 17 deletions
|
|
@ -472,12 +472,14 @@ export default class {
|
||||||
}, { abort: abortController.signal })
|
}, { abort: abortController.signal })
|
||||||
return new Promise((res, rej) => {
|
return new Promise((res, rej) => {
|
||||||
stream.responses.onError(error => {
|
stream.responses.onError(error => {
|
||||||
this.log(ERROR, "error with trackPaymentV2", error.message)
|
if (abortController.signal.aborted) {
|
||||||
rej(null)
|
this.log(ERROR, "error with trackPaymentV2", error.message)
|
||||||
|
rej(null)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
stream.responses.onMessage(payment => {
|
stream.responses.onMessage(payment => {
|
||||||
abortController.abort()
|
|
||||||
res(payment)
|
res(payment)
|
||||||
|
abortController.abort()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -71,13 +71,12 @@ export default class {
|
||||||
const log = getLogger({ component: 'pendingPaymentsOnStart' })
|
const log = getLogger({ component: 'pendingPaymentsOnStart' })
|
||||||
const pendingPayments = await this.storage.paymentStorage.GetPendingPayments()
|
const pendingPayments = await this.storage.paymentStorage.GetPendingPayments()
|
||||||
for (const p of pendingPayments) {
|
for (const p of pendingPayments) {
|
||||||
|
log("checking state of payment: ", p.invoice)
|
||||||
if (p.internal) {
|
if (p.internal) {
|
||||||
log("found pending internal payment", p.serial_id)
|
log("found pending internal payment", p.serial_id)
|
||||||
return
|
|
||||||
} else if (p.liquidityProvider) {
|
} else if (p.liquidityProvider) {
|
||||||
log("found pending liquidity provider payment", p.serial_id)
|
log("found pending liquidity provider payment", p.serial_id)
|
||||||
await this.checkPendingProviderPayment(log, p)
|
await this.checkPendingProviderPayment(log, p)
|
||||||
return
|
|
||||||
} else {
|
} else {
|
||||||
log("found pending external payment", p.serial_id)
|
log("found pending external payment", p.serial_id)
|
||||||
await this.checkPendingLndPayment(log, p)
|
await this.checkPendingLndPayment(log, p)
|
||||||
|
|
@ -93,7 +92,7 @@ export default class {
|
||||||
await this.storage.txQueue.PushToQueue({
|
await this.storage.txQueue.PushToQueue({
|
||||||
dbTx: true, description: "refund failed provider payment", exec: async tx => {
|
dbTx: true, description: "refund failed provider payment", exec: async tx => {
|
||||||
await this.storage.userStorage.IncrementUserBalance(p.user.user_id, fullAmount, "payment_refund:" + p.invoice, tx)
|
await this.storage.userStorage.IncrementUserBalance(p.user.user_id, fullAmount, "payment_refund:" + p.invoice, tx)
|
||||||
await this.storage.paymentStorage.UpdateExternalPayment(p.serial_id, 0, 0, false)
|
await this.storage.paymentStorage.UpdateExternalPayment(p.serial_id, 0, 0, false, undefined, tx)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
|
|
@ -106,9 +105,9 @@ export default class {
|
||||||
dbTx: true, description: "pending provider payment success after restart", exec: async tx => {
|
dbTx: true, description: "pending provider payment success after restart", exec: async tx => {
|
||||||
if (routingFeeLimit - actualFee > 0) {
|
if (routingFeeLimit - actualFee > 0) {
|
||||||
this.log("refund pending provider payment routing fee", routingFeeLimit, actualFee, "sats")
|
this.log("refund pending provider payment routing fee", routingFeeLimit, actualFee, "sats")
|
||||||
await this.storage.userStorage.IncrementUserBalance(p.user.user_id, routingFeeLimit - actualFee, "routing_fee_refund:" + p.invoice)
|
await this.storage.userStorage.IncrementUserBalance(p.user.user_id, routingFeeLimit - actualFee, "routing_fee_refund:" + p.invoice, tx)
|
||||||
}
|
}
|
||||||
await this.storage.paymentStorage.UpdateExternalPayment(p.serial_id, actualFee, p.service_fees, true)
|
await this.storage.paymentStorage.UpdateExternalPayment(p.serial_id, actualFee, p.service_fees, true, undefined, tx)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (p.linkedApplication && p.user.user_id !== p.linkedApplication.owner.user_id && serviceFee > 0) {
|
if (p.linkedApplication && p.user.user_id !== p.linkedApplication.owner.user_id && serviceFee > 0) {
|
||||||
|
|
@ -119,8 +118,6 @@ export default class {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log("provider payment still pending", p.serial_id, "no action will be performed")
|
log("provider payment still pending", p.serial_id, "no action will be performed")
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
checkPendingLndPayment = async (log: PubLogger, p: UserInvoicePayment) => {
|
checkPendingLndPayment = async (log: PubLogger, p: UserInvoicePayment) => {
|
||||||
|
|
@ -147,9 +144,9 @@ export default class {
|
||||||
dbTx: true, description: "pending payment success after restart", exec: async tx => {
|
dbTx: true, description: "pending payment success after restart", exec: async tx => {
|
||||||
if (routingFeeLimit - actualFee > 0) {
|
if (routingFeeLimit - actualFee > 0) {
|
||||||
this.log("refund pending payment routing fee", routingFeeLimit, actualFee, "sats")
|
this.log("refund pending payment routing fee", routingFeeLimit, actualFee, "sats")
|
||||||
await this.storage.userStorage.IncrementUserBalance(p.user.user_id, routingFeeLimit - actualFee, "routing_fee_refund:" + p.invoice)
|
await this.storage.userStorage.IncrementUserBalance(p.user.user_id, routingFeeLimit - actualFee, "routing_fee_refund:" + p.invoice, tx)
|
||||||
}
|
}
|
||||||
await this.storage.paymentStorage.UpdateExternalPayment(p.serial_id, actualFee, p.service_fees, true)
|
await this.storage.paymentStorage.UpdateExternalPayment(p.serial_id, actualFee, p.service_fees, true, undefined, tx)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (p.linkedApplication && p.user.user_id !== p.linkedApplication.owner.user_id && serviceFee > 0) {
|
if (p.linkedApplication && p.user.user_id !== p.linkedApplication.owner.user_id && serviceFee > 0) {
|
||||||
|
|
@ -164,7 +161,7 @@ export default class {
|
||||||
await this.storage.txQueue.PushToQueue({
|
await this.storage.txQueue.PushToQueue({
|
||||||
dbTx: true, description: "refund failed pending payment", exec: async tx => {
|
dbTx: true, description: "refund failed pending payment", exec: async tx => {
|
||||||
await this.storage.userStorage.IncrementUserBalance(p.user.user_id, fullAmount, "payment_refund:" + p.invoice, tx)
|
await this.storage.userStorage.IncrementUserBalance(p.user.user_id, fullAmount, "payment_refund:" + p.invoice, tx)
|
||||||
await this.storage.paymentStorage.UpdateExternalPayment(p.serial_id, 0, 0, false)
|
await this.storage.paymentStorage.UpdateExternalPayment(p.serial_id, 0, 0, false, undefined, tx)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -177,13 +177,16 @@ export default class {
|
||||||
async SetExternalPaymentIndex(invoicePaymentSerialId: number, index: number, entityManager = this.DB) {
|
async SetExternalPaymentIndex(invoicePaymentSerialId: number, index: number, entityManager = this.DB) {
|
||||||
return entityManager.getRepository(UserInvoicePayment).update(invoicePaymentSerialId, { paymentIndex: index })
|
return entityManager.getRepository(UserInvoicePayment).update(invoicePaymentSerialId, { paymentIndex: index })
|
||||||
}
|
}
|
||||||
async UpdateExternalPayment(invoicePaymentSerialId: number, routingFees: number, serviceFees: number, success: boolean, providerDestination?: string) {
|
async UpdateExternalPayment(invoicePaymentSerialId: number, routingFees: number, serviceFees: number, success: boolean, providerDestination?: string, entityManager = this.DB) {
|
||||||
return this.DB.getRepository(UserInvoicePayment).update(invoicePaymentSerialId, {
|
const up: Partial<UserInvoicePayment> = {
|
||||||
routing_fees: routingFees,
|
routing_fees: routingFees,
|
||||||
service_fees: serviceFees,
|
service_fees: serviceFees,
|
||||||
paid_at_unix: success ? Math.floor(Date.now() / 1000) : -1,
|
paid_at_unix: success ? Math.floor(Date.now() / 1000) : -1,
|
||||||
liquidityProvider: providerDestination
|
}
|
||||||
})
|
if (providerDestination) {
|
||||||
|
up.liquidityProvider = providerDestination
|
||||||
|
}
|
||||||
|
return entityManager.getRepository(UserInvoicePayment).update(invoicePaymentSerialId, up)
|
||||||
}
|
}
|
||||||
|
|
||||||
async AddInternalPayment(userId: string, invoice: string, amount: number, serviceFees: number, linkedApplication: Application, debitNpub?: string): Promise<UserInvoicePayment> {
|
async AddInternalPayment(userId: string, invoice: string, amount: number, serviceFees: number, linkedApplication: Application, debitNpub?: string): Promise<UserInvoicePayment> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue