diff --git a/src/pretix/plugins/stripe/payment.py b/src/pretix/plugins/stripe/payment.py index 8dc7f6544e..6dc0ce022a 100644 --- a/src/pretix/plugins/stripe/payment.py +++ b/src/pretix/plugins/stripe/payment.py @@ -133,7 +133,7 @@ logger = logging.getLogger('pretix.plugins.stripe') # - Zip: ✗ # # Real-time payments -# - Swish: ✗ +# - Swish: ✓ # - PayNow: ✗ # - PromptPay: ✗ # - Pix: ✗ @@ -441,6 +441,14 @@ class StripeSettingsHolder(BasePaymentProvider): 'before they work properly.'), required=False, )), + ('method_swish', + forms.BooleanField( + label=_('Swish'), + disabled=self.event.currency != 'SEK', + help_text=_('Some payment methods might need to be enabled in the settings of your Stripe account ' + 'before they work properly.'), + required=False, + )), ('method_affirm', forms.BooleanField( label=_('Affirm'), @@ -1907,3 +1915,27 @@ class StripePayPal(StripeRedirectMethod): verbose_name = _('PayPal via Stripe') public_name = _('PayPal') method = 'paypal' + + +class StripeSwish(StripeRedirectMethod): + identifier = 'stripe_swish' + verbose_name = _('Swish via Stripe') + public_name = _('Swish') + method = 'swish' + confirmation_method = 'automatic' + explanation = _( + 'This payment method is available to users of the Swedish apps Swish and BankID. Please have your app ' + 'ready.' + ) + + def _payment_intent_kwargs(self, request, payment): + return { + "payment_method_data": { + "type": "swish", + }, + "payment_method_options": { + "swish": { + "reference": payment.order.full_code, + }, + } + } diff --git a/src/pretix/plugins/stripe/signals.py b/src/pretix/plugins/stripe/signals.py index e73306e62b..9e97706264 100644 --- a/src/pretix/plugins/stripe/signals.py +++ b/src/pretix/plugins/stripe/signals.py @@ -48,13 +48,13 @@ def register_payment_provider(sender, **kwargs): StripeAffirm, StripeAlipay, StripeBancontact, StripeCC, StripeEPS, StripeGiropay, StripeIdeal, StripeKlarna, StripeMultibanco, StripePayPal, StripePrzelewy24, StripeSEPADirectDebit, - StripeSettingsHolder, StripeSofort, StripeWeChatPay, + StripeSettingsHolder, StripeSofort, StripeSwish, StripeWeChatPay, ) return [ StripeSettingsHolder, StripeCC, StripeGiropay, StripeIdeal, StripeAlipay, StripeBancontact, StripeSofort, StripeEPS, StripeMultibanco, StripePrzelewy24, StripeWeChatPay, - StripeSEPADirectDebit, StripeAffirm, StripeKlarna, StripePayPal, + StripeSEPADirectDebit, StripeAffirm, StripeKlarna, StripePayPal, StripeSwish ] diff --git a/src/pretix/plugins/stripe/views.py b/src/pretix/plugins/stripe/views.py index 9b9fcf1d37..a6605b6900 100644 --- a/src/pretix/plugins/stripe/views.py +++ b/src/pretix/plugins/stripe/views.py @@ -599,7 +599,8 @@ class ScaView(StripeOrderView, View): return self._redirect_to_order() if intent.status == 'requires_action' and intent.next_action.type in [ - 'use_stripe_sdk', 'redirect_to_url', 'alipay_handle_redirect', 'wechat_pay_display_qr_code' + 'use_stripe_sdk', 'redirect_to_url', 'alipay_handle_redirect', 'wechat_pay_display_qr_code', + 'swish_handle_redirect_or_display_qr_code', ]: ctx = { 'order': self.order, @@ -611,6 +612,9 @@ class ScaView(StripeOrderView, View): elif intent.next_action.type == 'redirect_to_url': ctx['payment_intent_next_action_redirect_url'] = intent.next_action.redirect_to_url['url'] ctx['payment_intent_redirect_action_handling'] = prov.redirect_action_handling + elif intent.next_action.type == 'swish_handle_redirect_or_display_qr_code': + ctx['payment_intent_next_action_redirect_url'] = intent.next_action.swish_handle_redirect_or_display_qr_code['hosted_instructions_url'] + ctx['payment_intent_redirect_action_handling'] = 'iframe' r = render(request, 'pretixplugins/stripe/sca.html', ctx) r._csp_ignore = True