Allow an in-transaction condition for billing

Stephen Paul Weber created

Change summary

lib/customer_plan.rb | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

Detailed changes

lib/customer_plan.rb 🔗

@@ -71,9 +71,12 @@ class CustomerPlan
 
 	def bill_plan(note: nil)
 		EM.promise_fiber do
-			DB.transaction do
+			DB.transaction do |db|
+				next false unless !block_given? || yield(db)
+
 				charge_for_plan(note)
 				add_one_month_to_current_plan unless activate_plan_starting_now
+				true
 			end
 		end
 	end