Class: Spreedly::Environment

Inherits:
Object
  • Object
show all
Includes:
SslRequester, Urls
Defined in:
lib/spreedly/environment.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Urls

#add_gateway_url, #add_payment_method_url, #add_receiver_url, #authorize_url, #capture_url, #deliver_to_receiver_url, #find_gateway_url, #find_payment_method_url, #find_transaction_url, #find_transcript_url, #gateway_options_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, #verify_url, #void_transaction_url

Methods included from SslRequester

#ssl_get, #ssl_options, #ssl_post, #ssl_put, #ssl_raw_get

Constructor Details

#initialize(environment_key, access_secret, options = {}) ⇒ Environment

Returns a new instance of Environment.



12
13
14
15
16
# File 'lib/spreedly/environment.rb', line 12

def initialize(environment_key, access_secret, options={})
  @key, @access_secret = environment_key, access_secret
  @base_url = options[:base_url] || "https://core.spreedly.com"
  @currency_code = options[:currency_code] || 'USD'
end

Instance Attribute Details

#base_urlObject (readonly)

Returns the value of attribute base_url.



10
11
12
# File 'lib/spreedly/environment.rb', line 10

def base_url
  @base_url
end

#currency_codeObject (readonly)

Returns the value of attribute currency_code.



10
11
12
# File 'lib/spreedly/environment.rb', line 10

def currency_code
  @currency_code
end

#keyObject (readonly)

Returns the value of attribute key.



10
11
12
# File 'lib/spreedly/environment.rb', line 10

def key
  @key
end

Class Method Details

.gateway_optionsObject



104
105
106
# File 'lib/spreedly/environment.rb', line 104

def self.gateway_options
  self.new("", "").gateway_options
end

Instance Method Details

#add_credit_card(options) ⇒ Object



120
121
122
# File 'lib/spreedly/environment.rb', line 120

def add_credit_card(options)
  api_post(add_payment_method_url, add_credit_card_body(options), false)
end

#add_gateway(gateway_type, credentials = {}) ⇒ Object



108
109
110
111
112
# File 'lib/spreedly/environment.rb', line 108

def add_gateway(gateway_type, credentials = {})
  body = add_gateway_body(gateway_type, credentials)
  xml_doc = ssl_post(add_gateway_url, body, headers)
  Gateway.new(xml_doc)
end

#add_receiver(receiver_type, host_names = nil, credentials = []) ⇒ Object



114
115
116
117
118
# File 'lib/spreedly/environment.rb', line 114

def add_receiver(receiver_type, host_names = nil, credentials = [])
  body = add_receiver_body(receiver_type, host_names, credentials)
  xml_doc = ssl_post(add_receiver_url, body, headers)
  Receiver.new(xml_doc)
end

#authorize_on_gateway(gateway_token, payment_method_token, amount, options = {}) ⇒ Object



46
47
48
49
# File 'lib/spreedly/environment.rb', line 46

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



56
57
58
# File 'lib/spreedly/environment.rb', line 56

def capture_transaction(authorization_token, options = {})
  api_post(capture_url(authorization_token), capture_body(options))
end

#deliver_to_receiver(receiver_token, payment_method_token, receiver_options) ⇒ Object



130
131
132
133
134
# File 'lib/spreedly/environment.rb', line 130

def deliver_to_receiver(receiver_token, payment_method_token, receiver_options)
  body = deliver_to_receiver_body(payment_method_token, receiver_options)
  xml_doc = ssl_post(deliver_to_receiver_url(receiver_token), body, headers)
  DeliverPaymentMethod.new_from(xml_doc)
end

#find_gateway(token) ⇒ Object



36
37
38
39
# File 'lib/spreedly/environment.rb', line 36

def find_gateway(token)
  xml_doc = ssl_get(find_gateway_url(token), headers)
  Gateway.new(xml_doc)
end

#find_payment_method(token) ⇒ Object



22
23
24
25
# File 'lib/spreedly/environment.rb', line 22

def find_payment_method(token)
  xml_doc = ssl_get(find_payment_method_url(token), headers)
  PaymentMethod.new_from(xml_doc)
end

#find_transaction(token) ⇒ Object



27
28
29
30
# File 'lib/spreedly/environment.rb', line 27

def find_transaction(token)
  xml_doc = ssl_get(find_transaction_url(token), headers)
  Transaction.new_from(xml_doc)
end

#find_transcript(transaction_token) ⇒ Object



32
33
34
# File 'lib/spreedly/environment.rb', line 32

def find_transcript(transaction_token)
  ssl_raw_get(find_transcript_url(transaction_token), headers)
end

#gateway_optionsObject



99
100
101
102
# File 'lib/spreedly/environment.rb', line 99

def gateway_options
  xml_doc = ssl_options(gateway_options_url)
  GatewayClass.new_list_from(xml_doc)
end

#list_gateways(since_token = nil) ⇒ Object



94
95
96
97
# File 'lib/spreedly/environment.rb', line 94

def list_gateways(since_token = nil)
  xml_doc = ssl_get(list_gateways_url(since_token), headers)
  Gateway.new_list_from(xml_doc)
end

#list_payment_methods(since_token = nil) ⇒ Object



89
90
91
92
# File 'lib/spreedly/environment.rb', line 89

def list_payment_methods(since_token = nil)
  xml_doc = ssl_get(list_payment_methods_url(since_token), headers)
  PaymentMethod.new_list_from(xml_doc)
end

#list_transactions(since_token = nil, payment_method_token = nil) ⇒ Object



84
85
86
87
# File 'lib/spreedly/environment.rb', line 84

def list_transactions(since_token = nil, payment_method_token = nil)
  xml_doc = ssl_get(list_transactions_url(since_token, payment_method_token), headers)
  Transaction.new_list_from(xml_doc)
end

#purchase_on_gateway(gateway_token, payment_method_token, amount, options = {}) ⇒ Object



41
42
43
44
# File 'lib/spreedly/environment.rb', line 41

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



79
80
81
82
# File 'lib/spreedly/environment.rb', line 79

def redact_gateway(gateway_token, options = {})
  xml_doc = ssl_put(redact_gateway_url(gateway_token), '', headers)
  Transaction.new_from(xml_doc)
end

#redact_payment_method(payment_method_token, options = {}) ⇒ Object



73
74
75
76
77
# File 'lib/spreedly/environment.rb', line 73

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, headers)
  Transaction.new_from(xml_doc)
end

#refund_transaction(token, options = {}) ⇒ Object



64
65
66
# File 'lib/spreedly/environment.rb', line 64

def refund_transaction(token, options = {})
  api_post(refund_transaction_url(token), refund_body(options))
end

#retain_payment_method(payment_method_token) ⇒ Object



68
69
70
71
# File 'lib/spreedly/environment.rb', line 68

def retain_payment_method(payment_method_token)
  xml_doc = ssl_put(retain_payment_method_url(payment_method_token), '', headers)
  Transaction.new_from(xml_doc)
end

#transparent_redirect_form_actionObject



18
19
20
# File 'lib/spreedly/environment.rb', line 18

def transparent_redirect_form_action
  "#{base_url}/v1/payment_methods"
end

#update_credit_card(credit_card_token, options) ⇒ Object



124
125
126
127
128
# File 'lib/spreedly/environment.rb', line 124

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, headers)
  PaymentMethod.new_from(xml_doc)
end

#verify_on_gateway(gateway_token, payment_method_token, options = {}) ⇒ Object



51
52
53
54
# File 'lib/spreedly/environment.rb', line 51

def verify_on_gateway(gateway_token, payment_method_token, options = {})
  body = verify_body(payment_method_token, options)
  api_post(verify_url(gateway_token), body)
end

#void_transaction(token, options = {}) ⇒ Object



60
61
62
# File 'lib/spreedly/environment.rb', line 60

def void_transaction(token, options = {})
  api_post(void_transaction_url(token), void_body(options))
end