Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
assert type(proration) is bool
if description is not None:
assert type(description) is str
else:
description = 'Invoice item'
if tax_rates is not None:
assert type(tax_rates) is list
assert all(type(tr) is str for tr in tax_rates)
except AssertionError:
raise UserError(400, 'Bad request')
Customer._api_retrieve(customer) # to return 404 if not existant
if invoice is not None:
Invoice._api_retrieve(invoice) # to return 404 if not existant
if plan is not None:
plan = Plan._api_retrieve(plan) # to return 404 if not existant
if tax_rates is not None:
# To return 404 if not existant:
tax_rates = [TaxRate._api_retrieve(tr) for tr in tax_rates]
# All exceptions must be raised before this point.
super().__init__()
self.invoice = invoice
self.subscription = subscription
self.plan = plan
self.quantity = 1
self.amount = amount
self.currency = currency
self.customer = customer
self.date = int(time.time())
self.period = dict(start=period_start, end=period_end)
assert type(subscription_default_tax_rates) is list
assert all(type(txr) is str and txr.startswith('txr_')
for txr in subscription_default_tax_rates)
assert all(type(tr) is str
for tr in subscription_default_tax_rates)
if subscription_proration_date is not None:
assert type(subscription_proration_date) is int
assert subscription_proration_date > 1500000000
except AssertionError:
raise UserError(400, 'Bad request')
# return 404 if not existant
customer_obj = Customer._api_retrieve(customer)
if subscription_items:
for si in subscription_items:
Plan._api_retrieve(si['plan']) # to return 404 if not existant
# To return 404 if not existant:
if si['tax_rates'] is not None:
[TaxRate._api_retrieve(tr) for tr in si['tax_rates']]
# To return 404 if not existant:
if subscription_default_tax_rates is not None:
[TaxRate._api_retrieve(tr)
for tr in subscription_default_tax_rates]
pending_items = [ii for ii in InvoiceItem._api_list_all(
None, customer=customer, limit=99)._list
if ii.invoice is None]
if (not upcoming and not subscription and
not subscription_items and not pending_items):
raise UserError(400, 'Bad request')
simulation = subscription_items is not None or \
assert all(type(tr) is str for tr in item['tax_rates'])
except AssertionError:
raise UserError(400, 'Bad request')
old_plan = self.plan
if items is not None:
if len(items) != 1:
raise UserError(500, 'Not implemented')
# If no plan specified in update request, we stay on the current
# one
if not items[0].get('plan', None):
items[0]['plan'] = self.plan.id
# To return 404 if not existant:
Plan._api_retrieve(items[0]['plan'])
# To return 404 if not existant:
if items[0]['tax_rates'] is not None:
[TaxRate._api_retrieve(tr) for tr in items[0]['tax_rates']]
self.quantity = items[0]['quantity']
if (self.items._list[0].plan.id != items[0]['plan'] or
self.items._list[0].quantity != items[0]['quantity']):
self.items = List('/v1/subscription_items?subscription=' +
self.id)
item = SubscriptionItem(subscription=self.id,
plan=items[0]['plan'],
quantity=items[0]['quantity'],
tax_rates=items[0]['tax_rates'])
self.items._list.append(item)
raise UserError(400, 'Unexpected ' + ', '.join(kwargs.keys()))
quantity = try_convert_to_int(quantity)
try:
if subscription is not None:
assert type(subscription) is str
assert subscription.startswith('sub_')
assert type(plan) is str
assert type(quantity) is int and quantity > 0
if tax_rates is not None:
assert type(tax_rates) is list
assert all(type(tr) is str for tr in tax_rates)
except AssertionError:
raise UserError(400, 'Bad request')
plan = Plan._api_retrieve(plan) # to return 404 if not existant
# To return 404 if not existant:
if tax_rates is not None:
tax_rates = [TaxRate._api_retrieve(tr) for tr in tax_rates]
# All exceptions must be raised before this point.
super().__init__()
self.plan = plan
self.quantity = quantity
self.tax_rates = tax_rates
self.metadata = metadata or {}
self._subscription = subscription
raise UserError(404, 'No such subscription for customer')
if default_tax_rates is None:
if subscription_default_tax_rates is not None:
default_tax_rates = subscription_default_tax_rates
elif current_subscription is not None and \
current_subscription.default_tax_rates is not None:
default_tax_rates = \
[tr.id for tr in current_subscription.default_tax_rates]
invoice_items = []
items = subscription_items or \
(current_subscription and current_subscription.items._list) or []
for si in items:
if subscription_items is not None:
plan = Plan._api_retrieve(si['plan'])
quantity = si.get('quantity', 1)
tax_rates = si['tax_rates']
else:
plan = si.plan
quantity = si.quantity
tax_rates = [tr.id for tr in (si.tax_rates or [])]
invoice_items.append(
SubscriptionItem(subscription=subscription,
plan=plan.id,
quantity=quantity,
tax_rates=tax_rates))
if tax_percent is None:
if subscription_tax_percent is not None:
tax_percent = subscription_tax_percent
elif current_subscription:
item['tax_rates'] = item.get('tax_rates', None)
if item['tax_rates'] is not None:
assert type(item['tax_rates']) is list
assert all(type(tr) is str for tr in item['tax_rates'])
assert type(enable_incomplete_payments) is bool
assert payment_behavior in ('allow_incomplete',
'error_if_incomplete')
except AssertionError:
raise UserError(400, 'Bad request')
if len(items) != 1:
raise UserError(500, 'Not implemented')
Customer._api_retrieve(customer) # to return 404 if not existant
for item in items:
Plan._api_retrieve(item['plan']) # to return 404 if not existant
# To return 404 if not existant:
if item['tax_rates'] is not None:
[TaxRate._api_retrieve(tr) for tr in item['tax_rates']]
# To return 404 if not existant:
if default_tax_rates is not None:
default_tax_rates = [TaxRate._api_retrieve(tr)
for tr in default_tax_rates]
# All exceptions must be raised before this point.
super().__init__()
self.customer = customer
self.metadata = metadata or {}
self.tax_percent = tax_percent
self.default_tax_rates = default_tax_rates
self.application_fee_percent = None