Bad import statement, minor docs cleanup #3

Merged
merged 8 commits into from Oct 15, 2012
View
77 README
@@ -1,77 +0,0 @@
-Django Shop Stripe plugin
-============================
-
-A plugin to use stripe with django-shop.
-
-http://www.stripe.com
-
-Installation
---------------
-
-Add `shop_stripe` to your INSTALLED_APPS variable in your settings.py file.
-
-Next, add a few configuration variables in the same file:
-
- SHOP_STRIPE_PUBLISHABLE_KEY='my-publishable-key'
- SHOP_STRIPE_PRIVATE_KEY='my-super-secret-private-key'
-
- SHOP_PAYMENT_BACKENDS = (
- ...
- 'shop_stripe.offsite_stripe.StripeBackend',
- ...
- )
-
-That's it!
-
-Usage
--------
-
-Thanks to Stripe.com's wonderful jscript features, it's painfully simple to integrate.
-
-The shop_stripe plugin uses all the default django-shop templates, and the most important for our purposes is:
-
- shop/payment.html
-
-Here's an example to handle Stripe test input:
-
- {% extends "base.html" %}
-
- {% block extra-head %}
- {% include "shop/_stripe_head.html" %}
- {% endblock %}
-
- {% block content %}
- <h2>Enter your payment information</h2>
- <br/>
- form action="" method="POST" id="payment-form">
- <p class="form-row">
- <label>Card Number</label>
- <input type="text" size="20" autocomplete="off" class="card-number" value="4242424242424242"/>
- </p>
- <p class="form-row">
- <label>CVC</label>
- <input type="text" size="4" autocomplete="off" class="card-cvc" value="123"/>
- </p>
- <p class="form-row">
- <label>Expiration (MM/YYYY)</label>
- <input type="text" size="2" class="card-expiry-month" value="12"/>
- <span> / </span>
- <input type="text" size="4" class="card-expiry-year" value="2013"/>
- </p>
- <button class="btn right submit-button" type="submit">Checkout</button>
- </form>
- {% endblock %}
-
-Note that we include shop/_stripe_head.html, that's the heavy lifting template that just pulls in the Stripe jscript.
-
-Conclusion
------------
-
-That's really it for now. The bulk of our logic is the offsite_stripe.py file.
-
-TODOs
-------
-
-1. Allow user-configurable fields to validate. django-shop-stripe currently doesn't even check the billing address of a user (which is becoming increasingly passe with credit cards anyhow...)
-2. Provide better, functional forms for the library. Do you know how to render id-less form field inputs with Django forms? Stripe requires that you have no IDs on inputs, which means the form data NEVER hits your server and you stay clean with the law.
-
View
@@ -30,14 +30,14 @@ Thanks to Stripe.com's wonderful jscript features, it's painfully simple to inte
The shop_stripe plugin uses all the default django-shop templates, and the most important for our purposes is:
- shop/payment.html
+ shop_stripe/payment.html
Here's an example to handle Stripe test input:
{% extends "base.html" %}
{% block extra-head %}
- {% include "shop/_stripe_head.html" %}
+ {% include "_stripe_head.html" %}
{% endblock %}
{% block content %}
@@ -62,7 +62,7 @@ Here's an example to handle Stripe test input:
</form>
{% endblock %}
-Note that we include shop/_stripe_head.html, that's the heavy lifting template that just pulls in the Stripe jscript.
+Note that we include _stripe_head.html, that's the heavy lifting template that just pulls in the Stripe jscript.
Conclusion
-----------
@@ -6,12 +6,11 @@
from django.http import HttpResponseRedirect
from shop.util.decorators import on_method, shop_login_required
from django.forms.forms import DeclarativeFieldsMetaclass
-from django.http import (HttpResponseBadRequest, HttpResponse,
- HttpResponseRedirect)
+from django.http import HttpResponseBadRequest, HttpResponse, HttpResponseRedirect
from django.template import RequestContext
from django.shortcuts import render_to_response
-import stripe
from shop_stripe.forms import CardForm
+import stripe
class ConfigError(Exception):
def __init__(self, value):
@@ -24,7 +23,7 @@ class StripeBackend(object):
A django-shop payment backend for the stripe service, this
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.
'''
backend_name="Stripe"
@@ -44,7 +43,7 @@ def get_urls(self):
def stripe_payment_view(self, request):
if request.POST:
- if request.user.is_authenticated() and request.user.get_profile().stripe_customer_id:
+ if request.user.is_authenticated() and not request.user.get_profile().stripe_customer_id == '':
customer_id = request.user.get_profile().stripe_customer_id
else:
customer_id=None
@@ -53,16 +52,18 @@ def stripe_payment_view(self, 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.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
-
+
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,
@@ -76,15 +77,15 @@ def stripe_payment_view(self, request):
'customer':customer_id,
'description':description,}
- stripe.Charge.create(**stripe_dict)
-
- self.shop.confirm_payment(self.shop.get_order_for_id(order_id), amount, transaction_id, self.backend_name)
+ stripe_result = stripe.Charge.create(**stripe_dict)
+ self.shop.confirm_payment(self.shop.get_order_for_id(order_id), amount, stripe_result['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()
+ profile = request.user.get_profile()
+ profile.stripe_customer_id = customer.id
+ profile.save()
if hasattr(settings, 'SHOP_STRIPE_PUBLISHABLE_KEY'):
pub_key=settings.SHOP_STRIPE_PUBLISHABLE_KEY