Skip to content

Commit

Permalink
if product price is updated - create new stripe price and assing to p…
Browse files Browse the repository at this point in the history
…roduct
  • Loading branch information
yshmarov committed Mar 11, 2021
1 parent c19566e commit a43e7c8
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/models/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ def to_builder
update(stripe_product_id: product.id, stripe_price_id: price.id)
end

after_update :create_and_assign_new_stripe_price, if: :saved_change_to_price?
def create_and_assign_new_stripe_price
price = Stripe::Price.create(product: self.stripe_product_id, unit_amount: self.price, currency: "usd")
update(stripe_price_id: price.id)
end

end

0 comments on commit a43e7c8

Please sign in to comment.