pinLimit added to lnurlw response

This commit is contained in:
Peter Rounce 2023-07-02 13:11:38 +00:00
parent 105323a680
commit 3d9e742dc1
3 changed files with 24 additions and 4 deletions

View file

@ -29,6 +29,9 @@ type Card struct {
One_time_code string
Card_name string
Allow_negative_balance string
Pin_enable string
Pin_number string
Pin_limit_sats int
}
type Payment struct {
@ -350,7 +353,8 @@ func Get_card_from_card_id(card_id int) (*Card, error) {
`last_counter_value, lnurlw_request_timeout_sec, ` +
`lnurlw_enable, tx_limit_sats, day_limit_sats, ` +
`email_enable, email_address, card_name, ` +
`allow_negative_balance FROM cards WHERE card_id=$1;`
`allow_negative_balance, pin_enable, pin_number, ` +
`pin_limit_sats FROM cards WHERE card_id=$1;`
row := db.QueryRow(sqlStatement, card_id)
err = row.Scan(
&c.Card_id,
@ -364,7 +368,10 @@ func Get_card_from_card_id(card_id int) (*Card, error) {
&c.Email_enable,
&c.Email_address,
&c.Card_name,
&c.Allow_negative_balance)
&c.Allow_negative_balance,
&c.Pin_enable,
&c.Pin_number,
&c.Pin_limit_sats)
if err != nil {
return &c, err
}

View file

@ -304,6 +304,15 @@ func Response(w http.ResponseWriter, req *http.Request) {
return
}
// get pin_enable & pin_limit_sats
c, err := db.Get_card_from_card_id(card_id)
if err != nil {
log.WithFields(log.Fields{"card_id": card_id}).Warn(err)
resp_err.Write(w)
return
}
default_description := db.Get_setting("DEFAULT_DESCRIPTION")
response := make(map[string]interface{})
@ -315,6 +324,10 @@ func Response(w http.ResponseWriter, req *http.Request) {
response["minWithdrawable"] = min_withdraw_sats * 1000 // milliSats
response["maxWithdrawable"] = max_withdraw_sats * 1000 // milliSats
if c.Pin_enable == "Y" {
response["pinLimit"] = c.Pin_limit_sats * 1000 // milliSats
}
jsonData, err := json.Marshal(response)
if err != nil {

View file

@ -18,7 +18,7 @@ INSERT INTO settings (name, value) VALUES ('MAX_WITHDRAW_SATS', '1000');
INSERT INTO cards
(k0_auth_key, k2_cmac_key, k3, k4, lnurlw_enable, last_counter_value, lnurlw_request_timeout_sec,
tx_limit_sats, day_limit_sats, card_name, pin_limit_sats)
tx_limit_sats, day_limit_sats, card_name, pin_enable, pin_number, pin_limit_sats)
VALUES
('', 'd3dffa1e12d2477e443a6ee9fcfeab18', '', '', 'Y', 0, 10,
0, 0, 'test_card', 0);
0, 0, 'test_card', 'Y', '1234', 1000);