本文整理汇总了Python中pretix.base.settings.SettingsSandbox类的典型用法代码示例。如果您正苦于以下问题:Python SettingsSandbox类的具体用法?Python SettingsSandbox怎么用?Python SettingsSandbox使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SettingsSandbox类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_sandbox
def test_sandbox(self):
sandbox = SettingsSandbox("testing", "foo", self.event)
sandbox.set("foo", "bar")
self.assertEqual(sandbox.get("foo"), "bar")
self.assertEqual(self.event.settings.get("testing_foo_foo"), "bar")
self.assertIsNone(self.event.settings.get("foo"), "bar")
sandbox["bar"] = "baz"
sandbox.baz = 42
self.event = Event.objects.get(identity=self.event.identity)
sandbox = SettingsSandbox("testing", "foo", self.event)
self.assertEqual(sandbox["bar"], "baz")
self.assertEqual(sandbox.baz, "42")
del sandbox.baz
del sandbox["bar"]
self.assertIsNone(sandbox.bar)
self.assertIsNone(sandbox["baz"])
示例2: test_sandbox
def test_sandbox(self):
sandbox = SettingsSandbox('testing', 'foo', self.event)
sandbox.set('foo', 'bar')
self.assertEqual(sandbox.get('foo'), 'bar')
self.assertEqual(self.event.settings.get('testing_foo_foo'), 'bar')
self.assertIsNone(self.event.settings.get('foo'), 'bar')
sandbox['bar'] = 'baz'
sandbox.baz = 42
self.event = Event.objects.get(id=self.event.id)
sandbox = SettingsSandbox('testing', 'foo', self.event)
self.assertEqual(sandbox['bar'], 'baz')
self.assertEqual(sandbox.baz, '42')
del sandbox.baz
del sandbox['bar']
self.assertIsNone(sandbox.bar)
self.assertIsNone(sandbox['baz'])
示例3: __init__
def __init__(self, event: Event):
self.event = event
self.settings = SettingsSandbox('ticketoutput', self.identifier, event)
示例4: __init__
def __init__(self, event):
self.event = event
self.settings = SettingsSandbox('payment', self.identifier, event)
示例5: __init__
def __init__(self, event: Event):
super().__init__(event)
self.settings = SettingsSandbox('payment', 'paypal', event)
示例6: Paypal
class Paypal(BasePaymentProvider):
identifier = 'paypal'
verbose_name = _('PayPal')
payment_form_fields = OrderedDict([
])
def __init__(self, event: Event):
super().__init__(event)
self.settings = SettingsSandbox('payment', 'paypal', event)
@property
def settings_form_fields(self):
if self.settings.connect_client_id and not self.settings.secret:
# PayPal connect
if self.settings.connect_user_id:
fields = [
('connect_user_id',
forms.CharField(
label=_('PayPal account'),
disabled=True
)),
]
else:
return {}
else:
fields = [
('client_id',
forms.CharField(
label=_('Client ID'),
max_length=80,
min_length=80,
help_text=_('<a target="_blank" rel="noopener" href="{docs_url}">{text}</a>').format(
text=_('Click here for a tutorial on how to obtain the required keys'),
docs_url='https://docs.pretix.eu/en/latest/user/payments/paypal.html'
)
)),
('secret',
forms.CharField(
label=_('Secret'),
max_length=80,
min_length=80,
)),
('endpoint',
forms.ChoiceField(
label=_('Endpoint'),
initial='live',
choices=(
('live', 'Live'),
('sandbox', 'Sandbox'),
),
)),
]
d = OrderedDict(
fields + list(super().settings_form_fields.items())
)
d.move_to_end('_enabled', False)
return d
def get_connect_url(self, request):
request.session['payment_paypal_oauth_event'] = request.event.pk
self.init_api()
return Tokeninfo.authorize_url({'scope': 'openid profile email'})
def settings_content_render(self, request):
if self.settings.connect_client_id and not self.settings.secret:
# Use PayPal connect
if not self.settings.connect_user_id:
return (
"<p>{}</p>"
"<a href='{}' class='btn btn-primary btn-lg'>{}</a>"
).format(
_('To accept payments via PayPal, you will need an account at PayPal. By clicking on the '
'following button, you can either create a new PayPal account connect pretix to an existing '
'one.'),
self.get_connect_url(request),
_('Connect with {icon} PayPal').format(icon='<i class="fa fa-paypal"></i>')
)
else:
return (
"<button formaction='{}' class='btn btn-danger'>{}</button>"
).format(
reverse('plugins:paypal:oauth.disconnect', kwargs={
'organizer': self.event.organizer.slug,
'event': self.event.slug,
}),
_('Disconnect from PayPal')
)
else:
return "<div class='alert alert-info'>%s<br /><code>%s</code></div>" % (
_('Please configure a PayPal Webhook to the following endpoint in order to automatically cancel orders '
'when payments are refunded externally.'),
build_global_uri('plugins:paypal:webhook')
)
def init_api(self):
if self.settings.connect_client_id:
paypalrestsdk.set_config(
#.........这里部分代码省略.........
示例7: StripeMethod
class StripeMethod(BasePaymentProvider):
identifier = ''
method = ''
def __init__(self, event: Event):
super().__init__(event)
self.settings = SettingsSandbox('payment', 'stripe', event)
@property
def settings_form_fields(self):
return {}
@property
def is_enabled(self) -> bool:
return self.settings.get('_enabled', as_type=bool) and self.settings.get('method_{}'.format(self.method),
as_type=bool)
def payment_refund_supported(self, payment: OrderPayment) -> bool:
return True
def payment_partial_refund_supported(self, payment: OrderPayment) -> bool:
return True
def payment_prepare(self, request, payment):
return self.checkout_prepare(request, None)
def _amount_to_decimal(self, cents):
places = settings.CURRENCY_PLACES.get(self.event.currency, 2)
return round_decimal(float(cents) / (10 ** places), self.event.currency)
def _decimal_to_int(self, amount):
places = settings.CURRENCY_PLACES.get(self.event.currency, 2)
return int(amount * 10 ** places)
def _get_amount(self, payment):
return self._decimal_to_int(payment.amount)
@property
def api_kwargs(self):
if self.settings.connect_client_id and self.settings.connect_user_id:
if self.settings.get('endpoint', 'live') == 'live':
kwargs = {
'api_key': self.settings.connect_secret_key,
'stripe_account': self.settings.connect_user_id
}
else:
kwargs = {
'api_key': self.settings.connect_test_secret_key,
'stripe_account': self.settings.connect_user_id
}
else:
kwargs = {
'api_key': self.settings.secret_key,
}
return kwargs
def _init_api(self):
stripe.api_version = '2018-02-28'
stripe.set_app_info("pretix", version=__version__, url="https://pretix.eu")
def checkout_confirm_render(self, request) -> str:
template = get_template('pretixplugins/stripe/checkout_payment_confirm.html')
ctx = {'request': request, 'event': self.event, 'settings': self.settings, 'provider': self}
return template.render(ctx)
def payment_can_retry(self, payment):
return self._is_still_available(order=payment.order)
def _charge_source(self, request, source, payment):
try:
params = {}
if not source.startswith('src_'):
params['statement_descriptor'] = ugettext('{event}-{code}').format(
event=self.event.slug.upper(),
code=payment.order.code
)[:22]
params.update(self.api_kwargs)
charge = stripe.Charge.create(
amount=self._get_amount(payment),
currency=self.event.currency.lower(),
source=source,
metadata={
'order': str(payment.order.id),
'event': self.event.id,
'code': payment.order.code
},
# TODO: Is this sufficient?
idempotency_key=str(self.event.id) + payment.order.code + source,
**params
)
except stripe.error.CardError as e:
if e.json_body:
err = e.json_body['error']
logger.exception('Stripe error: %s' % str(err))
else:
err = {'message': str(e)}
logger.exception('Stripe error: %s' % str(e))
logger.info('Stripe card error: %s' % str(err))
payment.info_data = {
'error': True,
#.........这里部分代码省略.........