GithubHelp home page GithubHelp logo

btcpayserver / btcpay-python Goto Github PK

View Code? Open in Web Editor NEW
80.0 80.0 27.0 69 KB

Python client for the BTCPay API.

Home Page: https://docs.btcpayserver.org/integrations/customintegration

License: MIT License

Python 100.00%

btcpay-python's Introduction

BTCPay Server

BTCPay Server

Accept Bitcoin payments โ‚ฟ

BTCPay Server is a free and open-source Bitcoin payment processor which allows you to accept bitcoin without fees or intermediaries.

"This is lies, my trust in you is broken, I will make you obsolete" ๐Ÿ’š

View Demo ยท Report a bug ยท Request a feature ยท FAQ

๐Ÿ’ผ Table of Contents

๐ŸŽจ Features

  • Direct, peer-to-peer Bitcoin payments
  • No transaction fees (other than the network fee)
  • No fees, middleman or KYC
  • Non-custodial (complete control over the private key)
  • Enhanced privacy & security
  • Self-hosted
  • SegWit support
  • Lightning Network support (LND, Core Lightning (CLN), Eclair)
  • Tor support
  • Share your instance with friends (multi-tenant)
  • Invoice management and Payment requests
  • Apps: Point of sale, crowdfunding, donation button
  • Full-node reliant wallet with hardware wallet integration and SegWit support
  • Bitcoin-only build, separate community-maintained altcoin build (supported altcoins)

๐Ÿš€ Getting Started

Firstly, decide if you want to host an instance yourself or use a third-party host. If you've chosen to self-host, there are plenty of documented ways to deploy BTCPay Server.

After successful deployment, make sure to check our getting started and walkthrough guides. In case you would like to use Lightning Network, see Lightning guide.

๐Ÿ“— Documentation

Please check out our official website, complete documentation and FAQ for more details.

If you have trouble using BTCPay Server, consider joining communities listed on the official website to get help from other contributors. Only create a GitHub issue for technical issues you can't resolve through other channels or feature requests you've validated with other members of the community.

๐Ÿค Contributing

BTCPay Server is built and maintained entirely by volunteer contributors around the internet. We welcome and appreciate new contributions.

If you're a developer looking to help, but you're not sure where to begin, check the good first issue label, which contains small pieces of work that have been specifically flagged as being friendly to new contributors.

Contributors looking to do something a bit more challenging, before opening a pull request, please join our community chat or start a GitHub discussion to get early feedback, discuss the best ways to tackle the problem, and ensure there is no work duplication.

There are many other ways to get involved with the project. Check our contribution guidelines. To get the big-picture of the project development, visit our evolving roadmap.

๐Ÿง‘โ€๐Ÿ’ป Developing

To begin developing locally, visit our local development guide. There are also several video-tutorials:

How to build

While the documentation advises using docker-compose, you may want to build BTCPay Server yourself.

First, install .NET SDK v8.0 as specified by the Microsoft website.

On Powershell:

.\build.ps1

On linux:

./build.sh

How to run

Use the run scripts to run BTCPay Server, this example shows how to print the available command-line arguments of BTCPay Server.

On Powershell:

.\run.ps1 --help

On linux:

./run.sh --help

How to debug

If you want to debug, use Jetbrain's Rider or Visual Studio 2022.

You need to run the development time docker-compose as described in the test guide.

You can then run the debugger by using the Launch Profile Docker-Regtest.

If you need to debug ledger wallet interaction, install the development time certificate with:

# Install development time certificate in the trust store
dotnet dev-certs https --trust

Then use the Docker-Regtest-https debug profile.

Other dependencies

For more information, see the documentation: How to deploy a BTCPay Server instance.

๐Ÿงช API

BTCPay Server has two APIs:

The Greenfield API is our brand-new API which is still in development. Once complete, it will allow you to run BTCPay Server headlessly. The Legacy API, is fully compatible with BitPay's API. It has limited features, but allows instant migration from BitPay.

๐Ÿ’š Community

Our community is the โค๏ธ of the project. To chat with other community members in real-time, join our Mattermost chat. We're also on GitHub discussions.

๐Ÿ“ License

BTCPay Server software, logo and designs are provided under MIT License.

๐Ÿ™ Supporters

The BTCPay Server Project is proudly supported by these entities through the BTCPay Server Foundation.

Spiral OpenSats Baillie Gifford Tether Human Rights Foundation Strike LunaNode Wallet of Satoshi Coincards IVPN

If you'd like to support the project, please visit the donation page.

btcpay-python's People

Contributors

amperture avatar jeffvandrewjr avatar joeblackwaslike avatar nicolasdorier avatar saurabh130 avatar theseatoms avatar vesellov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

btcpay-python's Issues

testnet server not working

hi, i have issue connecting to testnet server.
here is my code
from btcpay import BTCPayClient

client = BTCPayClient.create_client(host='https://testnet.demo.btcpayserver.org', code="sDRbK7H")

invoice_list = client.get_invoices(status='confirmed')
print(invoice_list)
Do i need to have my own server to test it or it works on testnet?. Thanks

Retrieving Transaction ID from an invoice

Once an invoice is paid/completed/confirmed I need to access the transaction id using the client. It doesn't seem available based on the json response. Is this possible to retrieve or do i need to write my own code to pull it from elsewhere

Getting an issue while integrating my project with btcpay

raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='mybtcpay.local', port=443): Max retries exceeded with url: /tokens (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:645)'),)) 

I am getting this error followed by other traceback error during custom integration while I run this -

client = BTCPayClient.create_client(host='https://btcpay.example.com', code=<pairing-code>)

Testnet pairing

Hello,

When I set up my own btcpayserver I could pair, but when I run it on testnet (I created a store on testnet.demo.btcpayserver.org/) I get 400 Client Error: Bad Request for url: https://testnet.demo.btcpayserver.org/tokens

The error is on create_client

BTCPayClient.create_client(
                    host=settings.BTCPAY_SERVER,
                    code=settings.BTCPAY_SERVER_TOKEN)

Any ideas why? Is the server up to date?

IndexError in get_rate() method

Hello guys. Thank you for the work you are doing.

Wanted to report a small bug to you. It looks like our BTCPay node is not very stable sometimes or there are some networking issues. For some reason client.get_rate("USD") occasionally may throw an IndexError list index out of range exception.

Based on the info from our Sentry dashboard I do see that get_rates() method returned an empty list and then further, on line 97 it will brake, because it tries to access the first element of the empty list rates = [] : https://github.com/btcpayserver/btcpay-python/blob/master/btcpay/client.py#L97

Not sure if you like to raise another error in that case, but just decided to report it here.

Thanks!

SSL Verification Error

I have deployed BTCPAY on a Digital Ocean server for testing (btc testnet), and everything is working fine so far except for when I try to create a client in python to connect to the server.

I have generated the pairing code in the server dashboard, but each time I try to create the client in python I get the following SSL errors:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 603, in urlopen
    chunked=chunked)
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 344, in _make_request
    self._validate_conn(conn)
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 843, in _validate_conn
    conn.connect()
  File "/usr/local/lib/python3.7/site-packages/urllib3/connection.py", line 370, in connect
    ssl_context=context)
  File "/usr/local/lib/python3.7/site-packages/urllib3/util/ssl_.py", line 355, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "/usr/local/lib/python3.7/ssl.py", line 412, in wrap_socket
    session=session
  File "/usr/local/lib/python3.7/ssl.py", line 853, in _create
    self.do_handshake()
  File "/usr/local/lib/python3.7/ssl.py", line 1117, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/local/lib/python3.7/site-packages/urllib3/connectionpool.py", line 641, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/local/lib/python3.7/site-packages/urllib3/util/retry.py", line 399, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host=XXX, port=443): Max retries exceeded with url: /tokens (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/btcpay/client.py", line 134, in pair_client
    data = self._unsigned_request('/tokens', payload)
  File "/usr/local/lib/python3.7/site-packages/btcpay/client.py", line 81, in _unsigned_request
    r = self.s.post(uri, data=payload)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 581, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 668, in send
    history = [resp for resp in gen] if allow_redirects else []
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 668, in <listcomp>
    history = [resp for resp in gen] if allow_redirects else []
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 247, in resolve_redirects
    **adapter_kwargs
  File "/usr/local/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/requests/adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host=XXX, port=443): Max retries exceeded with url: /tokens (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1056)')))

When I log the nginx container, I can only see on POST request come in for the /token url for each client connection attempt
[30/Jul/2019:13:28:22 +0000] "POST /tokens HTTP/1.1" 301 162 "-" "python-requests/2.22.0"),
though the SSL error (Max retries exceeded with url: /tokens) makes it seem like it was denied because of too many requests

I did have to add a security exception to access my btcpay website so perhaps the cert wasn't configured properly during the docker setup?

Error 400 on get_rates

I have my client working with creating invoices. However, when I try to call get_rates(), I get
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://testnet.demo.btcpayserver.org/rates/?cryptoCode=BTC&token=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

It's the same client, so I'm thinking this might be a bug?

Client Error: Not Found for url

When running BTCPayClient.create_client I'm getting the error:

requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://*******/tokens

I do have a working SSL certificate (checked due to #11 (comment)).

The issue might be the different certificates:

  • BTCPay - Let's encrypt (used this tutorial to deploy)
  • webhook server - AWS Certificate

Both have the same domain, different subdomains.

Is there any way around this or should I somehow make sure they use the same certificate?

When generating an invoice for less than 20 cents, client does not return BTC addresses

invoice_response = client.create_invoice({"price": 1.0, "currency": "USD"})

Returns a normal response.

invoice_response = client.create_invoice({"price": .19, "currency": "USD"})

Returns a response without a BTC address (but does include other currencies).

invoice_response = client.create_invoice({"price": .20, "currency": "USD"})

Also returns a normal response.

Trouble pairing

Here's my test program directly following the README:

import btcpay.crypto
from btcpay import BTCPayClient

URL = "https://test.buidlbootcamp.com"

privkey = btcpay.crypto.generate_privkey()
client = BTCPayClient(
    host=URL, 
    pem=privkey,
)

pairing_code = "SECRET!!!"
tokens = client.pair_client(pairing_code)

print(client.get_rates())

I encounter this exception:

$ python script.py 
Traceback (most recent call last):
  File "script.py", line 13, in <module>
    tokens = client.pair_client(pairing_code)
  File "/home/justin/dev/buidl-treasury/venv/lib/python3.7/site-packages/btcpay/client.py", line 97, in pair_client
    data = self._unsigned_request('/tokens', payload)
  File "/home/justin/dev/buidl-treasury/venv/lib/python3.7/site-packages/btcpay/client.py", line 65, in _unsigned_request
    r.raise_for_status()
  File "/home/justin/dev/buidl-treasury/venv/lib/python3.7/site-packages/requests/models.py", line 939, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: Bad Request for url: https://test.buidlbootcamp.com/tokens

This server is on testnet FWIW

requests.exceptions.InvalidURL: Failed to parse:

Hello,
i have try to use the library but i have this error: requests.exceptions.InvalidURL: Failed to parse: https//myserver.com/tokens

i have create Access Tokens and i have put in my script pairing code

i use python 3.8.10

and in script i have put:

from btcpay import BTCPayClient

client = BTCPayClient.create_client(host='MYSERVERULR', code="PAIRINGCODE")

Client not found error

Hello!

I'm getting issue with any client action:

  1. Generated key
  2. Paired with server
  3. Trying to get_rates() or gen_Invoice(), but getting this error:

Traceback (most recent call last):
File "main.py", line 31, in
client.get_rates()
File "/usr/local/lib/python3.6/site-packages/btcpay/client.py", line 74, in get_rates
return self._signed_get_request('/rates/', params=params)
File "/usr/local/lib/python3.6/site-packages/btcpay/client.py", line 45, in _signed_get_request
r.raise_for_status()
File "/usr/lib/python3.6/site-packages/requests/models.py", line 935, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: %mybtcpayurl%

JSONDecodeError: Expecting value: line 3 column 1 (char 2)

I am getting error JSONDecodeError: Expecting value: line 3 column 1 (char 2) when trying to create or get an invoices.
The URL I use for the API calls works fine in the browser when creating a new BTCPay client, but gives this error when creating or getting an invoices within the BTCPay client.

Create invoice

Get a list of invoices matching certain parameters

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.