python-payway


Namepython-payway JSON
Version 0.0.5 PyPI version JSON
download
home_pageNone
SummaryPython client for working with Westpac's PayWay REST API
upload_time2024-12-31 06:49:59
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT
keywords payway westpac api client
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PayWay REST API - Python

- Store customers, their card and bank account in PayWay
- Take payment using a stored credit card or bank account
- Process and Capture a pre-authorisation
- Lookup or poll transactions
- Refund transactions
- Void transactions
- Update a customer's payment setup in PayWay

## Install

```bash
pip install python-payway
```

## Take payment using a stored credit card

Create a Client class with your PayWay API credentials

```python
from payway.client import Client

client = Client(merchant_id='<your_payway_merchant_id>',
                bank_account_id='<your_payway_bank_account_id>',
                publishable_api_key='<your_payway_publishable_api_key>',
                secret_api_key='<your_payway_secret_api_key>')
```

Create a PayWayCustomer class with your customer's details

```python
customer = PayWayCustomer(custom_id='c981a',
                          customer_name='John Smith',
                          email_address='johnsmith@example.com',
                          send_email_receipts=False,  # not available in sandbox
                          phone_number='0343232323',
                          street='1 Test Street',
                          street2='2 Test Street',
                          city_name='Sydney',
                          state='NSW',
                          postal_code='2000')
```

Create a PayWayCard class with your customer's card details

```python
card = PayWayCard(card_number='',
                  cvn='',
                  card_holder_name='',
                  expiry_date_month='',
                  expiry_date_year='')
```

Create a token from your card and create a customer in PayWay

```python
token_response, errors = client.create_card_token(card)
token = token_response.token        
customer.token = token
payway_customer, customer_errors = client.create_customer(customer)
```

Note the 'payway_customer' object contains the full customer response fields from PayWay.

Create a Payment class with the payment details and process the transaction

```python
customer_number = payway_customer.customer_number
payment = PayWayPayment(customer_number=customer_number,
                        transaction_type='payment',
                        amount='',
                        currency='aud',
                        order_number='',
                        ip_address='')
transaction, errors = client.process_payment(payment)
```

Check the `transaction` for the result

```python
if not errors and transaction.status == 'approved':
    # process successful response
```

## Take payment using a credit card token only

```python
client = Client(merchant_id='',
                bank_account_id='',
                publishable_api_key='',
                secret_api_key='')
card = PayWayCard(card_number='',
                  cvn='',
                  card_holder_name='',
                  expiry_date_month='',
                  expiry_date_year='')
token_response, errors = client.create_card_token(card)
# your customer reference number or a stored PayWay customer number
customer_number = ''    
payment = PayWayPayment(customer_number=customer_number,
                        transaction_type='payment',
                        amount='',
                        currency='aud',
                        order_number='',
                        ip_address='',
                        token=token_response.token,
                        merchant_id=client.merchant_id)
transaction, errors = client.process_payment(payment)
```

## Handling errors

Documented errors (such as 422 Unprocessable entity) are parsed into an PaymentError class that you can use in an customer error message.
For more info, visit <https://www.payway.com.au/docs/rest.html#http-response-codes>

```python
if errors:
    for error in errors: 
        print(error.field_name)
        print(error.message) 
        print(error.field_name)
    # or use a method
    PaymentError().list_to_message(errors) 
```

## Direct Debit

Direct debit transactions are possible by creating a token from a bank account:

```python
bank_account = BankAccount(account_name='Test', bsb='000-000', account_number=123456)
token_response, errors = client.create_bank_account_token(bank_account)
token = token_response.token
```

Store the token with a customer in PayWay using the same process as the card outlined above.

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

## Lookup transaction

Poll a transaction using the `get_transaction` method.

```python
transaction, errors = client.get_transaction(transaction.transaction_id)
```

## Process and capture a pre-authorisation

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.

```python
pre_auth_payment = PayWayPayment(customer_number='',
                                 transaction_type='preAuth',
                                 amount='',
                                 currency='aud',
                                 order_number='',
                                 ip_address='')
transaction, errors = client.process_payment(pre_auth_payment)
```

To capture the pre-authorisation supply a pre-authorisation transaction ID,  `capture` as the `transaction_type` along with an amount to capture.

```python
capture_payment = PayWayPayment(transaction_type='capture',
                                parent_transaction_id='',
                                amount='',
                                order_number='',
                                ip_address='')
transaction, errors = client.process_payment(capture_payment)
```

## Refunds

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

```python
refund, errors = client.refund_transaction(
    transaction_id=transaction.transaction_id,
    amount=transaction.principal_amount,
)
```

## Voiding a transaction

Void a transaction by supplying a PayWay transaction ID.

```python
void_transaction, errors = client.void_transaction(transaction.transaction_id)
```

## Update Payment Setup

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.

```python
payment_setup, errors = client.update_payment_setup(new_token, payway_customer.customer_number)
```

## Additional notes

PayWay API documentation <https://www.payway.com.au/docs/rest.html>

It is recommended to use PayWay's Trusted Frame <https://www.payway.com.au/docs/rest.html#trusted-frame>
when creating a single use token of a card or bank account so your PCI-compliance scope is reduced.  

## Fraud

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

## Running the project

```bash
uv python install 3.8.19
uv venv
source .venv/bin/activate
uv sync --extra dev
```

## Testing

```bash
python -m unittest discover tests
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "python-payway",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "payway, westpac, api, client",
    "author": null,
    "author_email": "Ben Napper <reppan197@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/04/fb/2f4b977f235fb95fd5667b39fea1cba604ccfb2a2bd02d1da82bee810698/python_payway-0.0.5.tar.gz",
    "platform": null,
    "description": "# PayWay REST API - Python\n\n- Store customers, their card and bank account in PayWay\n- Take payment using a stored credit card or bank account\n- Process and Capture a pre-authorisation\n- Lookup or poll transactions\n- Refund transactions\n- Void transactions\n- Update a customer's payment setup in PayWay\n\n## Install\n\n```bash\npip install python-payway\n```\n\n## Take payment using a stored credit card\n\nCreate a Client class with your PayWay API credentials\n\n```python\nfrom payway.client import Client\n\nclient = Client(merchant_id='<your_payway_merchant_id>',\n                bank_account_id='<your_payway_bank_account_id>',\n                publishable_api_key='<your_payway_publishable_api_key>',\n                secret_api_key='<your_payway_secret_api_key>')\n```\n\nCreate a PayWayCustomer class with your customer's details\n\n```python\ncustomer = PayWayCustomer(custom_id='c981a',\n                          customer_name='John Smith',\n                          email_address='johnsmith@example.com',\n                          send_email_receipts=False,  # not available in sandbox\n                          phone_number='0343232323',\n                          street='1 Test Street',\n                          street2='2 Test Street',\n                          city_name='Sydney',\n                          state='NSW',\n                          postal_code='2000')\n```\n\nCreate a PayWayCard class with your customer's card details\n\n```python\ncard = PayWayCard(card_number='',\n                  cvn='',\n                  card_holder_name='',\n                  expiry_date_month='',\n                  expiry_date_year='')\n```\n\nCreate a token from your card and create a customer in PayWay\n\n```python\ntoken_response, errors = client.create_card_token(card)\ntoken = token_response.token        \ncustomer.token = token\npayway_customer, customer_errors = client.create_customer(customer)\n```\n\nNote the 'payway_customer' object contains the full customer response fields from PayWay.\n\nCreate a Payment class with the payment details and process the transaction\n\n```python\ncustomer_number = payway_customer.customer_number\npayment = PayWayPayment(customer_number=customer_number,\n                        transaction_type='payment',\n                        amount='',\n                        currency='aud',\n                        order_number='',\n                        ip_address='')\ntransaction, errors = client.process_payment(payment)\n```\n\nCheck the `transaction` for the result\n\n```python\nif not errors and transaction.status == 'approved':\n    # process successful response\n```\n\n## Take payment using a credit card token only\n\n```python\nclient = Client(merchant_id='',\n                bank_account_id='',\n                publishable_api_key='',\n                secret_api_key='')\ncard = PayWayCard(card_number='',\n                  cvn='',\n                  card_holder_name='',\n                  expiry_date_month='',\n                  expiry_date_year='')\ntoken_response, errors = client.create_card_token(card)\n# your customer reference number or a stored PayWay customer number\ncustomer_number = ''    \npayment = PayWayPayment(customer_number=customer_number,\n                        transaction_type='payment',\n                        amount='',\n                        currency='aud',\n                        order_number='',\n                        ip_address='',\n                        token=token_response.token,\n                        merchant_id=client.merchant_id)\ntransaction, errors = client.process_payment(payment)\n```\n\n## Handling errors\n\nDocumented errors (such as 422 Unprocessable entity) are parsed into an PaymentError class that you can use in an customer error message.\nFor more info, visit <https://www.payway.com.au/docs/rest.html#http-response-codes>\n\n```python\nif errors:\n    for error in errors: \n        print(error.field_name)\n        print(error.message) \n        print(error.field_name)\n    # or use a method\n    PaymentError().list_to_message(errors) \n```\n\n## Direct Debit\n\nDirect debit transactions are possible by creating a token from a bank account:\n\n```python\nbank_account = BankAccount(account_name='Test', bsb='000-000', account_number=123456)\ntoken_response, errors = client.create_bank_account_token(bank_account)\ntoken = token_response.token\n```\n\nStore the token with a customer in PayWay using the same process as the card outlined above.\n\nNote: direct debit transactions take days to process so they must be polled regularly for the latest transaction status from the customer's bank.\n\n## Lookup transaction\n\nPoll a transaction using the `get_transaction` method.\n\n```python\ntransaction, errors = client.get_transaction(transaction.transaction_id)\n```\n\n## Process and capture a pre-authorisation\n\nTo 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.\n\n```python\npre_auth_payment = PayWayPayment(customer_number='',\n                                 transaction_type='preAuth',\n                                 amount='',\n                                 currency='aud',\n                                 order_number='',\n                                 ip_address='')\ntransaction, errors = client.process_payment(pre_auth_payment)\n```\n\nTo capture the pre-authorisation supply a pre-authorisation transaction ID,  `capture` as the `transaction_type` along with an amount to capture.\n\n```python\ncapture_payment = PayWayPayment(transaction_type='capture',\n                                parent_transaction_id='',\n                                amount='',\n                                order_number='',\n                                ip_address='')\ntransaction, errors = client.process_payment(capture_payment)\n```\n\n## Refunds\n\nRefund a transaction by supplying a PayWay transaction ID and the refund amount.\n\n```python\nrefund, errors = client.refund_transaction(\n    transaction_id=transaction.transaction_id,\n    amount=transaction.principal_amount,\n)\n```\n\n## Voiding a transaction\n\nVoid a transaction by supplying a PayWay transaction ID.\n\n```python\nvoid_transaction, errors = client.void_transaction(transaction.transaction_id)\n```\n\n## Update Payment Setup\n\nUpdate 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.\n\n```python\npayment_setup, errors = client.update_payment_setup(new_token, payway_customer.customer_number)\n```\n\n## Additional notes\n\nPayWay API documentation <https://www.payway.com.au/docs/rest.html>\n\nIt is recommended to use PayWay's Trusted Frame <https://www.payway.com.au/docs/rest.html#trusted-frame>\nwhen creating a single use token of a card or bank account so your PCI-compliance scope is reduced.  \n\n## Fraud\n\nPlease follow PayWay's advice about reducing your risk of fraudulent transactions. <https://www.payway.com.au/docs/card-testing.html#card-testing>\n\n## Running the project\n\n```bash\nuv python install 3.8.19\nuv venv\nsource .venv/bin/activate\nuv sync --extra dev\n```\n\n## Testing\n\n```bash\npython -m unittest discover tests\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Python client for working with Westpac's PayWay REST API",
    "version": "0.0.5",
    "project_urls": null,
    "split_keywords": [
        "payway",
        " westpac",
        " api",
        " client"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "5d8c07fa97da637506c63f2706fe2825c6d1857ea72f1d8f4c711e3444054b06",
                "md5": "d0c2c508265727144b2435a1970bb3e9",
                "sha256": "83e1dc05cb5e8f2754bf7c5087ae17497a4f356291dd1a9d8a7a5e5a1318f3d1"
            },
            "downloads": -1,
            "filename": "python_payway-0.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d0c2c508265727144b2435a1970bb3e9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 16092,
            "upload_time": "2024-12-31T06:49:57",
            "upload_time_iso_8601": "2024-12-31T06:49:57.057386Z",
            "url": "https://files.pythonhosted.org/packages/5d/8c/07fa97da637506c63f2706fe2825c6d1857ea72f1d8f4c711e3444054b06/python_payway-0.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "04fb2f4b977f235fb95fd5667b39fea1cba604ccfb2a2bd02d1da82bee810698",
                "md5": "cf7cce3c9537d83c5ae422681b870aff",
                "sha256": "ff9b88a7c96bc4fee3298023739e28b0a71c57354e76a06c43831bb8dbcb64b1"
            },
            "downloads": -1,
            "filename": "python_payway-0.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "cf7cce3c9537d83c5ae422681b870aff",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 19055,
            "upload_time": "2024-12-31T06:49:59",
            "upload_time_iso_8601": "2024-12-31T06:49:59.577997Z",
            "url": "https://files.pythonhosted.org/packages/04/fb/2f4b977f235fb95fd5667b39fea1cba604ccfb2a2bd02d1da82bee810698/python_payway-0.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-31 06:49:59",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "python-payway"
}
        
Elapsed time: 2.39511s