Multiple Items in django-paypal
I am using dcramer's version of django-paypal(but i think it shouldnt matter whether it is dcramer or johnboxall's).
1) How can i specify multiple items in my paypal_dict(to be used in PayPalPaymentsForm)? 2) Also, i need to suita开发者_如何学Pythonbly specify the shipping cost and the individual quantities in the Summary that appears in the Paypal screen - how do i do this?
I'm not fond of django-paypal. Just read the PayPal api: https://www.paypal.com/cgi-bin/webscr?cmd=p/pdn/howto_checkout-outside.
To push all the items in your cart to PayPal:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="you@youremail.com">
<input type="hidden" name="currency_code" value="EUR">
<!-- Run a for loop -->
{% for item in cart %}
<input type="hidden" name="item_name_1" value="Item Name 1">
<input type="hidden" name="amount_1" value="10.00">
<input type="hidden" name="item_name_2" value="Item Name 2">
<input type="hidden" name="amount_2" value="20.00">
.
.
.
<input type="hidden" name="item_name_N" value="Item Name N">
<input type="hidden" name="amount_N" value="30.00">
{% endfor %}
<input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
I end up building item dictionaries like this in the view:
item = {
'cancelurl': 'http://%s%s' % DYNAMIC_URL, reverse('pay_cancel')), # Express checkout cancel url
'returnurl': 'http://%s%s' % (DYNAMIC_URL, reverse('pay_now')), # Express checkout return url
'l_name0': 'Your product name',
'l_number0': 1234,
'l_desc0': 'longer description',
'l_amt0': 100.00,
'l_qty0': 1,
'l_name1': 'Your product name',
'l_number1': 1234,
'l_desc1': 'longer description',
'l_amt1': 200.00
'l_qty1': 2,
'itemamt': 500.00,
'taxamt': 0.00,
'shippingamt': 0.00,
'handlingamt': 0.00,
'shipdiscamt': 0.00,
'insuranceamt': 0.00,
'amt': 500.00, # Amount to charge for basket
}
This dict then gets bundled up like this:
kw = {
'item': item,
'payment_template': 'cms/register.html', # Template name for payment
'confirm_template': 'cms/paypal-confirmation.html', # Template name for confirmation
'success_url': reverse('pay_success'), # Ultimate return URL
}
ppp = PayPalPro(**kw)
return ppp(request)
Is that what you mean?
Assuming you want to to make paypal work with your cart. Use a for loop for items in the cart. In order to get a number for each item for paypal to recognize them i use item.id
{% extends 'base.html' %}
{% block content %}
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="account@mail.com">
<input type="hidden" name="currency_code" value="USD">
{% for item in cart %}
<input type="hidden" name="item_name_{{item.id}}" value="
{{item.name}}">
<input type="hidden" name="amount_{{item.id}}" value="{{item.price}}">
{% endfor %}
<input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif"
name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
</form>
{% endblock %}
精彩评论