Search code examples
paypaldjango-formsdjango-paypal

Paypal "_cart" implementation with django-paypal


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?


Solution

  • I figured what I was missing. The form should be created with "cart" option:

    form = PayPalPaymentForm(initial=cart, button_type="cart")