Class: RubyPsigate::Charge
- Defined in:
- lib/ruby_psigate/charge.rb
Instance Attribute Summary collapse
-
#accountid ⇒ Object
Returns the value of attribute accountid.
-
#endtime ⇒ Object
Returns the value of attribute endtime.
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#price ⇒ Object
Returns the value of attribute price.
-
#productid ⇒ Object
Returns the value of attribute productid.
-
#quantity ⇒ Object
Returns the value of attribute quantity.
-
#rbcid ⇒ Object
Returns the value of attribute rbcid.
-
#rbname ⇒ Object
Returns the value of attribute rbname.
-
#rbtrigger ⇒ Object
Returns the value of attribute rbtrigger.
-
#response ⇒ Object
Returns the value of attribute response.
-
#starttime ⇒ Object
Returns the value of attribute starttime.
-
#status ⇒ Object
Returns the value of attribute status.
Attributes inherited from Request
Class Method Summary collapse
- .disable(rbcid) ⇒ Object
- .enable(rbcid) ⇒ Object
- .find(rbcid) ⇒ Object
- .serialno ⇒ Object
- .serialno=(x) ⇒ Object
- .update(options = {}) ⇒ Object
Instance Method Summary collapse
-
#immediately ⇒ Object
Immediately charges the credit card.
-
#initialize(attributes = {}) ⇒ Charge
constructor
A new instance of Charge.
-
#save ⇒ Object
Creates (adds) or Updates recurring charges.
Methods inherited from Request
credential, credential=, #post, storeid, storeid=
Constructor Details
#initialize(attributes = {}) ⇒ Charge
Returns a new instance of Charge.
102 103 104 105 106 107 108 109 110 |
# File 'lib/ruby_psigate/charge.rb', line 102 def initialize(attributes={}) attributes.each_pair do |attribute, value| if self.respond_to?(attribute) setter = "#{attribute}=".to_sym self.send(setter, value) end end super end |
Instance Attribute Details
#accountid ⇒ Object
Returns the value of attribute accountid.
4 5 6 |
# File 'lib/ruby_psigate/charge.rb', line 4 def accountid @accountid end |
#endtime ⇒ Object
Returns the value of attribute endtime.
4 5 6 |
# File 'lib/ruby_psigate/charge.rb', line 4 def endtime @endtime end |
#interval ⇒ Object
Returns the value of attribute interval.
4 5 6 |
# File 'lib/ruby_psigate/charge.rb', line 4 def interval @interval end |
#price ⇒ Object
Returns the value of attribute price.
4 5 6 |
# File 'lib/ruby_psigate/charge.rb', line 4 def price @price end |
#productid ⇒ Object
Returns the value of attribute productid.
4 5 6 |
# File 'lib/ruby_psigate/charge.rb', line 4 def productid @productid end |
#quantity ⇒ Object
Returns the value of attribute quantity.
4 5 6 |
# File 'lib/ruby_psigate/charge.rb', line 4 def quantity @quantity end |
#rbcid ⇒ Object
Returns the value of attribute rbcid.
4 5 6 |
# File 'lib/ruby_psigate/charge.rb', line 4 def rbcid @rbcid end |
#rbname ⇒ Object
Returns the value of attribute rbname.
4 5 6 |
# File 'lib/ruby_psigate/charge.rb', line 4 def rbname @rbname end |
#rbtrigger ⇒ Object
Returns the value of attribute rbtrigger.
4 5 6 |
# File 'lib/ruby_psigate/charge.rb', line 4 def rbtrigger @rbtrigger end |
#response ⇒ Object
Returns the value of attribute response.
4 5 6 |
# File 'lib/ruby_psigate/charge.rb', line 4 def response @response end |
#starttime ⇒ Object
Returns the value of attribute starttime.
4 5 6 |
# File 'lib/ruby_psigate/charge.rb', line 4 def starttime @starttime end |
#status ⇒ Object
Returns the value of attribute status.
4 5 6 |
# File 'lib/ruby_psigate/charge.rb', line 4 def status @status end |
Class Method Details
.disable(rbcid) ⇒ Object
98 99 100 |
# File 'lib/ruby_psigate/charge.rb', line 98 def self.disable(rbcid) toggle(rbcid, :off) end |
.enable(rbcid) ⇒ Object
94 95 96 |
# File 'lib/ruby_psigate/charge.rb', line 94 def self.enable(rbcid) toggle(rbcid, :on) end |
.find(rbcid) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ruby_psigate/charge.rb', line 14 def self.find(rbcid) begin params = { :Request => { :CID => credential.cid, :UserID => credential.userid, :Password => credential.password, :Action => "RBC00", :Condition => { :RBCID => rbcid } } } @result = Request.new @result.params = params @result = @result.post if @result.returncode == "RRC-0060" # Adds basic attributes attributes = {} %w( rbcid interval trigger status ).each do |info| attributes[info.downcase.to_sym] = @result.send(info.downcase.to_sym) end attributes["starttime"] = @result.startdate attributes["endtime"] = @result.enddate attributes["response"] = @result.response @charge = Charge.new(attributes) else @charge = nil end rescue ConnectionError => e @charge = nil end @charge end |
.serialno ⇒ Object
6 7 8 |
# File 'lib/ruby_psigate/charge.rb', line 6 def self.serialno @serialno end |
.serialno=(x) ⇒ Object
10 11 12 |
# File 'lib/ruby_psigate/charge.rb', line 10 def self.serialno=(x) @serialno=x end |
.update(options = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ruby_psigate/charge.rb', line 51 def self.update(={}) rbname = [:rbname] rbcid = [:rbcid] serialno = [:serialno] interval = [:interval] rbtrigger = [:rbtrigger] starttime = [:starttime] endtime = [:endtime] begin params = { :Request => { :CID => credential.cid, :UserID => credential.userid, :Password => credential.password, :Action => "RBC02", :Condition => { :RBCID => rbcid }, :Update => { :RBName => rbname, :SerialNo => serialno, :Interval => interval, :RBTrigger => rbtrigger, :StartTime => starttime, :EndTime => endtime } } } @result = Request.new @result.params = params @result = @result.post if @result.returncode = "RRC-0072" result = true else result = false end rescue ConnectionError => e result = false end result end |
Instance Method Details
#immediately ⇒ Object
Immediately charges the credit card
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/ruby_psigate/charge.rb', line 153 def immediately raise ArgumentError, "StoreID is not specified in superclass" if self.class.storeid.nil? begin @request[:Request][:Action] = "RBC99" @request[:Request][:Charge] = { :StoreID => self.class.storeid, :SerialNo => self.class.serialno, :AccountID => accountid, :ItemInfo => { :ProductID => productid, :Quantity => quantity, :Price => price } } # Creates parameters params = RubyPsigate::Serializer.new(@request, :header => true).to_xml connection = RubyPsigate::Connection.new(self.class.credential.endpoint) response = connection.post(params) response = Response.new(response) self.response = response if response.success? && response.returncode == "PSI-0000" result = true else result = false end rescue ConnectionError => e result = false end result end |
#save ⇒ Object
Creates (adds) or Updates recurring charges
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/ruby_psigate/charge.rb', line 113 def save raise ArgumentError, "StoreID is not specified in superclass" if self.class.storeid.nil? begin @request[:Request][:Action] = "RBC01" @request[:Request][:Charge] = { :RBName => rbname, :StoreID => self.class.storeid, :SerialNo => self.class.serialno, :AccountID => accountid, :Interval => interval, :RBTrigger => rbtrigger, :StartTime => starttime, :EndTime => endtime, :ItemInfo => { :ProductID => productid, :Quantity => quantity, :Price => price } } # Creates parameters params = RubyPsigate::Serializer.new(@request, :header => true).to_xml connection = RubyPsigate::Connection.new(self.class.credential.endpoint) response = connection.post(params) response = Response.new(response) self.response = response if response.success? && response.returncode == "RRC-0000" self.rbcid = response.rbcid result = true else result = false end rescue ConnectionError => e result = false end result end |