Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SP-1029 - Add X-BitPay-Platform-Info header #126

Merged
merged 2 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/bitpay/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,13 @@ def __init__(
)

@staticmethod
def create_pos_client(pos_token: str, environment: Environment = Environment.PROD): # type: ignore
def create_pos_client(pos_token: str, environment: Environment = Environment.PROD, platform_info: Optional[str] = None): # type: ignore
token_container = TokenContainer()
token_container.add_pos(pos_token)

bitpay_client = BitPayClient(Client.get_base_url(environment))
bitpay_client = BitPayClient(
Client.get_base_url(environment), None, platform_info
)

return Client(bitpay_client, token_container, GuidGenerator())

Expand All @@ -75,14 +77,15 @@ def create_client( # type: ignore
token_container: TokenContainer,
environment: Environment = Environment.PROD,
proxy: Optional[str] = None,
platform_info: Optional[str] = None,
):
"""
:raises BitPayGenericException
"""
try:
base_url = Client.get_base_url(environment)
ec_key = Client.get_ec_key(private_key_or_private_key_path)
bitpay_client = BitPayClient(base_url, ec_key, proxy)
bitpay_client = BitPayClient(base_url, ec_key, proxy, platform_info)
guid_generator = GuidGenerator()

return Client(bitpay_client, token_container, guid_generator)
Expand All @@ -92,7 +95,7 @@ def create_client( # type: ignore
)

@staticmethod
def create_client_by_config_file_path(config_file_path: str): # type: ignore
def create_client_by_config_file_path(config_file_path: str, platform_info: Optional[str] = None): # type: ignore
"""
:raises BitPayGenericException
"""
Expand Down Expand Up @@ -125,7 +128,11 @@ def create_client_by_config_file_path(config_file_path: str): # type: ignore
environment = Environment.PROD

return Client.create_client(
private_key_or_private_key_path, token_container, environment, proxy
private_key_or_private_key_path,
token_container,
environment,
proxy,
platform_info,
)
except Exception as exe:
BitPayExceptionProvider.throw_generic_exception_with_message(
Expand Down
11 changes: 10 additions & 1 deletion src/bitpay/clients/bitpay_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@ class BitPayClient:
__base_url: str
__ec_key: Optional[str] = None
__proxy: Optional[str] = None
__platform_info: Optional[str] = None

def __init__(
self, base_url: str, ec_key: Optional[str] = None, proxy: Optional[str] = None
self,
base_url: str,
ec_key: Optional[str] = None,
proxy: Optional[str] = None,
platform_info: Optional[str] = None,
):
self.__base_url = base_url
self.__ec_key = ec_key
self.__proxy = proxy
self.__platform_info = platform_info
self.init()

def init(self) -> None:
Expand All @@ -38,6 +44,9 @@ def init(self) -> None:
if self.__proxy is not None:
self.__headers["proxy"] = self.__proxy

if self.__platform_info is not None:
self.__headers["x-bitpay-platform-info"] = self.__platform_info

def post(
self, uri: str, form_data: Any = {}, signature_required: bool = True
) -> Response:
Expand Down