Class: SlidePay::Payment
Instance Attribute Summary
Attributes inherited from ApiResource
#api_key, #endpoint, #id_attribute, #token, #url_root
Instance Method Summary
collapse
Methods inherited from ApiResource
api_resource_array_from_response, find, find_between, find_greater_than, find_less_than, find_where, #id, #is_new?, #populate_from_response, retrieve, #retrieve, #url
Constructor Details
#initialize(values_hash = {}) ⇒ Payment
Returns a new instance of Payment.
6
7
8
9
10
11
|
# File 'lib/slidepay/resources/payment.rb', line 6
def initialize(values_hash={})
@url_root = "payment"
@id_attribute = "payment_id"
super(values_hash)
end
|
Instance Method Details
#destroy(options_hash = {}) ⇒ Object
17
18
19
|
# File 'lib/slidepay/resources/payment.rb', line 17
def destroy(options_hash={})
refund(options_hash)
end
|
#is_settled? ⇒ Boolean
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/slidepay/resources/payment.rb', line 21
def is_settled?
raise "Cannot check settlement status for a payment with no ID." unless is_new? == false
if ! self['provider_capture_state'].eql? "Captured"
return false
elsif self['settlement_transaction_token'] == nil
return false
elsif self['settlement_transaction_token'].is_a?(String) && self['settlement_transaction_token'].empty?
return false
else
return true
end
end
|
#process(options_hash = {}) ⇒ Object
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/slidepay/resources/payment.rb', line 38
def process(options_hash={})
token = @token || options_hash[:token]
api_key = @api_key || options_hash[:api_key]
endpoint = @endpoint || options_hash[:endpoint]
response = SlidePay.post(path: "payment/simple", api_key: api_key, token: token, endpoint: endpoint, data: self.to_json)
if response.was_successful?
self["payment_id"] = response.data["payment_id"]
self["order_master_id"] = response.data["order_master_id"]
true
elsif response.error_text
raise Exception.new(response.error_text)
elsif response.data["status_message"]
raise Exception.new(response.data["status_message"])
else
raise Exception.new("Payment could not be processed.")
end
end
|
#refund(options_hash = {}) ⇒ Object
58
59
60
61
62
63
64
65
66
|
# File 'lib/slidepay/resources/payment.rb', line 58
def refund(options_hash={})
token = @token || options_hash[:token]
api_key = @api_key || options_hash[:api_key]
endpoint = @endpoint || options_hash[:endpoint]
response = SlidePay.post(path: "payment/refund/#{self.id()}", api_key: api_key, token: token, endpoint: endpoint, data: self.to_json)
response.was_successful?
end
|
#save(options_hash = {}) ⇒ Object
13
14
15
|
# File 'lib/slidepay/resources/payment.rb', line 13
def save(options_hash={})
process(options_hash)
end
|