lnbits / satspay

Create onchain and LN charges
MIT License
8 stars 4 forks source link

'extra' data overwritten after payment, when webhook is present #38

Closed lightningcheckout closed 9 months ago

lightningcheckout commented 9 months ago

Given a request with a webhook url present and the extra tag is filled When the invoice is paid, the extra data is overwritten, and initial data is gone.

Steps to reproduce: Create a satspay request with the following body:

{
  "lnbitswallet": "***",
  "name": "Test1",
  "description": "Test1",
  "webhook": "https://webhook.site/40dca456-0eb9-48cf-b52a-36f82fd99940",
  "completelink": "string",
  "completelinktext": "Back to Merchant",
  "custom_css": "string",
  "time": 1440,
  "amount": 100,
  "zeroconf": false,
  "extra": "{\"product\": \"btc\"}"
}

When you retrieve the charge, before paying it the 'extra' data is returned. When you retrieve the charge after it's paid, the extra data is gone. It's replaced by the webhook result

Additional: When you request the example, without the webhook data the extra data is shown, even after the payment

motorina0 commented 9 months ago

I was not able to reproduce this issue. The old extra values are kept next to the webhook response.

lightningcheckout commented 9 months ago

Just checked on legend, but there it's still reproducible. To be clear, It's about the extra data at charge level, not at invoice level.

I started with the request from the example above. The call to the url below results in the response https://legend.lnbits.com/satspay/api/v1/charge/DfxFXQQ9FGtk4z2AW2mZ3R

{
  "id": "DfxFXQQ9FGtk4z2AW2mZ3R",
  "name": "Test1",
  "description": "Test1",
  "onchainwallet": null,
  "onchainaddress": null,
  "lnbitswallet": "b7171e77ee1a4c639c3d427d114a87f9",
  "payment_request": "lnbc10n1pjafq24sp5yku3d79h3mzn3x94d6u3mnhewym9hvvfrkf4hvuq24umlag328espp5c2s098qvtyqsd670g6ylau3v57tk878ujwyjwfxh406etz09vvysdqg23jhxap3xqyz5vqcqpjrzjq2t02g8hdr7y9zzuextve490q2s4wfsx8m5twdn5dalltql2ct8syrrlguqqncsqqyqqqqqqqqqqqpgq9q9qxpqysgquy7f4ccndn2glcjm4t0kpwm5ucxamypk6u3np4ax669zr2r94as4cvqy365xr29f38xl4yrqqphswtk58luhffjx8tdu0p0f2mee3pcqdar44p",
  "payment_hash": "c2a0f29c0c590106ebcf4689fef22ca79763f8fc93892724d7abf59589e56309",
  "webhook": "https://webhook.site/40dca456-0eb9-48cf-b52a-36f82fd99940",
  "completelink": "string",
  "completelinktext": "Back to Merchant",
  "custom_css": "string",
  "extra": "{\"product\": \"btc\"}",
  "time": 1440,
  "amount": 1,
  "zeroconf": false,
  "balance": 0,
  "pending": 0,
  "timestamp": 1708425558,
  "last_accessed_at": 1708425570,
  "time_elapsed": false,
  "time_left": 1439.8,
  "paid": false
}

After the payment the result is:

{
  "id": "DfxFXQQ9FGtk4z2AW2mZ3R",
  "name": "Test1",
  "description": "Test1",
  "onchainwallet": null,
  "onchainaddress": null,
  "lnbitswallet": "b7171e77ee1a4c639c3d427d114a87f9",
  "payment_request": "lnbc10n1pjafq24sp5yku3d79h3mzn3x94d6u3mnhewym9hvvfrkf4hvuq24umlag328espp5c2s098qvtyqsd670g6ylau3v57tk878ujwyjwfxh406etz09vvysdqg23jhxap3xqyz5vqcqpjrzjq2t02g8hdr7y9zzuextve490q2s4wfsx8m5twdn5dalltql2ct8syrrlguqqncsqqyqqqqqqqqqqqpgq9q9qxpqysgquy7f4ccndn2glcjm4t0kpwm5ucxamypk6u3np4ax669zr2r94as4cvqy365xr29f38xl4yrqqphswtk58luhffjx8tdu0p0f2mee3pcqdar44p",
  "payment_hash": "c2a0f29c0c590106ebcf4689fef22ca79763f8fc93892724d7abf59589e56309",
  "webhook": "https://webhook.site/40dca456-0eb9-48cf-b52a-36f82fd99940",
  "completelink": "string",
  "completelinktext": "Back to Merchant",
  "custom_css": "string",
  "extra": "{\"mempool_endpoint\": null, \"network\": null, \"webhook_success\": true, \"webhook_message\": \"OK\", \"webhook_response\": \"This URL has no default content configured. View in Webhook.site.\"}",
  "time": 1440,
  "amount": 1,
  "zeroconf": false,
  "balance": 1,
  "pending": 0,
  "timestamp": 1708425558,
  "last_accessed_at": 1708425653,
  "time_elapsed": false,
  "time_left": 1438.4166666666667,
  "paid": true
}

So the extra data is changed at this point.

motorina0 commented 9 months ago

How did you initially set "extra": "{\"product\": \"btc\"}",?

motorina0 commented 9 months ago

The extra field is not a generic dict, but a strongly typed class:

class ChargeConfig(BaseModel):
    mempool_endpoint: Optional[str]
    network: Optional[str]
    webhook_success: Optional[bool] = False
    webhook_message: Optional[str]
motorina0 commented 9 months ago

But your usecase is valid. I have added a misc field to extra. In misc one can store any random data.

Will be out on the next release: https://github.com/lnbits/satspay/releases/tag/v0.2.7

lightningcheckout commented 9 months ago

But your usecase is valid. I have added a misc field to extra. In misc one can store any random data.

Will be out on the next release: https://github.com/lnbits/satspay/releases/tag/v0.2.7

Awesome, thanks for this solution!

motorina0 commented 9 months ago

Deployed to legend.lnbits.com