From 6a7c0e90d57d7dc1b6f5e0776ff90dd723012b94 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 20 Apr 2022 14:26:37 -0500 Subject: [PATCH] Allow an in-transaction condition for billing --- lib/customer_plan.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/customer_plan.rb b/lib/customer_plan.rb index c349a546bfb572ee808ef36a427874bb7032f485..f4716a3bbd27e24c25501ab59740e5f7a58ce84f 100644 --- a/lib/customer_plan.rb +++ b/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