A pass to get a charge iframe show up for wepay

pull/1/head
Raymond Yee 2012-08-20 15:19:27 -07:00
parent 6c4f98095f
commit 214bc4b9e5
6 changed files with 90 additions and 4 deletions

View File

@ -7,4 +7,7 @@ class StripePledgeForm(forms.Form):
stripeToken = forms.CharField(required=False, widget=forms.HiddenInput())
class BalancedPledgeForm(forms.Form):
card_uri = forms.CharField(required=False, widget=forms.HiddenInput())
card_uri = forms.CharField(required=False, widget=forms.HiddenInput())
class WepayPledgeForm(forms.Form):
pass

View File

@ -0,0 +1,24 @@
{% extends "basepledge.html" %}
{% load humanize %}
{% block title %}WePay{% endblock %}
{% block extra_extra_head %}
<link type="text/css" rel="stylesheet" href="/static/css/campaign.css" />
<link type="text/css" rel="stylesheet" href="/static/css/pledge.css" />
<script type="text/javascript" src="https://www.wepay.com/js/iframe.wepay.js"></script>{% endblock %}
{% block doccontent %}
<div id="checkout_div"></div>
<script type="text/javascript">
WePay.iframe_checkout("checkout_div", "{{checkout_uri}}");
</script>
{% endblock %}

View File

@ -1,6 +1,6 @@
from django.conf.urls.defaults import *
from django.conf import settings
from regluit.payment.views import StripeView, BalancedView
from regluit.payment.views import StripeView, BalancedView, WepayView
urlpatterns = patterns(
"regluit.payment.views",
@ -31,6 +31,7 @@ if settings.DEBUG:
url(r"^testmodify", "testModify"),
url(r"^stripe/test", StripeView.as_view()),
url(r"^balanced/test", BalancedView.as_view()),
url(r"^wepay/test", WepayView.as_view()),
)

View File

@ -5,8 +5,9 @@ from regluit.core.models import Campaign, Wishlist
from regluit.payment.stripelib import STRIPE_PK
from regluit.payment.balancedlib import MARKETPLACE_URI
from regluit.payment import wepaylib
from regluit.payment.forms import StripePledgeForm, BalancedPledgeForm
from regluit.payment.forms import StripePledgeForm, BalancedPledgeForm, WepayPledgeForm
from django.conf import settings
from django.core.urlresolvers import reverse
@ -367,6 +368,25 @@ class BalancedView(FormView):
card_uri = form.cleaned_data["card_uri"]
return HttpResponse("card_uri: {0}".format(card_uri))
class WepayView(FormView):
template_name="wepay.html"
form_class = WepayPledgeForm
def get_context_data(self, **kwargs):
context = super(WepayView, self).get_context_data(**kwargs)
# compute a uri to embed in frame
# test payment of $10
r = wepaylib.create_checkout(10.00, "test charge of 10.00", mode='iframe')
context.update({
'checkout_uri':r['checkout_uri']
})
return context

37
payment/wepaylib.py Normal file
View File

@ -0,0 +1,37 @@
from wepay import WePay
# should load the keys for WePay from db -- but for now just hardcode here
try:
from regluit.core.models import Key
WEPAY_ACCESS_TOKEN = Key.objects.get(name="WEPAY_ACCESS_TOKEN").value
WEPAY_CLIENT_SECRET = Key.objects.get(name="WEPAY_CLIENT_SECRET").value
WEPAY_ACCOUNT_ID = Key.objects.get(name="WEPAY_ACCOUNT_ID").value
logger.info('Successful loading of WEPAY_*_KEYs')
except Exception, e:
WEPAY_ACCESS_TOKEN = 'a680cfd2b814ef0e4938b865c96879136a74970ad6c9425e8c98de50b40007af'
WEPAY_CLIENT_SECRET= 'f9bf05cd50'
WEPAY_ACCOUNT_ID = 1226963
# set production to True for live environments
PRODUCTION = False
wepay = WePay(PRODUCTION, WEPAY_ACCESS_TOKEN)
# collect credit card and do a delay charge to gluejar -- then to LR....
# Then, you can charge customers on their behalf. It?s just like charging a customer normally, except you should use their access_token and account_id instead of your own.
def create_checkout(amount, description, account_id=WEPAY_ACCOUNT_ID, mode="iframe", type='GOODS'):
# type: one of GOODS, SERVICE, PERSONAL, or DONATION
# create the checkout
response = wepay.call('/checkout/create', {
'account_id': WEPAY_ACCOUNT_ID,
'amount': amount,
'short_description': description,
'type': type,
'mode': mode
})
# display the response
return response

View File

@ -29,4 +29,5 @@ django-maintenancemode
django-smtp-ssl
django-ckeditor
stripe
balanced
balanced
git+ssh://git@github.com/wepay/Python-SDK.git