1- from square .http .auth .o_auth_2 import BearerAuthCredentials
2- from square .client import Client
1+ from square import Square
2+ from square .environment import SquareEnvironment
3+ from square .core .api_error import ApiError
34from dotenv import load_dotenv
45import os
56
67load_dotenv ()
78
8- client = Client (
9- bearer_auth_credentials = BearerAuthCredentials (
10- access_token = os .environ ['SQUARE_ACCESS_TOKEN' ]
11- ),
12- environment = 'sandbox' )
9+ client = Square (
10+ environment = SquareEnvironment .SANDBOX ,
11+ token = os .environ ['SQUARE_ACCESS_TOKEN' ]
12+ )
1313
14- result = client .locations .list_locations ()
14+ try :
15+ response = client .locations .list ()
16+ for location in response .locations :
17+ print (f"{ location .id } : " , end = "" )
18+ print (f"{ location .name } , " , end = "" )
19+ print (f"{ location .address } , " , end = "" )
1520
16- if result .is_success ():
17- for location in result .body ['locations' ]:
18- print (f"{ location ['id' ]} : " , end = "" )
19- print (f"{ location ['name' ]} , " , end = "" )
20- print (f"{ location ['address' ]['address_line_1' ]} , " , end = "" )
21- print (f"{ location ['address' ]['locality' ]} " )
22-
23- elif result .is_error ():
24- for error in result .errors :
25- print (error ['category' ])
26- print (error ['code' ])
27- print (error ['detail' ])
21+ except ApiError as e :
22+ for error in e .errors :
23+ print (error .category )
24+ print (error .code )
25+ print (error .detail )
0 commit comments