mirror of
https://github.com/pretix/pretix.git
synced 2026-05-05 15:14:04 +00:00
Stripe: ApplePay/Payment Request Button (#988)
As discussed, this is a WIP for integrating Stripe's Payment Request Buttons (with also includes the ApplePay-Button on iOS-devices). Todos: - [x] Payment Request Button is still displayed, even when a card has already been tokenized (when going back in the order-flow) - [x] The domains used need to be verified using the Stripe API to enable ApplePay: https://stripe.com/docs/stripe-js/elements/payment-request-button#verifying-your-domain-with-apple-pay - [x] Migration: Get the account-country for existing Stripe Connect users - [x] Migration: Verify the domains using the above mentioned API for existing users - [x] Converting the chargeable amount is not right for non-decimal currencies like JPY Other considerations: - On iOS-devices using Safari (probably also on MacBooks, etc. - not tested), the [regular payment request button](https://user-images.githubusercontent.com/157270/38515749-f53f8392-3be9-11e8-8917-61ef78dd354a.png) is automatically replaced with a [buy with Apple Pay button](https://docs-assets.developer.apple.com/published/094d0eb90e/988c36a8-a43c-4ff9-85ef-beda16c4b7c9.png). - On all other platforms, the generic payment request button is displayed. Even if the device supports a specific payment provider like Google Pay, Microsoft Wallet, Samsung Pay, etc., the generic button will first offer the cards saved within the webbrowser in addition to the other payment methods. Only upon selecting the specific payment provider like GPay, the corresponding payment flow is started. - Right now, the rendering of the payment button is completely in the hands of Stripe. Once pretix takes on the task of doing this, we should try to detect if the browser supports well known payment methods like GPay in addition to the browser-saved cards. If that's the case, we should add the corresponding marks onto the "Pay Now"-Button (like [this](https://developers.google.com/pay/api/images/brand-guidelines/google-pay-mark.png), [this](https://assets.pcmag.com/media/images/490984-samsung-pay.png?width=1600&height=900), or [this](https://www.firstffcu.com/images/MS-Wallet_stacked_rgb_grey.png)), so the customer can identify the purpose of the button easier. - [x] Also, all of this is still based against the pretix 1.x codebase ;-)
This commit is contained in:
committed by
Raphael Michel
parent
673a4e6805
commit
a4ced609cd
51
src/pretix/plugins/stripe/tasks.py
Normal file
51
src/pretix/plugins/stripe/tasks.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import logging
|
||||
from urllib.parse import urlsplit
|
||||
|
||||
import stripe
|
||||
from django.conf import settings
|
||||
|
||||
from pretix.base.models import Event
|
||||
from pretix.celery_app import app
|
||||
from pretix.multidomain.urlreverse import get_domain
|
||||
from pretix.plugins.stripe.models import RegisteredApplePayDomain
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_domain_for_event(event):
|
||||
domain = get_domain(event.organizer)
|
||||
if not domain:
|
||||
siteurlsplit = urlsplit(settings.SITE_URL)
|
||||
return siteurlsplit.hostname
|
||||
return domain
|
||||
|
||||
|
||||
def get_stripe_account_key(prov):
|
||||
if prov.settings.connect_user_id:
|
||||
return prov.settings.connect_user_id
|
||||
else:
|
||||
return prov.settings.publishable_key
|
||||
|
||||
|
||||
@app.task(max_retries=5, default_retry_delay=1)
|
||||
def stripe_verify_domain(event_id, domain):
|
||||
from pretix.plugins.stripe.payment import StripeCC
|
||||
event = Event.objects.get(pk=event_id)
|
||||
prov = StripeCC(event)
|
||||
account = get_stripe_account_key(prov)
|
||||
|
||||
if RegisteredApplePayDomain.objects.filter(account=account, domain=domain).exists():
|
||||
return
|
||||
|
||||
try:
|
||||
stripe.ApplePayDomain.create(
|
||||
domain_name=domain,
|
||||
**prov.api_kwargs
|
||||
)
|
||||
except stripe.error.StripeError:
|
||||
logger.exception('Could not verify domain with Stripe')
|
||||
else:
|
||||
RegisteredApplePayDomain.objects.create(
|
||||
domain=domain,
|
||||
account=account
|
||||
)
|
||||
Reference in New Issue
Block a user