You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: subscription.rb
    path of file: ./repos/pay/lib/pay/paddle_billing
    
    the code of the file until where you have to start completion: module Pay
  module PaddleBilling
    class Subscription
      attr_reader :pay_subscription

      delegate :active?,
        :canceled?,
        :on_grace_period?,
        :on_trial?,
        :ends_at,
        :name,
        :owner,
        :pause_starts_at,
        :pause_starts_at?
    
      def cancel(**options)
        return if canceled?

        response = ::Paddle::Subscription.cancel(
          id: processor_id,
          effective_from: options.fetch(:effective_from, (paused? ? "immediately" : "next_billing_period"))
        )
        pay_subscription.update(
          status: response.status,
          ends_at: response.scheduled_change&.effective_at || Time.current
        )
      rescue ::Paddle::Error => e
        raise Pay::PaddleBilling::Error, e
      end