Skip to content

Commit 2e190cb

Browse files
authored
Merge pull request #1 from napper1/feature/typing
Add typing
2 parents 0b336ce + 21e1efe commit 2e190cb

27 files changed

+1125
-628
lines changed

.github/workflows/ci.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: CI Workflow
2+
3+
on:
4+
release:
5+
types: [published]
6+
push:
7+
branches:
8+
- master
9+
pull_request:
10+
11+
jobs:
12+
build:
13+
timeout-minutes: 10
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Install uv
18+
uses: astral-sh/setup-uv@v4
19+
with:
20+
enable-cache: true
21+
cache-dependency-glob: "uv.lock"
22+
- name: Set up Python 3.8
23+
run: uv python install 3.8.19
24+
- name: Install the project
25+
run: uv sync --extra dev
26+
- name: Run pre-commit
27+
run: uv run pre-commit run --all-files --config .pre-commit-config.ci.yaml
28+
- name: Run tests
29+
run: uv run python -m unittest discover tests

.gitignore

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,13 @@ __pycache__/
2424
dist/
2525
build/
2626
*.egg-info
27-
.envrc
27+
.envrc
28+
.env
29+
.venv
30+
env/
31+
venv/
32+
ENV/
33+
env.bak/
34+
venv.bak/
35+
.ruff_cache
36+
.mypy_cache

.pre-commit-config.ci.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
repos:
2+
- repo: https://github.com/charliermarsh/ruff-pre-commit
3+
rev: v0.6.6
4+
hooks:
5+
# Run linter
6+
- id: ruff
7+
language: system
8+
types_or: [ python, pyi, ]
9+
args: [--fix, --exit-non-zero-on-fix, --select, I]
10+
# Run formatter
11+
- id: ruff-format
12+
language: system
13+
types_or: [ python, pyi, ]
14+
15+
- repo: https://github.com/pre-commit/pre-commit-hooks
16+
rev: v4.6.0
17+
hooks:
18+
- id: trailing-whitespace
19+
exclude: "(^static/|/static/|^fobi/|.md$|.django.po$|.csv$)"
20+
- id: end-of-file-fixer
21+
exclude: "(^static/|/static/|^fobi/)"
22+
- id: debug-statements
23+
- id: check-added-large-files
24+
- id: check-merge-conflict
25+
- id: mixed-line-ending
26+
args: ["--fix=lf"]
27+
exclude: "^(static/|theme/|fixtures/static/|core/static/|fobi/)"
28+
29+
- repo: https://github.com/pycqa/bandit
30+
rev: 1.7.9
31+
hooks:
32+
- id: bandit
33+
args: ['-iii', '-ll', "-c", "pyproject.toml"]
34+
additional_dependencies: ["bandit[toml]"]

.pre-commit-config.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v5.0.0
4+
hooks:
5+
- id: trailing-whitespace
6+
exclude: "(^static/|/static/|^fobi/|.md$|.django.po$|.csv$)"
7+
- id: end-of-file-fixer
8+
exclude: "(^static/|/static/|^fobi/)"
9+
- id: debug-statements
10+
- id: check-added-large-files
11+
- id: check-merge-conflict
12+
- id: check-json
13+
- id: check-toml
14+
- id: detect-private-key
15+
- id: check-builtin-literals
16+
- id: check-case-conflict
17+
18+
- repo: https://github.com/pycqa/bandit
19+
rev: 1.7.10
20+
hooks:
21+
- id: bandit
22+
args: ['-iii', '-ll', "-c", "pyproject.toml"]
23+
additional_dependencies: ["bandit[toml]"]
24+
25+
- repo: https://github.com/charliermarsh/ruff-pre-commit
26+
rev: v0.6.6
27+
hooks:
28+
- id: ruff
29+
args: [ --fix ]
30+
- id: ruff-format

README.md

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
- Void transactions
99
- Update a customer's payment setup in PayWay
1010

11-
# Install
11+
## Install
1212

13-
```
13+
```bash
1414
pip install python-payway
1515
```
1616

17-
# Take payment using a stored credit card
17+
## Take payment using a stored credit card
1818

1919
Create a Client class with your PayWay API credentials
2020

@@ -41,7 +41,7 @@ customer = PayWayCustomer(custom_id='c981a',
4141
state='NSW',
4242
postal_code='2000')
4343
```
44-
44+
4545
Create a PayWayCard class with your customer's card details
4646

4747
```python
@@ -62,7 +62,7 @@ payway_customer, customer_errors = client.create_customer(customer)
6262
```
6363

6464
Note the 'payway_customer' object contains the full customer response fields from PayWay.
65-
65+
6666
Create a Payment class with the payment details and process the transaction
6767

6868
```python
@@ -74,16 +74,16 @@ payment = PayWayPayment(customer_number=customer_number,
7474
order_number='',
7575
ip_address='')
7676
transaction, errors = client.process_payment(payment)
77-
```
78-
77+
```
78+
7979
Check the `transaction` for the result
8080

8181
```python
8282
if not errors and transaction.status == 'approved':
8383
# process successful response
8484
```
8585

86-
# Take payment using a credit card token only
86+
## Take payment using a credit card token only
8787

8888
```python
8989
client = Client(merchant_id='',
@@ -109,10 +109,10 @@ payment = PayWayPayment(customer_number=customer_number,
109109
transaction, errors = client.process_payment(payment)
110110
```
111111

112-
# Handling errors
112+
## Handling errors
113113

114114
Documented errors (such as 422 Unprocessable entity) are parsed into an PaymentError class that you can use in an customer error message.
115-
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>
116116

117117
```python
118118
if errors:
@@ -122,9 +122,10 @@ if errors:
122122
print(error.field_name)
123123
# or use a method
124124
PaymentError().list_to_message(errors)
125-
```
125+
```
126+
127+
## Direct Debit
126128

127-
# Direct Debit
128129
Direct debit transactions are possible by creating a token from a bank account:
129130

130131
```python
@@ -137,15 +138,15 @@ Store the token with a customer in PayWay using the same process as the card out
137138

138139
Note: direct debit transactions take days to process so they must be polled regularly for the latest transaction status from the customer's bank.
139140

140-
# Lookup transaction
141+
## Lookup transaction
141142

142143
Poll a transaction using the `get_transaction` method.
143144

144145
```python
145146
transaction, errors = client.get_transaction(transaction.transaction_id)
146-
```
147+
```
147148

148-
# Process and capture a pre-authorisation
149+
## Process and capture a pre-authorisation
149150

150151
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.
151152

@@ -170,7 +171,7 @@ capture_payment = PayWayPayment(transaction_type='capture',
170171
transaction, errors = client.process_payment(capture_payment)
171172
```
172173

173-
# Refunds
174+
## Refunds
174175

175176
Refund a transaction by supplying a PayWay transaction ID and the refund amount.
176177

@@ -181,34 +182,44 @@ refund, errors = client.refund_transaction(
181182
)
182183
```
183184

184-
# Voiding a transaction
185+
## Voiding a transaction
185186

186187
Void a transaction by supplying a PayWay transaction ID.
187188

188189
```python
189190
void_transaction, errors = client.void_transaction(transaction.transaction_id)
190191
```
191192

192-
# Update Payment Setup
193+
## Update Payment Setup
193194

194195
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.
195196

196197
```python
197198
payment_setup, errors = client.update_payment_setup(new_token, payway_customer.customer_number)
198199
```
199200

200-
# Additional notes
201-
PayWay API documentation
202-
https://www.payway.com.au/docs/rest.html
201+
## Additional notes
202+
203+
PayWay API documentation <https://www.payway.com.au/docs/rest.html>
203204

204-
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>
205206
when creating a single use token of a card or bank account so your PCI-compliance scope is reduced.
206207

207-
# Fraud
208+
## Fraud
209+
210+
Please follow PayWay's advice about reducing your risk of fraudulent transactions. <https://www.payway.com.au/docs/card-testing.html#card-testing>
208211

209-
Please follow PayWay's advice about reducing your risk of fraudulent transactions.
210-
https://www.payway.com.au/docs/card-testing.html#card-testing
212+
## Running the project
211213

212-
# Testing
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
213222

214-
1. Run the tests using `python -m unittest discover tests`
223+
```bash
224+
python -m unittest discover tests
225+
```

0 commit comments

Comments
 (0)