Class: Poundpay::Payment

Inherits:
Resource
  • Object
show all
Defined in:
lib/poundpay/elements.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#collection_name, collection_path, custom_method_collection_url, element_path, #encode, instantiate_collection, new_element_path

Class Method Details

.batch_update(params) ⇒ Object



74
75
76
77
78
# File 'lib/poundpay/elements.rb', line 74

def self.batch_update(params)
  body = self.put('', {}, self.urlencode(params)).body
  collection = self.format.decode(body)
  return self.instantiate_collection(collection)
end

Instance Method Details

#authorizeObject



80
81
82
83
84
85
86
# File 'lib/poundpay/elements.rb', line 80

def authorize
  unless state == 'CREATED'
    raise PaymentAuthorizeException.new "Payment state is #{state}.  Only CREATED payments may be AUTHORIZED."
  end
  attributes['state'] = 'AUTHORIZED'
  save
end

#cancelObject



107
108
109
110
111
112
113
114
115
116
# File 'lib/poundpay/elements.rb', line 107

def cancel
  states = ['CREATED', 'AUTHORIZED', 'ESCROWED']
  unless states.include?(state)
    raise PaymentCancelException.new "Payment state is #{state}.  Only payments with states " \
    "#{states.join(', ')} may be canceled"
  end

  attributes['state'] = 'CANCELED'
  save
end

#escrowObject



88
89
90
91
92
93
94
# File 'lib/poundpay/elements.rb', line 88

def escrow
  unless state == 'AUTHORIZED'
    raise PaymentEscrowException.new "Payment state is #{state}.  Only AUTHORIZED payments may be ESCROWED."
  end
  attributes['state'] = 'ESCROWED'
  save
end

#releaseObject



96
97
98
99
100
101
102
103
104
105
# File 'lib/poundpay/elements.rb', line 96

def release
  states = ['ESCROWED']
  unless states.include?(state)
    raise PaymentReleaseException.new "Payment state is #{state}.  Only ESCROWED payments may be RELEASED."
  end
  # Tried setting state with state=, but save still had state == 'ESCROWED'.
  # Setting the state through the attributes, however, does work.
  attributes['state'] = 'RELEASED'
  save
end