Name | getswish JSON |
Version |
0.2.4
JSON |
| download |
home_page | None |
Summary | Getswish python client library |
upload_time | 2023-06-09 12:39:34 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.10 |
license | None |
keywords |
swish
getswish
payment
payout
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Swish - Python client
Client library to integrate with the swish commerce and payout api.
## Supported APIs
* https://developer.swish.nu/documentation/getting-started/swish-commerce-api
* https://developer.swish.nu/documentation/getting-started/swish-payout-api
## Installation
pip install getswish
## Prerequisites
Swish api integration require communication certificates and keys to integrate with the commerce api and additional
signing certificates and keys for signing payout in the payout api. The client setup require that all the certificates
are available through file paths which are given on client setup. The communication certificates are create through your
bank portal after the appropriate agreements are signed and signing certificates are set up after additional payout
agreements are signed, trough https://portal.swish.nu/.
The signing certificate, private key and serial is only required when using the payout API.
## Example - Test Client
The example code uses the test environment and certificates in this library.
```python
import getswish
swish_client = getswish.SwishClient()
callback_url = "https://example.com/callback/"
### Example - Commerce API
# Perform a payment request - E-commerce.
payment_e = swish_client.create_payment(
100.00, callback_url, message="Product name."
)
# Perform a payment request - M-commerce.
payment_m = swish_client.create_payment(
100.00, callback_url, "46701234567", message="Product name."
)
# Retrieve info about the payment
payment_retrieved = swish_client.retrieve_payment(payment_m.id)
# Cancel the payment
payment_cancelled = swish_client.cancel_payment(payment_m.id)
# Refund payment the whole amount to the previous payer which now is the payee.
payment_refund = swish_client.create_refund(
payment_e.id, callback_url, payment_e.payer_alias, payment_e.amount
)
### Example - Payout API
# Generate a merchant specific reference.
# This reference could be order id or similar.
# Use generate_transaction_id for convenience.
from getswish.utils import generate_transaction_id
reference_id = generate_transaction_id()
# Perform a payment request
payout = swish_client.create_payout(
reference_id, "46701234567", "197001019876", 10.00, callback_url, message="Test payout message."
)
# Retrieve info about the payout
payout_retrieved = swish_client.retrieve_payout(payout.payout_instruction_uuid)
```
## Example - Production Client
In production the environment must be set
to `swish.ProductionEnvironment` and all path must be modified to the production certificates that you have generated
through your bank and swish company portals. The example below is the default configuration for the test certificates
and environment. Replace all paths and files with your generated production instances.
```python
from pathlib import Path
import getswish
cert_base = Path(__file__).parent.parent.parent.resolve()
cert_base = cert_base / "mss_test_1.9" / "Getswish_Test_Certificates"
swish_client = getswish.SwishClient(
environment=getswish.TestEnvironment,
certificates=getswish.Certificates(
communication=getswish.Certificate(
public=f"{cert_base}/Swish_Merchant_TestCertificate_1234679304.pem",
private_key=f"{cert_base}/Swish_Merchant_TestCertificate_1234679304.key",
),
verify=getswish.Certificate(public=f"{cert_base}/Swish_TLS_RootCA.pem"),
),
merchant_swish_number="1234679304",
)
```
## Example - Production Client with payout
Using the payout API require an additional certificate from your bank and called a signing certificate.
```python
from pathlib import Path
import getswish
cert_base = Path(__file__).parent.parent.parent.resolve()
cert_base = cert_base / "mss_test_1.9" / "Getswish_Test_Certificates"
swish_client = getswish.SwishClient(
environment=getswish.TestEnvironment,
certificates=getswish.Certificates(
communication=getswish.Certificate(
public=f"{cert_base}/Swish_Merchant_TestCertificate_1234679304.pem",
private_key=f"{cert_base}/Swish_Merchant_TestCertificate_1234679304.key",
),
verify=getswish.Certificate(public=f"{cert_base}/Swish_TLS_RootCA.pem"),
signing=getswish.Certificate(
public=f"{cert_base}/Swish_Merchant_TestSigningCertificate_1234679304.pem",
private_key=f"{cert_base}/Swish_Merchant_TestSigningCertificate_1234679304.key",
public_serial="51FFA3C2336C8D5B4904D53CD9FAB21D",
),
),
merchant_swish_number="1234679304",
)
callback_url = "https://example.com/callback/"
```
### Generating public_serial for signing certificate
The signing certificate `public_serial` is extracted from the certificate using this command on linux.
openssl x509 -in Swish_Merchant_TestSigningCertificate_1234679304.pem -serial -noout
## Development setup
Clone the repository and set up a local virtual environment.
git clone https://github.com/nibon/getswish-python.git && cd getswish-python
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install flit
flit install --only-deps
### Testing installing package and pytest
Symlink getswish and run pytest. You might want to uninstall the getswish library depending on your workflow.
flit install --symlink
pytest
### Testing using nox
Isolated testing on configured python versions and running a coverage test.
nox
Raw data
{
"_id": null,
"home_page": null,
"name": "getswish",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "swish,getswish,payment,payout",
"author": null,
"author_email": "Daniel Nibon <daniel@nibon.se>",
"download_url": "https://files.pythonhosted.org/packages/10/78/d7896c798f9190e2aad77431b232f2894bfce6813f57eeb63c8660f16649/getswish-0.2.4.tar.gz",
"platform": null,
"description": "# Swish - Python client\n\nClient library to integrate with the swish commerce and payout api.\n\n## Supported APIs\n\n* https://developer.swish.nu/documentation/getting-started/swish-commerce-api\n* https://developer.swish.nu/documentation/getting-started/swish-payout-api\n\n## Installation\n\n pip install getswish\n\n## Prerequisites\n\nSwish api integration require communication certificates and keys to integrate with the commerce api and additional\nsigning certificates and keys for signing payout in the payout api. The client setup require that all the certificates\nare available through file paths which are given on client setup. The communication certificates are create through your\nbank portal after the appropriate agreements are signed and signing certificates are set up after additional payout\nagreements are signed, trough https://portal.swish.nu/.\n\nThe signing certificate, private key and serial is only required when using the payout API.\n\n## Example - Test Client\n\nThe example code uses the test environment and certificates in this library.\n\n```python\nimport getswish\n\nswish_client = getswish.SwishClient()\n\ncallback_url = \"https://example.com/callback/\"\n\n### Example - Commerce API\n\n# Perform a payment request - E-commerce.\npayment_e = swish_client.create_payment(\n 100.00, callback_url, message=\"Product name.\"\n)\n\n# Perform a payment request - M-commerce.\npayment_m = swish_client.create_payment(\n 100.00, callback_url, \"46701234567\", message=\"Product name.\"\n)\n\n# Retrieve info about the payment\npayment_retrieved = swish_client.retrieve_payment(payment_m.id)\n\n# Cancel the payment\npayment_cancelled = swish_client.cancel_payment(payment_m.id)\n\n# Refund payment the whole amount to the previous payer which now is the payee.\npayment_refund = swish_client.create_refund(\n payment_e.id, callback_url, payment_e.payer_alias, payment_e.amount\n)\n\n### Example - Payout API\n\n# Generate a merchant specific reference.\n# This reference could be order id or similar.\n# Use generate_transaction_id for convenience.\n\nfrom getswish.utils import generate_transaction_id\n\nreference_id = generate_transaction_id()\n\n# Perform a payment request\n\npayout = swish_client.create_payout(\n reference_id, \"46701234567\", \"197001019876\", 10.00, callback_url, message=\"Test payout message.\"\n)\n\n# Retrieve info about the payout\npayout_retrieved = swish_client.retrieve_payout(payout.payout_instruction_uuid)\n```\n\n## Example - Production Client\n\nIn production the environment must be set\nto `swish.ProductionEnvironment` and all path must be modified to the production certificates that you have generated\nthrough your bank and swish company portals. The example below is the default configuration for the test certificates\nand environment. Replace all paths and files with your generated production instances.\n\n```python\nfrom pathlib import Path\nimport getswish\n\ncert_base = Path(__file__).parent.parent.parent.resolve()\ncert_base = cert_base / \"mss_test_1.9\" / \"Getswish_Test_Certificates\"\n\nswish_client = getswish.SwishClient(\n environment=getswish.TestEnvironment,\n certificates=getswish.Certificates(\n communication=getswish.Certificate(\n public=f\"{cert_base}/Swish_Merchant_TestCertificate_1234679304.pem\",\n private_key=f\"{cert_base}/Swish_Merchant_TestCertificate_1234679304.key\",\n ),\n verify=getswish.Certificate(public=f\"{cert_base}/Swish_TLS_RootCA.pem\"),\n ),\n merchant_swish_number=\"1234679304\",\n)\n```\n\n## Example - Production Client with payout\n\nUsing the payout API require an additional certificate from your bank and called a signing certificate.\n\n```python\nfrom pathlib import Path\nimport getswish\n\ncert_base = Path(__file__).parent.parent.parent.resolve()\ncert_base = cert_base / \"mss_test_1.9\" / \"Getswish_Test_Certificates\"\n\nswish_client = getswish.SwishClient(\n environment=getswish.TestEnvironment,\n certificates=getswish.Certificates(\n communication=getswish.Certificate(\n public=f\"{cert_base}/Swish_Merchant_TestCertificate_1234679304.pem\",\n private_key=f\"{cert_base}/Swish_Merchant_TestCertificate_1234679304.key\",\n ),\n verify=getswish.Certificate(public=f\"{cert_base}/Swish_TLS_RootCA.pem\"),\n signing=getswish.Certificate(\n public=f\"{cert_base}/Swish_Merchant_TestSigningCertificate_1234679304.pem\",\n private_key=f\"{cert_base}/Swish_Merchant_TestSigningCertificate_1234679304.key\",\n public_serial=\"51FFA3C2336C8D5B4904D53CD9FAB21D\",\n ),\n ),\n merchant_swish_number=\"1234679304\",\n)\n\ncallback_url = \"https://example.com/callback/\"\n```\n\n### Generating public_serial for signing certificate\n\nThe signing certificate `public_serial` is extracted from the certificate using this command on linux.\n\n openssl x509 -in Swish_Merchant_TestSigningCertificate_1234679304.pem -serial -noout\n\n## Development setup\n\nClone the repository and set up a local virtual environment.\n\n git clone https://github.com/nibon/getswish-python.git && cd getswish-python\n\n python3 -m venv .venv\n source .venv/bin/activate\n python3 -m pip install flit\n flit install --only-deps\n\n### Testing installing package and pytest\n\nSymlink getswish and run pytest. You might want to uninstall the getswish library depending on your workflow.\n\n flit install --symlink\n pytest\n\n### Testing using nox\n\nIsolated testing on configured python versions and running a coverage test.\n\n nox\n",
"bugtrack_url": null,
"license": null,
"summary": "Getswish python client library",
"version": "0.2.4",
"project_urls": {
"Source": "https://github.com/nibon/getswish-python"
},
"split_keywords": [
"swish",
"getswish",
"payment",
"payout"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "9c4cf22b4029717a4878c844719db52d588c268ea37bbbf181b3c39e6c493d1a",
"md5": "057825539be9a31afe14179ebd98b689",
"sha256": "e5227bafdd4ba392c4df8af8f5628028cdeea07a9f42e0a5a55eaf1381ee54dc"
},
"downloads": -1,
"filename": "getswish-0.2.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "057825539be9a31afe14179ebd98b689",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 8478,
"upload_time": "2023-06-09T12:39:30",
"upload_time_iso_8601": "2023-06-09T12:39:30.894757Z",
"url": "https://files.pythonhosted.org/packages/9c/4c/f22b4029717a4878c844719db52d588c268ea37bbbf181b3c39e6c493d1a/getswish-0.2.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "1078d7896c798f9190e2aad77431b232f2894bfce6813f57eeb63c8660f16649",
"md5": "873a9f38367cfa8e5f492c9cd1c3ea1d",
"sha256": "177bafcd36bb338c20a5e369015994e98c14e90c111e70402b42cf7968fba0c5"
},
"downloads": -1,
"filename": "getswish-0.2.4.tar.gz",
"has_sig": false,
"md5_digest": "873a9f38367cfa8e5f492c9cd1c3ea1d",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 487459,
"upload_time": "2023-06-09T12:39:34",
"upload_time_iso_8601": "2023-06-09T12:39:34.839455Z",
"url": "https://files.pythonhosted.org/packages/10/78/d7896c798f9190e2aad77431b232f2894bfce6813f57eeb63c8660f16649/getswish-0.2.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-06-09 12:39:34",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "nibon",
"github_project": "getswish-python",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "getswish"
}