Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- +----+--------------------+---------------------+---------------+--------------------------+---------+--------------+--------+
- | id | charge_id | created_at | email | description | user_id | theplan | amount |
- +----+--------------------+---------------------+---------------+--------------------------+---------+--------------+--------+
- | 16 | cus_72tu5qgHlo5qQM | 2015-09-25 04:50:42 | root@root.com | Charge for root@root.com | 1 | test1usd | 195 |
- | 17 | cus_72uCNERCFC6ce2 | 2015-09-25 05:09:02 | root@root.com | Charge for root@root.com | 1 | test12months | 1999 |
- +----+--------------------+---------------------+---------------+--------------------------+---------+--------------+--------+
- class Payment(models.Model):
- class Meta:
- app_label = 'name'
- charge_id = models.CharField(max_length=128, null=True, blank=True)
- user = models.ForeignKey(User)
- created_at = models.DateTimeField(null=False, auto_now_add=True)
- email = models.CharField(max_length=256, null=True, blank=True)
- theplan = models.CharField(max_length=64, null=True, blank=True)
- amount = models.CharField(max_length=16, null=True, blank=True)
- description = models.CharField(max_length=256, null=True, blank=True)
- class StripeApi(View):
- @staticmethod
- def post(request):
- charge = stripe.Customer.create(
- source=request.POST['stripeToken'],
- email=request.POST['stripeEmail'],
- plan=request.POST['plan'],
- description='Charge for {}'.format(request.POST.get("stripeEmail", "")),
- )
- customer_description = charge["description"]
- customer_email = charge["email"]
- customer_id = charge.id
- plan = stripe.Plan.retrieve(
- request.POST['plan']
- )
- payment_plan = plan.id
- payment_amount = plan.amount
- try:
- site_user = User.objects.get(username=customer_email)
- Payment.objects.create(
- charge_id=customer_id,
- user=site_user,
- email=customer_email,
- description=customer_description,
- theplan=payment_plan,
- amount=payment_amount
- )
- except User.DoesNotExist:
- return HttpResponse(
- json.dumps({
- 'success': 'There is no user with this email address in DB'
- })
- )
- return HttpResponse(
- json.dumps({
- 'success': True
- }), content_type="application/json")
- @staticmethod
- def get(request):
- return render(request, 'index.html',
- {
- 'stripe_pub_key': settings.STRIPE_PUBLISHABLE_KEY
- })
Add Comment
Please, Sign In to add comment