BTCPay implements the same API as Bitpay for creating and managing invoices.
Migrating from BitPay to BTCPay normally is as easy as changing a URL.
While Bitpay only allows one account for one merchant, BTCPay allows a user to manage multiple stores.
BTCPay maintains official client libraries for both Python and NodeJS.
In addition, there are forked repositories of Bitpay's PHP and Ruby clients.
If not using one of the libraries above, the REST API can be accessed manually.
The authentication mechanism is using BitId
.
With BitId
, the client
of the API (like an e-commerce plugin) generates a private key, then inform the server
(BTCPay) about the public key
.
Every requests to the API sent by the client is signed with the client's private key
.
We call pairing
the process to inform BTCPay about your public key
.
Your first need to create a new store:
- Log in
- Go to Stores menu
- Click on
Create a new store
- Enter a friendly name for the store, validate.
There is two method of pairing
, client side pairing and server side pairing.
With client side pairing, the client
generates a URL from his public key
which a human user can browse to validate the pairing.
Typically the URL looks like https://btcpay.example.com/api-access-request?pairingCode=<pairingcode_goes_here>
.
You can find documentation about how to achieve this with this link.
The second way, is to generate your private key via some bitcoin library then:
- Go to the store's settings
- Click on
Access tokens
- Click on
Create new Token
- Select merchant's facade and enter your public key,
- Click request pairing
- Click on Approve
BTCPay Server has an API compatible with Bitpay; changing your e-commerce application from Bitpay to BTCPay should take minimal effort.
You can read the full API documentation on Bitpay's website.
There is only one difference: Bitpay only allows one account for one merchant, BTCPay allows a user to manage multiple stores.
To geneate a pop-up modal experience:
- Include the btcpay.js script in your html page
<script src ="https://your.btcpay.url/modal/btcpay.js"></script>
- Call the invoice API to generate an invoice (example code). This is sample backend code as it contains an auth token that should not be exposed in your front-end.
const axiosClient = axios.create({
baseURL: BTCPAY_URL,
timeout: 5000,
responseType: 'json',
headers: {
'Content-Type': 'application/json',
'Authorization': BTCPAY_AUTH
}
});
const invoiceCreation = {
"price": 12345,
"currency": "USD",
"orderId": "something",
"itemDesc": "item description",
"notificationUrl": "https://webhook.after.checkout.com/goeshere",
"redirectURL": "https://go.here.after.checkout.com"
};
const response = await axiosClient.post("/invoices", invoiceCreation);
const invoiceId = response.data.data.id;
- Use the invoiceId to pop up the modal
window.btcpay.showInvoice(invoiceId);
- You'll often want to do something like refresh the state of your page when the invoice is paid, or note some kind of state before the modal pops up. You can attach event listeners like this:
window.btcpay.onModalWillEnter(yourCallbackFunction);
window.btcpay.onModalWillLeave(yourCallbackFunction);