payrex-python 0.1.3__tar.gz → 0.1.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: payrex-python
3
- Version: 0.1.3
3
+ Version: 0.1.4
4
4
  Summary: PayRex Python Library
5
5
  Home-page: https://github.com/payrexhq/payrex-python
6
6
  Author: PayRex
@@ -1,5 +1,6 @@
1
1
  import json
2
2
  import requests
3
+ import re
3
4
 
4
5
  from urllib.parse import urlencode
5
6
 
@@ -19,10 +20,18 @@ class HttpClient:
19
20
 
20
21
  auth = requests.auth.HTTPBasicAuth(self.api_key, '')
21
22
 
22
- headers = {'Content-Type': 'application/x-www-form-urlencoded'}
23
+ headers = {
24
+ 'Content-Type': 'application/x-www-form-urlencoded'
25
+ }
23
26
 
24
- if method.lower() in ['post', 'put']:
25
- data = self._encode_params(params)
27
+ if method.lower() in ['post', 'put', 'delete']:
28
+ data = re.sub(
29
+ r'%5B[\d+]%5D',
30
+ '%5B%5D',
31
+ urlencode(
32
+ self._http_build_query(params)
33
+ )
34
+ )
26
35
  else:
27
36
  data = None
28
37
 
@@ -36,6 +45,24 @@ class HttpClient:
36
45
 
37
46
  return ApiResource(response.json())
38
47
 
48
+ def _http_build_query(self, params, parent_key='', sep='&'):
49
+ items = []
50
+
51
+ for key, value in params.items():
52
+ new_key = f"{parent_key}[{key}]" if parent_key else key
53
+ if isinstance(value, dict):
54
+ items.extend(self._http_build_query(value, new_key, sep=sep).items())
55
+ elif isinstance(value, list):
56
+ for i, v in enumerate(value):
57
+ if isinstance(v, dict):
58
+ items.extend(self._http_build_query(v, f"{new_key}[{i}]", sep=sep).items())
59
+ else:
60
+ items.append((f"{new_key}[{i}]", v))
61
+ else:
62
+ items.append((new_key, value))
63
+
64
+ return dict(items)
65
+
39
66
  def _handle_error(self, response):
40
67
  try:
41
68
  json_response_body = response.json()
@@ -50,21 +77,3 @@ class HttpClient:
50
77
  raise ResourceNotFoundException(json_response_body)
51
78
  else:
52
79
  raise BaseException(json_response_body)
53
-
54
- def _encode_params(self, params):
55
- encoded_params = {}
56
- for key, value in params.items():
57
- if isinstance(value, list):
58
- for item in value:
59
- encoded_params.setdefault(f'{key}[]', []).append(item)
60
- elif isinstance(value, dict):
61
- for k, v in value.items():
62
- if isinstance(v, dict):
63
- for nk, nv in v.items():
64
- encoded_params.setdefault(f'{key}[{k}][{nk}]', []).append(nv)
65
- else:
66
- encoded_params.setdefault(f'{key}[{k}]', []).append(v)
67
- else:
68
- encoded_params[key] = value
69
-
70
- return urlencode(encoded_params, doseq=True)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: payrex-python
3
- Version: 0.1.3
3
+ Version: 0.1.4
4
4
  Summary: PayRex Python Library
5
5
  Home-page: https://github.com/payrexhq/payrex-python
6
6
  Author: PayRex
@@ -3,7 +3,7 @@ from pathlib import Path
3
3
 
4
4
  setup(
5
5
  name='payrex-python',
6
- version='0.1.3',
6
+ version='0.1.4',
7
7
  author='PayRex',
8
8
  author_email='support@payrexhq.com',
9
9
  description='PayRex Python Library',
File without changes
File without changes
@@ -10,11 +10,11 @@ from payrex.exceptions.value_unexpected_exception import ValueUnexpectedExceptio
10
10
 
11
11
  from payrex.http_client import HttpClient
12
12
 
13
+ from payrex.entities.payment_intent_entity import PaymentIntentEntity
13
14
  from payrex.entities.checkout_session_entity import CheckoutSessionEntity
14
15
  from payrex.entities.event_entity import EventEntity
15
16
  from payrex.entities.listing_entity import ListingEntity
16
17
  from payrex.entities.merchant_entity import MerchantEntity
17
- from payrex.entities.payment_intent_entity import PaymentIntentEntity
18
18
  from payrex.entities.payment_method_entity import PaymentMethodEntity
19
19
  from payrex.entities.refund_entity import RefundEntity
20
20
  from payrex.entities.webhook_entity import WebhookEntity
File without changes