Skip to content

Commit

Permalink
refactoring how all the things get created and are linked together
Browse files Browse the repository at this point in the history
  • Loading branch information
fermion committed Feb 24, 2024
1 parent 89ee1e2 commit 0945d6f
Show file tree
Hide file tree
Showing 20 changed files with 7,107 additions and 997 deletions.
23 changes: 23 additions & 0 deletions app/sidekiq/create_stripe_customer_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,28 @@ def perform(id)
)

company.update(stripe_id: stripe_customer.id)

# create base subscription
stripe_subscription = Stripe::Subscription.create({
customer: company.stripe_id,
items: [{
price: Rails.application.credentials.stripe_price_id,
quantity: company.memberships.active.count
}],
trial_period_days: 30,
trial_settings: {
end_behavior: {
missing_payment_method: "cancel"
}
},
})

company.create_subscription(
stripe_id: stripe_subscription.id,
stripe_price_id: stripe_subscription.items.data.first.price.id,
customer_name: stripe_customer.name,
customer_email: stripe_customer.email,
plan_amount: stripe_subscription.items.data.first.price.unit_amount,
)
end
end
2 changes: 0 additions & 2 deletions app/sidekiq/sync_customer_subscription_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ def perform(id)
company = Company.find_by!(id: id)
return if company.blank?

company.create_subscription if company.subscription.blank?

# TODO: when there's a free trial, we'll check the trial's expiration here
stripe_subscription = company.stripe_subscription
return if stripe_subscription.blank?
Expand Down
Loading

0 comments on commit 0945d6f

Please sign in to comment.