class RubyPsigate::Charge
Attributes
accountid[RW]
endtime[RW]
interval[RW]
price[RW]
productid[RW]
quantity[RW]
rbcid[RW]
rbname[RW]
rbtrigger[RW]
response[RW]
starttime[RW]
status[RW]
Public Class Methods
disable(rbcid)
click to toggle source
# File lib/ruby_psigate/charge.rb, line 98 def self.disable(rbcid) toggle(rbcid, :off) end
enable(rbcid)
click to toggle source
# File lib/ruby_psigate/charge.rb, line 94 def self.enable(rbcid) toggle(rbcid, :on) end
find(rbcid)
click to toggle source
# 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
new(attributes={})
click to toggle source
Calls superclass method
# 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
serialno()
click to toggle source
# File lib/ruby_psigate/charge.rb, line 6 def self.serialno @serialno end
serialno=(x)
click to toggle source
# File lib/ruby_psigate/charge.rb, line 10 def self.serialno=(x) @serialno=x end
update(options={})
click to toggle source
# File lib/ruby_psigate/charge.rb, line 51 def self.update(options={}) rbname = options[:rbname] rbcid = options[:rbcid] serialno = options[:serialno] interval = options[:interval] rbtrigger = options[:rbtrigger] starttime = options[:starttime] endtime = options[: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
Private Class Methods
toggle(rbcid, set_action)
click to toggle source
Toggles a charge to be active or inactive
# File lib/ruby_psigate/charge.rb, line 189 def self.toggle(rbcid, set_action) action = case set_action when :on "RBC08" when :off "RBC09" end begin params = { :Request => { :CID => credential.cid, :UserID => credential.userid, :Password => credential.password, :Action => action, :Condition => { :RBCID => rbcid } } } @result = Request.new @result.params = params @result = @result.post if set_action==:on && @result.returncode == "RRC-0190" result = true elsif set_action==:off && @result.returncode == "RRC-0090" result = true else result = false end rescue ConnectionError => e result = false end result end
Public Instance Methods
immediately()
click to toggle source
Immediately charges the credit card
# 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()
click to toggle source
Creates (adds) or Updates recurring charges
# 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