def get(self): user = self.get_current_user_object() payments = [] if user.is_paid: payments = PaymentLog.last_payments(count=3, user_id=user.id) already_requested = self.get_secure_cookie("image_request") promotions = Promotion.active() return self.render("account/settings.html", user=user, payments=payments, already_requested=already_requested, promotions=promotions)
def get(self): user = self.get_current_user_object() payments = [] if user.is_paid: payments = PaymentLog.last_payments(count=3, user_id=user.id) already_requested = self.get_secure_cookie("image_request") cancel_flag = "canceled" in (user.stripe_plan_id or "") migrated_flag = self.get_argument('migrated', 0) promotions = Promotion.active() has_data_to_migrate = not MigrationState.has_migrated(user.id) return self.render("account/settings.html", user=user, payments=payments, already_requested=already_requested, promotions=promotions, plan_name=plan_name(user.stripe_plan_id), has_data_to_migrate=has_data_to_migrate, migrated_flag=migrated_flag, cancel_flag=cancel_flag)
def get(self): user = self.get_current_user_object() payments = [] if user.is_paid: payments = [] if user.stripe_customer_id: customer_id = user.stripe_customer_id charges = stripe.Charge.list(limit=5, customer=customer_id) for charge in charges.data: payments.append({ "transaction_amount": "USD %0.2f" % (charge.amount / 100.0, ), "refund_amount": charge.refunded and "USD %0.2f" % (charge.amount_refunded / 100.0, ) or "", "created_at": datetime.datetime.fromtimestamp(charge.created), "status": "charged", "is_pending": charge.status == "pending", "is_failed": charge.status == "failed", "is_success": charge.status == "succeeded", "is_refund": charge.refunded, }) else: log = PaymentLog.last_payments(count=5, user_id=user.id) for payment in log: payments.append({ "transaction_amount": payment.transaction_amount, "refund_amount": "", "created_at": payment.created_at, "status": payment.status, "is_pending": False, "is_success": True, "is_failed": False, "is_refund": False, }) already_requested = self.get_secure_cookie("image_request") cancel_flag = "canceled" in (user.stripe_plan_id or "") updated_flag = self.get_argument("update", "") == "1" migrated_flag = self.get_argument("migrated", 0) past_due = False source_card_type = None source_last_4 = None source_expiration = None promotions = Promotion.active() has_data_to_migrate = not MigrationState.has_migrated(user.id) if user.stripe_customer_id: customer = None try: customer = stripe.Customer.retrieve(user.stripe_customer_id) except stripe.error.InvalidRequestError: pass if customer and not hasattr(customer, 'deleted'): if customer.subscriptions.total_count >= 1: subscriptions = [ sub for sub in customer.subscriptions.data if sub.plan.id == user.stripe_plan_id ] if subscriptions: subscription = subscriptions[0] past_due = subscription.status == "past_due" if customer.sources.total_count > 0: if customer.sources.data[0].object == "card": card = customer.sources.data[0] elif customer.sources.data[0].object == "source": card = customer.sources.data[0].card source_card_type = card.brand source_last_4 = card.last4 source_expiration = "%d/%d" % (card.exp_month, card.exp_year) return self.render("account/settings.html", user=user, payments=payments, already_requested=already_requested, promotions=promotions, plan_name=plan_name(user.stripe_plan_id), past_due=past_due, stripe_public_key=options.stripe_public_key, source_card_type=source_card_type, source_last_4=source_last_4, source_expiration=source_expiration, has_data_to_migrate=has_data_to_migrate, updated_flag=updated_flag, migrated_flag=migrated_flag, cancel_flag=cancel_flag)