Stripe: Do not show secret key in backend

This commit is contained in:
Raphael Michel
2021-05-03 21:54:17 +02:00
parent 2b5a704412
commit d5a0facb92

View File

@@ -57,6 +57,7 @@ from django_countries import countries
from pretix import __version__ from pretix import __version__
from pretix.base.decimal import round_decimal from pretix.base.decimal import round_decimal
from pretix.base.forms import SecretKeySettingsField
from pretix.base.models import Event, OrderPayment, OrderRefund, Quota from pretix.base.models import Event, OrderPayment, OrderRefund, Quota
from pretix.base.payment import BasePaymentProvider, PaymentException from pretix.base.payment import BasePaymentProvider, PaymentException
from pretix.base.plugins import get_all_plugins from pretix.base.plugins import get_all_plugins
@@ -196,7 +197,7 @@ class StripeSettingsHolder(BasePaymentProvider):
), ),
)), )),
('secret_key', ('secret_key',
forms.CharField( SecretKeySettingsField(
label=_('Secret key'), label=_('Secret key'),
validators=( validators=(
StripeKeyValidator(['sk_', 'rk_']), StripeKeyValidator(['sk_', 'rk_']),
@@ -357,6 +358,10 @@ class StripeMethod(BasePaymentProvider):
fee = max(fee, self.settings.get('connect_app_fee_min', as_type=Decimal)) fee = max(fee, self.settings.get('connect_app_fee_min', as_type=Decimal))
if fee: if fee:
d['application_fee_amount'] = self._decimal_to_int(fee) d['application_fee_amount'] = self._decimal_to_int(fee)
if self.settings.connect_destination:
d['transfer_data'] = {
'destination': self.settings.connect_destination
}
return d return d
def statement_descriptor(self, payment, length=22): def statement_descriptor(self, payment, length=22):
@@ -557,8 +562,12 @@ class StripeMethod(BasePaymentProvider):
chargeid = payment_info['id'] chargeid = payment_info['id']
ch = stripe.Charge.retrieve(chargeid, **self.api_kwargs) ch = stripe.Charge.retrieve(chargeid, **self.api_kwargs)
kwargs = {}
if self.settings.connect_destination:
kwargs['reverse_transfer'] = True
r = ch.refunds.create( r = ch.refunds.create(
amount=self._get_amount(refund), amount=self._get_amount(refund),
**kwargs,
) )
ch.refresh() ch.refresh()
except (stripe.error.InvalidRequestError, stripe.error.AuthenticationError, stripe.error.APIConnectionError) \ except (stripe.error.InvalidRequestError, stripe.error.AuthenticationError, stripe.error.APIConnectionError) \