python-payway 0.0.2__tar.gz → 0.0.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.
Files changed (36) hide show
  1. python_payway-0.0.4/LICENSE +21 -0
  2. python_payway-0.0.4/PKG-INFO +244 -0
  3. {python-payway-0.0.2 → python_payway-0.0.4}/README.md +60 -55
  4. python_payway-0.0.4/payway/client.py +367 -0
  5. python_payway-0.0.4/payway/conf.py +8 -0
  6. python_payway-0.0.4/payway/constants.py +134 -0
  7. python_payway-0.0.4/payway/customers.py +105 -0
  8. python_payway-0.0.4/payway/exceptions.py +22 -0
  9. {python-payway-0.0.2 → python_payway-0.0.4}/payway/model.py +161 -126
  10. python_payway-0.0.4/payway/test_utils.py +10 -0
  11. {python-payway-0.0.2 → python_payway-0.0.4}/payway/transactions.py +5 -3
  12. {python-payway-0.0.2 → python_payway-0.0.4}/payway/utils.py +9 -3
  13. python_payway-0.0.4/pyproject.toml +133 -0
  14. python_payway-0.0.4/python_payway.egg-info/PKG-INFO +244 -0
  15. {python-payway-0.0.2 → python_payway-0.0.4}/python_payway.egg-info/SOURCES.txt +3 -1
  16. python_payway-0.0.4/python_payway.egg-info/requires.txt +6 -0
  17. {python-payway-0.0.2 → python_payway-0.0.4}/python_payway.egg-info/top_level.txt +0 -1
  18. python_payway-0.0.4/tests/test_client.py +260 -0
  19. python_payway-0.0.4/tests/test_customers.py +217 -0
  20. python_payway-0.0.4/tests/test_transactions.py +33 -0
  21. python-payway-0.0.2/PKG-INFO +0 -235
  22. python-payway-0.0.2/payway/client.py +0 -277
  23. python-payway-0.0.2/payway/conf.py +0 -11
  24. python-payway-0.0.2/payway/constants.py +0 -135
  25. python-payway-0.0.2/payway/customers.py +0 -83
  26. python-payway-0.0.2/payway/exceptions.py +0 -31
  27. python-payway-0.0.2/python_payway.egg-info/PKG-INFO +0 -235
  28. python-payway-0.0.2/python_payway.egg-info/requires.txt +0 -1
  29. python-payway-0.0.2/setup.py +0 -28
  30. python-payway-0.0.2/tests/test_client.py +0 -393
  31. python-payway-0.0.2/tests/test_customers.py +0 -226
  32. python-payway-0.0.2/tests/test_transactions.py +0 -88
  33. {python-payway-0.0.2 → python_payway-0.0.4}/payway/__init__.py +0 -0
  34. {python-payway-0.0.2 → python_payway-0.0.4}/python_payway.egg-info/dependency_links.txt +0 -0
  35. {python-payway-0.0.2 → python_payway-0.0.4}/setup.cfg +0 -0
  36. {python-payway-0.0.2 → python_payway-0.0.4}/tests/__init__.py +0 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 Ben Napper
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 all
13
+ 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 THE
21
+ SOFTWARE.
@@ -0,0 +1,244 @@
1
+ Metadata-Version: 2.1
2
+ Name: python-payway
3
+ Version: 0.0.4
4
+ Summary: Python client for working with Westpac's PayWay REST API
5
+ Author-email: Ben Napper <reppan197@gmail.com>
6
+ License: MIT
7
+ Keywords: payway,westpac,api,client
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: requests>=2.20.0
15
+ Provides-Extra: dev
16
+ Requires-Dist: pre-commit>=3.5.0; extra == "dev"
17
+ Requires-Dist: ruff==0.6.6; extra == "dev"
18
+ Requires-Dist: mypy>=0.971; extra == "dev"
19
+
20
+ # PayWay REST API - Python
21
+
22
+ - Store customers, their card and bank account in PayWay
23
+ - Take payment using a stored credit card or bank account
24
+ - Process and Capture a pre-authorisation
25
+ - Lookup or poll transactions
26
+ - Refund transactions
27
+ - Void transactions
28
+ - Update a customer's payment setup in PayWay
29
+
30
+ ## Install
31
+
32
+ ```bash
33
+ pip install python-payway
34
+ ```
35
+
36
+ ## Take payment using a stored credit card
37
+
38
+ Create a Client class with your PayWay API credentials
39
+
40
+ ```python
41
+ from payway.client import Client
42
+
43
+ client = Client(merchant_id='<your_payway_merchant_id>',
44
+ bank_account_id='<your_payway_bank_account_id>',
45
+ publishable_api_key='<your_payway_publishable_api_key>',
46
+ secret_api_key='<your_payway_secret_api_key>')
47
+ ```
48
+
49
+ Create a PayWayCustomer class with your customer's details
50
+
51
+ ```python
52
+ customer = PayWayCustomer(custom_id='c981a',
53
+ customer_name='John Smith',
54
+ email_address='johnsmith@example.com',
55
+ send_email_receipts=False, # not available in sandbox
56
+ phone_number='0343232323',
57
+ street='1 Test Street',
58
+ street2='2 Test Street',
59
+ city_name='Sydney',
60
+ state='NSW',
61
+ postal_code='2000')
62
+ ```
63
+
64
+ Create a PayWayCard class with your customer's card details
65
+
66
+ ```python
67
+ card = PayWayCard(card_number='',
68
+ cvn='',
69
+ card_holder_name='',
70
+ expiry_date_month='',
71
+ expiry_date_year='')
72
+ ```
73
+
74
+ Create a token from your card and create a customer in PayWay
75
+
76
+ ```python
77
+ token_response, errors = client.create_card_token(card)
78
+ token = token_response.token
79
+ customer.token = token
80
+ payway_customer, customer_errors = client.create_customer(customer)
81
+ ```
82
+
83
+ Note the 'payway_customer' object contains the full customer response fields from PayWay.
84
+
85
+ Create a Payment class with the payment details and process the transaction
86
+
87
+ ```python
88
+ customer_number = payway_customer.customer_number
89
+ payment = PayWayPayment(customer_number=customer_number,
90
+ transaction_type='payment',
91
+ amount='',
92
+ currency='aud',
93
+ order_number='',
94
+ ip_address='')
95
+ transaction, errors = client.process_payment(payment)
96
+ ```
97
+
98
+ Check the `transaction` for the result
99
+
100
+ ```python
101
+ if not errors and transaction.status == 'approved':
102
+ # process successful response
103
+ ```
104
+
105
+ ## Take payment using a credit card token only
106
+
107
+ ```python
108
+ client = Client(merchant_id='',
109
+ bank_account_id='',
110
+ publishable_api_key='',
111
+ secret_api_key='')
112
+ card = PayWayCard(card_number='',
113
+ cvn='',
114
+ card_holder_name='',
115
+ expiry_date_month='',
116
+ expiry_date_year='')
117
+ token_response, errors = client.create_card_token(card)
118
+ # your customer reference number or a stored PayWay customer number
119
+ customer_number = ''
120
+ payment = PayWayPayment(customer_number=customer_number,
121
+ transaction_type='payment',
122
+ amount='',
123
+ currency='aud',
124
+ order_number='',
125
+ ip_address='',
126
+ token=token_response.token,
127
+ merchant_id=client.merchant_id)
128
+ transaction, errors = client.process_payment(payment)
129
+ ```
130
+
131
+ ## Handling errors
132
+
133
+ Documented errors (such as 422 Unprocessable entity) are parsed into an PaymentError class that you can use in an customer error message.
134
+ For more info, visit <https://www.payway.com.au/docs/rest.html#http-response-codes>
135
+
136
+ ```python
137
+ if errors:
138
+ for error in errors:
139
+ print(error.field_name)
140
+ print(error.message)
141
+ print(error.field_name)
142
+ # or use a method
143
+ PaymentError().list_to_message(errors)
144
+ ```
145
+
146
+ ## Direct Debit
147
+
148
+ Direct debit transactions are possible by creating a token from a bank account:
149
+
150
+ ```python
151
+ bank_account = BankAccount(account_name='Test', bsb='000-000', account_number=123456)
152
+ token_response, errors = client.create_bank_account_token(bank_account)
153
+ token = token_response.token
154
+ ```
155
+
156
+ Store the token with a customer in PayWay using the same process as the card outlined above.
157
+
158
+ Note: direct debit transactions take days to process so they must be polled regularly for the latest transaction status from the customer's bank.
159
+
160
+ ## Lookup transaction
161
+
162
+ Poll a transaction using the `get_transaction` method.
163
+
164
+ ```python
165
+ transaction, errors = client.get_transaction(transaction.transaction_id)
166
+ ```
167
+
168
+ ## Process and capture a pre-authorisation
169
+
170
+ To process a credit card pre-authorisation using a credit card stored against a customer use `preAuth` as the `transaction_type` along with the customer's PayWay number, amount and currency.
171
+
172
+ ```python
173
+ pre_auth_payment = PayWayPayment(customer_number='',
174
+ transaction_type='preAuth',
175
+ amount='',
176
+ currency='aud',
177
+ order_number='',
178
+ ip_address='')
179
+ transaction, errors = client.process_payment(pre_auth_payment)
180
+ ```
181
+
182
+ To capture the pre-authorisation supply a pre-authorisation transaction ID, `capture` as the `transaction_type` along with an amount to capture.
183
+
184
+ ```python
185
+ capture_payment = PayWayPayment(transaction_type='capture',
186
+ parent_transaction_id='',
187
+ amount='',
188
+ order_number='',
189
+ ip_address='')
190
+ transaction, errors = client.process_payment(capture_payment)
191
+ ```
192
+
193
+ ## Refunds
194
+
195
+ Refund a transaction by supplying a PayWay transaction ID and the refund amount.
196
+
197
+ ```python
198
+ refund, errors = client.refund_transaction(
199
+ transaction_id=transaction.transaction_id,
200
+ amount=transaction.principal_amount,
201
+ )
202
+ ```
203
+
204
+ ## Voiding a transaction
205
+
206
+ Void a transaction by supplying a PayWay transaction ID.
207
+
208
+ ```python
209
+ void_transaction, errors = client.void_transaction(transaction.transaction_id)
210
+ ```
211
+
212
+ ## Update Payment Setup
213
+
214
+ Update a customer's payment setup with a new credit card or bank account in PayWay. Supply the new token and an existing PayWay customer number.
215
+
216
+ ```python
217
+ payment_setup, errors = client.update_payment_setup(new_token, payway_customer.customer_number)
218
+ ```
219
+
220
+ ## Additional notes
221
+
222
+ PayWay API documentation <https://www.payway.com.au/docs/rest.html>
223
+
224
+ It is recommended to use PayWay's Trusted Frame <https://www.payway.com.au/docs/rest.html#trusted-frame>
225
+ when creating a single use token of a card or bank account so your PCI-compliance scope is reduced.
226
+
227
+ ## Fraud
228
+
229
+ Please follow PayWay's advice about reducing your risk of fraudulent transactions. <https://www.payway.com.au/docs/card-testing.html#card-testing>
230
+
231
+ ## Running the project
232
+
233
+ ```bash
234
+ uv python install 3.8.19
235
+ uv venv
236
+ source .venv/bin/activate
237
+ uv sync --extra dev
238
+ ```
239
+
240
+ ## Testing
241
+
242
+ ```bash
243
+ python -m unittest discover tests
244
+ ```
@@ -1,4 +1,4 @@
1
- # `PayWay REST API - Python`
1
+ # PayWay REST API - Python
2
2
 
3
3
  - Store customers, their card and bank account in PayWay
4
4
  - Take payment using a stored credit card or bank account
@@ -8,29 +8,28 @@
8
8
  - Void transactions
9
9
  - Update a customer's payment setup in PayWay
10
10
 
11
- # `Install`
11
+ ## Install
12
12
 
13
- ```
13
+ ```bash
14
14
  pip install python-payway
15
15
  ```
16
16
 
17
- # `Take payment using a stored credit card`
17
+ ## Take payment using a stored credit card
18
18
 
19
19
  Create a Client class with your PayWay API credentials
20
20
 
21
- ```
22
- from payway.model import *
23
- from payway.client import *
21
+ ```python
22
+ from payway.client import Client
24
23
 
25
- client = Client(merchant_id='',
26
- bank_account_id='',
27
- publishable_api_key='',
28
- secret_api_key='')
24
+ client = Client(merchant_id='<your_payway_merchant_id>',
25
+ bank_account_id='<your_payway_bank_account_id>',
26
+ publishable_api_key='<your_payway_publishable_api_key>',
27
+ secret_api_key='<your_payway_secret_api_key>')
29
28
  ```
30
-
29
+
31
30
  Create a PayWayCustomer class with your customer's details
32
31
 
33
- ```
32
+ ```python
34
33
  customer = PayWayCustomer(custom_id='c981a',
35
34
  customer_name='John Smith',
36
35
  email_address='johnsmith@example.com',
@@ -42,10 +41,10 @@ customer = PayWayCustomer(custom_id='c981a',
42
41
  state='NSW',
43
42
  postal_code='2000')
44
43
  ```
45
-
44
+
46
45
  Create a PayWayCard class with your customer's card details
47
46
 
48
- ```
47
+ ```python
49
48
  card = PayWayCard(card_number='',
50
49
  cvn='',
51
50
  card_holder_name='',
@@ -55,7 +54,7 @@ card = PayWayCard(card_number='',
55
54
 
56
55
  Create a token from your card and create a customer in PayWay
57
56
 
58
- ```
57
+ ```python
59
58
  token_response, errors = client.create_card_token(card)
60
59
  token = token_response.token
61
60
  customer.token = token
@@ -63,10 +62,10 @@ payway_customer, customer_errors = client.create_customer(customer)
63
62
  ```
64
63
 
65
64
  Note the 'payway_customer' object contains the full customer response fields from PayWay.
66
-
65
+
67
66
  Create a Payment class with the payment details and process the transaction
68
67
 
69
- ```
68
+ ```python
70
69
  customer_number = payway_customer.customer_number
71
70
  payment = PayWayPayment(customer_number=customer_number,
72
71
  transaction_type='payment',
@@ -75,18 +74,18 @@ payment = PayWayPayment(customer_number=customer_number,
75
74
  order_number='',
76
75
  ip_address='')
77
76
  transaction, errors = client.process_payment(payment)
78
- ```
79
-
77
+ ```
78
+
80
79
  Check the `transaction` for the result
81
80
 
82
- ```
81
+ ```python
83
82
  if not errors and transaction.status == 'approved':
84
83
  # process successful response
85
84
  ```
86
85
 
87
- # `Take payment using a credit card token only`
86
+ ## Take payment using a credit card token only
88
87
 
89
- ```
88
+ ```python
90
89
  client = Client(merchant_id='',
91
90
  bank_account_id='',
92
91
  publishable_api_key='',
@@ -110,12 +109,12 @@ payment = PayWayPayment(customer_number=customer_number,
110
109
  transaction, errors = client.process_payment(payment)
111
110
  ```
112
111
 
113
- # `Handling errors`
112
+ ## Handling errors
114
113
 
115
114
  Documented errors (such as 422 Unprocessable entity) are parsed into an PaymentError class that you can use in an customer error message.
116
- https://www.payway.com.au/docs/rest.html#http-response-codes
115
+ For more info, visit <https://www.payway.com.au/docs/rest.html#http-response-codes>
117
116
 
118
- ```
117
+ ```python
119
118
  if errors:
120
119
  for error in errors:
121
120
  print(error.field_name)
@@ -123,12 +122,13 @@ if errors:
123
122
  print(error.field_name)
124
123
  # or use a method
125
124
  PaymentError().list_to_message(errors)
126
- ```
125
+ ```
126
+
127
+ ## Direct Debit
127
128
 
128
- # `Direct Debit`
129
129
  Direct debit transactions are possible by creating a token from a bank account:
130
130
 
131
- ```
131
+ ```python
132
132
  bank_account = BankAccount(account_name='Test', bsb='000-000', account_number=123456)
133
133
  token_response, errors = client.create_bank_account_token(bank_account)
134
134
  token = token_response.token
@@ -138,19 +138,19 @@ Store the token with a customer in PayWay using the same process as the card out
138
138
 
139
139
  Note: direct debit transactions take days to process so they must be polled regularly for the latest transaction status from the customer's bank.
140
140
 
141
- # `Lookup transaction`
141
+ ## Lookup transaction
142
142
 
143
143
  Poll a transaction using the `get_transaction` method.
144
144
 
145
- ```
145
+ ```python
146
146
  transaction, errors = client.get_transaction(transaction.transaction_id)
147
- ```
147
+ ```
148
148
 
149
- # `Process and capture a pre-authorisation`
149
+ ## Process and capture a pre-authorisation
150
150
 
151
151
  To process a credit card pre-authorisation using a credit card stored against a customer use `preAuth` as the `transaction_type` along with the customer's PayWay number, amount and currency.
152
152
 
153
- ```
153
+ ```python
154
154
  pre_auth_payment = PayWayPayment(customer_number='',
155
155
  transaction_type='preAuth',
156
156
  amount='',
@@ -162,7 +162,7 @@ transaction, errors = client.process_payment(pre_auth_payment)
162
162
 
163
163
  To capture the pre-authorisation supply a pre-authorisation transaction ID, `capture` as the `transaction_type` along with an amount to capture.
164
164
 
165
- ```
165
+ ```python
166
166
  capture_payment = PayWayPayment(transaction_type='capture',
167
167
  parent_transaction_id='',
168
168
  amount='',
@@ -171,50 +171,55 @@ capture_payment = PayWayPayment(transaction_type='capture',
171
171
  transaction, errors = client.process_payment(capture_payment)
172
172
  ```
173
173
 
174
- # `Refunds`
174
+ ## Refunds
175
175
 
176
176
  Refund a transaction by supplying a PayWay transaction ID and the refund amount.
177
177
 
178
- ```
178
+ ```python
179
179
  refund, errors = client.refund_transaction(
180
180
  transaction_id=transaction.transaction_id,
181
181
  amount=transaction.principal_amount,
182
182
  )
183
183
  ```
184
184
 
185
- # `Voiding a transaction`
185
+ ## Voiding a transaction
186
186
 
187
187
  Void a transaction by supplying a PayWay transaction ID.
188
188
 
189
- ```
189
+ ```python
190
190
  void_transaction, errors = client.void_transaction(transaction.transaction_id)
191
191
  ```
192
192
 
193
- # `Update Payment Setup`
193
+ ## Update Payment Setup
194
194
 
195
195
  Update a customer's payment setup with a new credit card or bank account in PayWay. Supply the new token and an existing PayWay customer number.
196
196
 
197
- ```
197
+ ```python
198
198
  payment_setup, errors = client.update_payment_setup(new_token, payway_customer.customer_number)
199
199
  ```
200
200
 
201
- # `Additional notes`
202
- PayWay API documentation
203
- https://www.payway.com.au/docs/rest.html
201
+ ## Additional notes
202
+
203
+ PayWay API documentation <https://www.payway.com.au/docs/rest.html>
204
204
 
205
- It is recommended to use PayWay's Trusted Frame https://www.payway.com.au/docs/rest.html#trusted-frame
205
+ It is recommended to use PayWay's Trusted Frame <https://www.payway.com.au/docs/rest.html#trusted-frame>
206
206
  when creating a single use token of a card or bank account so your PCI-compliance scope is reduced.
207
207
 
208
- # `Fraud`
208
+ ## Fraud
209
209
 
210
- Please follow PayWay's advice about reducing your risk of fraudulent transactions.
211
- https://www.payway.com.au/docs/card-testing.html#card-testing
210
+ Please follow PayWay's advice about reducing your risk of fraudulent transactions. <https://www.payway.com.au/docs/card-testing.html#card-testing>
212
211
 
213
- # `Testing`
212
+ ## Running the project
214
213
 
215
- 1. Sign up for a PayWay sandbox account: https://www.payway.com.au/sandbox
216
- 2. Test the integration by adding your PayWay REST API keys to your local environment. These keys are in Account Settings > `REST API Keys`. Copy your `Publishable` and `Secret` API keys.
217
- 3. `export PAYWAY_PUBLISHABLE_API_KEY="your PayWay Publishable API Key"`
218
- 4. `export PAYWAY_SECRET_API_KEY="your PayWay Secret API Key"`
219
- 5. Run the tests to ensure the integration is working.
220
- `python -m unittest discover tests`
214
+ ```bash
215
+ uv python install 3.8.19
216
+ uv venv
217
+ source .venv/bin/activate
218
+ uv sync --extra dev
219
+ ```
220
+
221
+ ## Testing
222
+
223
+ ```bash
224
+ python -m unittest discover tests
225
+ ```