jazzband / django-payments

Universal payment handling for Django.
https://django-payments.readthedocs.io
Other
1.07k stars 282 forks source link

Support for subscription #419

Open paulocoutinhox opened 2 months ago

paulocoutinhox commented 2 months ago

Hi,

Can you add support for subscription?

This is a nice project.

Thanks.

mariofix commented 2 months ago

Can you elaborate?

There are a few ways to handle recurring subscriptions (assuming that's what you are referring).

paulocoutinhox commented 2 months ago

Yes,

Im talking about recurring subscriptions.

This lib already have support for this?

I see some PRs to add support for this.

Things that help understand if the user is a subscriber will help.

mariofix commented 2 months ago

Perhaps this project would be helpful? https://github.com/PetrDlouhy/django-plans-payments

paulocoutinhox commented 2 months ago

Hi,

I want pay with this library a product with recurring subscription on checkout, it possible?

I don't know where i put the product-id in this library.

Thanks.

mariofix commented 2 months ago

Hi Paulo, the stripe endpoints available in this library are for Checkout Sessions.

I would suggest trying dj-stripe, I think they have support for other Stripe products.

deeprave commented 1 week ago

There are only a few differences between direct payment processing and subscriptions, but subscriptions/automatic payments will require a bit more backend work in periodic processing later. The initial part would be turning the capture off and saving the authorization ID, then processing the initial payment request as usual. A schedule - and some way of executing it - would be needed to initiate further payments using the same authorization/billing ID returned by the provider. The provider endpoints and content may differ slightly, but these are just provider variants. The infrastructure is already there for most of this.

I am looking for the same feature, so I will look into this further unless someone is already on it (in which case, I am more than willing to help in testing).

mariofix commented 1 week ago

hey @deeprave thanks for your message, I've been thinking about the subscription/recurring payments thing, and i'm not sure it'll be as straightforward, i was thinking something like:

I'm worried about the payment_type, since it breaks backwards compatibility. I'm not sure how to store each payment made within the subscription, using extra_data seems a bit much since a single payment would take a lot of space.

It looks interesting, unfortunately i have a bit of a backlog with this project, but i'll be willing to assist if you'd like to contribute.

deeprave commented 1 week ago

You're right. I was working through an implementation and now better appreciate the complexity.

Breaking changes and restructuring the data in the db will be required to track individual payments against each provider authorization.

A suitable migration for payment_type could be done to backfill with the default value "one_time," but I think that, in reality, it requires more. There is a relationship between provider, available payment types, payment period and even amounts—which needs configuration. Sometimes, this can be fetched via provider-specific API.