| 1 |
from __future__ import annotations |
| 2 |
|
| 3 |
from allauth.socialaccount.providers.base import ProviderAccount |
| 4 |
from allauth.socialaccount.providers.oauth2.provider import OAuth2Provider |
| 5 |
from allauth.socialaccount.providers.stripe.views import StripeOAuth2Adapter |
| 6 |
|
| 7 |
|
| 8 |
class StripeAccount(ProviderAccount): |
| 9 |
def to_str(self): |
| 10 |
default = super().to_str() |
| 11 |
email = self.account.extra_data.get("email") |
| 12 |
business = self.account.extra_data.get("business_name") |
| 13 |
if business: |
| 14 |
return f"{email or default} ({business})" |
| 15 |
else: |
| 16 |
return email or default |
| 17 |
|
| 18 |
|
| 19 |
class StripeProvider(OAuth2Provider): |
| 20 |
id = "stripe" |
| 21 |
name = "Stripe" |
| 22 |
account_class = StripeAccount |
| 23 |
oauth2_adapter_class = StripeOAuth2Adapter |
| 24 |
|
| 25 |
def extract_uid(self, data): |
| 26 |
return data["id"] |
| 27 |
|
| 28 |
def extract_common_fields(self, data): |
| 29 |
return dict(name=data.get("display_name"), email=data.get("email")) |
| 30 |
|
| 31 |
def get_default_scope(self): |
| 32 |
return ["read_only"] |
| 33 |
|
| 34 |
|
| 35 |
provider_classes = [StripeProvider] |