mirror of https://github.com/zulip/zulip.git
billing: Make source optional when creating stripe customer.
This commit is contained in:
parent
4ad8f20c28
commit
d229948a43
|
@ -19,7 +19,7 @@ class Customer:
|
|||
|
||||
@staticmethod
|
||||
def create(description: str, email: str, metadata: Dict[str, Any],
|
||||
source: str) -> Customer:
|
||||
source: Optional[str]) -> Customer:
|
||||
...
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -136,7 +136,7 @@ def extract_current_subscription(stripe_customer: stripe.Customer) -> Any:
|
|||
return None
|
||||
|
||||
@catch_stripe_errors
|
||||
def do_create_customer_with_payment_source(user: UserProfile, stripe_token: str) -> stripe.Customer:
|
||||
def do_create_customer(user: UserProfile, stripe_token: Optional[str]=None) -> stripe.Customer:
|
||||
realm = user.realm
|
||||
# We could do a better job of handling race conditions here, but if two
|
||||
# people from a realm try to upgrade at exactly the same time, the main
|
||||
|
@ -154,6 +154,7 @@ def do_create_customer_with_payment_source(user: UserProfile, stripe_token: str)
|
|||
RealmAuditLog.objects.create(
|
||||
realm=user.realm, acting_user=user, event_type=RealmAuditLog.STRIPE_CUSTOMER_CREATED,
|
||||
event_time=event_time)
|
||||
if stripe_token is not None:
|
||||
RealmAuditLog.objects.create(
|
||||
realm=user.realm, acting_user=user, event_type=RealmAuditLog.STRIPE_CARD_ADDED,
|
||||
event_time=event_time)
|
||||
|
@ -231,7 +232,7 @@ def do_subscribe_customer_to_plan(stripe_customer: stripe.Customer, stripe_plan_
|
|||
def process_initial_upgrade(user: UserProfile, plan: Plan, seat_count: int, stripe_token: str) -> None:
|
||||
customer = Customer.objects.filter(realm=user.realm).first()
|
||||
if customer is None:
|
||||
stripe_customer = do_create_customer_with_payment_source(user, stripe_token)
|
||||
stripe_customer = do_create_customer(user, stripe_token=stripe_token)
|
||||
else:
|
||||
stripe_customer = do_replace_payment_source(user, stripe_token)
|
||||
do_subscribe_customer_to_plan(
|
||||
|
|
|
@ -17,7 +17,7 @@ from zerver.lib.test_classes import ZulipTestCase
|
|||
from zerver.lib.timestamp import timestamp_to_datetime, datetime_to_timestamp
|
||||
from zerver.models import Realm, UserProfile, get_realm, RealmAuditLog
|
||||
from zilencer.lib.stripe import catch_stripe_errors, \
|
||||
do_create_customer_with_payment_source, do_subscribe_customer_to_plan, \
|
||||
do_subscribe_customer_to_plan, \
|
||||
get_seat_count, extract_current_subscription, sign_string, unsign_string, \
|
||||
get_next_billing_log_entry, run_billing_processor_one_step, \
|
||||
BillingError, StripeCardError, StripeConnectionError
|
||||
|
|
Loading…
Reference in New Issue