Class: Upay::Plan

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

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Plan

Returns a new instance of Plan.



3
4
5
6
7
# File 'lib/upay/plan.rb', line 3

def initialize(args = {})
  args.each do |k,v|
    instance_variable_set("@#{k}", v) unless v.nil?
  end
end

Instance Method Details

#accountIdObject



9
# File 'lib/upay/plan.rb', line 9

def accountId; @accountId end

#accountId=(accountId) ⇒ Object



10
11
12
# File 'lib/upay/plan.rb', line 10

def accountId=(accountId)
  @accountId = accountId
end

#additionalValuesObject



54
# File 'lib/upay/plan.rb', line 54

def additionalValues; @additionalValues end

#additionalValues=(additionalValues) ⇒ Object



55
56
57
# File 'lib/upay/plan.rb', line 55

def additionalValues=(additionalValues)
  @additionalValues = additionalValues
end

#createObject

Verb: POST Description: Returns: JSON



72
73
74
75
76
# File 'lib/upay/plan.rb', line 72

def create
  url = "rest/v4.3/plans"
  Requestor.new.post(url, self.to_hash)

end

#currencyObject



34
# File 'lib/upay/plan.rb', line 34

def currency; @currency end

#currency=(currency) ⇒ Object



35
36
37
# File 'lib/upay/plan.rb', line 35

def currency=(currency)
  @currency = currency
end

#deleteObject

Verb: DELETE Description: Returns: JSON



107
108
109
110
# File 'lib/upay/plan.rb', line 107

def delete
  url = "rest/v4.3/plans/#{self.planCode}"
  Requestor.new.delete(url, self.to_hash)
end

#descriptionObject



19
# File 'lib/upay/plan.rb', line 19

def description; @description end

#description=(description) ⇒ Object



20
21
22
# File 'lib/upay/plan.rb', line 20

def description=(description)
  @description = description
end

#find_by_name(name) ⇒ Object



94
95
96
97
98
99
100
101
102
# File 'lib/upay/plan.rb', line 94

def find_by_name(name)
  url = "rest/v4.3/plans/"
  request = Requestor.new.get(url, {})
  obtained_plan = {}
  request["subscriptionPlanList"].each do |plan|
    obtained_plan = plan if plan["planCode"] == name
  end
  obtained_plan
end

#intervalObject



24
# File 'lib/upay/plan.rb', line 24

def interval; @interval end

#interval=(interval) ⇒ Object



25
26
27
# File 'lib/upay/plan.rb', line 25

def interval=(interval)
  @interval = interval
end

#intervalCountObject



39
# File 'lib/upay/plan.rb', line 39

def intervalCount; @intervalCount end

#intervalCount=(intervalCount) ⇒ Object



40
41
42
# File 'lib/upay/plan.rb', line 40

def intervalCount=(intervalCount)
  @intervalCount = intervalCount
end

#maxPaymentsAllowedObject



44
# File 'lib/upay/plan.rb', line 44

def maxPaymentsAllowed; @maxPaymentsAllowed end

#maxPaymentsAllowed=(maxPaymentsAllowed) ⇒ Object



45
46
47
# File 'lib/upay/plan.rb', line 45

def maxPaymentsAllowed=(maxPaymentsAllowed)
  @maxPaymentsAllowed = maxPaymentsAllowed
end

#paymentAttempsDelayObject



49
# File 'lib/upay/plan.rb', line 49

def paymentAttempsDelay; @paymentAttempsDelay end

#paymentAttempsDelay=(paymentAttempsDelay) ⇒ Object



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

def paymentAttempsDelay=(paymentAttempsDelay)
  @paymentAttempsDelay = paymentAttempsDelay
end

#planCodeObject



14
# File 'lib/upay/plan.rb', line 14

def planCode; @planCode end

#planCode=(planCode) ⇒ Object



15
16
17
# File 'lib/upay/plan.rb', line 15

def planCode=(planCode)
  @planCode = planCode
end

#showObject

Verb: POST Description: Returns: JSON



89
90
91
92
# File 'lib/upay/plan.rb', line 89

def show
  url = "rest/v4.3/plans/#{self.planCode}"
  Requestor.new.get(url, self.to_hash)
end

#to_hashObject



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/upay/plan.rb', line 112

def to_hash
  {
    :accountId => self.accountId || nil,
    :planCode => self.planCode,
    :description => self.description,
    :interval => self.interval,
    :intervalCount => self.intervalCount,
    :maxPaymentsAllowed => self.maxPaymentsAllowed || nil,
    :paymentAttemptsDelay => "1",
    :additionalValues => [
      {
        :name => "PLAN_VALUE",
        :value => self.value,
        :currency => "COP"
      }
    ]
  }
end

#trialDaysObject



59
# File 'lib/upay/plan.rb', line 59

def trialDays; @trialDays end

#trialDays=(trialDays) ⇒ Object



60
61
62
# File 'lib/upay/plan.rb', line 60

def trialDays=(trialDays)
  @trialDays = trialDays
end

#updateObject

Verb: UPDATE Description: Returns: JSON



81
82
83
84
# File 'lib/upay/plan.rb', line 81

def update
  url = "rest/v4.3/plans/#{self.planCode}"
  Requestor.new.put(url, self.to_hash)
end

#valid?Boolean

Returns:

  • (Boolean)


64
65
66
67
# File 'lib/upay/plan.rb', line 64

def valid?
  validator = PlanValidator.new
  validator.valid?(self) 
end

#valueObject



29
# File 'lib/upay/plan.rb', line 29

def value; @value end

#value=(value) ⇒ Object



30
31
32
# File 'lib/upay/plan.rb', line 30

def value=(value)
  @value = value
end