def link_stripe_customer(sender, user, request, customer, plan=None, **kwargs): user_profile = user.get_profile() user_profile.customer_id = customer.id user_profile.card_last4 = customer.active_card.last_4 user_profile.plan = plan try: user_profile.trial_end = datetime.utcfromtimestamp(customer.subscription.trial_end) except AttributeError: pass user_profile.save() upcoming_invoice_updated.send(sender=None, customer=customer)
def invoice_user(sender, customer, invoice, **kwargs): try: user_profile = UserProfile.objects.get(customer_id=customer) amount = int(user_profile.collaborator_count * user_profile.get_price()) if not user_profile.trialing and amount > 0: stripe.InvoiceItem.create( \ customer=customer, amount=amount * 100, currency='usd', description="%s Collaborators" \ % user_profile.collaborator_count ) upcoming_invoice_updated.send(sender=None, customer=customer) except UserProfile.DoesNotExist: pass