Module: StripeLocal::InstanceDelegation
- Defined in:
- lib/stripe_local/instance_delegation.rb
Instance Method Summary collapse
- #method_missing(method, *args, &block) ⇒ Object
- #respond_to_missing?(method, include_private = false) ⇒ Boolean
-
#signup(params) ⇒ Object
this is the primary interface for subscribing.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/stripe_local/instance_delegation.rb', line 35 def method_missing method, *args, &block if customer and customer.respond_to?( method, false ) customer.send method, *args, &block else super end end |
Instance Method Details
#respond_to_missing?(method, include_private = false) ⇒ Boolean
43 44 45 |
# File 'lib/stripe_local/instance_delegation.rb', line 43 def respond_to_missing? method, include_private = false super || customer and customer.respond_to?( method, false ) 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
-
- example
-
: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" ]
]
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/stripe_local/instance_delegation.rb', line 20 def signup 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 _customer_.to_hash.reverse_merge({model_id: self.id}) end |