payrex-python 0.1.0__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.
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) Evolut10n Labs, Inc. (https://payrexhq.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,114 @@
1
+ Metadata-Version: 2.1
2
+ Name: payrex-python
3
+ Version: 0.1.0
4
+ Summary: PayRex Python Library
5
+ Home-page: https://github.com/payrexhq/payrex-python
6
+ Author: PayRex
7
+ Author-email: support@payrexhq.com
8
+ License: MIT
9
+ Keywords: payrex
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: requests
19
+
20
+ # PayRex Python
21
+
22
+ PayRex Python library provides Python applications an easy access to the PayRex API. Explore various Python classes that represents PayRex API resources on object instantiation.
23
+
24
+ ## Requirements
25
+
26
+ Python 3.9.+
27
+
28
+ ## Installation
29
+
30
+ If you want to use the package, run the following command:
31
+
32
+ ```sh
33
+ pip install payrex-python
34
+ ```
35
+
36
+ If you want to build the library from source:
37
+
38
+ Create a virtual environment
39
+
40
+ ```sh
41
+ python -m venv venv
42
+ ```
43
+
44
+ Activate the virtual environment
45
+
46
+ ```sh
47
+ source venv/bin/activate
48
+ ```
49
+
50
+ Install the package to the virtual environment
51
+
52
+ ```sh
53
+ pip install -e /Your/Local/Path/payrex-python
54
+
55
+ python
56
+ ```
57
+
58
+ ## Getting Started
59
+
60
+ Simple usage looks like:
61
+
62
+ ```python
63
+ from payrex import Client as PayrexClient
64
+
65
+ payrex_client = PayrexClient('sk_test_...')
66
+ payment_intent = payrex_client.payment_intents.retrieve('pi_...')
67
+
68
+ payment_intent = payrex_client.payment_intents.create(
69
+ {
70
+ 'amount': 10000,
71
+ 'currency': 'PHP',
72
+ 'description': 'Dino Treat',
73
+ 'payment_methods': ['gcash']
74
+ }
75
+ )
76
+ ```
77
+
78
+ ## Handle errors
79
+
80
+ ```python
81
+ try:
82
+ payrex_client = PayrexClient('sk_test_...')
83
+
84
+ payment_intent = payrex_client.payment_intents.create(
85
+ {
86
+ 'amount': 10000,
87
+ 'description': 'Dino Treat',
88
+ 'payment_methods': ['gcash']
89
+ }
90
+ )
91
+ except BaseException as e:
92
+ # Handle error
93
+ print(type(e))
94
+ print(e.errors[0].code)
95
+ print(e.errors[0].detail)
96
+ print(e.errors[0].parameter)
97
+ ```
98
+
99
+ ## Verify webhook signature
100
+
101
+ ```python
102
+ try:
103
+ payload = '{"id":"evt_...","resource":"event","type":"payment_intent.succeeded","data":{...'
104
+ signature_header = 't=1715236958,te=,li=...'
105
+ webhook_secret_key = 'whsk_...'
106
+
107
+ payrex_client.webhooks.parse_event(
108
+ payload,
109
+ signature_header,
110
+ webhook_secret_key
111
+ )
112
+ except SignatureVerificationException as e:
113
+ # Handle invalid signature
114
+ ```
@@ -0,0 +1,95 @@
1
+ # PayRex Python
2
+
3
+ PayRex Python library provides Python applications an easy access to the PayRex API. Explore various Python classes that represents PayRex API resources on object instantiation.
4
+
5
+ ## Requirements
6
+
7
+ Python 3.9.+
8
+
9
+ ## Installation
10
+
11
+ If you want to use the package, run the following command:
12
+
13
+ ```sh
14
+ pip install payrex-python
15
+ ```
16
+
17
+ If you want to build the library from source:
18
+
19
+ Create a virtual environment
20
+
21
+ ```sh
22
+ python -m venv venv
23
+ ```
24
+
25
+ Activate the virtual environment
26
+
27
+ ```sh
28
+ source venv/bin/activate
29
+ ```
30
+
31
+ Install the package to the virtual environment
32
+
33
+ ```sh
34
+ pip install -e /Your/Local/Path/payrex-python
35
+
36
+ python
37
+ ```
38
+
39
+ ## Getting Started
40
+
41
+ Simple usage looks like:
42
+
43
+ ```python
44
+ from payrex import Client as PayrexClient
45
+
46
+ payrex_client = PayrexClient('sk_test_...')
47
+ payment_intent = payrex_client.payment_intents.retrieve('pi_...')
48
+
49
+ payment_intent = payrex_client.payment_intents.create(
50
+ {
51
+ 'amount': 10000,
52
+ 'currency': 'PHP',
53
+ 'description': 'Dino Treat',
54
+ 'payment_methods': ['gcash']
55
+ }
56
+ )
57
+ ```
58
+
59
+ ## Handle errors
60
+
61
+ ```python
62
+ try:
63
+ payrex_client = PayrexClient('sk_test_...')
64
+
65
+ payment_intent = payrex_client.payment_intents.create(
66
+ {
67
+ 'amount': 10000,
68
+ 'description': 'Dino Treat',
69
+ 'payment_methods': ['gcash']
70
+ }
71
+ )
72
+ except BaseException as e:
73
+ # Handle error
74
+ print(type(e))
75
+ print(e.errors[0].code)
76
+ print(e.errors[0].detail)
77
+ print(e.errors[0].parameter)
78
+ ```
79
+
80
+ ## Verify webhook signature
81
+
82
+ ```python
83
+ try:
84
+ payload = '{"id":"evt_...","resource":"event","type":"payment_intent.succeeded","data":{...'
85
+ signature_header = 't=1715236958,te=,li=...'
86
+ webhook_secret_key = 'whsk_...'
87
+
88
+ payrex_client.webhooks.parse_event(
89
+ payload,
90
+ signature_header,
91
+ webhook_secret_key
92
+ )
93
+ except SignatureVerificationException as e:
94
+ # Handle invalid signature
95
+ ```
@@ -0,0 +1,32 @@
1
+ from payrex.api_resource import ApiResource
2
+ from payrex.error import Error
3
+
4
+ from payrex.exceptions.base_exception import BaseException
5
+ from payrex.exceptions.authentication_invalid_exception import AuthenticationInvalidException
6
+ from payrex.exceptions.request_invalid_exception import RequestInvalidException
7
+ from payrex.exceptions.resource_not_found_exception import ResourceNotFoundException
8
+ from payrex.exceptions.signature_invalid_exception import SignatureInvalidException
9
+ from payrex.exceptions.value_unexpected_exception import ValueUnexpectedException
10
+
11
+ from payrex.http_client import HttpClient
12
+
13
+ from payrex.entities.checkout_session_entity import CheckoutSessionEntity
14
+ from payrex.entities.event_entity import EventEntity
15
+ from payrex.entities.listing_entity import ListingEntity
16
+ from payrex.entities.merchant_entity import MerchantEntity
17
+ from payrex.entities.payment_intent_entity import PaymentIntentEntity
18
+ from payrex.entities.payment_method_entity import PaymentMethodEntity
19
+ from payrex.entities.refund_entity import RefundEntity
20
+ from payrex.entities.webhook_entity import WebhookEntity
21
+
22
+ from payrex.services.base_service import BaseService
23
+ from payrex.services.checkout_session_service import CheckoutSessionService
24
+ from payrex.services.merchant_service import MerchantService
25
+ from payrex.services.payment_intent_service import PaymentIntentService
26
+ from payrex.services.payment_method_service import PaymentMethodService
27
+ from payrex.services.refund_service import RefundService
28
+ from payrex.services.webhook_service import WebhookService
29
+ from payrex.services.service_factory import ServiceFactory
30
+
31
+ from payrex.config import Config
32
+ from payrex.client import Client
@@ -0,0 +1,3 @@
1
+ class ApiResource:
2
+ def __init__(self, response):
3
+ self.data = response
@@ -0,0 +1,12 @@
1
+ from payrex import Config
2
+ from payrex import ServiceFactory
3
+
4
+ class Client:
5
+ def __init__(self, api_key):
6
+ self.config = Config(api_key)
7
+ self._initialize_services()
8
+
9
+ def _initialize_services(self):
10
+ for name in ServiceFactory.names():
11
+ service = ServiceFactory.get(name)
12
+ setattr(self, f'{name}s', service(self))
@@ -0,0 +1,6 @@
1
+ class Config:
2
+ API_BASE_URL = 'https://api.payrexhq.com'
3
+
4
+ def __init__(self, api_key):
5
+ self.api_base_url = self.API_BASE_URL
6
+ self.api_key = api_key
@@ -0,0 +1,5 @@
1
+ class Error:
2
+ def __init__(self, error):
3
+ self.code = error.get('code')
4
+ self.detail = error.get('detail')
5
+ self.parameter = error.get('parameter')
@@ -0,0 +1,64 @@
1
+ import json
2
+ import requests
3
+
4
+ from urllib.parse import urlencode
5
+
6
+ from payrex import ApiResource
7
+ from payrex import BaseException
8
+ from payrex import RequestInvalidException
9
+ from payrex import AuthenticationInvalidException
10
+ from payrex import ResourceNotFoundException
11
+
12
+ class HttpClient:
13
+ def __init__(self, api_key, base_url):
14
+ self.api_key = api_key
15
+ self.base_url = base_url
16
+
17
+ def request(self, method, params=None, path=None):
18
+ url = f'{self.base_url}/{path}'
19
+
20
+ auth = requests.auth.HTTPBasicAuth(self.api_key, '')
21
+
22
+ headers = {'Content-Type': 'application/x-www-form-urlencoded'}
23
+
24
+ if method.lower() in ['post', 'put']:
25
+ data = self._encode_params(params)
26
+ else:
27
+ data = None
28
+
29
+ response = requests.request(method, url, auth=auth, headers=headers, data=data)
30
+
31
+ if response.status_code != 200:
32
+ self._handle_error(response)
33
+
34
+ return ApiResource(response.json())
35
+
36
+ def _handle_error(self, response):
37
+ json_response_body = response.json()
38
+
39
+ if response.status_code == 400:
40
+ raise RequestInvalidException(json_response_body)
41
+ elif response.status_code == 401:
42
+ raise AuthenticationInvalidException(json_response_body)
43
+ elif response.status_code == 404:
44
+ raise ResourceNotFoundException(json_response_body)
45
+ else:
46
+ raise BaseException(json_response_body)
47
+
48
+ def _encode_params(self, params):
49
+ encoded_params = {}
50
+ for key, value in params.items():
51
+ if isinstance(value, list):
52
+ for item in value:
53
+ encoded_params.setdefault(f'{key}[]', []).append(item)
54
+ elif isinstance(value, dict):
55
+ for k, v in value.items():
56
+ if isinstance(v, dict):
57
+ for nk, nv in v.items():
58
+ encoded_params.setdefault(f'{key}[{k}][{nk}]', []).append(nv)
59
+ else:
60
+ encoded_params.setdefault(f'{key}[{k}]', []).append(v)
61
+ else:
62
+ encoded_params[key] = value
63
+
64
+ return urlencode(encoded_params, doseq=True)
@@ -0,0 +1,28 @@
1
+ import re
2
+
3
+ from payrex import BaseService
4
+ from payrex import CheckoutSessionService
5
+ from payrex import MerchantService
6
+ from payrex import PaymentIntentService
7
+ from payrex import PaymentMethodService
8
+ from payrex import RefundService
9
+ from payrex import WebhookService
10
+
11
+ class ServiceFactory:
12
+ @staticmethod
13
+ def get(name):
14
+ service_name = ''.join(word.capitalize() for word in name.split('_'))
15
+ service_class = globals().get(service_name + 'Service')
16
+
17
+ if not isinstance(service_class, type):
18
+ raise ValueError(f'Unknown service: {name}')
19
+
20
+ return service_class
21
+
22
+ @staticmethod
23
+ def names():
24
+ return [
25
+ re.sub(r'(?<!^)(?=[A-Z])', '_', c.__name__.split('Service')[0]).lower()
26
+
27
+ for c in BaseService.__subclasses__()
28
+ ]
@@ -0,0 +1,114 @@
1
+ Metadata-Version: 2.1
2
+ Name: payrex-python
3
+ Version: 0.1.0
4
+ Summary: PayRex Python Library
5
+ Home-page: https://github.com/payrexhq/payrex-python
6
+ Author: PayRex
7
+ Author-email: support@payrexhq.com
8
+ License: MIT
9
+ Keywords: payrex
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: requests
19
+
20
+ # PayRex Python
21
+
22
+ PayRex Python library provides Python applications an easy access to the PayRex API. Explore various Python classes that represents PayRex API resources on object instantiation.
23
+
24
+ ## Requirements
25
+
26
+ Python 3.9.+
27
+
28
+ ## Installation
29
+
30
+ If you want to use the package, run the following command:
31
+
32
+ ```sh
33
+ pip install payrex-python
34
+ ```
35
+
36
+ If you want to build the library from source:
37
+
38
+ Create a virtual environment
39
+
40
+ ```sh
41
+ python -m venv venv
42
+ ```
43
+
44
+ Activate the virtual environment
45
+
46
+ ```sh
47
+ source venv/bin/activate
48
+ ```
49
+
50
+ Install the package to the virtual environment
51
+
52
+ ```sh
53
+ pip install -e /Your/Local/Path/payrex-python
54
+
55
+ python
56
+ ```
57
+
58
+ ## Getting Started
59
+
60
+ Simple usage looks like:
61
+
62
+ ```python
63
+ from payrex import Client as PayrexClient
64
+
65
+ payrex_client = PayrexClient('sk_test_...')
66
+ payment_intent = payrex_client.payment_intents.retrieve('pi_...')
67
+
68
+ payment_intent = payrex_client.payment_intents.create(
69
+ {
70
+ 'amount': 10000,
71
+ 'currency': 'PHP',
72
+ 'description': 'Dino Treat',
73
+ 'payment_methods': ['gcash']
74
+ }
75
+ )
76
+ ```
77
+
78
+ ## Handle errors
79
+
80
+ ```python
81
+ try:
82
+ payrex_client = PayrexClient('sk_test_...')
83
+
84
+ payment_intent = payrex_client.payment_intents.create(
85
+ {
86
+ 'amount': 10000,
87
+ 'description': 'Dino Treat',
88
+ 'payment_methods': ['gcash']
89
+ }
90
+ )
91
+ except BaseException as e:
92
+ # Handle error
93
+ print(type(e))
94
+ print(e.errors[0].code)
95
+ print(e.errors[0].detail)
96
+ print(e.errors[0].parameter)
97
+ ```
98
+
99
+ ## Verify webhook signature
100
+
101
+ ```python
102
+ try:
103
+ payload = '{"id":"evt_...","resource":"event","type":"payment_intent.succeeded","data":{...'
104
+ signature_header = 't=1715236958,te=,li=...'
105
+ webhook_secret_key = 'whsk_...'
106
+
107
+ payrex_client.webhooks.parse_event(
108
+ payload,
109
+ signature_header,
110
+ webhook_secret_key
111
+ )
112
+ except SignatureVerificationException as e:
113
+ # Handle invalid signature
114
+ ```
@@ -0,0 +1,15 @@
1
+ LICENSE
2
+ README.md
3
+ setup.py
4
+ payrex/__init__.py
5
+ payrex/api_resource.py
6
+ payrex/client.py
7
+ payrex/config.py
8
+ payrex/error.py
9
+ payrex/http_client.py
10
+ payrex/services/service_factory.py
11
+ payrex_python.egg-info/PKG-INFO
12
+ payrex_python.egg-info/SOURCES.txt
13
+ payrex_python.egg-info/dependency_links.txt
14
+ payrex_python.egg-info/requires.txt
15
+ payrex_python.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ requests
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,27 @@
1
+ from setuptools import setup, find_packages
2
+ from pathlib import Path
3
+
4
+ setup(
5
+ name='payrex-python',
6
+ version='0.1.0',
7
+ author='PayRex',
8
+ author_email='support@payrexhq.com',
9
+ description='PayRex Python Library',
10
+ long_description=(Path(__file__).parent / 'README.md').read_text(),
11
+ long_description_content_type='text/markdown',
12
+ packages=find_packages(),
13
+ install_requires=[
14
+ 'requests'
15
+ ],
16
+ keywords='payrex',
17
+ classifiers=[
18
+ 'Development Status :: 4 - Beta',
19
+ 'Intended Audience :: Developers',
20
+ 'Operating System :: OS Independent',
21
+ 'Programming Language :: Python',
22
+ 'Programming Language :: Python :: 3',
23
+ 'License :: OSI Approved :: MIT License'
24
+ ],
25
+ license='MIT',
26
+ url='https://github.com/payrexhq/payrex-python'
27
+ )