Reputation: 2095
I am working with django-paypal ipn.standard and am trying to get it working with a paypal's "_cart" option. However, I cannot make it work.
I use this dictionary to initialize the forms:
cart {
'amount_1': '0.99',
'amount_2': '0.99',
'business': '[email protected]',
'cancel_return': 'http://www.foo.com/ccled/',
'cmd': '_cart',
'invoice': '1',
'item_name_1': 'Item 1',
'item_name_2': 'Item 2',
'notify_url': 'http://www.foo.com/ntfy/',
'return_url': 'http://www.doo.com/done/'
}
form = PayPalPaymentForm(initial=cart)
I have also tried adding "CMD_CHOICES":"_cart" to the above dict, but didn't make a difference
However, on using {{ form.render }} I get the Buy-Now button with the html below:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="business" value="[email protected]" id="id_business" />
<input type="hidden" name="notify_url" value="'http://www.foo.com/ntfy//" id="id_notify_url" />
<input type="hidden" name="cancel_return" value="http://www.foo.com/ccled/" id="id_cancel_return" />
<input type="hidden" name="return" value="http://www.foo.com/done/" id="id_return_url" />
<input type="hidden" name="invoice" value="1" id="id_invoice" />
<input type="hidden" name="cmd" value="_cart" id="id_cmd" />
<input type="hidden" name="charset" value="utf-8" id="id_charset" />
<input type="hidden" name="currency_code" value="USD" id="id_currency_code" />
<input type="hidden" name="no_shipping" value="1" id="id_no_shipping" />
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="Buy it Now" />
</form>
None of the shopping cart items are shown.
I was looking at a couple of other threads like Multiple Items in django-paypal. To try it out, I cut-pasted the 'item' dictionary from that example, and passed it to my PayPalPaymentForm. However, again, in the form, I do not see the items being sold.
What am I missing, please?
Upvotes: 1
Views: 692
Reputation: 1
If ever someone struggles again with this, here is how I managed to fix this for my project. I spent way too much time on this as it was not really well documented and I couldn't find a working example:
paypal_dict = {
'upload': 1,
'business': '[email protected]',
'invoice': 'INVOICE1',
'currency_code': 'CAD',
'cmd': '_cart',
'charset': 'utf-8',
'notify_url': 'http://website.ca/paypal/',
'return_url': 'http://website.ca/payment-completed',
'cancel_return': 'http://website.ca/payment-failed',
'quantity_1': 1,
'item_name_1': 'item 1',
'item_number_1': 1, #This is just a product ID for your reference
'shipping_1': 0,
'amount_1': 150,
'quantity_2': 1,
'item_name_2': 'item2',
'item_number_2': 2,
'shipping_2': 0,
'amount_2': 125,
}
paypal_payment_button = PayPalPaymentsForm(initial=paypal_dict, button_type="buy")
So what I do is basically just specifying all requirements for each individual products to the PaymentsForm and I also make sure to specify the cmd as _cart. I also provide the upload flag to the cart got uploaded to paypal.
With this I can have all my item with product ID and description directly on the paypal invoice.
Upvotes: 0
Reputation: 2095
I figured what I was missing. The form should be created with "cart" option:
form = PayPalPaymentForm(initial=cart, button_type="cart")
Upvotes: 1