Permalink
Browse files

A number of bugfixes to the offsite_stripe module. Also a minor fix t…

…o MANFIEST.in to include templates.
  • Loading branch information...
1 parent c95fc0b commit 64bb653ac4b0ba9bc203d211dba98f66dc84bd93 Colin Powell committed Dec 4, 2011
Showing with 43 additions and 40 deletions.
  1. +1 −0 MANIFEST.in
  2. +42 −40 shop_stripe/offsite_stripe.py
View
@@ -1 +1,2 @@
include README
+recursive-include templates *.html
@@ -8,6 +8,7 @@
from django.forms.forms import DeclarativeFieldsMetaclass
from django.http import (HttpResponseBadRequest, HttpResponse,
HttpResponseRedirect)
+from django.template import RequestContext
from django.shortcuts import render_to_response
class ConfigError(Exception):
@@ -19,7 +20,7 @@ def __str__(self):
class StripeBackend(object):
'''
A django-shop payment backend for the stripe service, this
- is the workhorse view. It processes what the StripeForm class
+ is the workhorse view. It processes what the CardForm class
kicks back to the server.
It also saves the customer billing information for later use.
@@ -34,60 +35,61 @@ def __init__(self, shop):
def get_urls(self):
urlpatterns = patterns('',
- url(r'^$', self.stripe_payment_view, name='stripe_payment' ),
+ url(r'^$', self.stripe_payment_view, name='stripe' ),
url(r'^success/$', self.stripe_return_successful_view, name='stripe_success' ),
)
return urlpatterns
- @on_method(shop_login_required)
def stripe_payment_view(self, request):
- if request.user.is_authenticated() and request.user.get_profile().stripe_customer_id:
- customer_id = request.user.get_profile().stripe_customer_id
- else:
- card_token = request.POST['stripeToken']
- order = self.shop.get_order(request)
- order_id = self.shop.get_order_unique_id(order)
- amount = self.shop.get_order_total(order)
- amount = str(int(amount * 100))
- if request.user.is_authenticated(): description = request.user.email
- else: description = 'guest customer'
+ if request.POST:
+ if request.user.is_authenticated() and request.user.get_profile().stripe_customer_id:
+ customer_id = request.user.get_profile().stripe_customer_id
+ else:
+ card_token = request.POST['stripeToken']
+ order = self.shop.get_order(request)
+ order_id = self.shop.get_order_unique_id(order)
+ amount = self.shop.get_order_total(order)
+ amount = str(int(amount * 100))
+ if request.user.is_authenticated(): description = request.user.email
+ else: description = 'guest customer'
- currency = getattr(settings, 'SHOP_STRIPE_CURRENCY', 'usd') # Default to good ol' U.S. Dollar
+ currency = getattr(settings, 'SHOP_STRIPE_CURRENCY', 'usd') # Default to good ol' U.S. Dollar
- if hasattr(settings, 'SHOP_STRIPE_PRIVATE_KEY'):
- stripe.api_key=settings.SHOP_STRIPE_PRIVATE_KEY
- else:
- raise ConfigError('You must set SHOP_STRIPE_PRIVATE_KEY in your configuration file.')
+ if hasattr(settings, 'SHOP_STRIPE_PRIVATE_KEY'):
+ stripe.api_key=settings.SHOP_STRIPE_PRIVATE_KEY
+ else:
+ raise ConfigError('You must set SHOP_STRIPE_PRIVATE_KEY in your configuration file.')
- if not customer_id:
- stripe_dict = {
- 'amount':amount,
- 'currency':currency,
- 'card':card_token,
- 'description':description,}
- else:
- stripe_dict = {
- 'amount':amount,
- 'currency':currency,
- 'customer':customer_id,
- 'description':description,}
-
- stripe.Charge.create(**stripe_dict)
+ if not customer_id:
+ stripe_dict = {
+ 'amount':amount,
+ 'currency':currency,
+ 'card':card_token,
+ 'description':description,}
+ else:
+ stripe_dict = {
+ 'amount':amount,
+ 'currency':currency,
+ 'customer':customer_id,
+ 'description':description,}
+
+ stripe.Charge.create(**stripe_dict)
- # If we're logged in, save the transaction token for use again later. Sweet.
- if request.user.is_authenticated and request.user.get_profile().stripe_customer_id == None:
- customer = stripe.Customer.create(card=card_token, description=description)
- request.user.get_profile().stripe_customer_id=customer.id
- request.user.save()
+ self.shop.confirm_payment(self.shop.get_order_for_id(order_id), amount, transaction_id, self.backend_name)
+ # If we're logged in, save the transaction token for use again later. Sweet.
+ if request.user.is_authenticated and request.user.get_profile().stripe_customer_id == None:
+ customer = stripe.Customer.create(card=card_token, description=description)
+ request.user.get_profile().stripe_customer_id=customer.id
+ request.user.save()
+
if hasattr(settings, 'SHOP_STRIPE_PUBLISHABLE_KEY'):
pub_key=settings.SHOP_STRIPE_PUBLISHABLE_KEY
else:
raise ConfigError('You must set SHOP_STRIPE_PUBLISHABLE_KEY in your configuration file.')
- form_class = DeclarativeFieldsMetaclass('StripeForm', (forms.Form), fields)
- form = form_class(initial=stripe_dict)
+ form = CardForm
context = RequestContext(request, {'form':form, 'STRIPE_PUBLISHABLE_KEY':pub_key})
- return render_to_response("payment.html", context)
+ return render_to_response("shop_stripe/payment.html", context)
def stripe_return_successful_view(self, request):

0 comments on commit 64bb653

Please sign in to comment.