Sha256: d3357ab967fdfd01828535d3efa5b1e483bf2c9a1f139bebb1bc05ce16bae650
Contents?: true
Size: 1.12 KB
Versions: 14
Compression:
Stored size: 1.12 KB
Contents
module Pay module PaddleClassic module Webhooks class SubscriptionCancelled def call(event) pay_subscription = Pay::Subscription.find_by_processor_and_id(:paddle_classic, event.subscription_id) # We couldn't find the subscription for some reason, maybe it's from another service return if pay_subscription.nil? # User canceled subscriptions have an ends_at # Automatically cancelled subscriptions need this value set # Paddle subscriptions are canceled immediately, however we still want to give the user access to the end of the period they paid for ends_at = Time.zone.parse(event.cancellation_effective_date) pay_subscription.update!( status: (ends_at.future? ? :active : :canceled), trial_ends_at: (ends_at if pay_subscription.trial_ends_at?), ends_at: ends_at ) # Paddle classic doesn't allow reusing customers, so we should remove their payment methods Pay::PaymentMethod.where(customer_id: pay_subscription.customer_id).destroy_all end end end end end
Version data entries
14 entries across 14 versions & 1 rubygems