1

I am using django paypal to allow users to make a payment on my site however i have a few queries.

The way how it is currently working for me is that i have a template called profile.html. When a user clicks the button "Click for more subscription options" he will be redirected to the subscriptions.html template showing a table of the subscriptions and a paypal button. When the button is clicked, the user gets redirected to another template called paypal.html which shows another paypal button derived from django-paypal's forms.py

My question here would be how i can modify the paypal view such that i can do away with the paypal.html and direct the user directly to the actual paypal website when he clicks the paypal button in subscription.html?

I hope my description of the question is clear enough.

in my views.py:

def paypal(request):
    paypal_dict = {"business":settings.PAYPAL_RECEIVER_EMAIL,"amount": "1.00","item_name": "Milk" ,"invoice": "12345678", "notify_url": "%s%s" % (settings.SITE_NAME, reverse('paypal-ipn')),"return_url": "http://rosebud.mosuma.net",}
    # Create the instance.
    form = PayPalPaymentsForm(initial=paypal_dict)
    context = {"form": form.sandbox()}
    return render_to_response("paypal.html", context)

in my profile.html:

....
<INPUT TYPE="submit" Value="Click to find out subscription plans" name="subscription" onClick="/subscribe/>

in my subscription.html:

<form method="post" action="paypal/">
<select name="subscription_input" id="id_subscription" style = "float: center">
<option>Monthly</option>
<option>Yearly</option>
</select></br></br>

{{ form }}
</form>

in my urls.py:

url(r'^paypal/$', 'r2.views.paypal', name='paypal'),
url(r'^profile/paypal/$', 'r2.views.paypal', name='paypal'),
4

1 回答 1

1

如果您希望用户在单击 subscription.html 中的 PayPal 按钮时直接进入 PayPal 网站,您必须在 subscription.html 而不是 paypal.html 中呈现 PayPal 表单。此外,您需要在 forms.py 中对 PayPalPaymentsForm 进行子类化,以覆盖“立即购买”的默认 PayPal 图像,因为您首先希望自己的按钮起作用。


表格.py

from paypal.standard.forms import PayPalPaymentsForm
from django.utils.html import format_html

class ExtPayPalPaymentsForm(PayPalPaymentsForm):
    def render(self):
        form_open  = u'''<form action="%s" id="PayPalForm" method="post">''' % (self.get_endpoint())
        form_close = u'</form>'
        # format html as you need
        submit_elm = u'''<input type="submit" class="btn btn-success my-custom-class">'''
        return format_html(form_open+self.as_p()+submit_elm+form_close)

视图.py

from .forms import ExtPayPalPaymentsForm
def paypal(request):
    paypal_dict = {"business":settings.PAYPAL_RECEIVER_EMAIL,"amount": "1.00","item_name": "Milk" ,"invoice": "12345678", "notify_url": "%s%s" % (settings.SITE_NAME, reverse('paypal-ipn')),"return_url": "http://rosebud.mosuma.net",}
    # Create the instance.
    form = ExtPayPalPaymentsForm(initial=paypal_dict)
    context = {"form": form.sandbox()}
    return render_to_response("subscription.html", context)
于 2019-05-18T05:13:32.783 回答