From cb4edfe259316ef8fbcbe2fd73ed3cf641c0cad7 Mon Sep 17 00:00:00 2001 From: Chloe Jung Date: Wed, 29 Mar 2023 10:28:53 +1300 Subject: [PATCH] Remove the day limit and add the 'Update_payment_paid' function to lndhub pay function --- lnurlw/lnurlw_callback.go | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/lnurlw/lnurlw_callback.go b/lnurlw/lnurlw_callback.go index 5e75bbb..b5d5a61 100644 --- a/lnurlw/lnurlw_callback.go +++ b/lnurlw/lnurlw_callback.go @@ -41,14 +41,7 @@ func lndhub_payment(w http.ResponseWriter, p *db.Payment, bolt11 decodepay.Bolt1 // check amount limits invoice_sats := int(bolt11.MSatoshi / 1000) - day_total_sats, err := db.Get_card_totals(p.Card_id) - if err != nil { - log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Warn(err) - resp_err.Write(w) - return - } - - //check the tx limit + //check the tx limit if invoice_sats > c.Tx_limit_sats { log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Info("invoice_sats: ", invoice_sats) log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Info("tx_limit_sats: ", c.Tx_limit_sats) @@ -57,16 +50,6 @@ func lndhub_payment(w http.ResponseWriter, p *db.Payment, bolt11 decodepay.Bolt1 return } - //check the daily limit - if day_total_sats+invoice_sats > c.Day_limit_sats { - log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Info("invoice_sats: ", invoice_sats) - log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Info("day_total_sats: ", day_total_sats) - log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Info("day_limit_sats: ", c.Day_limit_sats) - log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Info("over day_limit_sats!") - resp_err.Write(w) - return - } - //lndhub.auth API call //the login JSON is held in the Card_name field // as "login:password" @@ -127,6 +110,14 @@ func lndhub_payment(w http.ResponseWriter, p *db.Payment, bolt11 decodepay.Bolt1 return } + // update paid_flag so we only attempt payment once + err = db.Update_payment_paid(p.Card_payment_id) + if err != nil { + log.WithFields(log.Fields{"card_payment_id": p.Card_payment_id}).Warn(err) + resp_err.Write(w) + return + } + // https://github.com/fiatjaf/lnurl-rfc/blob/luds/03.md // // LN SERVICE sends a {"status": "OK"} or