Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if 'subscription_id' in request.match_info:
data['subscription_id'] = request.match_info['subscription_id']
expand = data.pop('expand', None)
return json_response(func(**data)._export(expand=expand))
return f
# Extra routes must be added *before* regular routes, because otherwise
# `/invoices/upcoming` would fall into `/invoices/{id}`.
for method, url, func in extra_apis:
app.router.add_route(method, url, api_extra(func, url))
for cls in (Charge, Coupon, Customer, Event, Invoice, InvoiceItem,
PaymentIntent, PaymentMethod, Plan, Product, Refund, SetupIntent,
Source, Subscription, SubscriptionItem, TaxRate, Token):
for method, url, func in (
('POST', '/v1/' + cls.object + 's', api_create),
('GET', '/v1/' + cls.object + 's/{id}', api_retrieve),
('POST', '/v1/' + cls.object + 's/{id}', api_update),
('DELETE', '/v1/' + cls.object + 's/{id}', api_delete),
('GET', '/v1/' + cls.object + 's', api_list_all)):
app.router.add_route(method, url, func(cls, url))
def localstripe_js(request):
path = os.path.dirname(os.path.realpath(__file__)) + '/localstripe-v3.js'
with open(path) as f:
return web.Response(text=f.read(),
content_type='application/javascript')
def __init__(self, item):
try:
assert isinstance(item, (InvoiceItem, SubscriptionItem))
except AssertionError:
raise UserError(400, 'Bad request')
# All exceptions must be raised before this point.
super().__init__()
self.type = \
'invoiceitem' if isinstance(item, InvoiceItem) else 'subscription'
if self.type == 'subscription':
self.subscription_item = item.id
self.subscription = item._subscription
self.plan = item.plan
self.proration = False
self.currency = item.plan.currency
self.description = item.plan.name
for previous_invoice in previous._list:
previous_tax_rates = [tr.id for tr in (
previous_invoice.lines._list[0].tax_rates or [])]
InvoiceItem(amount=- previous_invoice.subtotal,
currency=previous_invoice.currency,
proration=True,
description='Unused time',
subscription=self.id,
plan=old_plan.id,
tax_rates=previous_tax_rates,
customer=self.customer)
elif self.items._list[0].tax_rates != items[0]['tax_rates']:
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)
if tax_percent is not None:
self.tax_percent = tax_percent
if default_tax_rates is not None:
self.default_tax_rates = [TaxRate._api_retrieve(tr)
for tr in default_tax_rates]
if trial_end is not None:
self.trial_end = trial_end
if cancel_at_period_end is not None:
self.cancel_at_period_end = cancel_at_period_end
[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:
tax_percent = current_subscription.tax_percent
date = int(time.time()) # now
if current_subscription:
date = current_subscription.current_period_end
if not simulation and not current_subscription:
raise UserError(404, 'No upcoming invoices for customer')
self.ended_at = None
self.quantity = items[0]['quantity']
self.status = 'incomplete'
self.trial_end = trial_end
self.trial_start = None
self.trial_period_days = trial_period_days
self.latest_invoice = None
self.start_date = backdate_start_date or int(time.time())
self.billing_cycle_anchor = billing_cycle_anchor
self._enable_incomplete_payments = (
enable_incomplete_payments and
payment_behavior != 'error_if_incomplete')
self.items = List('/v1/subscription_items?subscription=' + self.id)
self.items._list.append(
SubscriptionItem(
subscription=self.id,
plan=items[0]['plan'],
quantity=items[0]['quantity'],
tax_rates=items[0]['tax_rates']))
create_an_invoice = \
self.trial_end is None and self.trial_period_days is None
if create_an_invoice:
self._create_invoice()
schedule_webhook(Event('customer.subscription.created', self))