~singpolyma/jmp-pay

d2d3d3c7703559096ddfe53ddef621655ad9bd6f — Stephen Paul Weber 2 years ago e6c4d2c
Only notify expired users once a week
1 files changed, 17 insertions(+), 6 deletions(-)

M bin/billing_monthly_cronjob
M bin/billing_monthly_cronjob => bin/billing_monthly_cronjob +17 -6
@@ 128,10 128,14 @@ class ExpiredCustomer
		@plan = plan
	end

	def customer_id
		@row["customer_id"]
	end

	def try_renew(db, stats)
		@plan.renew(
			db,
			@row["customer_id"],
			customer_id,
			@row["expires_at"]
		)



@@ 140,8 144,19 @@ class ExpiredCustomer
	end

	class WithLowBalance < ExpiredCustomer
		ONE_WEEK = 60 * 60 * 24 * 7

		def try_renew(_, stats)
			jid = REDIS.get("jmp_customer_jid-#{@row['customer_id']}")
			stats.add(:not_renewed, 1)
			return if REDIS.exists?("jmp_customer_low_balance-#{customer_id}")
			REDIS.set("jmp_customer_low_balance-#{customer_id}", Time.now, ex: ONE_WEEK)
			send_notification
		end

	protected

		def send_notification
			jid = REDIS.get("jmp_customer_jid-#{customer_id}")
			tel = REDIS.lindex("catapult_cred-#{jid}", 3)
			BlatherNotify.say(
				CONFIG[:notify_using][:target].call(jid),


@@ 149,12 164,8 @@ class ExpiredCustomer
					jid, format_renewal_notification(tel)
				)
			)

			stats.add(:not_renewed, 1)
		end

	protected

		def format_renewal_notification(tel)
			<<~NOTIFY
				Failed to renew account for #{tel},