1111from src .bitpay .exceptions .bitpay_exception import BitPayException
1212
1313# Will be set to Test otherwise
14- private_key_name = ' private_key.pem' # Add here the name for your Private key
14+ private_key_name = " private_key.pem" # Add here the name for your Private key
1515private_key_path = os .path .join (os .path .abspath (os .curdir ), private_key_name )
1616plain_private_key = None
1717proxy = None
@@ -25,12 +25,12 @@ def select_env():
2525 global environment
2626 try :
2727 print ("Select target environment: " )
28- target_environment = input (' Press T for testing or P for production: \n ' )
28+ target_environment = input (" Press T for testing or P for production: \n " )
2929
30- if target_environment .lower () == 't' :
31- environment = ' Test'
32- elif target_environment .lower () == 'p' :
33- environment = ' Prod'
30+ if target_environment .lower () == "t" :
31+ environment = " Test"
32+ elif target_environment .lower () == "p" :
33+ environment = " Prod"
3434 else :
3535 select_env ()
3636
@@ -42,16 +42,18 @@ def select_env():
4242
4343def set_environment (env ):
4444 global api_url
45- if env == ' Test' :
46- api_url = ' https://test.bitpay.com'
45+ if env == " Test" :
46+ api_url = " https://test.bitpay.com"
4747 else :
48- api_url = ' https://bitpay.com'
48+ api_url = " https://bitpay.com"
4949
5050
5151def select_create_key ():
5252 try :
53- input_value = input ('Press enter to generate a brand new key or enter your private key location:' )
54- if input_value == '' :
53+ input_value = input (
54+ "Press enter to generate a brand new key or enter your private key location:"
55+ )
56+ if input_value == "" :
5557 create_new_key ()
5658 else :
5759 load_key ()
@@ -71,15 +73,17 @@ def store_key(private_key):
7173 global plain_private_key , private_key_path
7274 try :
7375 print ("Select the way you want to store your private key:" )
74- input_value = input ("Press F for storing in a pem file or T for plain text in your config file: " )
76+ input_value = input (
77+ "Press F for storing in a pem file or T for plain text in your config file: "
78+ )
7579
76- if input_value .lower () == 'f' :
80+ if input_value .lower () == "f" :
7781 with open (str (private_key_path ), "wb" ) as f :
7882 f .write (private_key .encode ())
7983 plain_private_key = None
8084 print ("Private key saved at path:" , private_key_path )
8185 select_tokens (private_key )
82- elif input_value .lower () == 't' :
86+ elif input_value .lower () == "t" :
8387 plain_private_key = private_key
8488 private_key_path = None
8589 print ("Saving private key... \n " )
@@ -93,8 +97,8 @@ def store_key(private_key):
9397def select_tokens (private_key ):
9498 try :
9599 print ("Select the tokens that you would like to request:" )
96- input_value = input (' Press M for merchant, P for payout, or B for both: \n ' )
97- if input_value .lower () in ['m' , 'p' , 'b' ]:
100+ input_value = input (" Press M for merchant, P for payout, or B for both: \n " )
101+ if input_value .lower () in ["m" , "p" , "b" ]:
98102 print ("Requesting Tokens... \n " )
99103 request_tokens (input_value .lower (), private_key )
100104 else :
@@ -112,27 +116,37 @@ def request_tokens(token_type, private_key):
112116 url = "%s/tokens" % api_url
113117 headers = {"content-type" : "application/json" , "X-accept-version" : "2.0.0" }
114118
115- if token_type in ['m' , 'b' ]:
119+ if token_type in ["m" , "b" ]:
116120 print ("Requesting Merchant token... \n " )
117- facade = ' merchant'
118- payload = {'id' : sin , ' facade' : facade }
121+ facade = " merchant"
122+ payload = {"id" : sin , " facade" : facade }
119123
120- response = requests .post (url , verify = True , data = json .dumps (payload ), headers = headers )
124+ response = requests .post (
125+ url , verify = True , data = json .dumps (payload ), headers = headers
126+ )
121127 if response .ok :
122- merchant_token = response .json ()['data' ][0 ]['token' ]
123- print ("Merchant Token: " , response .json ()['data' ][0 ]['token' ])
124- print ("Merchant Token Pairing Code: " , response .json ()['data' ][0 ]['pairingCode' ] + "\n " )
125-
126- if token_type in ['p' , 'b' ]:
128+ merchant_token = response .json ()["data" ][0 ]["token" ]
129+ print ("Merchant Token: " , response .json ()["data" ][0 ]["token" ])
130+ print (
131+ "Merchant Token Pairing Code: " ,
132+ response .json ()["data" ][0 ]["pairingCode" ] + "\n " ,
133+ )
134+
135+ if token_type in ["p" , "b" ]:
127136 print ("Requesting Payout token... \n " )
128- facade = ' payout'
129- payload = {'id' : sin , ' facade' : facade }
137+ facade = " payout"
138+ payload = {"id" : sin , " facade" : facade }
130139
131- response = requests .post (url , verify = True , data = json .dumps (payload ), headers = headers )
140+ response = requests .post (
141+ url , verify = True , data = json .dumps (payload ), headers = headers
142+ )
132143 if response .ok :
133- payout_token = response .json ()['data' ][0 ]['token' ]
134- print ("Payout Token: " , response .json ()['data' ][0 ]['token' ])
135- print ("Payout Token Pairing Code: " , response .json ()['data' ][0 ]['pairingCode' ] + "\n " )
144+ payout_token = response .json ()["data" ][0 ]["token" ]
145+ print ("Payout Token: " , response .json ()["data" ][0 ]["token" ])
146+ print (
147+ "Payout Token Pairing Code: " ,
148+ response .json ()["data" ][0 ]["pairingCode" ] + "\n " ,
149+ )
136150
137151 update_config_file ()
138152 except BitPayException as exe :
@@ -150,23 +164,30 @@ def update_config_file():
150164 "PrivateKey" : plain_private_key ,
151165 "ApiTokens" : {
152166 "merchant" : merchant_token ,
153- "payout" : payout_token
167+ "payout" : payout_token ,
154168 },
155- "proxy" : proxy
169+ "proxy" : proxy ,
156170 }
157- }
171+ },
158172 }
159173 }
160174
161- with open (os .path .abspath ("bitpay.config.json" ), 'w' ) as outfile :
175+ with open (os .path .abspath ("bitpay.config.json" ), "w" ) as outfile :
162176 json .dump (config , outfile )
163- print ('Generated configuration file at path: ' , os .path .abspath ("bitpay.config.json" ))
164-
165- print ('Configuration generated successfully! \n ' )
166- print ("\r \n Please, copy the above pairing code/s and approve on your BitPay Account at the following link:\r \n " )
177+ print (
178+ "Generated configuration file at path: " ,
179+ os .path .abspath ("bitpay.config.json" ),
180+ )
181+
182+ print ("Configuration generated successfully! \n " )
183+ print (
184+ "\r \n Please, copy the above pairing code/s and approve on your BitPay Account at the following link:\r \n "
185+ )
167186 print (f"{ api_url } /dashboard/merchant/api-tokens\r \n " )
168- print ("\r \n Once you have this Pairing Code/s approved you can move the generated files to a secure location "
169- "and start using the Client.\r \n " )
187+ print (
188+ "\r \n Once you have this Pairing Code/s approved you can move the generated files to a secure location "
189+ "and start using the Client.\r \n "
190+ )
170191 except BitPayException as exe :
171192 print (exe )
172193
@@ -176,6 +197,5 @@ def load_key():
176197 pass
177198
178199
179- if __name__ == ' __main__' :
200+ if __name__ == " __main__" :
180201 select_env ()
181-
0 commit comments