forked from FundedByMe/django-paypal-adaptive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
57 lines (38 loc) · 1.75 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
A trivial example for now:
---------------
urls.py:
from buzzcar.accounting.views import view_that_asks_for_money
from django.conf.urls.defaults import patterns, url, include
urlpatterns = patterns('',
url(r'^payment/$', view_that_asks_for_money, name="payment"),
url(r'^paypal/', include('paypaladaptive.urls')),
)
views.py:
from django.contrib.auth.decorators import login_required
from django.http import HttpResponseServerError, HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template.context import RequestContext
from django.views.decorators.http import require_GET
from money.Money import Money
from paypaladaptive import settings, forms
from paypaladaptive.models import Payment
import logging
logger = logging.getLogger(__name__)
@login_required
@require_GET
def view_that_asks_for_money(request):
payment = Payment(amount=Money('5.00'), purchaser=request.user)
if not payment.process(request):
# TODO: unable to process payment
logger.error('Payment returned error during processing: %s' % payment.status_detail)
return HttpResponseServerError("Unexpected error")
if not settings.USE_EMBEDDED:
return HttpResponseRedirect(payment.next_url())
form = forms.PayPalAdaptiveEmbeddedForm(payment.pay_key)
context = RequestContext(request)
template_vars = {"form": form}
return render_to_response("payment.html", template_vars, context)
templates/payment.html (not showing inheritance):
<h1>Show me the money!</h1>
<!-- writes out the form tag automatically -->
{{ form.render }}