btcpayserver / btcpayserver-doc

BTCPay Server Official Documentation
https://docs.btcpayserver.org
378 stars 255 forks source link

Fix Using the BTCPay API for Custom Integration #1356

Open iBobik opened 9 months ago

iBobik commented 9 months ago

Described API is not correct on the "Using the BTCPay API for Custom Integration" page (/CustomIntegration/).

window.btcpay.onModalReceiveMessage(yourCallbackFunction) // available from v1.0.5.6

onModalReceiveMessage will invoke your callback when a new status has been pushed from BTCPay Server to the invoice UI. The data format is {invoiceId: "x", status: "y" }

But the callback receives objects like this: Snímek obrazovky 2023-12-26 v 18 14 50

Generally I would like to read much more complete docs about this frontend SDK. Ideally have it as a TypeScript package, so I does not need to handle loading by <script> and my code will know what types to expect.

pavlenex commented 4 months ago

@ndeet can you take a look at this one and if we fixed it?

ndeet commented 4 months ago

Hey @iBobik, will look into that, seems that information may be outdated. You can find a better example here https://docs.btcpayserver.org/Development/ecommerce-integration-guide/#modal-invoice-page-advanced-optional

We don't have any dedicated Javascript dev around that's why there is no api library or for the modal, would be great if you or somebody could contribute that. That said, the functionality seems simple enough that it maybe is not needed.

ndeet commented 4 months ago

internal docs note:

Checking the mentioned custom integration page it is outdated in several ways:

iBobik commented 4 months ago

Btw, keep in mind e-commerce use cases with static website or limited backend capabilities, where it is handy to have API without authentication like this (sadly) deprecated one.

See this small integration I wrote for Shoptet.cz, major e-commerce SaaS in Czechia: https://gitlab.com/janpoboril/shoptet-btcpay/-/blob/master/public/checkout.js?ref_type=heads

ndeet commented 4 months ago

Yes you can do that when payment button is enabled, it is not deprecated, but it has problems. Users can modify sent parameters like price easily and e.g. lower the invoice amount and trick the chekout if you have no other checks in place.