Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persist stripe subscription ID on Subscription #192

Open
wants to merge 2 commits into
base: bt/link-mink
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/concerns/koudoku/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def processing!
end
end

Stripe::Subscription.create(subscription_attributes)
subscription = Stripe::Subscription.create(subscription_attributes)

rescue Stripe::CardError => card_error
errors[:base] << card_error.message
Expand All @@ -125,6 +125,14 @@ def processing!
self.stripe_id = customer.id
self.last_four = customer.sources.retrieve(customer.default_source).last4

if respond_to? :stripe_subscription_id
self.stripe_subscription_id = subscription.id
end

if subscription_owner.respond_to? :stripe_id
subscription_owner.update(stripe_id: customer.id)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@trestrantham Hey. Curious why you'd want to write the Stripe ID to the subscription owner instead of just referencing from the Subscription (where it would already be)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just a half measure to moving Stripe::Customer#id from Subscription to Team while maintaining backward compatibility. Ideally IMO, Subscription#stripe_id would be a Stripe::Subscription#id and Team#stripe_id would be a Stripe::Customer#id. I keep getting hung up on the current mismatch. That being said, happy to remove it to avoid confusion. 😄

end

finalize_new_subscription!
finalize_upgrade!

Expand Down