• Stars
    star
    106
  • Rank 325,871 (Top 7 %)
  • Language
    Python
  • Created almost 13 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Gateway-agnostic payment processing for Python

dinero

Gateway-agnostic payment processing library for Python.

This library aims to be a minimal, pythonic, and highly usable payment processing library. It has a simple API and it hides the differences between payment processors from the user.

USAGE

The API for dinero is simple to use.

Configuration

dinero allows for more than one payment gateway configuration.

import dinero

dinero.configure({
    'auth.net': { # the name for this gateway
        'default': True, # the default gateway
        'type': 'dinero.gateways.AuthorizeNet' # the gateway path
        # ... gateway-specific configuration
    }})

For Django projects, just include this in your settings.py.

Transaction Objects

The following code will charge a customer's credit card:

transaction = dinero.Transaction.create(
    price=2000,
    number='4111111111111111',
    month='12',
    year='2012',
    )

price, number, month, and year are the only required arguments, additional optional arguments are

  • first_name
  • last_name
  • zip
  • address
  • city
  • state
  • cvv
  • customer_id
  • email

dinero.Transaction.create returns a Transaction object.

Note: despite the confusion that may arise, it is possible to associate a transaction with a customer (id, email) without creating a Customer object. This is so that transactions can be associated with a table in your system without incurring the overhead of storing credit cards and customer information in your gateway. In braintree, this is accomplish by storing the customer_id in custom_fields.

Transaction objects contain data about the payment. Every transaction object has a transaction_id and a price. Additionally, transaction objects have a to_dict method which returns a dictionary of data which can be passed to Transaction.from_dict to restore the Transaction object. This is useful for caching the transaction data.

After creating a payment, you can retrieve it using dinero.Transaction.retrieve:

transaction = dinero.Transaction.retrieve(
    transaction_id = '1234567'
    )

dinero.Transaction.retrieve also returns a Transaction object.

In order to refund or cancel a payment, there is a refund method on Transaction objects:

transaction.refund()

Delayed settlement

A transaction can be submitted with settle=False for an authorization-only transaction. Later, the transaction can be settle() ed:

transaction = dinero.Transaction.create(
    ...
    settle=False
    )

# Up to 30 days later...
transaction.settle()

TODO: braintree support

Customer Objects

You can also create transactions using a Customer object. A Customer object, much like the gateway configuration, can have multiple named accounts, one of which should be declared the "default":

customer = dinero.Customer.create(
    # email is used as a unique identifier for this customer
    email='[email protected]',
    # these are all optional
    first_name='Joey',
    last_name='Shabadoo',
    company='Shabadoo, Inc.',
    phone='000-000-0000',
    fax='000-000-0001',
    address='123 somewhere st',
    state='SW',
    city='somewhere',
    zip='12345',
    country='US',  # this is the 2-letter country code

    # credit card information is required
    number='4111-1111-1111-1111',  # dinero removes all symbols *except X*
    year=2012,                     # Why?  Authorize.net expects credit card numbers in the form
    month=2,                       # "XXXX1111" when updating payment information
    )

# the most important value:
customer_id = customer.customer_id

# and later, to update some information
customer = dinero.Customer.retrieve(customer_id)
customer.company = 'Joey Junior, Inc.'
customer.save()

# you can update the CC, too
customer = dinero.Customer.retrieve(customer_id)
customer.number = '4222-2222-2222-2222'
customer.year = '2012'
customer.month = '02'
customer.save()

The credit card information is required, at least on Authorize.net. So, assuming you've got a customer object, you can now make transactions against it:

customer = dinero.Customer.create(
    # minimum information to create a new account
    email='[email protected]',
    number='4111-1111-1111-1111',
    year='2012',
    month='02',
    )

transaction = dinero.Transaction.create(
    price=2000,
    customer=customer
    )

Multiple Cards

Like this:

customer = dinero.Customer.retrieve(...)
print customer.cards # existing cards
cc = customer.add_card(
  number='4111-1111-1111-1111',
  year='2012',
  month='02',
  )
# charge the new card
dinero.Transaction.create(
  price=12,
  cc=cc,
  )

TESTING

$ pip install pytest
    ...
$ py.test

More Repositories

1

django-authtools

A custom User model for everybody!
Python
371
star
2

django-widgy

A CMS framework for Django built on a heterogenous tree editor.
JavaScript
333
star
3

django-betterforms

Making forms suck less
Python
132
star
4

django-argonauts

DEPRECATED: A lightweight collection of JSON helpers for Django.
Python
46
star
5

django-backupdb

Management commands for automatically backing up and restoring databases in Django
Python
32
star
6

django-separated

Class-based view and mixins for handling CSV with Django.
Python
23
star
7

moment-isocalendar

isocalendar support for moment
JavaScript
22
star
8

django-pyscss

Makes it easier to use PyScss in Django
Python
19
star
9

mouseware

Secure random passwords in javascript
JavaScript
17
star
10

jquery-multifile

HTML file inputs suck...
JavaScript
17
star
11

django-absoluteuri

Absolute URI functions and template tags for Django
Python
13
star
12

django-fusionbox

Useful stuff for django
Python
12
star
13

django-ogmios

No hassle, just sending emails
Python
11
star
14

eek

eek, a spider
Python
9
star
15

django-darkknight

SSL Keys and CSR generation and management
Python
8
star
16

jquery-dontJustLeaveMe

Checks if the form is the same before leaving the page as it was when we came in, if not, make sure they want to leave.
JavaScript
5
star
17

gacookiesparser.js

Google Analytics Javascript Cookies Parser
JavaScript
5
star
18

fusionbox-fabric-helpers

helper functions for fabric
Python
4
star
19

django-widgy-blog

Reusable blog app for Django-Widgy
Python
4
star
20

event-helpers

Utils and decorators to help with event handling.
JavaScript
4
star
21

fusionbox.github.com

CSS
3
star
22

django-app-admin

Adds a missing layer to the django admin by subclassing AdminSite and providing a new class, AppAdmin, where app-level admin actions can go.
Python
3
star
23

buggy

A bug tracker.
Python
2
star
24

jquery-nearest

A combination of `jQuery.find` and `jQuery.closest`, to find the element that matches the selector that is *somewhere nearby*
JavaScript
2
star
25

django-i18ntools

helpers for i18n-ing in Django
Python
2
star
26

django-importcsvadmin

Allow the user to import CSV from the django admin
Python
2
star
27

solr-virtualenv

Makefile to deploy a local solr instance in the solr/ directory of a project
Makefile
2
star
28

django-project-template

CSS
2
star
29

makedecorator-js

Wraps a function-wrapping function and returns an ES7 decorator capable of decorating an ES6 class method.
JavaScript
2
star
30

filer-migration-bug-example

This project exists to illustrate a bug in migrations caused in django-filer.
Python
1
star
31

jquery-peek

Form preview helper for jQuery
JavaScript
1
star
32

paths.json

1
star
33

django-gtf

Generic Template Finder Middleware for Django
Python
1
star
34

django-fusionbox-blog

Python
1
star
35

django-verified-email-change

Python
1
star
36

hat-trick

JavaScript
1
star
37

django-decoratormixins

Python
1
star