After talking with Chris at DjangoCon, I decided to tackle one of the
biggest, most obvious refactoring opportunities available in Satchmo,
the Payment system. It is our opinion that making the Satchmo Payment
modules available via a generic interface would be a massive help to
many other projects. Sort of like Ruby's "active-merchant", but with
a different approach and a Python/Django feel.
To that end, I've spent far too many hours over the last few days
working on the split. I'm calling it "Bursar", and I'm developing it
with these guidelines:
- No reliance on any part of Satchmo. Not even keyedcache or
livesettings. Hopefully no external dependencies at all.
- It just handles authorizations and payments, nothing else.
- It requires little-to-no changes to existing Satchmo code, other
than the payment module itself.
- Every processor needs its own tests, and documentation about the
prerequisites (dev keys, etc) needed to run the tests.
- No cruft. I'm removing all Python 2.3 compatibility, and simplifying the API.
The existing Satchmo payment modules are all split into two parts for
Bursar. The views, config, and urls remain in Satchmo. The processor
itself goes to Bursar. To add a new payment module, one would develop
the processor in Bursar, and a "Satchmofied" interface for it in
satchmo.payment.
After days of work, I've finally gotten the "dummy" processor to work
and to pass all the new tests I've written for it. I think the
remaining processors should go quickly now that I've gotten that one
done. I've also cured a few Satchmo bugs while I was at it.
Refactoring (while painful and slow) makes bugs far more obvious.
I'm working off of a large fork of Satchmo at the moment. For obvious
reasons, I'm not going to check that in until the split is complete
and solid. If you are an adventurous sort, send me an email and I'll
send you a link where you can download the fork.
If you just want to see what is going on so far, the code is available
at: http://bitbucket.org/bkroeze/django-bursar
I've adopted a moderately strict formal refactoring process for this
project. The first step is to replicate functionality with as few
changes to existing Satchmo processes as possible. When that is done,
I hope to simplify and document with the aim of making it easy to add
new processors in the future. I am no documentation expert, so I will
really need help with that part. I'm open to discussion, wishlists,
and random comments about the project.
--
Bruce Kroeze
http://www.ecomsmith.com
It's time to hammer your site into shape.
I've separately sent you my Satchmo fork which uses Bursar.
On Thu, Oct 8, 2009 at 7:50 AM, mihau <michal....@gmail.com> wrote:
>
> 1. Refunds: Some of the payment gateways handle refunds and also some
> of them do them automatically if there are some problems with credit
> cards (reported frauds, etc.) At least PayPal is konwn to do it and to
> send IPN message to notify the shop about refunded orders.
> The objective is to have some way of notifying the shop software about
> refunded payments, in order to deal with the affected Order (change
> status, cancel, etc.). Perhaps some signal would be useful here, to
> allow developers to define custom response -- I suppose that every
> show would want to react in different way.
So, if the payment system "hears about" a forced refund, it should
signal. Satchmo could pick up the signal and make the appropriate
change to the order record.
> 2. Additional data recording: My customer asked me to have IP address
> stored together with a payment. However, just saving it into DB is not
> a good thing, as it may possibly cause security/legal issues somewhere
> for someone.
> My idea here is to have another signal, called upon payment
> initiation, which takes Order, Request and perhaps the original Cart
> (which together allow to access any customer data), which fills a
> dictionary of payment details. The dictionary is saved with the
> Payment then (sth. like ItemDetails for OrderItem).
>
That's pretty much what I'm doing in Bursar. The Bursar models keep a
separate record of everything charged. The API just accepts a list of
items and quantities to be charged, along with their costs and saves
that. Optionally, it can just take shipping/tax/total and charge with
no details. It also takes a separate snapshot of the contact (after
all, it could change over time, so we need the at-the-moment
information) and associates it to the Payment.
Adding more information to the Payment record is a good idea. We
could just use simple name/value pairs, and let different processors
capture more information if they so desire.
Actually, the base processor object can already do refunds, just not
gateway-initiated ones. IIRC, the only processor which currently
implements the refund method is Authorizenet.
We definitely need some sort of admin screen to do
store-owner-initated refunds, but that should be pretty
straightforward.
> - Pre-Auths - for a client of mine I'm using Satchmo in a Rental
> situation, where a pre-auth is used as "insurance" for the item being
> rented (basically a short lived bond). Basically this means two
> transactions, one for the pre-auth and one for the actual purchase of
> the item. I imagine that this is not a common scenario however I would
> be interested in contributing this back to the Satchmo community, some
> guidance about how you would prefer it to be approached would be nice.
> More details can be found at http://groups.google.com/group/satchmo-users/browse_thread/thread/84659c96ee1a1712#
Authorizenet can do this as well. In fact, it is the default way it
operates if you don't check the "capture payment immediately" button.
An AUTH is made on the order, which is then captured when the order is
marked complete.
> I also have a payment processor to contribute for an Australian
> gateway provider, NetRegistry, which would need switching over to use
> the django-bursar api when its stable.
Great, we can always use more.
--
Bruce Kroeze
They do have test interfaces in django-bursar, which is the name I've
given to the payment system split from Satchmo. I think the ability
to test outside of a Satchmo environment is critical for reliability
and flexibility.
In the meantime, it will require some custom programming, but if you
notice, you can auth for whatever you want. When you capture, the
processor can request a specific amount to capture, instead of the
full amount of the auth. That hasn't been completely tested, but it
was the idea, and it is already built-in.