Class: Pin::Plan

Inherits:
Base
  • Object
show all
Defined in:
lib/pin_up/plan.rb

Overview

This class models Pins Plans API

Instance Attribute Summary

Attributes inherited from Base

#key

Class Method Summary collapse

Methods inherited from Base

#base_uri, build_collection_response, build_response, #initialize, make_request

Constructor Details

This class inherits a constructor from Pin::Base

Class Method Details

.all(page = nil, pagination = false) ⇒ Object

Lists all plans for your account args: page (Fixnum), pagination (Boolean) returns: a collection of customer objects

if pagination is passed, access the response hash with [:response] and the pagination hash with [:pagination]

www.pinpayments.com/developers/api-reference/plans



14
15
16
# File 'lib/pin_up/plan.rb', line 14

def self.all(page = nil, pagination = false)
  build_collection_response(make_request(:get, {url: "plans?page=#{page}" } ), pagination)
end

.create(options = {}) ⇒ Object

Create a plan given plan details args: options (Hash) returns: a plan object www.pinpayments.com/developers/api-reference/plans



23
24
25
# File 'lib/pin_up/plan.rb', line 23

def self.create(options = {})
  build_response(make_request(:post, { url: 'plans', options: options }))
end

.create_subscription(token, customer_token, card_token = nil) ⇒ Object

Create a subscription for a plan given a customer_token OR a card_token args: customer_token (String), card (String) see docs. returns: a subscription object



68
69
70
71
72
73
74
75
76
77
# File 'lib/pin_up/plan.rb', line 68

def self.create_subscription(token, customer_token, card_token = nil)
  options = if card_token
              { customer_token: customer_token,
                card_token: card_token}
            else
              { customer_token: customer_token }
            end

  build_response(make_request(:post, {url: "plans/#{token}/subscriptions", options: options} ))
end

.delete(token) ⇒ Object

Delete a plan given a token args: token (String) returns: nil www.pinpayments.com/developers/api-reference/plans#delete-plan



50
51
52
# File 'lib/pin_up/plan.rb', line 50

def self.delete(token)
  build_response(make_request(:delete, { url: "plans/#{token}" } ))
end

.find(token) ⇒ Object

Find a plan for your account given a token args: token (String) returns: a plan object www.pinpayments.com/developers/api-reference/plans#get-plan



32
33
34
# File 'lib/pin_up/plan.rb', line 32

def self.find(token)
  build_response(make_request(:get, {url: "plans/#{token}" } ))
end

.subscriptions(token, page = nil, pagination = false) ⇒ Object

List Subscriptions associated with a plan given a token args: token (String) returns: nil



59
60
61
# File 'lib/pin_up/plan.rb', line 59

def self.subscriptions(token, page = nil, pagination = false)
  build_collection_response(make_request(:get, { url: "plans/#{token}/subscriptions" } ), pagination)
end

.update(token, options = {}) ⇒ Object

Update a plan given a token args: token (String), options (Hash) returns: a plan object www.pinpayments.com/developers/api-reference/plans#put-plan



41
42
43
# File 'lib/pin_up/plan.rb', line 41

def self.update(token, options = {})
  build_response(make_request(:put, { url: "plans/#{token}", options: options }))
end