views:

177

answers:

2

I'm using Django PayPal. PayPal has a list of options you can pass on your button. I'm trying to add some of these to my paypal_dict

paypal_dict = {
    # ...

    # preopulate paypal checkout page
    "email": invoice.user.email,
    "first_name": invoice.user.first_name,
    "last_name": invoice.user.last_name,
    "address1": invoice.user.address.street,
    "city": invoice.user.address.city,
    "country": invoice.user.address.get_country_display,
    "address_country_code": invoice.user.address.country
}

form = PayPalPaymentsForm(initial=paypal_dict)

But when I inspect the form, these fields are never added. How can I get them to be added?

A: 

I hacked it in:

def __init__(self, button_type="buy", extra_options={}, *args, **kwargs):
    super(PayPalPaymentsForm, self).__init__(*args, **kwargs)
    self.extra_options = extra_options
    self.button_type = button_type

def render(self):
    extra_fields = u''.join(['<input type="hidden" name="%s" value="%s" />' % (escape(name), escape(value)) for name, value in self.extra_options.iteritems()])          
    return mark_safe(u"""<form action="%s" method="post">
%s
%s
<input type="image" src="%s" border="0" name="submit" alt="Buy it Now" />
</form>""" % (POSTBACK_ENDPOINT, self.as_p(), extra_fields, self.get_image()))


def sandbox(self):
    extra_fields = u''.join(['<input type="hidden" name="%s" value="%s" />' % (escape(name), escape(value)) for name, value in self.extra_options.iteritems()])  
    return mark_safe(u"""<form action="%s" method="post">
%s
%s
<input type="image" src="%s" border="0" name="submit" alt="Buy it Now" />
</form>""" % (SANDBOX_POSTBACK_ENDPOINT, self.as_p(), extra_fields, self.get_image()))
Mark
A: 

The above hack doesnt seem to work for me. I am using dcramer's version and have the above code in paypal\standard\forms.py - is that right?

sprezzatura
I think i jumped the gun. i had to pass extra_options while creating the form and then it works. BUT BUT BUT..i still have a problem, how do i specify multiple items?? Also, i need to specify the total quantity and the shipping cost...how do i include this in the order summary?
sprezzatura
@sprezzatura: It's a dictionary... pass in as many items as you want. `{'item1:'value1','item2':'value2'}`. Like I said, it's a hack, I can't support it. Quantity and shipping cost should be supported natively by Django-PayPal.. you don't need my hack to pass those in.
Mark
Multiple items doesnt seem to work. If you happen to get it by any chance, do let me know.
sprezzatura