Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

need model howto #8

Open
mixmastamyk opened this issue Jan 3, 2012 · 13 comments
Open

need model howto #8

mixmastamyk opened this issue Jan 3, 2012 · 13 comments

Comments

@mixmastamyk
Copy link
Contributor

Have installed the app and it is almost working correctly, however its not clear from the docs or sample app what fields I should add to my user profiles?

From the form blurb I see:
user.stripe_id, profile.last_4_digits, profile.stripe_customer_id

Would appreciate some guidance on where these come from and how to define these.

@skoczen
Copy link
Member

skoczen commented Jan 3, 2012

Hey Mixmastamyk,

You shouldn't have to add any fields directly - just use the models as mixins to your profile, and you should be set. (ie. have MyProfileModel inherit StripeCustomer, MyPlanModel inherit StripePlan, etc.

Agree that we need better docs on this though, leaving this issue open until we have them.

-S

@mixmastamyk
Copy link
Contributor Author

Thanks, interesting design. I chose this app over django-stripe because it had some documentation.

Do I need to make a plan model? Hmmm.

@skoczen
Copy link
Member

skoczen commented Jan 3, 2012

Hey,

Yeah, the mixin/subclass is pretty standard, and a nice pattern. You don't need to have a plan model, unless you want to do something with it within your app. In short, I'd figure out your data needs, and see what you need to store locally. Then, use the mixins to get the functionality you need.

Also, since it is open source, more/better doc pull requests are always appreciated. :)

@mixmastamyk
Copy link
Contributor Author

Sorry, I know this isn't a chat client, but what is user.stripe_id ? It seems to come out of nowhere in the view. Later on customer(Profile).stripe_customer_id is set. Are they the same thing? Is there a typo?

I made a profile model so I wouldn't have to hack on the Django user so would rather not save things to user.

@skoczen
Copy link
Member

skoczen commented Jan 4, 2012

Absolutely put it on your profile. And stripe_customer_id is the field you want. I think it's a typo. I'll double-check, then fix it up real quick.

@mixmastamyk
Copy link
Contributor Author

Thanks again, and for the quick response.

@skoczen
Copy link
Member

skoczen commented Jan 4, 2012

Yup, and fixed up now. Will look at your pull request a bit later this week when I do my code reviews for all the projects I'm maintaining.

@mixmastamyk
Copy link
Contributor Author

Thanks. I added StripeCustomer mixin to my profile (had to go before Model).

However, it doesn't have the last_4_digits field. I don't see the field in mixins.py or models.py. I guess this code hasn't actually been run? hehe. Also the form code assumes the customer was already created, but I've got it handled now.

@skoczen
Copy link
Member

skoczen commented Jan 4, 2012

Parts of the code have been run, but as a part of a bigger app. The rest is (and was intended to be) pseudocode. I need to make the docs better. The last_4_digits field is supposed to show an example of storing some data locally, to cache it for speedier access, etc.

It's the developer's decision on whether or not they need last_4, or any of the stripe data to be cached locally. Creating the customer's up to you, unless you have ZEBRA_AUTO_CREATE_STRIPE_CUSTOMERS set to True. Then, one would be auto-created on the first stripe_customer access.

Clearly, the docs could use some cleanup. :)

@mixmastamyk
Copy link
Contributor Author

Ok, thanks. I missed that the id was in the StripeCustomer and not the StripeMixin. I found the auto-create code.

Hopefully last question, :) ... what is the difference between saving the customer_id in the user profile vs saving it in the Customer table that the app created on install?

@skoczen
Copy link
Member

skoczen commented Jan 4, 2012

No real difference - it's all in where you want to keep it. We designed zebra to be really, really flexible, since it often has to fit into existing billing models. (I moved mine over from chargify to stripe.) There's not really a "right" way to do it, just a lot of options of which hopefully one fits you well. :)

@thom-nic
Copy link

curious, why wouldn't StripeCustomer use a foreign key relationship to User?

@skoczen
Copy link
Member

skoczen commented May 15, 2012

@tomstrummer - because that's not always what someone's schema needs.

In my case, my stripe accounts are tied to organizations, which have several users. For other people, it's profiles (one-to-one with user), for others, it's none of the above, and has nothing to do with users. Leaving it as a mixin is a more flexible way to solve the problem.

Also, for cases where what you want is a FK to User, the recommended way is to subclass your Profile class with StripeCustomer, to keep django happy, and keep things DRY.

@skoczen skoczen closed this as completed May 15, 2012
@skoczen skoczen reopened this May 15, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants