~singpolyma/jmp-pay

b243062f2e341c65ffcf4daeb91ccedcc43a0b26 — Stephen Paul Weber 2 years ago ceae65b
Include BTC addresses in notification, if there are any
1 files changed, 26 insertions(+), 9 deletions(-)

M bin/billing_monthly_cronjob
M bin/billing_monthly_cronjob => bin/billing_monthly_cronjob +26 -9
@@ 155,23 155,40 @@ class ExpiredCustomer

	protected

		def jid
			REDIS.get("jmp_customer_jid-#{customer_id}")
		end

		def tel
			REDIS.lindex("catapult_cred-#{jid}", 3)
		end

		def btc_addresses
			@btc_addresses ||= REDIS.smembers(
				"jmp_customer_btc_addresses-#{customer_id}"
			)
		end

		def btc_addresses_for_notification
			return if btc_addresses.empty?
			"\nYou can buy credit by sending any amount of Bitcoin to one of "\
			"these addresses:\n#{btc_addresses.join("\n")}"
		end

		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),
				CONFIG[:notify_using][:body].call(
					jid, format_renewal_notification(tel)
					jid, renewal_notification
				)
			)
		end

		def format_renewal_notification(tel)
			<<~NOTIFY
				Failed to renew account for #{tel},
				balance of #{@row['balance']} is too low.
				To keep your number, please buy more credit soon.
			NOTIFY
		def renewal_notification
			"Failed to renew account for #{tel}, " \
			"balance of #{@row['balance']} is too low. " \
			"To keep your number, please buy more credit soon. " \
			"#{btc_addresses_for_notification}"
		end
	end
end