Stripe: Add support for Swish (#4149)

* Stripe: Add support for Swish

* Update src/pretix/plugins/stripe/payment.py

Co-authored-by: Martin Gross <gross@rami.io>

---------

Co-authored-by: Martin Gross <gross@rami.io>
This commit is contained in:
Raphael Michel
2024-05-17 13:33:03 +02:00
committed by GitHub
parent a6a93555b6
commit 7188e44fe5
3 changed files with 40 additions and 4 deletions

View File

@@ -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,
},
}
}

View File

@@ -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
]

View File

@@ -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