django-oscar / django-oscar-paypal

PayPal integration for django-oscar. Can be used without Oscar too.
https://django-oscar-paypal.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
164 stars 213 forks source link

Add support for recurring payments #20

Open codeinthehole opened 11 years ago

codeinthehole commented 11 years ago

In PayPal Express, you can create recurring billing profiles, which is something we should support.

Tasks:

eukreign commented 11 years ago

Is there any updates on this feature? I'm trying to determine if I should try to implement it myself or wait for the official version.

codeinthehole commented 11 years ago

I haven't really done any work on it other than a simple POC commit: https://github.com/tangentlabs/django-oscar-paypal/commit/e239980938b91bf811fdbf8d36c942f80df25852

Someone else from Tangent is definitely working on this at the moment though as we have a client who needs subscription products that require recurring payments. However, I'm not sure how long it would take for that work to make it into this extension. @a-musing-moose - can you offer any further advice?

So my advice would probably be to fork the extension and implement the recurring logic yourself (so you're not waiting for us). I'd happily review your work and merge it if you submit a PR afterwards.

a-musing-moose commented 11 years ago

@eukreign As @codeinthehole says I have been working on a little on this over the past few days. I have a very basic working branch now: https://github.com/a-musing-moose/django-oscar-paypal/commit/ad54d265aa72488eccc2fcffa825b0688b61783d

There are no real test or documentation for it yet I'm afraid and some pretty limiting restrictions.

What is does allow:

Restrictions:

The way paypal recurring payments work (at least in express checkout) is that a separate recurring payment needs to be set up for each product purchased. This is somewhat different to how normal payments are constructed. You also need to call CreateRecurringPaymentProfile for each of these payments. You also need to perform a DoExpressCheckoutPayment if there are any normal payments in the basket as well. i.e. you end up with multiple transactions at the end of the process.

So full support is a fairly complex proposal. For the project I am currently working on, and the time frame I have, this is not possible. Hence compromising on a limited implementation.

Within the project that is using the recurring payments I am extending the basket app to include additional logic. Namely, that whenever a product with a recurring profile is added to the basket. That basket is first cleared so that the recurring product is the only one in it. I am also added logic to only allow a quantity of 1.

If you are still interested in using the modification I have made thus far then I should also explain the PAYPAL_RECURRING_PREDICATE settings. This is the method by which we determine if a product has a recurring profile. It specifies the full path to a function. e.g.:

PAYPAL_RECURRING_PREDICATE = 'myapp.mymodule.get_recurring_profile'

This function is passed a product and returns either None if the product does not have a recurring profile. Or a dictionary in the following form for one that does:

{
    'billing_description': 'a description - $10 per month',
    'billing_frequency': 1,
    'billing_period': 'Month',
}  

Since you do not pass the actual amount to paypal until the CreateRecurringPaymentProfile call right at the end. It is recommended that the billing description contains not only the product description but all the cost, and recurring profile.

billing_period can be 'Day', 'Week', 'Month', 'SemiMonth', 'Year' and billing_frequency is an integer value. So the above example is every 1 month.

There is one additional part I have yet to implement. Which is IPN support. Instant Payment Notifications are sent out for recurring payments. One for the initial set and then one for every successful payment after that, or if the customer cancels the payment. That I'm afraid is still an exercise for the user.

Hit me up if you have any further question. Either here or on the mailing list.

eukreign commented 11 years ago

You guys are awesome, thank you for the explanation.

I am using PayPal Payments Advanced which requires tokens and CC input being hosted by them.

I'll make pull requests if I'm able to generalize my implementation.

One problem I've found with the hosted pages and tokens is that they do not support creating Recurring transactions.

I found a stackoverflow post which explains the problem and provides a possible solution: http://stackoverflow.com/questions/13629023/secure-tokens-for-paypal-recurring-payments

I will try to see if that solution could be generalized.

SalahAdDin commented 8 years ago

What happen with this?

DanSmall commented 8 years ago

Can I also ask if there are there any plans to implement this?

nhondong commented 3 years ago

Any updates on this Issue?

SalahAdDin commented 3 years ago

I guess it died.

Any updates on this Issue?

pije76 commented 3 years ago

Please someone add subscription modul for oscar.

j2l commented 9 months ago

Meanwhile, 11y, waiting.