Module: StripeLocal::InstanceDelegation

Defined in:
lib/stripe_local/instance_delegation.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/stripe_local/instance_delegation.rb', line 37

def method_missing method, *args, &block
  if customer && customer.respond_to?( method )
    customer.send method, *args, &block
  else
    super
  end
end

Instance Method Details

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/stripe_local/instance_delegation.rb', line 44

def respond_to_missing? method, include_private = false
  customer && customer.respond_to?( method ) || super
end

#signup(params) ⇒ Object

!=#

this is the primary interface for subscribing.

params
  • card (required) -> the token returned by stripe.js

  • plan (required) -> the id of the plan being subscribed to

  • email (optional) -> the client’s email address

  • description (optional) -> a description to attach to the stripe object for future reference

  • coupon (optional) -> the id of a coupon if the subscription should be discounted

  • lines (optional) -> an array of (amount,description) tuples

:card => "tok_abc123",
:plan => "MySaaS",
:email => subscriber.email,
:description => "a one year subscription to our flagship service at $99.00 per month"
:lines => [
   [ 20000, "a one time setup fee of $200.00 for new members" ]
]

¡=#



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/stripe_local/instance_delegation.rb', line 22

def  params
  plan  = params.delete( :plan )
  lines = params.delete( :lines ) || []

  _customer_ = Stripe::Customer.create( params )

  lines.each do |(amount,desc)|
    _customer_.add_invoice_item({currency: 'usd', amount: amount, description: desc})
  end
  _customer_.update_subscription({ plan: plan })

  StripeLocal::Customer.create( {model_id: self.id}.merge _customer_.to_hash )
end