def pairing(code, host): privkey = generate_privkey() btc_client = BTCPayClient(host=host, pem=privkey) btc_token = btc_client.pair_client(code) btc_client = BTCPayClient(host=host, pem=privkey, tokens=btc_token) client_store = BTCPayClientStore.query.first() if client_store is None: client_store = BTCPayClientStore(client=btc_client) db.session.add(client_store) else: client_store.client = btc_client db.session.commit()
def initialize_btcpay(cfg): try: from btcpay import BTCPayClient except ImportError: print('btcpay_not_installed') sys.exit() btcpay = cfg.invoice.btcpay host = input("Enter your btcpay server's host name (blank to quit) :") cfg.invoice.btcpay.host = host if len(cfg.invoice.btcpay.host) == 0: sys.exit() print(btcpay_instructions.format(btcpay.host)) generate_privkey = input( "Should hourly generate your private key? (yes/n) ") if generate_privkey.lower() == 'yes': try: from btcpay import crypto except ImportError(): print(btcpay_not_installed) sys.exit() btcpay.pem = crypto.generate_privkey() save_privkey = input("Should hourly save your private key? (yes/n) ") if save_privkey == 'yes': pem_file = input( "Enter private key filename (leave blank for btcpayserver.pem):" ) if len(pem_file) == 0: pem_file = 'btcpayserver.pem' if path.exists(pem_file): print("File already exists! Exiting.") sys.exit() with open(pem_file, 'w') as pem: pem.write(btcpay.pem) print("private key written to {}".format(btcpay.pem)) print( "Do not commit {} to your repo! List it in .gitignore just to be safe" .format(btcpay.pem)) else: print("Ok, assuming your btcpay.pem has not yet been paired already") client = BTCPayClient(host=btcpay.host, pem=btcpay.pem) pairing_code = input("Paste your 7 digit pairing code here: ") if len(pairing_code) != 7: print("Pairing code is not 7 digits!") sys.exit() btcpay.tokens = client.pair_client(pairing_code) print("merchant token generated") save_configuration = input("save configuration? (yes/n) ") if save_configuration.lower() == 'yes': btcpay_filename = input( "enter configuration file name (leave blank for btcpay.yaml):") with open(btcpay_filename, 'w') as btcpay_file: btcpay_file.write(btcpay.pretty()) print("btcpay config written to {}".format(btcpay_filename)) print( "Do not commit {} to your repo! List ig in .gitignore just to be safe" .format(btcpay_filename)) print("Your btcpay configuration is given below:\n") print(btcpay.pretty())
from btcpay import BTCPayClient, crypto host_url = "http://raspberrypi.local" privkey = crypto.generate_privkey() with open('btcpayserver.pem', 'w') as pem: pem.write(privkey) pairing_code = "cPbc35p" client = BTCPayClient(host=host_url, pem=privkey) token = client.pair_client(pairing_code) merchant_token = token['merchant'] with open('merchant_token', 'w') as tok: tok.write(merchant_token)