From b243062f2e341c65ffcf4daeb91ccedcc43a0b26 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Tue, 11 May 2021 09:30:30 -0500 Subject: [PATCH] Include BTC addresses in notification, if there are any --- bin/billing_monthly_cronjob | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/bin/billing_monthly_cronjob b/bin/billing_monthly_cronjob index 83169f6c41b99200ba4e1312eb0e1df6390b2a38..9dae4b933ee314d90f2070242b6d77d4fa66de60 100755 --- a/bin/billing_monthly_cronjob +++ b/bin/billing_monthly_cronjob @@ -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