diff --git a/src/pretix/plugins/stripe/payment.py b/src/pretix/plugins/stripe/payment.py index 2e447a5d3e..7deaa4a980 100644 --- a/src/pretix/plugins/stripe/payment.py +++ b/src/pretix/plugins/stripe/payment.py @@ -137,7 +137,7 @@ logger = logging.getLogger('pretix.plugins.stripe') # Real-time payments # - Swish: ✓ # - PayNow: ✗ -# - PromptPay: ✗ +# - PromptPay: ✓ # - Pix: ✗ # # Vouchers @@ -428,6 +428,14 @@ class StripeSettingsHolder(BasePaymentProvider): 'before they work properly.'), required=False, )), + ('method_promptpay', + forms.BooleanField( + label='PromptPay', + disabled=self.event.currency != 'THB', + help_text=_('Some payment methods might need to be enabled in the settings of your Stripe account ' + 'before they work properly.'), + required=False, + )), ('method_swish', forms.BooleanField( label=_('Swish'), @@ -1842,6 +1850,31 @@ class StripeSwish(StripeRedirectMethod): } +class StripePromptPay(StripeRedirectMethod): + identifier = 'stripe_promptpay' + verbose_name = _('PromptPay via Stripe') + public_name = 'PromptPay' + method = 'promptpay' + confirmation_method = 'automatic' + explanation = _( + 'This payment method is available to PromptPay users in Thailand. Please have your app ready.' + ) + + def is_allowed(self, request: HttpRequest, total: Decimal=None) -> bool: + return super().is_allowed(request, total) and request.event.currency == "THB" + + def _payment_intent_kwargs(self, request, payment): + return { + "payment_method_data": { + "type": "promptpay", + "billing_details": { + "email": payment.order.email, + }, + + }, + } + + class StripeTwint(StripeRedirectMethod): identifier = 'stripe_twint' verbose_name = _('TWINT via Stripe') diff --git a/src/pretix/plugins/stripe/signals.py b/src/pretix/plugins/stripe/signals.py index 8202c10e1a..7bbb73e140 100644 --- a/src/pretix/plugins/stripe/signals.py +++ b/src/pretix/plugins/stripe/signals.py @@ -47,15 +47,16 @@ def register_payment_provider(sender, **kwargs): from .payment import ( StripeAffirm, StripeAlipay, StripeBancontact, StripeCC, StripeEPS, StripeGiropay, StripeIdeal, StripeKlarna, StripeMobilePay, - StripeMultibanco, StripePayPal, StripePrzelewy24, StripeRevolutPay, - StripeSEPADirectDebit, StripeSettingsHolder, StripeSofort, StripeSwish, - StripeTwint, StripeWeChatPay, + StripeMultibanco, StripePayPal, StripePromptPay, StripePrzelewy24, + StripeRevolutPay, StripeSEPADirectDebit, StripeSettingsHolder, + StripeSofort, StripeSwish, StripeTwint, StripeWeChatPay, ) return [ StripeSettingsHolder, StripeCC, StripeGiropay, StripeIdeal, StripeAlipay, StripeBancontact, - StripeSofort, StripeEPS, StripeMultibanco, StripePrzelewy24, StripeRevolutPay, StripeWeChatPay, - StripeSEPADirectDebit, StripeAffirm, StripeKlarna, StripePayPal, StripeSwish, StripeTwint, StripeMobilePay + StripeSofort, StripeEPS, StripeMultibanco, StripePrzelewy24, StripePromptPay, StripeRevolutPay, + StripeWeChatPay, StripeSEPADirectDebit, StripeAffirm, StripeKlarna, StripePayPal, StripeSwish, + StripeTwint, StripeMobilePay ] diff --git a/src/pretix/plugins/stripe/static/pretixplugins/stripe/pretix-stripe.js b/src/pretix/plugins/stripe/static/pretixplugins/stripe/pretix-stripe.js index 85b6784594..cf71266f80 100644 --- a/src/pretix/plugins/stripe/static/pretixplugins/stripe/pretix-stripe.js +++ b/src/pretix/plugins/stripe/static/pretixplugins/stripe/pretix-stripe.js @@ -325,6 +325,8 @@ $(function () { } else if ($("#stripe_payment_intent_next_action_redirect_url").length) { let payment_intent_next_action_redirect_url = $.trim($("#stripe_payment_intent_next_action_redirect_url").html()); pretixstripe.handlePaymentRedirectAction(payment_intent_next_action_redirect_url); + } else if ($.trim($("#stripe_payment_intent_action_type").html()) === "promptpay_display_qr_code") { + waitingDialog.hide(); } else if ($.trim($("#stripe_payment_intent_action_type").html()) === "wechat_pay_display_qr_code") { let payment_intent_client_secret = $.trim($("#stripe_payment_intent_client_secret").html()); pretixstripe.handleWechatAction(payment_intent_client_secret); diff --git a/src/pretix/plugins/stripe/templates/pretixplugins/stripe/pending.html b/src/pretix/plugins/stripe/templates/pretixplugins/stripe/pending.html index 1628170405..f1e8d4b710 100644 --- a/src/pretix/plugins/stripe/templates/pretixplugins/stripe/pending.html +++ b/src/pretix/plugins/stripe/templates/pretixplugins/stripe/pending.html @@ -58,6 +58,14 @@
+{% elif payment.state == "created" and payment.provider == "stripe_promptpay" %} +

{% blocktrans trimmed %} + Please scan the QR code below to complete your PromptPay payment. + Once you have completed your payment, you can refresh this page. + {% endblocktrans %}

+
+ {% trans 'PromptPay QR code' %} +
{% else %}

{% blocktrans trimmed %} The payment transaction could not be completed for the following reason: diff --git a/src/pretix/plugins/stripe/templates/pretixplugins/stripe/sca.html b/src/pretix/plugins/stripe/templates/pretixplugins/stripe/sca.html index 47ad0e929a..a2daca7551 100644 --- a/src/pretix/plugins/stripe/templates/pretixplugins/stripe/sca.html +++ b/src/pretix/plugins/stripe/templates/pretixplugins/stripe/sca.html @@ -28,7 +28,11 @@

- + {% if payment_intent_promptpay_image_url %} +
+ {% trans 'PromptPay QR code' %} +
+ {% endif %}
diff --git a/src/pretix/plugins/stripe/views.py b/src/pretix/plugins/stripe/views.py index adc14965d3..e7732fd7f8 100644 --- a/src/pretix/plugins/stripe/views.py +++ b/src/pretix/plugins/stripe/views.py @@ -595,7 +595,7 @@ class ScaView(StripeOrderView, View): 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', - 'swish_handle_redirect_or_display_qr_code', 'multibanco_display_details', + 'swish_handle_redirect_or_display_qr_code', 'multibanco_display_details', 'promptpay_display_qr_code', ]: ctx = { 'order': self.order, @@ -613,6 +613,8 @@ class ScaView(StripeOrderView, View): elif intent.next_action.type == 'multibanco_display_details': ctx['payment_intent_next_action_redirect_url'] = intent.next_action.multibanco_display_details['hosted_voucher_url'] ctx['payment_intent_redirect_action_handling'] = 'iframe' + elif intent.next_action.type == 'promptpay_display_qr_code': + ctx['payment_intent_promptpay_image_url'] = intent.next_action.promptpay_display_qr_code['image_url_svg'] r = render(request, 'pretixplugins/stripe/sca.html', ctx) r._csp_ignore = True