Skip to content

Commit

Permalink
Merge branch 'fix-localhost-pro-account' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
gbp committed Feb 20, 2025
2 parents b77da22 + 9d40aa5 commit 1c79af7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/models/pro_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ def update_stripe_customer
@subscriptions = nil unless stripe_customer

attributes = {}
attributes[:email] = user.email if stripe_customer.try(:email) != user.email
attributes[:source] = @token.id if @token

if stripe_customer&.email != user.email && user.email !~ /@localhost$/
attributes[:email] = user.email
end

@stripe_customer = (
if attributes.empty?
stripe_customer
Expand All @@ -64,7 +67,7 @@ def update_stripe_customer
end
)

update(stripe_customer_id: @stripe_customer.id)
update(stripe_customer_id: @stripe_customer&.id)
end

private
Expand Down
9 changes: 9 additions & 0 deletions spec/models/pro_account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,15 @@
).from(old_source)
end

context 'when user uses localhost development email' do
before { user.update(email: 'user@localhost') }

it 'does not create Stripe customer' do
expect(Stripe::Customer).to_not receive(:create)
pro_account.update_stripe_customer
end
end

context 'with pro_pricing disabled' do
it 'does not store Stripe customer ID' do
with_feature_disabled(:pro_pricing) do
Expand Down

0 comments on commit 1c79af7

Please sign in to comment.