lib/pay/braintree/billable.rb
def create_braintree_subscription(name, plan, options = {})
        token = customer.payment_methods.find(&:default?).try(:token)
        raise Pay::Error, "Customer has no default payment method" if token.nil?

        # Standardize the trial period options
        if (trial_period_days = options.delete(:trial_period_days)) && trial_period_days > 0
          options.merge!(trial_period: true, trial_duration: trial_period_days, trial_duration_unit: :day)
        end

        subscription_options = options.merge(
          payment_method_token: token,
          plan_id: plan
        )

        result = gateway.subscription.create(subscription_options)
        raise BraintreeError.new(result), result.message unless result.success?

        create_subscription(result.subscription, "braintree", name, plan, status: :active)
      rescue ::Braintree::AuthorizationError => e
        raise BraintreeAuthorizationError
      rescue ::Braintree::BraintreeError => e
        raise BraintreeError, e.message
      end
# Handles Billable#subscribe
#
# Returns Pay::Subscription
Handles Billable#subscribe
Returns Pay::Subscription
Handles Billable#subscribe Returns Pay :: Subscription
def create_braintree_subscription(name, plan, options = {})
        token = customer.payment_methods.find(&:default?).try(:token)
        raise Pay::Error, "Customer has no default payment method" if token.nil?
        if (trial_period_days = options.delete(:trial_period_days)) && trial_period_days > 0
          options.merge!(trial_period: true, trial_duration: trial_period_days, trial_duration_unit: :day)
        end
        subscription_options = options.merge(
          payment_method_token: token,
          plan_id: plan
        )
        result = gateway.subscription.create(subscription_options)
        raise BraintreeError.new(result), result.message unless result.success?
        create_subscription(result.subscription, "braintree", name, plan, status: :active)
      rescue ::Braintree::AuthorizationError => e
        raise BraintreeAuthorizationError
      rescue ::Braintree::BraintreeError => e
        raise BraintreeError, e.message
      end
def create_braintree_subscription ( name , plan , options = { } ) token = customer . payment_methods . find ( & :default? ) . try ( :token ) raise Pay :: Error , "Customer has no default payment method" if token . nil? if ( trial_period_days = options . delete ( :trial_period_days ) ) && trial_period_days > 0 options . merge! ( trial_period : true , trial_duration : trial_period_days , trial_duration_unit : :day ) end subscription_options = options . merge ( payment_method_token : token , plan_id : plan ) result = gateway . subscription . create ( subscription_options ) raise BraintreeError . new ( result ) , result . message unless result . success? create_subscription ( result . subscription , "braintree" , name , plan , status : :active ) rescue :: Braintree :: AuthorizationError => e raise BraintreeAuthorizationError rescue :: Braintree :: BraintreeError => e raise BraintreeError , e . message end
Handles Billable#subscribe
Returns Pay::Subscription
Handles Billable#subscribe Returns Pay :: Subscription
# Standardize the trial period options
name
plan
options