Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
obj = cls._api_retrieve(id)
if client_secret != obj.client_secret:
raise UserError(401, 'Unauthorized')
if obj.status != 'requires_action':
raise UserError(400, 'Bad request')
obj.next_action = None
if success:
obj._trigger_payment()
else:
obj._authentication_failed = True
obj.payment_method = None
if obj.invoice:
invoice = Invoice._api_retrieve(obj.invoice)
invoice._on_payment_failure_later()
return obj
def on_failure_later():
if self.invoice:
invoice = Invoice._api_retrieve(self.invoice)
invoice._on_payment_failure_later()
else:
period_start = period_end = int(time.time())
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
def on_success():
if self.invoice:
invoice = Invoice._api_retrieve(self.invoice)
invoice._on_payment_success()
def on_failure_now():
if self.invoice:
invoice = Invoice._api_retrieve(self.invoice)
invoice._on_payment_failure_now()
def _api_void_invoice(cls, id):
obj = Invoice._api_retrieve(id)
if obj.status not in ('draft', 'open'):
raise UserError(400, 'Bad request')
PaymentIntent._api_cancel(obj.payment_intent)
obj._draft = False
obj._voided = True
obj.status_transitions['voided_at'] = int(time.time())
if obj.subscription:
sub = Subscription._api_retrieve(obj.subscription)
sub._on_initial_payment_voided(obj)
return obj
def _api_pay_invoice(cls, id):
obj = Invoice._api_retrieve(id)
if obj.status == 'paid':
raise UserError(400, 'Invoice is already paid')
elif obj.status not in ('draft', 'open'):
raise UserError(400, 'Bad request')
obj._draft = False
if obj.total <= 0:
obj._on_payment_success()
else:
cus = Customer._api_retrieve(obj.customer)
if cus._get_default_payment_method_or_source() is None:
raise UserError(404, 'This customer has no payment method')
pm = cus._get_default_payment_method_or_source()
pi = PaymentIntent(amount=obj.total,