yetanothernguyen-activemerchant 1.16.0 → 1.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +95 -0
- data/CONTRIBUTORS +29 -0
- data/lib/active_merchant/billing/credit_card.rb +105 -19
- data/lib/active_merchant/billing/credit_card_methods.rb +5 -1
- data/lib/active_merchant/billing/gateway.rb +1 -1
- data/lib/active_merchant/billing/gateways/authorize_net.rb +24 -2
- data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +104 -18
- data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +110 -4
- data/lib/active_merchant/billing/gateways/beanstream.rb +29 -1
- data/lib/active_merchant/billing/gateways/braintree_blue.rb +9 -4
- data/lib/active_merchant/billing/gateways/braintree_orange.rb +4 -0
- data/lib/active_merchant/billing/gateways/card_save.rb +23 -0
- data/lib/active_merchant/billing/gateways/certo_direct.rb +279 -0
- data/lib/active_merchant/billing/gateways/efsnet.rb +9 -9
- data/lib/active_merchant/billing/gateways/elavon.rb +2 -1
- data/lib/active_merchant/billing/gateways/epay.rb +12 -6
- data/lib/active_merchant/billing/gateways/eway_managed.rb +46 -12
- data/lib/active_merchant/billing/gateways/exact.rb +5 -0
- data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +3 -3
- data/lib/active_merchant/billing/gateways/ipay88.rb +157 -0
- data/lib/active_merchant/billing/gateways/iridium.rb +3 -3
- data/lib/active_merchant/billing/gateways/itransact.rb +450 -0
- data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +1 -0
- data/lib/active_merchant/billing/gateways/moneris.rb +4 -0
- data/lib/active_merchant/billing/gateways/nab_transact.rb +244 -0
- data/lib/active_merchant/billing/gateways/ogone.rb +94 -56
- data/lib/active_merchant/billing/gateways/optimal_payment.rb +277 -0
- data/lib/active_merchant/billing/gateways/orbital.rb +57 -34
- data/lib/active_merchant/billing/gateways/pay_junction.rb +6 -1
- data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +1 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +2 -2
- data/lib/active_merchant/billing/gateways/payflow.rb +10 -2
- data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +8 -5
- data/lib/active_merchant/billing/gateways/paypal_digital_goods.rb +43 -0
- data/lib/active_merchant/billing/gateways/paypal_express.rb +93 -40
- data/lib/active_merchant/billing/gateways/paypal_express_common.rb +8 -3
- data/lib/active_merchant/billing/gateways/qbms.rb +4 -0
- data/lib/active_merchant/billing/gateways/quickpay.rb +97 -22
- data/lib/active_merchant/billing/gateways/realex.rb +5 -1
- data/lib/active_merchant/billing/gateways/samurai.rb +121 -0
- data/lib/active_merchant/billing/gateways/secure_pay_au.rb +136 -49
- data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +1 -1
- data/lib/active_merchant/billing/gateways/skip_jack.rb +7 -2
- data/lib/active_merchant/billing/gateways/stripe.rb +51 -19
- data/lib/active_merchant/billing/gateways/usa_epay.rb +13 -184
- data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1496 -0
- data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +206 -0
- data/lib/active_merchant/billing/gateways/verifi.rb +2 -2
- data/lib/active_merchant/billing/gateways/viaklix.rb +1 -1
- data/lib/active_merchant/billing/gateways/worldpay.rb +1 -1
- data/lib/active_merchant/billing/integrations/action_view_helper.rb +6 -2
- data/lib/active_merchant/billing/integrations/authorize_net_sim/helper.rb +228 -0
- data/lib/active_merchant/billing/integrations/authorize_net_sim/notification.rb +340 -0
- data/lib/active_merchant/billing/integrations/authorize_net_sim.rb +38 -0
- data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +4 -4
- data/lib/active_merchant/billing/integrations/dwolla/helper.rb +31 -0
- data/lib/active_merchant/billing/integrations/dwolla/notification.rb +55 -0
- data/lib/active_merchant/billing/integrations/dwolla/return.rb +38 -0
- data/lib/active_merchant/billing/integrations/dwolla.rb +30 -0
- data/lib/active_merchant/billing/integrations/helper.rb +19 -2
- data/lib/active_merchant/billing/integrations/ipay88/helper.rb +120 -0
- data/lib/active_merchant/billing/integrations/ipay88/return.rb +121 -0
- data/lib/active_merchant/billing/integrations/ipay88.rb +40 -0
- data/lib/active_merchant/billing/integrations/nochex.rb +1 -1
- data/lib/active_merchant/billing/integrations/payflow_link/helper.rb +100 -0
- data/lib/active_merchant/billing/integrations/payflow_link/notification.rb +78 -0
- data/lib/active_merchant/billing/integrations/payflow_link.rb +21 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +4 -4
- data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +18 -2
- data/lib/active_merchant/billing/integrations/two_checkout.rb +1 -2
- data/lib/active_merchant/railtie.rb +7 -7
- data/lib/active_merchant/railtie.rb.orig +19 -0
- data/lib/active_merchant/version.rb +1 -1
- data/lib/active_merchant.rb +23 -10
- data/lib/active_merchant.rb.orig +78 -0
- metadata +147 -63
- data/lib/active_merchant/common/connection.rb +0 -177
- data/lib/active_merchant/common/country.rb +0 -328
- data/lib/active_merchant/common/error.rb +0 -26
- data/lib/active_merchant/common/post_data.rb +0 -24
- data/lib/active_merchant/common/posts_data.rb +0 -63
- data/lib/active_merchant/common/requires_parameters.rb +0 -16
- data/lib/active_merchant/common/utils.rb +0 -22
- data/lib/active_merchant/common/validateable.rb +0 -81
- data/lib/active_merchant/common.rb +0 -14
- data/lib/certs/cacert.pem +0 -7815
@@ -4,30 +4,33 @@ module ActiveMerchant #:nodoc:
|
|
4
4
|
module Billing #:nodoc:
|
5
5
|
class SecurePayAuGateway < Gateway
|
6
6
|
API_VERSION = 'xml-4.2'
|
7
|
-
|
7
|
+
PERIODIC_API_VERSION = 'spxml-3.0'
|
8
|
+
|
8
9
|
TEST_URL = 'https://www.securepay.com.au/test/payment'
|
9
10
|
LIVE_URL = 'https://www.securepay.com.au/xmlapi/payment'
|
10
|
-
|
11
|
+
TEST_PERIODIC_URL = "https://test.securepay.com.au/xmlapi/periodic"
|
12
|
+
LIVE_PERIODIC_URL = "https://api.securepay.com.au/xmlapi/periodic"
|
13
|
+
|
11
14
|
self.supported_countries = ['AU']
|
12
15
|
self.supported_cardtypes = [:visa, :master, :american_express, :diners_club, :jcb]
|
13
|
-
|
16
|
+
|
14
17
|
# The homepage URL of the gateway
|
15
18
|
self.homepage_url = 'http://securepay.com.au'
|
16
|
-
|
19
|
+
|
17
20
|
# The name of the gateway
|
18
21
|
self.display_name = 'SecurePay'
|
19
|
-
|
22
|
+
|
20
23
|
class_attribute :request_timeout
|
21
24
|
self.request_timeout = 60
|
22
|
-
|
25
|
+
|
23
26
|
self.money_format = :cents
|
24
27
|
self.default_currency = 'AUD'
|
25
|
-
|
28
|
+
|
26
29
|
# 0 Standard Payment
|
27
|
-
# 4 Refund
|
28
|
-
# 6 Client Reversal (Void)
|
29
|
-
# 10 Preauthorise
|
30
|
-
# 11 Preauth Complete (Advice)
|
30
|
+
# 4 Refund
|
31
|
+
# 6 Client Reversal (Void)
|
32
|
+
# 10 Preauthorise
|
33
|
+
# 11 Preauth Complete (Advice)
|
31
34
|
TRANSACTIONS = {
|
32
35
|
:purchase => 0,
|
33
36
|
:authorization => 10,
|
@@ -35,33 +38,50 @@ module ActiveMerchant #:nodoc:
|
|
35
38
|
:void => 6,
|
36
39
|
:refund => 4
|
37
40
|
}
|
38
|
-
|
41
|
+
|
42
|
+
PERIODIC_ACTIONS = {
|
43
|
+
:add_triggered => "add",
|
44
|
+
:remove_triggered => "delete",
|
45
|
+
:trigger => "trigger"
|
46
|
+
}
|
47
|
+
|
48
|
+
PERIODIC_TYPES = {
|
49
|
+
:add_triggered => 4,
|
50
|
+
:remove_triggered => nil,
|
51
|
+
:trigger => nil
|
52
|
+
}
|
53
|
+
|
39
54
|
SUCCESS_CODES = [ '00', '08', '11', '16', '77' ]
|
40
|
-
|
55
|
+
|
41
56
|
def initialize(options = {})
|
42
57
|
requires!(options, :login, :password)
|
43
58
|
@options = options
|
44
59
|
super
|
45
60
|
end
|
46
|
-
|
61
|
+
|
47
62
|
def test?
|
48
63
|
@options[:test] || super
|
49
64
|
end
|
50
|
-
|
51
|
-
def purchase(money,
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
65
|
+
|
66
|
+
def purchase(money, credit_card_or_stored_id, options = {})
|
67
|
+
if credit_card_or_stored_id.is_a?(ActiveMerchant::Billing::CreditCard)
|
68
|
+
requires!(options, :order_id)
|
69
|
+
commit :purchase, build_purchase_request(money, credit_card_or_stored_id, options)
|
70
|
+
else
|
71
|
+
options[:billing_id] = credit_card_or_stored_id.to_s
|
72
|
+
commit_periodic(build_periodic_item(:trigger, money, nil, options))
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
56
76
|
def authorize(money, credit_card, options = {})
|
57
77
|
requires!(options, :order_id)
|
58
78
|
commit :authorization, build_purchase_request(money, credit_card, options)
|
59
79
|
end
|
60
|
-
|
80
|
+
|
61
81
|
def capture(money, reference, options = {})
|
62
82
|
commit :capture, build_reference_request(money, reference)
|
63
83
|
end
|
64
|
-
|
84
|
+
|
65
85
|
def refund(money, reference, options = {})
|
66
86
|
commit :refund, build_reference_request(money, reference)
|
67
87
|
end
|
@@ -74,54 +94,64 @@ module ActiveMerchant #:nodoc:
|
|
74
94
|
def void(reference, options = {})
|
75
95
|
commit :void, build_reference_request(nil, reference)
|
76
96
|
end
|
77
|
-
|
97
|
+
|
98
|
+
def store(creditcard, options = {})
|
99
|
+
requires!(options, :billing_id, :amount)
|
100
|
+
commit_periodic(build_periodic_item(:add_triggered, options[:amount], creditcard, options))
|
101
|
+
end
|
102
|
+
|
103
|
+
def unstore(identification, options = {})
|
104
|
+
options[:billing_id] = identification
|
105
|
+
commit_periodic(build_periodic_item(:remove_triggered, options[:amount], nil, options))
|
106
|
+
end
|
107
|
+
|
78
108
|
private
|
79
|
-
|
109
|
+
|
80
110
|
def build_purchase_request(money, credit_card, options)
|
81
111
|
xml = Builder::XmlMarkup.new
|
82
|
-
|
112
|
+
|
83
113
|
xml.tag! 'amount', amount(money)
|
84
|
-
xml.tag! 'currency', options[:currency] || currency(money)
|
114
|
+
xml.tag! 'currency', options[:currency] || currency(money)
|
85
115
|
xml.tag! 'purchaseOrderNo', options[:order_id].to_s.gsub(/[ ']/, '')
|
86
|
-
|
116
|
+
|
87
117
|
xml.tag! 'CreditCardInfo' do
|
88
118
|
xml.tag! 'cardNumber', credit_card.number
|
89
119
|
xml.tag! 'expiryDate', expdate(credit_card)
|
90
120
|
xml.tag! 'cvv', credit_card.verification_value if credit_card.verification_value?
|
91
121
|
end
|
92
|
-
|
122
|
+
|
93
123
|
xml.target!
|
94
124
|
end
|
95
|
-
|
125
|
+
|
96
126
|
def build_reference_request(money, reference)
|
97
127
|
xml = Builder::XmlMarkup.new
|
98
|
-
|
128
|
+
|
99
129
|
transaction_id, order_id, preauth_id, original_amount = reference.split("*")
|
100
130
|
xml.tag! 'amount', (money ? amount(money) : original_amount)
|
101
131
|
xml.tag! 'currency', options[:currency] || currency(money)
|
102
132
|
xml.tag! 'txnID', transaction_id
|
103
133
|
xml.tag! 'purchaseOrderNo', order_id
|
104
134
|
xml.tag! 'preauthID', preauth_id
|
105
|
-
|
135
|
+
|
106
136
|
xml.target!
|
107
137
|
end
|
108
|
-
|
138
|
+
|
109
139
|
def build_request(action, body)
|
110
140
|
xml = Builder::XmlMarkup.new
|
111
141
|
xml.instruct!
|
112
142
|
xml.tag! 'SecurePayMessage' do
|
113
143
|
xml.tag! 'MessageInfo' do
|
114
|
-
xml.tag! 'messageID', Utils.generate_unique_id.slice(0, 30)
|
144
|
+
xml.tag! 'messageID', ActiveMerchant::Utils.generate_unique_id.slice(0, 30)
|
115
145
|
xml.tag! 'messageTimestamp', generate_timestamp
|
116
146
|
xml.tag! 'timeoutValue', request_timeout
|
117
147
|
xml.tag! 'apiVersion', API_VERSION
|
118
148
|
end
|
119
|
-
|
149
|
+
|
120
150
|
xml.tag! 'MerchantInfo' do
|
121
151
|
xml.tag! 'merchantID', @options[:login]
|
122
152
|
xml.tag! 'password', @options[:password]
|
123
153
|
end
|
124
|
-
|
154
|
+
|
125
155
|
xml.tag! 'RequestType', 'Payment'
|
126
156
|
xml.tag! 'Payment' do
|
127
157
|
xml.tag! 'TxnList', "count" => 1 do
|
@@ -133,40 +163,98 @@ module ActiveMerchant #:nodoc:
|
|
133
163
|
end
|
134
164
|
end
|
135
165
|
end
|
136
|
-
|
166
|
+
|
137
167
|
xml.target!
|
138
168
|
end
|
139
|
-
|
169
|
+
|
140
170
|
def commit(action, request)
|
141
171
|
response = parse(ssl_post(test? ? TEST_URL : LIVE_URL, build_request(action, request)))
|
142
|
-
|
143
|
-
Response.new(success?(response), message_from(response), response,
|
144
|
-
:test => test?,
|
172
|
+
|
173
|
+
Response.new(success?(response), message_from(response), response,
|
174
|
+
:test => test?,
|
175
|
+
:authorization => authorization_from(response)
|
176
|
+
)
|
177
|
+
end
|
178
|
+
|
179
|
+
def build_periodic_item(action, money, credit_card, options)
|
180
|
+
xml = Builder::XmlMarkup.new
|
181
|
+
|
182
|
+
xml.tag! 'actionType', PERIODIC_ACTIONS[action]
|
183
|
+
xml.tag! 'clientID', options[:billing_id].to_s
|
184
|
+
|
185
|
+
if credit_card
|
186
|
+
xml.tag! 'CreditCardInfo' do
|
187
|
+
xml.tag! 'cardNumber', credit_card.number
|
188
|
+
xml.tag! 'expiryDate', expdate(credit_card)
|
189
|
+
xml.tag! 'cvv', credit_card.verification_value if credit_card.verification_value?
|
190
|
+
end
|
191
|
+
end
|
192
|
+
xml.tag! 'amount', amount(money)
|
193
|
+
xml.tag! 'periodicType', PERIODIC_TYPES[action] if PERIODIC_TYPES[action]
|
194
|
+
|
195
|
+
xml.target!
|
196
|
+
end
|
197
|
+
|
198
|
+
def build_periodic_request(body)
|
199
|
+
xml = Builder::XmlMarkup.new
|
200
|
+
xml.instruct!
|
201
|
+
xml.tag! 'SecurePayMessage' do
|
202
|
+
xml.tag! 'MessageInfo' do
|
203
|
+
xml.tag! 'messageID', ActiveMerchant::Utils.generate_unique_id.slice(0, 30)
|
204
|
+
xml.tag! 'messageTimestamp', generate_timestamp
|
205
|
+
xml.tag! 'timeoutValue', request_timeout
|
206
|
+
xml.tag! 'apiVersion', PERIODIC_API_VERSION
|
207
|
+
end
|
208
|
+
|
209
|
+
xml.tag! 'MerchantInfo' do
|
210
|
+
xml.tag! 'merchantID', @options[:login]
|
211
|
+
xml.tag! 'password', @options[:password]
|
212
|
+
end
|
213
|
+
|
214
|
+
xml.tag! 'RequestType', 'Periodic'
|
215
|
+
xml.tag! 'Periodic' do
|
216
|
+
xml.tag! 'PeriodicList', "count" => 1 do
|
217
|
+
xml.tag! 'PeriodicItem', "ID" => 1 do
|
218
|
+
xml << body
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
xml.target!
|
224
|
+
end
|
225
|
+
|
226
|
+
def commit_periodic(request)
|
227
|
+
my_request = build_periodic_request(request)
|
228
|
+
#puts my_request
|
229
|
+
response = parse(ssl_post(test? ? TEST_PERIODIC_URL : LIVE_PERIODIC_URL, my_request))
|
230
|
+
|
231
|
+
Response.new(success?(response), message_from(response), response,
|
232
|
+
:test => test?,
|
145
233
|
:authorization => authorization_from(response)
|
146
234
|
)
|
147
235
|
end
|
148
|
-
|
236
|
+
|
149
237
|
def success?(response)
|
150
238
|
SUCCESS_CODES.include?(response[:response_code])
|
151
239
|
end
|
152
|
-
|
240
|
+
|
153
241
|
def authorization_from(response)
|
154
242
|
[response[:txn_id], response[:purchase_order_no], response[:preauth_id], response[:amount]].join('*')
|
155
243
|
end
|
156
|
-
|
244
|
+
|
157
245
|
def message_from(response)
|
158
246
|
response[:response_text] || response[:status_description]
|
159
247
|
end
|
160
|
-
|
248
|
+
|
161
249
|
def expdate(credit_card)
|
162
250
|
"#{format(credit_card.month, :two_digits)}/#{format(credit_card.year, :two_digits)}"
|
163
251
|
end
|
164
|
-
|
252
|
+
|
165
253
|
def parse(body)
|
166
254
|
xml = REXML::Document.new(body)
|
167
255
|
|
168
256
|
response = {}
|
169
|
-
|
257
|
+
|
170
258
|
xml.root.elements.to_a.each do |node|
|
171
259
|
parse_element(response, node)
|
172
260
|
end
|
@@ -181,13 +269,12 @@ module ActiveMerchant #:nodoc:
|
|
181
269
|
response[node.name.underscore.to_sym] = node.text
|
182
270
|
end
|
183
271
|
end
|
184
|
-
|
272
|
+
|
185
273
|
# YYYYDDMMHHNNSSKKK000sOOO
|
186
274
|
def generate_timestamp
|
187
275
|
time = Time.now.utc
|
188
276
|
time.strftime("%Y%d%m%H%M%S#{time.usec}+000")
|
189
|
-
end
|
277
|
+
end
|
190
278
|
end
|
191
279
|
end
|
192
280
|
end
|
193
|
-
|
@@ -20,7 +20,7 @@ module ActiveMerchant #:nodoc:
|
|
20
20
|
|
21
21
|
SUCCESS_MESSAGE = 'The transaction was successful.'
|
22
22
|
|
23
|
-
MONETARY_CHANGE_STATUSES = ['AUTHORIZE', 'AUTHORIZE ADDITIONAL', 'CREDIT', 'SPLITSETTLE']
|
23
|
+
MONETARY_CHANGE_STATUSES = ['SETTLE', 'AUTHORIZE', 'AUTHORIZE ADDITIONAL', 'CREDIT', 'SPLITSETTLE']
|
24
24
|
|
25
25
|
CARD_CODE_ERRORS = %w( N S "" )
|
26
26
|
|
@@ -236,7 +236,7 @@ module ActiveMerchant #:nodoc:
|
|
236
236
|
commit(:change_status, nil, post)
|
237
237
|
end
|
238
238
|
|
239
|
-
def
|
239
|
+
def refund(money, identification, options = {})
|
240
240
|
post = {}
|
241
241
|
add_status_action(post, 'CREDIT')
|
242
242
|
add_forced_settlement(post, options)
|
@@ -244,6 +244,11 @@ module ActiveMerchant #:nodoc:
|
|
244
244
|
commit(:change_status, money, post)
|
245
245
|
end
|
246
246
|
|
247
|
+
def credit(money, identification, options = {})
|
248
|
+
deprecated CREDIT_DEPRECATION_MESSAGE
|
249
|
+
refund(money, identification, options)
|
250
|
+
end
|
251
|
+
|
247
252
|
def status(order_id)
|
248
253
|
commit(:get_status, nil, :szOrderNumber => order_id)
|
249
254
|
end
|
@@ -35,50 +35,74 @@ module ActiveMerchant #:nodoc:
|
|
35
35
|
super
|
36
36
|
end
|
37
37
|
|
38
|
+
# To create a charge on a card or a token, call
|
39
|
+
#
|
40
|
+
# purchase(money, card_hash_or_token, { ... })
|
41
|
+
#
|
42
|
+
# To create a charge on a customer, call
|
43
|
+
#
|
44
|
+
# purchase(money, nil, { :customer => id, ... })
|
38
45
|
def purchase(money, creditcard, options = {})
|
39
46
|
post = {}
|
40
47
|
|
41
48
|
add_amount(post, money, options)
|
42
49
|
add_creditcard(post, creditcard, options)
|
43
50
|
add_customer(post, options)
|
44
|
-
|
51
|
+
post[:description] = options[:description] || options[:email]
|
45
52
|
add_flags(post, options)
|
46
53
|
|
54
|
+
meta = generate_meta(options)
|
55
|
+
|
47
56
|
raise ArgumentError.new("Customer or Credit Card required.") if !post[:card] && !post[:customer]
|
48
57
|
|
49
|
-
commit('charges', post)
|
58
|
+
commit(:post, 'charges', post, meta)
|
50
59
|
end
|
51
60
|
|
52
61
|
def authorize(money, creditcard, options = {})
|
53
|
-
|
62
|
+
raise "Stripe does not support separate authorization and capture"
|
54
63
|
end
|
55
64
|
|
56
65
|
def capture(money, identification, options = {})
|
57
|
-
|
66
|
+
raise "Stripe does not support separate authorization and capture"
|
58
67
|
end
|
59
68
|
|
60
|
-
def void(identification, options={})
|
61
|
-
commit("charges/#{CGI.escape(identification)}/refund", {})
|
69
|
+
def void(identification, options = {})
|
70
|
+
commit(:post, "charges/#{CGI.escape(identification)}/refund", {})
|
62
71
|
end
|
63
72
|
|
64
73
|
def refund(money, identification, options = {})
|
74
|
+
meta = generate_meta(options)
|
65
75
|
post = {}
|
66
76
|
|
67
77
|
post[:amount] = amount(money) if money
|
68
78
|
|
69
|
-
commit("charges/#{CGI.escape(identification)}/refund", post)
|
79
|
+
commit(:post, "charges/#{CGI.escape(identification)}/refund", post, meta)
|
70
80
|
end
|
71
81
|
|
72
|
-
def store(creditcard, options={})
|
82
|
+
def store(creditcard, options = {})
|
73
83
|
post = {}
|
74
84
|
add_creditcard(post, creditcard, options)
|
75
|
-
|
85
|
+
post[:description] = options[:description]
|
86
|
+
post[:email] = options[:email]
|
76
87
|
|
77
|
-
|
78
|
-
|
88
|
+
meta = generate_meta(options)
|
89
|
+
path = if options[:customer]
|
90
|
+
"customers/#{CGI.escape(options[:customer])}"
|
79
91
|
else
|
80
|
-
|
92
|
+
'customers'
|
81
93
|
end
|
94
|
+
|
95
|
+
commit(:post, path, post, meta)
|
96
|
+
end
|
97
|
+
|
98
|
+
def update(customer_id, creditcard, options = {})
|
99
|
+
options = options.merge(:customer => customer_id)
|
100
|
+
store(creditcard, options)
|
101
|
+
end
|
102
|
+
|
103
|
+
def unstore(customer_id, options = {})
|
104
|
+
meta = generate_meta(options)
|
105
|
+
commit(:delete, "customers/#{CGI.escape(customer_id)}", nil, meta)
|
82
106
|
end
|
83
107
|
|
84
108
|
private
|
@@ -89,7 +113,8 @@ module ActiveMerchant #:nodoc:
|
|
89
113
|
end
|
90
114
|
|
91
115
|
def add_customer_data(post, options)
|
92
|
-
post[:description] = options[:
|
116
|
+
post[:description] = options[:description]
|
117
|
+
post[:email] = options[:email]
|
93
118
|
end
|
94
119
|
|
95
120
|
def add_address(post, options)
|
@@ -132,6 +157,8 @@ module ActiveMerchant #:nodoc:
|
|
132
157
|
end
|
133
158
|
|
134
159
|
def post_data(params)
|
160
|
+
return nil unless params
|
161
|
+
|
135
162
|
params.map do |key, value|
|
136
163
|
next if value.blank?
|
137
164
|
if value.is_a?(Hash)
|
@@ -146,7 +173,11 @@ module ActiveMerchant #:nodoc:
|
|
146
173
|
end.compact.join("&")
|
147
174
|
end
|
148
175
|
|
149
|
-
def
|
176
|
+
def generate_meta(options)
|
177
|
+
{:ip => options[:ip]}
|
178
|
+
end
|
179
|
+
|
180
|
+
def headers(meta={})
|
150
181
|
@@ua ||= JSON.dump({
|
151
182
|
:bindings_version => ActiveMerchant::VERSION,
|
152
183
|
:lang => 'ruby',
|
@@ -157,17 +188,18 @@ module ActiveMerchant #:nodoc:
|
|
157
188
|
})
|
158
189
|
|
159
190
|
{
|
160
|
-
"Authorization" => "Basic " +
|
191
|
+
"Authorization" => "Basic " + Base64.encode64(@api_key.to_s + ":").strip,
|
161
192
|
"User-Agent" => "Stripe/v1 ActiveMerchantBindings/#{ActiveMerchant::VERSION}",
|
162
|
-
"X-Stripe-Client-User-Agent" => @@ua
|
193
|
+
"X-Stripe-Client-User-Agent" => @@ua,
|
194
|
+
"X-Stripe-Client-User-Metadata" => meta.to_json
|
163
195
|
}
|
164
196
|
end
|
165
197
|
|
166
|
-
def commit(url, parameters,
|
198
|
+
def commit(method, url, parameters=nil, meta={})
|
167
199
|
raw_response = response = nil
|
168
200
|
success = false
|
169
201
|
begin
|
170
|
-
raw_response = ssl_request(method, LIVE_URL + url, post_data(parameters), headers)
|
202
|
+
raw_response = ssl_request(method, LIVE_URL + url, post_data(parameters), headers(meta))
|
171
203
|
response = parse(raw_response)
|
172
204
|
success = !response.key?("error")
|
173
205
|
rescue ResponseError => e
|
@@ -177,7 +209,7 @@ module ActiveMerchant #:nodoc:
|
|
177
209
|
response = json_error(raw_response)
|
178
210
|
end
|
179
211
|
|
180
|
-
card = response["card"] || {}
|
212
|
+
card = response["card"] || response["active_card"] || {}
|
181
213
|
avs_code = AVS_CODE_TRANSLATOR["line1: #{card["address_line1_check"]}, zip: #{card["address_zip_check"]}"]
|
182
214
|
cvc_code = CVC_CODE_TRANSLATOR[card["cvc_check"]]
|
183
215
|
Response.new(success,
|