🚨Fix Rubocop lint errors

This commit is contained in:
Pranav Raj S
2019-10-20 14:17:26 +05:30
committed by GitHub
parent dd018f3682
commit 94c6d6db6f
124 changed files with 774 additions and 914 deletions

View File

@@ -4,8 +4,8 @@ module Facebook
def perform
return if message.private
return if inbox.channel.class.to_s != "FacebookPage"
return if !outgoing_message_from_chatwoot?
return if inbox.channel.class.to_s != 'FacebookPage'
return unless outgoing_message_from_chatwoot?
Bot.deliver(delivery_params, access_token: message.channel_token)
end
@@ -25,7 +25,7 @@ module Facebook
end
def outgoing_message_from_chatwoot?
#messages sent directly from chatwoot won't have fb_id.
# messages sent directly from chatwoot won't have fb_id.
message.outgoing? && !message.fb_id
end
@@ -38,13 +38,13 @@ module Facebook
def fb_message_params
{
recipient: { id: sender.source_id },
message: { text: message.content },
message: { text: message.content }
}
end
def delivery_params
if twenty_four_hour_window_over?
fb_message_params.merge(tag: "ISSUE_RESOLUTION")
fb_message_params.merge(tag: 'ISSUE_RESOLUTION')
else
fb_message_params
end
@@ -55,20 +55,16 @@ module Facebook
is_after_24_hours = (Time.current - last_incoming_message.created_at) / 3600 >= 24
if !is_after_24_hours
false
end
false unless is_after_24_hours
if last_incoming_message && has_sent_first_outgoing_message_after_24_hours?(last_incoming_message.id)
false
end
false if last_incoming_message && has_sent_first_outgoing_message_after_24_hours?(last_incoming_message.id)
true
end
def has_sent_first_outgoing_message_after_24_hours?(last_incoming_message_id)
#we can send max 1 message after 24 hour window
conversation.messages.outgoing.where("id > ?", last_incoming_message_id).count == 1
# we can send max 1 message after 24 hour window
conversation.messages.outgoing.where('id > ?', last_incoming_message_id).count == 1
end
end
end

View File

@@ -1,83 +1,70 @@
class Subscription::ChargebeeService
class << self
def create_subscription(account)
begin
result = ChargeBee::Subscription.create({
plan_id: Plan.paid_plan.id,
customer: {
email: account.users.administrator.try(:first).try(:email),
first_name: account.name,
company: account.name
}
})
subscription = account.subscription
subscription.stripe_customer_id = result.subscription.customer_id
subscription.save
rescue => e
Raven.capture_exception(e)
end
result = ChargeBee::Subscription.create(
plan_id: Plan.paid_plan.id,
customer: {
email: account.users.administrator.try(:first).try(:email),
first_name: account.name,
company: account.name
}
)
subscription = account.subscription
subscription.stripe_customer_id = result.subscription.customer_id
subscription.save
rescue StandardError => e
Raven.capture_exception(e)
end
def update_subscription(account)
begin
subscription = account.subscription
agents_count = account.users.count
ChargeBee::Subscription.update(subscription.stripe_customer_id, { plan_quantity: agents_count })
rescue => e
Raven.capture_exception(e)
end
subscription = account.subscription
agents_count = account.users.count
ChargeBee::Subscription.update(subscription.stripe_customer_id, plan_quantity: agents_count)
rescue StandardError => e
Raven.capture_exception(e)
end
def cancel_subscription(account)
begin
subscription = account.subscription
ChargeBee::Subscription.delete(subscription.stripe_customer_id)
rescue => e
Raven.capture_exception(e)
end
subscription = account.subscription
ChargeBee::Subscription.delete(subscription.stripe_customer_id)
rescue StandardError => e
Raven.capture_exception(e)
end
def reactivate_subscription(account)
begin
subscription = account.subscription
ChargeBee::Subscription.reactivate(subscription.stripe_customer_id)
subscription.active!
rescue => e
Raven.capture_exception(e)
end
subscription = account.subscription
ChargeBee::Subscription.reactivate(subscription.stripe_customer_id)
subscription.active!
rescue StandardError => e
Raven.capture_exception(e)
end
def deactivate_subscription(account)
begin
subscription = account.subscription
ChargeBee::Subscription.cancel(subscription.stripe_customer_id)
subscription.cancelled!
rescue => e
Raven.capture_exception(e)
end
subscription = account.subscription
ChargeBee::Subscription.cancel(subscription.stripe_customer_id)
subscription.cancelled!
rescue StandardError => e
Raven.capture_exception(e)
end
def hosted_page_url(account)
begin
subscription = account.subscription
subscription = account.subscription
# result = ChargeBee::HostedPage.checkout_existing({
# :subscription => {
# :id => subscription.stripe_customer_id,
# :plan_id => Plan.paid_plan.id
# }
# })
# result = ChargeBee::HostedPage.checkout_existing({
# :subscription => {
# :id => subscription.stripe_customer_id,
# :plan_id => Plan.paid_plan.id
# }
# })
result = ChargeBee::HostedPage.update_payment_method({
:customer => {
:id => subscription.stripe_customer_id
}
})
result.hosted_page.url
rescue => e
Raven.capture_exception(e)
end
result = ChargeBee::HostedPage.update_payment_method(
customer: {
id: subscription.stripe_customer_id
}
)
result.hosted_page.url
rescue StandardError => e
Raven.capture_exception(e)
end
end
end