Code Monkey home page Code Monkey logo

python-payson's Introduction

python-payson

Python API to the Payson payments provider.

Installation

From pypi (recommended):

$ pip install payson_api

If this doesn't work the entire library is contained in a single Python module, payson_api.py. Just drop it anywhere in your projects PYTHONPATH. It is not dependent on anything outside the Python standard library (except in the tests).

Tested with Python 2.7.

Examples

Initiate payment:

import decimal
import payson_api

from your_settings_module import payson_user_id, payson_user_key

api = payson_api.PaysonApi(payson_user_id, payson_user_key)

receiver = payson.Receiver(email='[email protected]',
                           firstName=u'Pelle',
                           lastName=u'Persson',
                           amount=decimal.Decimal('125.0'),
                           primary=False)

payment_response = api.pay(returnUrl='http://example.com/return_url',
                           cancelUrl='http://example.com/cancel_url',
                           memo=u'Purchase of nice things.',
                           senderEmail='[email protected]',
                           senderFirstName=u'Anna',
                           senderLastName=u'Andersson',
                           receiverList=[receiver, ])
                       
if payment_response.success:
    # Redirect users browser to Payson
    redirect(payment_response.forward_pay_url)

Get payment details:

payment_details = api.payment_details(payment_response.token)
if payment_details.status == 'COMPLETED':
    #  We got money :)
    ...

Data Types

  • all strings except urls and e-mail addresses are expected to be unicode
  • monetary values returned are converted to decimal.Decimal
  • timestamps are converted to datetime.datetime
  • true/false is converted to bool
  • error codes are converted to int
  • the 'custom' field is serialized/deserialized with JSON

More documentation

Please see the docstrings included in payson_api.py and/or the Payson API documentation

Testing

The PaysonApi constructor detects if user id and key used are testing credentials and will then use the Payson test system.

The included test.py file includes some automated tests using python-mechanize that can be run with nosetests. The tests are broken right now due to changes in the flow over at Payson. Fixing this is on the TODO list :)

Contact

The author of this software offers integration services if requested. Reach him through github.

Issues are reported through github.

python-payson's People

Contributors

tjwalch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

scbrg

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.