Code Monkey home page Code Monkey logo

swish-python's Introduction

swish

Build Status codecov.io

💰 Swish Python Client Library

This client library is designed to support the Swish handel API.

Offical Integration Guide

🏗 Installation

It's easy! Just install it with pip:

pip install swish

📋 Quick Start Example

import swish

swish_client = swish.SwishClient(
    environment=swish.Environment.MSS,
    merchant_swish_number='1231181189',
    cert=('/path/to/cert.pem', '/path/to/key.pem'),
    verify='/path/to/swish.pem'
)

payment = swish_client.create_payment(
    payee_payment_reference='0123456789',
    callback_url='https://example.com/api/swishcb/paymentrequests',
    payer_alias='46712345678',
    amount=100,
    currency='SEK',
    message='Kingston USB Flash Drive 8 GB'
)

# YOUR CODE: Save payment.id and other info in your database for later!

swish-python's People

Contributors

cthart avatar hanzketup avatar heyhugo avatar madspindel avatar metteludwig avatar zrajna avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

swish-python's Issues

Python 2 and non-ascii characters in the message

I've been trying to create payments where the message contains Swedish characters (åäö) in a Python 2 project. When I got the callback, Python failed to parse the message.

Wouldn't it be reasonable to encode the data as UTF-8, and add the appropriate headers? I haven't tried it myself, but I assume that doing so should resolve this issue.

test fails

Hello!

I have this problem on Digital Ocean (Amsterdam) and on localhost, is it problem of swish server?

# cat /etc/issue
Ubuntu 14.04.1 LTS \n \l

swish-python/tests# python -m unittest test_client

./usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
/usr/local/lib/python2.7/dist-packages/requests/packages/urllib3/connection.py:303: SubjectAltNameWarning: Certificate for mss.swicpc.bankgirot.se has no `subjectAltName`, falling back to check for a `commonName` for now. This feature is being removed by major browsers and deprecated by RFC 2818. (See https://github.com/shazow/urllib3/issues/497 for details.)
  SubjectAltNameWarning
...

E
======================================================================
ERROR: test_create_payment_ecommerce (test_client.SwishClientTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_client.py", line 35, in test_create_payment_ecommerce
    message='Kingston USB Flash Drive 8 GB'
  File "/usr/local/lib/python2.7/dist-packages/swish-1.0b1-py2.7.egg/swish/client.py", line 45, in create_payment
    response.raise_for_status()
  File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 844, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
HTTPError: 404 Client Error: Not Found for url: https://mss.swicpc.bankgirot.se/swish-cpcapi/api/v1/paymentrequests

======================================================================
ERROR: test_create_payment_error (test_client.SwishClientTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_client.py", line 59, in test_create_payment_error
    message='BE18'
  File "/usr/local/lib/python2.7/dist-packages/swish-1.0b1-py2.7.egg/swish/client.py", line 45, in create_payment
    response.raise_for_status()
  File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 844, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
HTTPError: 404 Client Error: Not Found for url: https://mss.swicpc.bankgirot.se/swish-cpcapi/api/v1/paymentrequests

======================================================================
ERROR: test_create_payment_mcommerce (test_client.SwishClientTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_client.py", line 46, in test_create_payment_mcommerce
    message='Kingston USB Flash Drive 8 GB'
  File "/usr/local/lib/python2.7/dist-packages/swish-1.0b1-py2.7.egg/swish/client.py", line 45, in create_payment
    response.raise_for_status()
  File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 844, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
HTTPError: 404 Client Error: Not Found for url: https://mss.swicpc.bankgirot.se/swish-cpcapi/api/v1/paymentrequests

======================================================================
ERROR: test_create_refund (test_client.SwishClientTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_client.py", line 83, in test_create_refund
    message='Kingston USB Flash Drive 8 GB'
  File "/usr/local/lib/python2.7/dist-packages/swish-1.0b1-py2.7.egg/swish/client.py", line 45, in create_payment
    response.raise_for_status()
  File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 844, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
HTTPError: 404 Client Error: Not Found for url: https://mss.swicpc.bankgirot.se/swish-cpcapi/api/v1/paymentrequests

======================================================================
ERROR: test_get_payment (test_client.SwishClientTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_client.py", line 68, in test_get_payment
    message='Kingston USB Flash Drive 8 GB'
  File "/usr/local/lib/python2.7/dist-packages/swish-1.0b1-py2.7.egg/swish/client.py", line 45, in create_payment
    response.raise_for_status()
  File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 844, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
HTTPError: 404 Client Error: Not Found for url: https://mss.swicpc.bankgirot.se/swish-cpcapi/api/v1/paymentrequests

======================================================================
ERROR: test_get_refund (test_client.SwishClientTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test_client.py", line 104, in test_get_refund
    message='Kingston USB Flash Drive 8 GB'
  File "/usr/local/lib/python2.7/dist-packages/swish-1.0b1-py2.7.egg/swish/client.py", line 45, in create_payment
    response.raise_for_status()
  File "/usr/local/lib/python2.7/dist-packages/requests/models.py", line 844, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
HTTPError: 404 Client Error: Not Found for url: https://mss.swicpc.bankgirot.se/swish-cpcapi/api/v1/paymentrequests

----------------------------------------------------------------------
Ran 7 tests in 7.713s

FAILED (errors=6)

Possible to generate release with updated dependency versions?

Hi! Nice work on this library! Would it be possible to create a new release with updated dependencies for this project and push it to PyPI? The schematics dependency specifically is somewhat out of date. Newer releases of that library contain fixes for things which emit deprecation warnings with the current version and it would be nice to stop getting those. 🙂

SSL: SSLV3_ALERT_HANDSHAKE_FAILURE under mod_wsgi Apache

Working fine in a flask app but when put on an Apache server using mod_wsgi I get the SSLV3_ALERT_HANDSHAKE_FAILURE error. Understand it is nothing wrong with the framework itself, but if somebody has any idea of what the issue is under mod_wsgi could be?

Thx

failed to run test from wiki

Hi, great work - looking at this and within python / django / ... framework for some integration work right now. Attempted to run test case but get the following issue

Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import swish
>>> swish_client = swish.SwishClient(
...     environment=swish.Environment.Test,
...     merchant_swish_number='1231181189',
...     cert=('tests/cert.pem', 'tests/key.pem')
... )
>>> 
>>> payment = swish_client.create_payment(
...     payee_payment_reference='0123456789',
...     callback_url='https://example.com/api/swishcb/paymentrequests',
...     payer_alias='46712345678',
...     amount=100,
...     currency='SEK',
...     message='Kingston USB Flash Drive 8 GB'
... )
Traceback (most recent call last):
  File "<stdin>", line 7, in <module>
  File "swish/client.py", line 42, in create_payment
    response = self.post('paymentrequests', payment_request.to_primitive())
  File "swish/client.py", line 24, in post
    verify=self.verify)
  File "xxx/lib/python2.7/site-packages/requests/api.py", line 107, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "xxx/lib/python2.7/site-packages/requests/api.py", line 53, in request
    return session.request(method=method, url=url, **kwargs)
  File "xxx/lib/python2.7/site-packages/requests/sessions.py", line 468, in request
    resp = self.send(prep, **send_kwargs)
  File "xxx/lib/python2.7/site-packages/requests/sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)
  File "xxx/lib/python2.7/site-packages/requests/adapters.py", line 447, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:581)

(Question, not Issues)How to use ENCRYPTED file or .p12 file to swish.SwishClient call?

image

In swish test environment sample, it use .p12 file and CA.pem file to communicate with swish.

"Swish_Merchant_TestCertificate_1234679304.p12" files includes “Certificate” and “private key”.

and the private key file is ENCRYPTED, you can see below:
-----BEGIN ENCRYPTED PRIVATE KEY-----
-----END ENCRYPTED PRIVATE KEY-----

but in your test case “swish-python/tests/key.pem”, it is
-----BEGIN PRIVATE KEY-----
-----END PRIVATE KEY-----

is there some way to use ENCRYPTED file as swish sample? or use .p12 file just like swish sample?

Looking forward to hearing from you!
Have a nice day!

Is this project maintained?

Implementing Swish payments, I note that several APIs now have v2 versions, while this code assumes all APIs are on the v1 endpoint.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.