I have a subscription model that has a upgrade event. This changes the
from free->paying and triggers a charge method in the subscription
This charge method then creates a new instance of the payment model
memory, using .new), and triggers the pay event on it. The pay event
to transition the payment from pending to paid and calls the do_pay
before the transition (before_transition).
Everything would be 100% if it weren’t for a small details. The payment
should be persisted even if the subscription transition from
has failed. In the do_pay method, if the payment failed, I do
(a FSM event that simply changes from pending->declined) and I have an
after_transition callback setup like: “after_transition any => any, do
p.save }” which gets triggered. However, since I return false in the
method to prevent the pendign->paid transition to complete (the payment
failed, remember?), state_machine then rollbacks the payment’s save.
What I did was to call:
after self.decline and before return false in the payment’s do_pay
This works, but is kind of ugly.
If anyone out there has any suggestions on how I could improve this
or maybe just tell me that this is ok to do, alleviating my worries
what seems to be a hack, I would be grateful!