|
1 | 1 | import requests |
2 | 2 | import urllib.parse |
| 3 | +import base64 |
3 | 4 |
|
4 | 5 |
|
5 | 6 | class BootpayBackend: |
@@ -33,18 +34,25 @@ def set_api_version(self, version): |
33 | 34 | # @param method: string, url: string, data: object, headers: object |
34 | 35 | # @returns ResponseForamt |
35 | 36 | def __request(self, method='', url='', data=None, headers={}, params={}): |
| 37 | + auth_header = None |
| 38 | + if self.token is not None: |
| 39 | + auth_header = f"Bearer {self.token}" |
| 40 | + elif self.application_id and self.private_key: |
| 41 | + encoded = base64.b64encode(f"{self.application_id}:{self.private_key}".encode('utf-8')).decode('utf-8') |
| 42 | + auth_header = f"Basic {encoded}" |
| 43 | + |
36 | 44 | if method in ['put', 'post']: |
37 | 45 | response = getattr(requests, method)(url, json=data, headers=dict(headers, **{ |
38 | 46 | 'Accept': 'application/json', |
39 | | - 'Authorization': (None if self.token is None else f"Bearer {self.token}"), |
| 47 | + 'Authorization': auth_header, |
40 | 48 | 'BOOTPAY-API-VERSION': self.api_version, |
41 | 49 | 'BOOTPAY-SDK-VERSION': self.SDK_VERSION, |
42 | 50 | 'BOOTPAY-SDK-TYPE': '302' |
43 | 51 | }), params=params) |
44 | 52 | else: |
45 | 53 | response = getattr(requests, method)(url, headers=dict(headers, **{ |
46 | 54 | 'Accept': 'application/json', |
47 | | - 'Authorization': (None if self.token is None else f"Bearer {self.token}") |
| 55 | + 'Authorization': auth_header |
48 | 56 | }), params=params) |
49 | 57 | return response.json() |
50 | 58 |
|
|
0 commit comments