Replies: 9 comments
-
What do your proposed changes look like? |
Beta Was this translation helpful? Give feedback.
-
Something along the lines of:
So basically allowing the param of This is just what I could think of to allow the convenience method of |
Beta Was this translation helpful? Give feedback.
-
The only record that Subscribe would create is a Are you suggesting that |
Beta Was this translation helpful? Give feedback.
-
I understand that and I believe that is a good design. To only have No, in my specific use case, I'm not looking for any knock on effects. I mean that would be possible with this implementation but that is not the goal. My specific use case is a customer can have multiple subscriptions where each subscription has a 1:1 relationship with an Item/Product. So really, what I want to add is references to In reality, I guess I could also just do the inverse and store the FK on the item. I know I could use the |
Beta Was this translation helpful? Give feedback.
-
That's how I've done it previously, adding One downside of that is if a subscription is canceled and you want to create a new one, you'd lose the association between them. Stripe provides the I could see adding a polymorphic relationship to the Subscription model to make that easier. That would mean you could have Item The downside is that subscriptions created in Stripe directly wouldn't be associated with a record, so you'd have to make sure they were created in Ruby. Any better name than |
Beta Was this translation helpful? Give feedback.
-
I agree on all points. I evaluated metadata as an option and then parsing it, the issue being that the record is created before metadata is set. What do you mean better name than On your point about Ruby and Stripe being out of sync, I think a good safety would be to pass the extra fields in metadata as well. This way on the return, you could validate the metadata against the actual attributes. |
Beta Was this translation helpful? Give feedback.
-
What do you think of something along these lines for using the metadata route to set the subscription without having to touch the module SubscriptionExtensions
extend ActiveSupport::Concern
included do
before_validation :associate_item
end
def associate_item
item = Item.find(metadata['item_id'])
item.update_column(:subscription_id, id) if !item.nil?
end
end
class Item
belongs_to :subscription, optional: true
before_validation :associate_subscription
def associate_subscription
pay_subscription = Pay::Subscription.where('metadata @> ?', "[{\"item_id\": \"#{self.id}\"}]").first
self.subscription = pay_subscription if !pay_subscription.nil?
end
end |
Beta Was this translation helpful? Give feedback.
-
That definitely works, so long as you're using a database with json columns. Sadly Here's how we had to do it in Noticed In the case of Noticed, that can be associated with many different records, but Pay only needs one, so I think we can go with a We can also support a I am going to start a branch and see how that might look. |
Beta Was this translation helpful? Give feedback.
-
If a PaymentIntent fails for SCA, we wouldn't have a charge to sync immediately, so the |
Beta Was this translation helpful? Give feedback.
-
Hi,
This gem does a lot of the boiler plate needed for accepting payments but one thing that would make this a real winner for me is the ability to extend the models. For example, consider the following:
You have the models User and Item.
To clarify the above, each
Item
would have its own subscription that the user of the items is responsible for.The current docs about extending models works well enough to add the relation to
Pay::Subscription
docsThe problem arises in
@user.payment_processor.subscribe
in that you are unable to pass attributes in to the subscription object that will eventually be created.
It appears that the subscription is created in the processor, then
sync
is called to create the record based on a few parameters and data returned from the API.My suggestion, and I would happily create a PR for this, would be to allow a param on
.subscribe
, perhapsrecord_attributes
orattributes
that accepts a set of params that would be passed to the underlying model on sync.For my specific example that would be some changes on around
pay/lib/pay/stripe/billable.rb
Line 104 in 6a7917f
I haven't looked, but I would assume something like this would be very similar on the other
Pay
models as well.What are your thoughts on this?
Beta Was this translation helpful? Give feedback.
All reactions