Class: Spreedly::Environment
- Inherits:
-
Object
- Object
- Spreedly::Environment
show all
- Includes:
- SslRequester, Urls
- Defined in:
- lib/spreedly/environment.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#add_credit_card(options) ⇒ Object
-
#add_gateway(gateway_type, credentials = {}) ⇒ Object
-
#authorize_on_gateway(gateway_token, payment_method_token, amount, options = {}) ⇒ Object
-
#capture_transaction(authorization_token, options = {}) ⇒ Object
-
#find_gateway(token) ⇒ Object
-
#find_payment_method(token) ⇒ Object
-
#find_transaction(token) ⇒ Object
-
#initialize(environment_key, access_secret, options = {}) ⇒ Environment
constructor
A new instance of Environment.
-
#list_gateways(since_token = nil) ⇒ Object
-
#list_payment_methods(since_token = nil) ⇒ Object
-
#list_transactions(since_token = nil, payment_method_token = nil) ⇒ Object
-
#purchase_on_gateway(gateway_token, payment_method_token, amount, options = {}) ⇒ Object
-
#redact_gateway(gateway_token, options = {}) ⇒ Object
-
#redact_payment_method(payment_method_token, options = {}) ⇒ Object
-
#refund_transaction(token, options = {}) ⇒ Object
-
#retain_payment_method(payment_method_token) ⇒ Object
-
#transparent_redirect_form_action ⇒ Object
-
#update_credit_card(credit_card_token, options) ⇒ Object
-
#void_transaction(token, options = {}) ⇒ Object
Methods included from Urls
#add_gateway_url, #add_payment_method_url, #authorize_url, #base_url, #capture_url, #find_gateway_url, #find_payment_method_url, #find_transaction_url, #list_gateways_url, #list_payment_methods_url, #list_transactions_url, #purchase_url, #redact_gateway_url, #redact_payment_method_url, #refund_transaction_url, #retain_payment_method_url, #update_payment_method_url, #void_transaction_url
#ssl_get, #ssl_post, #ssl_put
Constructor Details
#initialize(environment_key, access_secret, options = {}) ⇒ Environment
12
13
14
15
|
# File 'lib/spreedly/environment.rb', line 12
def initialize(environment_key, access_secret, options={})
@key, @access_secret = environment_key, access_secret
@currency_code = options[:currency_code] || 'USD'
end
|
Instance Attribute Details
#currency_code ⇒ Object
Returns the value of attribute currency_code.
10
11
12
|
# File 'lib/spreedly/environment.rb', line 10
def currency_code
@currency_code
end
|
#key ⇒ Object
Returns the value of attribute key.
10
11
12
|
# File 'lib/spreedly/environment.rb', line 10
def key
@key
end
|
Instance Method Details
#add_credit_card(options) ⇒ Object
95
96
97
|
# File 'lib/spreedly/environment.rb', line 95
def add_credit_card(options)
api_post(add_payment_method_url, add_credit_card_body(options))
end
|
#add_gateway(gateway_type, credentials = {}) ⇒ Object
89
90
91
92
93
|
# File 'lib/spreedly/environment.rb', line 89
def add_gateway(gateway_type, credentials = {})
body = add_gateway_body(gateway_type, credentials)
xml_doc = ssl_post(add_gateway_url, body, )
Gateway.new(xml_doc)
end
|
#authorize_on_gateway(gateway_token, payment_method_token, amount, options = {}) ⇒ Object
41
42
43
44
|
# File 'lib/spreedly/environment.rb', line 41
def authorize_on_gateway(gateway_token, payment_method_token, amount, options = {})
body = auth_purchase_body(amount, payment_method_token, options)
api_post(authorize_url(gateway_token), body)
end
|
#capture_transaction(authorization_token, options = {}) ⇒ Object
46
47
48
|
# File 'lib/spreedly/environment.rb', line 46
def capture_transaction(authorization_token, options = {})
api_post(capture_url(authorization_token), capture_body(options))
end
|
#find_gateway(token) ⇒ Object
31
32
33
34
|
# File 'lib/spreedly/environment.rb', line 31
def find_gateway(token)
xml_doc = ssl_get(find_gateway_url(token), )
Gateway.new(xml_doc)
end
|
#find_payment_method(token) ⇒ Object
21
22
23
24
|
# File 'lib/spreedly/environment.rb', line 21
def find_payment_method(token)
xml_doc = ssl_get(find_payment_method_url(token), )
PaymentMethod.new_from(xml_doc)
end
|
#find_transaction(token) ⇒ Object
26
27
28
29
|
# File 'lib/spreedly/environment.rb', line 26
def find_transaction(token)
xml_doc = ssl_get(find_transaction_url(token), )
Transaction.new_from(xml_doc)
end
|
#list_gateways(since_token = nil) ⇒ Object
84
85
86
87
|
# File 'lib/spreedly/environment.rb', line 84
def list_gateways(since_token = nil)
xml_doc = ssl_get(list_gateways_url(since_token), )
Gateway.new_list_from(xml_doc)
end
|
#list_payment_methods(since_token = nil) ⇒ Object
79
80
81
82
|
# File 'lib/spreedly/environment.rb', line 79
def list_payment_methods(since_token = nil)
xml_doc = ssl_get(list_payment_methods_url(since_token), )
PaymentMethod.new_list_from(xml_doc)
end
|
#list_transactions(since_token = nil, payment_method_token = nil) ⇒ Object
74
75
76
77
|
# File 'lib/spreedly/environment.rb', line 74
def list_transactions(since_token = nil, payment_method_token = nil)
xml_doc = ssl_get(list_transactions_url(since_token, payment_method_token), )
Transaction.new_list_from(xml_doc)
end
|
#purchase_on_gateway(gateway_token, payment_method_token, amount, options = {}) ⇒ Object
36
37
38
39
|
# File 'lib/spreedly/environment.rb', line 36
def purchase_on_gateway(gateway_token, payment_method_token, amount, options = {})
body = auth_purchase_body(amount, payment_method_token, options)
api_post(purchase_url(gateway_token), body)
end
|
#redact_gateway(gateway_token, options = {}) ⇒ Object
69
70
71
72
|
# File 'lib/spreedly/environment.rb', line 69
def redact_gateway(gateway_token, options = {})
xml_doc = ssl_put(redact_gateway_url(gateway_token), '', )
Transaction.new_from(xml_doc)
end
|
#redact_payment_method(payment_method_token, options = {}) ⇒ Object
63
64
65
66
67
|
# File 'lib/spreedly/environment.rb', line 63
def redact_payment_method(payment_method_token, options = {})
body = redact_payment_method_body(options)
xml_doc = ssl_put(redact_payment_method_url(payment_method_token), body, )
Transaction.new_from(xml_doc)
end
|
#refund_transaction(token, options = {}) ⇒ Object
54
55
56
|
# File 'lib/spreedly/environment.rb', line 54
def refund_transaction(token, options = {})
api_post(refund_transaction_url(token), refund_body(options))
end
|
#retain_payment_method(payment_method_token) ⇒ Object
58
59
60
61
|
# File 'lib/spreedly/environment.rb', line 58
def retain_payment_method(payment_method_token)
xml_doc = ssl_put(retain_payment_method_url(payment_method_token), '', )
Transaction.new_from(xml_doc)
end
|
17
18
19
|
# File 'lib/spreedly/environment.rb', line 17
def transparent_redirect_form_action
"#{base_url}/v1/payment_methods"
end
|
#update_credit_card(credit_card_token, options) ⇒ Object
99
100
101
102
103
|
# File 'lib/spreedly/environment.rb', line 99
def update_credit_card(credit_card_token, options)
body = update_credit_card_body(options)
xml_doc = ssl_put(update_payment_method_url(credit_card_token), body, )
PaymentMethod.new_from(xml_doc)
end
|
#void_transaction(token, options = {}) ⇒ Object
50
51
52
|
# File 'lib/spreedly/environment.rb', line 50
def void_transaction(token, options = {})
api_post(void_transaction_url(token), void_body(options))
end
|