Class: SpookAndPay::Providers::Spreedly
- Inherits:
-
Base
- Object
- Base
- SpookAndPay::Providers::Spreedly
show all
- Defined in:
- lib/spook_and_pay/providers/spreedly.rb
Constant Summary
collapse
- FORM_FIELD_NAMES =
The map of generic field names to what is specifically required by Spreedly.
{
:name => "credit_card[full_name]",
:number => "credit_card[number]",
:expiration_month => "credit_card[month]",
:expiration_year => "credit_card[year]",
:cvv => "credit_card[verification_value]"
}.freeze
Instance Attribute Summary collapse
Attributes inherited from Base
#config, #environment
Instance Method Summary
collapse
Methods inherited from Base
#credit_via_credit_card, #supports_partial_refund?, #supports_refund?
Constructor Details
#initialize(env, config) ⇒ Spreedly
Generate a new instance of the Spreedly provider.
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/spook_and_pay/providers/spreedly.rb', line 36
def initialize(env, config)
@gateway_token = config[:gateway_token]
@currency_code = config[:currency_code] || 'AUD'
@spreedly = ::Spreedly::Environment.new(
config[:environment_key],
config[:access_secret],
:currency_code => currency_code
)
super(env, config)
end
|
Instance Attribute Details
#currency_code ⇒ Object
Currency code. Spreedly defaults to USD, but we default to AUD.
27
28
29
|
# File 'lib/spook_and_pay/providers/spreedly.rb', line 27
def currency_code
@currency_code
end
|
#gateway_token ⇒ Object
The which refers to a specific gateway.
17
18
19
|
# File 'lib/spook_and_pay/providers/spreedly.rb', line 17
def gateway_token
@gateway_token
end
|
#spreedly ⇒ Object
An instance of the spreedly spreedly.
22
23
24
|
# File 'lib/spook_and_pay/providers/spreedly.rb', line 22
def spreedly
@spreedly
end
|
Instance Method Details
#authorize_via_credit_card(id, amount) ⇒ Object
155
156
157
158
|
# File 'lib/spook_and_pay/providers/spreedly.rb', line 155
def authorize_via_credit_card(id, amount)
result = spreedly.authorize_on_gateway(gateway_token, credit_card_id(id), (amount.to_f * 100).to_i)
coerce_result(result)
end
|
#capture_transaction(id) ⇒ Object
102
103
104
105
|
# File 'lib/spook_and_pay/providers/spreedly.rb', line 102
def capture_transaction(id)
result = spreedly.capture_transaction(transaction_id(id))
coerce_result(result)
end
|
#confirm_payment_submission(query_string, opts) ⇒ Object
Confirms the submission of payment details to Spreedly Core.
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/spook_and_pay/providers/spreedly.rb', line 72
def confirm_payment_submission(query_string, opts)
token = Rack::Utils.parse_nested_query(query_string)["token"]
card = credit_card(token)
if card.valid?
case opts[:execute]
when :authorize then card.authorize!(opts[:amount])
when :purchase then card.purchase!(opts[:amount])
else SpookAndPay::Result.new(true, nil, :credit_card => card)
end
else
SpookAndPay::Result.new(false, nil, :credit_card => card, :errors => (card.raw))
end
end
|
#credit_card(id) ⇒ Object
87
88
89
90
|
# File 'lib/spook_and_pay/providers/spreedly.rb', line 87
def credit_card(id)
result = spreedly.find_payment_method(id)
coerce_credit_card(result)
end
|
#credit_card_from_transaction(id) ⇒ Object
92
93
94
95
|
# File 'lib/spook_and_pay/providers/spreedly.rb', line 92
def credit_card_from_transaction(id)
result = spreedly.find_transaction(transaction_id(id))
coerce_credit_card(result.payment_method)
end
|
#delete_credit_card(id) ⇒ Object
165
166
167
168
|
# File 'lib/spook_and_pay/providers/spreedly.rb', line 165
def delete_credit_card(id)
result = spreedly.redact_payment_method(credit_card_id(id))
coerce_result(result)
end
|
#partially_refund_transaction(id, amount) ⇒ Object
112
113
114
115
|
# File 'lib/spook_and_pay/providers/spreedly.rb', line 112
def partially_refund_transaction(id, amount)
result = spreedly.refund_transaction(transaction_id(id), :amount => (amount.to_f * 100).to_i)
coerce_result(result)
end
|
#prepare_payment_submission(redirect_url, opts = {}) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/spook_and_pay/providers/spreedly.rb', line 51
def prepare_payment_submission(redirect_url, opts = {})
config = {
:url => spreedly.transparent_redirect_form_action,
:field_names => self.class::FORM_FIELD_NAMES,
:hidden_fields => {:redirect_url => redirect_url, :environment_key => spreedly.key}
}
if opts[:token]
config[:hidden_fields][:payment_method_token] = opts[:token]
end
config
end
|
#purchase_via_credit_card(id, amount) ⇒ Object
160
161
162
163
|
# File 'lib/spook_and_pay/providers/spreedly.rb', line 160
def purchase_via_credit_card(id, amount)
result = spreedly.purchase_on_gateway(gateway_token, credit_card_id(id), (amount.to_f * 100).to_i)
coerce_result(result)
end
|
#refund_transaction(id) ⇒ Object
107
108
109
110
|
# File 'lib/spook_and_pay/providers/spreedly.rb', line 107
def refund_transaction(id)
result = spreedly.refund_transaction(transaction_id(id))
coerce_result(result)
end
|
#retain_credit_card(id) ⇒ Object
This method is part of a private API.
You should avoid using this method if possible, as it may be removed or be changed in the future.
Calls the retain action on the provider’s vault.
175
176
177
178
|
# File 'lib/spook_and_pay/providers/spreedly.rb', line 175
def retain_credit_card(id)
result = spreedly.retain_payment_method(credit_card_id(id))
coerce_result(result)
end
|
#supports_authorize? ⇒ Boolean
145
146
147
|
# File 'lib/spook_and_pay/providers/spreedly.rb', line 145
def supports_authorize?
check_support_for('supports_authorize')
end
|
#supports_capture? ⇒ Boolean
141
142
143
|
# File 'lib/spook_and_pay/providers/spreedly.rb', line 141
def supports_capture?
check_support_for('supports_capture')
end
|
#supports_credit? ⇒ Boolean
137
138
139
|
# File 'lib/spook_and_pay/providers/spreedly.rb', line 137
def supports_credit?
false
end
|
#supports_delete? ⇒ Boolean
149
150
151
152
153
|
# File 'lib/spook_and_pay/providers/spreedly.rb', line 149
def supports_delete?
true
end
|
#supports_purchase? ⇒ Boolean
129
130
131
|
# File 'lib/spook_and_pay/providers/spreedly.rb', line 129
def supports_purchase?
check_support_for('supports_purchase')
end
|
#supports_void? ⇒ Boolean
133
134
135
|
# File 'lib/spook_and_pay/providers/spreedly.rb', line 133
def supports_void?
check_support_for('supports_void')
end
|
#transaction(id) ⇒ Object
97
98
99
100
|
# File 'lib/spook_and_pay/providers/spreedly.rb', line 97
def transaction(id)
result = spreedly.find_transaction(id)
coerce_transaction(result)
end
|
#void_transaction(id) ⇒ Object
117
118
119
120
|
# File 'lib/spook_and_pay/providers/spreedly.rb', line 117
def void_transaction(id)
result = spreedly.void_transaction(transaction_id(id))
coerce_result(result)
end
|