Sha256: 718c7050209cdc2ec423fc7d643b4182128a1ced0723ec46fbb849c90a02b8db
Contents?: true
Size: 1.35 KB
Versions: 24
Compression:
Stored size: 1.35 KB
Contents
module Pay module Paddle module Webhooks class SubscriptionUpdated def call(event) subscription = Pay::Subscription.find_by_processor_and_id(:paddle, event["subscription_id"]) return if subscription.nil? case event["status"] when "deleted" subscription.status = "canceled" subscription.ends_at = Time.zone.parse(event["next_bill_date"]) || Time.current if subscription.ends_at.blank? when "trialing" subscription.status = "trialing" subscription.trial_ends_at = Time.zone.parse(event["next_bill_date"]) when "active" subscription.status = "active" subscription.paddle_paused_from = Time.zone.parse(event["paused_from"]) if event["paused_from"].present? else subscription.status = event["status"] end subscription.quantity = event["new_quantity"] subscription.processor_plan = event["subscription_plan_id"] subscription.paddle_update_url = event["update_url"] subscription.paddle_cancel_url = event["cancel_url"] # If user was on trial, their subscription ends at the end of the trial subscription.ends_at = subscription.trial_ends_at if subscription.on_trial? subscription.save! end end end end end
Version data entries
24 entries across 24 versions & 1 rubygems