2

I installed django-paypal, and I'm trying to enable subscription button.

I have the following view.

def donate_root(request):
    paypal_dict = {
        "business": PAYPAL_RECEIVER_EMAIL,
        "amount": "10.00",
        "item_name": "foobar money",
        'currency_code': 'USD',
        "invoice": "unique-invoice-id",
        "notify_url": "https://www.example.com" + reverse('paypal-ipn'),
        "return_url": "https://www.example.com/your-return-location/",
        "cancel_return": "https://www.example.com/your-cancel-location/",
        't3': 'D',
        'p3': '1',

    }
    form = PayPalPaymentsForm(initial=paypal_dict)
    context = {"form": form}
    return render_to_response("main.html", context)

In main.html I have the following inside a div

{{ form.render }}

When I click the link, it takes me to paypal page that take the money once, and not recurring payment.

What did I do wrong?

Ahmed
  • 2,825
  • 1
  • 25
  • 39

1 Answers1

2

I found the mistake.

The testing account I used wasn't a business account, and the command that the form send is the wrong command.

The right command is "_xclick-subscriptions". If you look at the generated html you will see this line

<input id="id_cmd" type="hidden" value="_xclick" name="cmd">

That value must be replaced with the "_xclick-subscriptions" command.

Finally, I forgot another variable called a3 for the amount I want to bill every month.

If you're reading this, my advice is not to use django-paypal. It's confusing, and got a lot errors running it.

Ahmed
  • 2,825
  • 1
  • 25
  • 39
  • by replacing cmd as _xclick-subscriptions does recurring payment works? –  Jan 16 '15 at 07:32
  • Yes, if you replace it from the input itself. I didn't use django-paypal. I ended up using their button into my html, and replaced the values I need to change manually by using jQuery. If you change value="_xclick" to value="_xclick-subscriptions" you will have recurring payment. However, make sure you have all the right variables for the rest of the html – Ahmed Jan 17 '15 at 08:33
  • i have another doubt that how will the user cancel this subscription or if he do that via paypal website how will the website know he has cancelled his subscription.Have you done this? –  Jan 21 '15 at 05:05
  • I never implemented, but I think PayPal will call your IPN. See this example, http://stackoverflow.com/a/2092633/2135035 – Ahmed Jan 22 '15 at 21:57
  • Do i want to cancel from paypal website or is there any api to cancel from within our site –  Jan 24 '15 at 05:30
  • Sorry, I don't understand you. – Ahmed Jan 25 '15 at 21:02
  • @user2842009 you can do both – Barney Szabolcs Dec 24 '19 at 12:59
  • hey @Ahmed it's been awhile since this post... how did django-paypal work out? is it worth it? did you use any other tool? I am about to implement it myself and I would like to know your thoughts on it, thanks – edd Feb 17 '20 at 16:11
  • No, I ended up creating a my own post-hook view. It's not really worth it, all you have to do is have an html with the values you need, then have a post-hook view that will listen to incoming paypal call. I have done this 6 years ago. This answer might be out of date. – Ahmed Feb 17 '20 at 16:14