lib/pay/stripe/billable.rb
def create_stripe_subscription(name, plan, options = {})
        quantity = options.delete(:quantity) || 1
        opts = {
          expand: ["pending_setup_intent", "latest_invoice.payment_intent"],
          items: [plan: plan, quantity: quantity],
          off_session: true
        }.merge(options)

        # Inherit trial from plan unless trial override was specified
        opts[:trial_from_plan] = true unless opts[:trial_period_days]

        opts[:customer] = stripe_customer.id

        stripe_sub = ::Stripe::Subscription.create(opts)
        subscription = create_subscription(stripe_sub, "stripe", name, plan, status: stripe_sub.status, quantity: quantity)

        # No trial, card requires SCA
        if subscription.incomplete?
          Pay::Payment.new(stripe_sub.latest_invoice.payment_intent).validate

        # Trial, card requires SCA
        elsif subscription.on_trial? && stripe_sub.pending_setup_intent
          Pay::Payment.new(stripe_sub.pending_setup_intent).validate
        end

        subscription
      rescue ::Stripe::StripeError => e
        raise Error, e.message
      end
# Handles Billable#subscribe
#
# Returns Pay::Subscription
Handles Billable#subscribe
Returns Pay::Subscription
Handles Billable#subscribe Returns Pay :: Subscription
def create_stripe_subscription(name, plan, options = {})
        quantity = options.delete(:quantity) || 1
        opts = {
          expand: ["pending_setup_intent", "latest_invoice.payment_intent"],
          items: [plan: plan, quantity: quantity],
          off_session: true
        }.merge(options)
        opts[:trial_from_plan] = true unless opts[:trial_period_days]
        opts[:customer] = stripe_customer.id
        stripe_sub = ::Stripe::Subscription.create(opts)
        subscription = create_subscription(stripe_sub, "stripe", name, plan, status: stripe_sub.status, quantity: quantity)
        if subscription.incomplete?
          Pay::Payment.new(stripe_sub.latest_invoice.payment_intent).validate
        elsif subscription.on_trial? && stripe_sub.pending_setup_intent
          Pay::Payment.new(stripe_sub.pending_setup_intent).validate
        end
        subscription
      rescue ::Stripe::StripeError => e
        raise Error, e.message
      end
def create_stripe_subscription ( name , plan , options = { } ) quantity = options . delete ( :quantity ) || 1 opts = { expand : [ "pending_setup_intent" , "latest_invoice.payment_intent" ] , items : [ plan : plan , quantity : quantity ] , off_session : true } . merge ( options ) opts [ :trial_from_plan ] = true unless opts [ :trial_period_days ] opts [ :customer ] = stripe_customer . id stripe_sub = :: Stripe :: Subscription . create ( opts ) subscription = create_subscription ( stripe_sub , "stripe" , name , plan , status : stripe_sub . status , quantity : quantity ) if subscription . incomplete? Pay :: Payment . new ( stripe_sub . latest_invoice . payment_intent ) . validate elsif subscription . on_trial? && stripe_sub . pending_setup_intent Pay :: Payment . new ( stripe_sub . pending_setup_intent ) . validate end subscription rescue :: Stripe :: StripeError => e raise Error , e . message end
Handles Billable#subscribe
Returns Pay::Subscription
Handles Billable#subscribe Returns Pay :: Subscription
# Inherit trial from plan unless trial override was specified # No trial, card requires SCA # Trial, card requires SCA
name
plan
options