Ejemplo n.º 1
0
import re
import os.path

#API_HOST = "https://bitpay.com" #for production, live bitcoin
API_HOST = "https://test.bitpay.com" #for testing, testnet bitcoin
KEY_FILE = "/tmp/key.priv"
TOKEN_FILE = "/tmp/token.priv"

# check if there is a preexisting key file
if os.path.isfile(KEY_FILE):
    f = open(KEY_FILE, 'r')
    key = f.read()
    f.close()
    print("Creating a bitpay client using existing private key from disk.")
else:
    key = bku.generate_pem()
    f = open(KEY_FILE, 'w')
    f.write(key)
    f.close()

client = Client(API_HOST, False, key)

def fetch_token(facade):
    if os.path.isfile(TOKEN_FILE + facade):
        f = open(TOKEN_FILE + facade, 'r')
        token = f.read()
        f.close()
        print("Reading " + facade + " token from disk.")
        #global client
        #client = Client(API_HOST, False, key, {facade: token})
        client.tokens[facade] = token
Ejemplo n.º 2
0
#API_HOST = "https://bitpay.com" #for production, live bitcoin
API_HOST = "https://test.bitpay.com" #for testing, testnet bitcoin
KEY_FILE = "/tmp/key.priv"
TOKEN_FILE = "/tmp/token.priv"

# check if there is a preexisting key file and token file
if os.path.isfile(KEY_FILE) and os.path.isfile(TOKEN_FILE):
    f = open(KEY_FILE, 'r')
    key = f.read()
    f.close()
    f = open(TOKEN_FILE, 'r')
    token = f.read()
    f.close()
else:
    key = bku.generate_pem()
    token = ""

f = open(KEY_FILE, 'w')
f.write(key)
f.close()

if token == "":
    client = Client(API_HOST, False, key)
    pairingCode = client.create_token("merchant")
    print "Please go to:  %s/dashboard/merchant/api-tokens  then enter \"%s\" then click the \"Find\" button, then click \"Approve\"" % (API_HOST, pairingCode)
    raw_input("When you've complete the above, hit enter to continue...")
    print "token is: %s" % client.tokens['merchant']
    f = open(TOKEN_FILE, 'w')
    f.write(client.tokens['merchant'])
    f.close()