コード例 #1
0
ファイル: models.py プロジェクト: clytwynec/muckrock
 def make_recurring_payment(self, token, email, amount, show, user):
     """Make a recurring payment for the crowdfund"""
     # pylint: disable=too-many-arguments
     plan = self._get_stripe_plan()
     customer = stripe_get_customer(
         user,
         email,
         'Crowdfund {} for {}'.format(self.pk, email),
     )
     subscription = stripe_retry_on_error(
         customer.subscriptions.create,
         plan=plan,
         source=token,
         quantity=amount,
         idempotency_key=True,
     )
     RecurringCrowdfundPayment.objects.create(
         user=user,
         crowdfund=self,
         email=email,
         amount=amount,
         show=show,
         customer_id=customer.id,
         subscription_id=subscription.id,
     )
     return subscription
コード例 #2
0
ファイル: views.py プロジェクト: clytwynec/muckrock
 def make_subscription(self, token, amount, email):
     """Start a subscription for recurring donations"""
     subscription = None
     quantity = amount / 100
     customer = stripe_get_customer(
         self.request.user,
         email,
         'Donation for {}'.format(email),
     )
     if self.request.user.is_authenticated:
         user = self.request.user
     else:
         user = None
     try:
         subscription = stripe_retry_on_error(
             customer.subscriptions.create,
             plan='donate',
             source=token,
             quantity=quantity,
             idempotency_key=True,
         )
     except stripe.error.CardError:
         logger.warn('Card was declined.')
         messages.error(self.request, 'Your card was declined')
     except stripe.error.StripeError as exception:
         logger.error(exception, exc_info=sys.exc_info())
         messages.error(
             self.request,
             'Oops, something went wrong on our end. Sorry about that!',
         )
     else:
         RecurringDonation.objects.create(
             user=user,
             email=email,
             amount=quantity,
             customer_id=customer.id,
             subscription_id=subscription.id,
         )
         mixpanel_event(
             self.request,
             'Recurring Donation',
             {'Amount': quantity},
         )
     return subscription