activemerchant 1.56.0 → 1.66.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +331 -0
- data/README.md +9 -9
- data/lib/active_merchant/billing/check.rb +3 -0
- data/lib/active_merchant/billing/credit_card.rb +8 -3
- data/lib/active_merchant/billing/credit_card_methods.rb +41 -1
- data/lib/active_merchant/billing/gateway.rb +14 -6
- data/lib/active_merchant/billing/gateways/adyen.rb +228 -0
- data/lib/active_merchant/billing/gateways/authorize_net.rb +157 -44
- data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +7 -4
- data/lib/active_merchant/billing/gateways/barclaycard_smartpay.rb +283 -0
- data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +68 -2
- data/lib/active_merchant/billing/gateways/blue_pay.rb +2 -2
- data/lib/active_merchant/billing/gateways/blue_snap.rb +348 -0
- data/lib/active_merchant/billing/gateways/bpoint.rb +1 -1
- data/lib/active_merchant/billing/gateways/braintree_blue.rb +58 -20
- data/lib/active_merchant/billing/gateways/bridge_pay.rb +37 -8
- data/lib/active_merchant/billing/gateways/card_stream.rb +161 -40
- data/lib/active_merchant/billing/gateways/cashnet.rb +1 -0
- data/lib/active_merchant/billing/gateways/checkout_v2.rb +5 -2
- data/lib/active_merchant/billing/gateways/citrus_pay.rb +24 -0
- data/lib/active_merchant/billing/gateways/clearhaus.rb +24 -40
- data/lib/active_merchant/billing/gateways/conekta.rb +6 -1
- data/lib/active_merchant/billing/gateways/creditcall.rb +1 -1
- data/lib/active_merchant/billing/gateways/credorax.rb +310 -0
- data/lib/active_merchant/billing/gateways/culqi.rb +279 -0
- data/lib/active_merchant/billing/gateways/cyber_source.rb +80 -64
- data/lib/active_merchant/billing/gateways/data_cash.rb +10 -304
- data/lib/active_merchant/billing/gateways/digitzs.rb +292 -0
- data/lib/active_merchant/billing/gateways/elavon.rb +40 -26
- data/lib/active_merchant/billing/gateways/element.rb +356 -0
- data/lib/active_merchant/billing/gateways/fat_zebra.rb +16 -2
- data/lib/active_merchant/billing/gateways/firstdata_e4.rb +6 -1
- data/lib/active_merchant/billing/gateways/forte.rb +10 -2
- data/lib/active_merchant/billing/gateways/global_collect.rb +311 -0
- data/lib/active_merchant/billing/gateways/global_transport.rb +1 -0
- data/lib/active_merchant/billing/gateways/iats_payments.rb +13 -0
- data/lib/active_merchant/billing/gateways/in_context_paypal_express.rb +15 -0
- data/lib/active_merchant/billing/gateways/iveri.rb +251 -0
- data/lib/active_merchant/billing/gateways/jetpay.rb +33 -19
- data/lib/active_merchant/billing/gateways/kushki.rb +217 -0
- data/lib/active_merchant/billing/gateways/latitude19.rb +416 -0
- data/lib/active_merchant/billing/gateways/linkpoint.rb +2 -0
- data/lib/active_merchant/billing/gateways/litle.rb +29 -13
- data/lib/active_merchant/billing/gateways/mastercard.rb +268 -0
- data/lib/active_merchant/billing/gateways/maxipago.rb +145 -122
- data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +15 -1
- data/lib/active_merchant/billing/gateways/merchant_warrior.rb +10 -7
- data/lib/active_merchant/billing/gateways/mercury.rb +13 -5
- data/lib/active_merchant/billing/gateways/metrics_global.rb +1 -1
- data/lib/active_merchant/billing/gateways/migs.rb +23 -1
- data/lib/active_merchant/billing/gateways/monei.rb +1 -1
- data/lib/active_merchant/billing/gateways/moneris.rb +21 -1
- data/lib/active_merchant/billing/gateways/nab_transact.rb +12 -0
- data/lib/active_merchant/billing/gateways/ncr_secure_pay.rb +165 -0
- data/lib/active_merchant/billing/gateways/netbanx.rb +245 -0
- data/lib/active_merchant/billing/gateways/nmi.rb +30 -9
- data/lib/active_merchant/billing/gateways/omise.rb +9 -5
- data/lib/active_merchant/billing/gateways/openpay.rb +10 -1
- data/lib/active_merchant/billing/gateways/opp.rb +362 -0
- data/lib/active_merchant/billing/gateways/orbital.rb +28 -7
- data/lib/active_merchant/billing/gateways/pagarme.rb +248 -0
- data/lib/active_merchant/billing/gateways/pay_junction_v2.rb +190 -0
- data/lib/active_merchant/billing/gateways/payeezy.rb +61 -12
- data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +1 -1
- data/lib/active_merchant/billing/gateways/payflow.rb +6 -0
- data/lib/active_merchant/billing/gateways/payment_express.rb +1 -1
- data/lib/active_merchant/billing/gateways/paymill.rb +29 -11
- data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +1 -1
- data/lib/active_merchant/billing/gateways/paypal_express.rb +1 -6
- data/lib/active_merchant/billing/gateways/payu_in.rb +3 -2
- data/lib/active_merchant/billing/gateways/payu_latam.rb +402 -0
- data/lib/active_merchant/billing/gateways/pin.rb +6 -3
- data/lib/active_merchant/billing/gateways/pro_pay.rb +326 -0
- data/lib/active_merchant/billing/gateways/psl_card.rb +3 -3
- data/lib/active_merchant/billing/gateways/quickpay/quickpay_common.rb +1 -1
- data/lib/active_merchant/billing/gateways/quickpay/quickpay_v10.rb +0 -2
- data/lib/active_merchant/billing/gateways/quickpay/quickpay_v4to7.rb +1 -1
- data/lib/active_merchant/billing/gateways/quickpay.rb +3 -3
- data/lib/active_merchant/billing/gateways/qvalent.rb +44 -1
- data/lib/active_merchant/billing/gateways/redsys.rb +3 -0
- data/lib/active_merchant/billing/gateways/s5.rb +8 -5
- data/lib/active_merchant/billing/gateways/safe_charge.rb +220 -0
- data/lib/active_merchant/billing/gateways/sage.rb +397 -128
- data/lib/active_merchant/billing/gateways/sage_pay.rb +45 -20
- data/lib/active_merchant/billing/gateways/secure_net.rb +0 -5
- data/lib/active_merchant/billing/gateways/secure_pay.rb +1 -1
- data/lib/active_merchant/billing/gateways/secure_pay_au.rb +12 -0
- data/lib/active_merchant/billing/gateways/securion_pay.rb +46 -17
- data/lib/active_merchant/billing/gateways/stripe.rb +125 -29
- data/lib/active_merchant/billing/gateways/telr.rb +275 -0
- data/lib/active_merchant/billing/gateways/tns.rb +13 -222
- data/lib/active_merchant/billing/gateways/trans_first.rb +40 -16
- data/lib/active_merchant/billing/gateways/trans_first_transaction_express.rb +606 -0
- data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +114 -9
- data/lib/active_merchant/billing/gateways/vanco.rb +14 -10
- data/lib/active_merchant/billing/gateways/visanet_peru.rb +209 -0
- data/lib/active_merchant/billing/gateways/wepay.rb +73 -38
- data/lib/active_merchant/billing/gateways/wirecard.rb +1 -0
- data/lib/active_merchant/billing/gateways/world_net.rb +344 -0
- data/lib/active_merchant/billing/gateways/worldpay.rb +48 -16
- data/lib/active_merchant/billing/network_tokenization_credit_card.rb +15 -0
- data/lib/active_merchant/country.rb +6 -4
- data/lib/active_merchant/posts_data.rb +1 -1
- data/lib/active_merchant/version.rb +1 -1
- metadata +32 -13
- data/lib/active_merchant/billing/gateways/app55.rb +0 -176
- data/lib/active_merchant/billing/gateways/barclays_epdq.rb +0 -314
- data/lib/active_merchant/billing/gateways/certo_direct.rb +0 -278
- data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +0 -89
- data/lib/active_merchant/billing/gateways/sage/sage_core.rb +0 -115
- data/lib/active_merchant/billing/gateways/sage/sage_vault.rb +0 -149
- data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +0 -97
@@ -0,0 +1,248 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
class PagarmeGateway < Gateway
|
4
|
+
self.live_url = 'https://api.pagar.me/1/'
|
5
|
+
|
6
|
+
self.supported_countries = ['BR']
|
7
|
+
self.default_currency = 'BRL'
|
8
|
+
self.money_format = :cents
|
9
|
+
self.supported_cardtypes = [:visa, :master, :american_express, :discover, :diners_club]
|
10
|
+
|
11
|
+
self.homepage_url = 'https://pagar.me/'
|
12
|
+
self.display_name = 'Pagar.me'
|
13
|
+
|
14
|
+
STANDARD_ERROR_CODE_MAPPING = {
|
15
|
+
'refused' => STANDARD_ERROR_CODE[:card_declined],
|
16
|
+
'processing_error' => STANDARD_ERROR_CODE[:processing_error],
|
17
|
+
}
|
18
|
+
|
19
|
+
def initialize(options={})
|
20
|
+
requires!(options, :api_key)
|
21
|
+
@api_key = options[:api_key]
|
22
|
+
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
26
|
+
def purchase(money, payment_method, options={})
|
27
|
+
post = {}
|
28
|
+
add_amount(post, money)
|
29
|
+
add_payment_method(post, payment_method)
|
30
|
+
add_metadata(post, options)
|
31
|
+
|
32
|
+
commit(:post, 'transactions', post)
|
33
|
+
end
|
34
|
+
|
35
|
+
def authorize(money, payment_method, options={})
|
36
|
+
post = {}
|
37
|
+
add_amount(post, money)
|
38
|
+
add_payment_method(post, payment_method)
|
39
|
+
add_metadata(post, options)
|
40
|
+
|
41
|
+
post[:capture] = false
|
42
|
+
|
43
|
+
commit(:post, 'transactions', post)
|
44
|
+
end
|
45
|
+
|
46
|
+
def capture(money, authorization, options={})
|
47
|
+
if authorization.nil?
|
48
|
+
return Response.new(false, 'Não é possível capturar uma transação sem uma prévia autorização.')
|
49
|
+
end
|
50
|
+
|
51
|
+
post = {}
|
52
|
+
commit(:post, "transactions/#{authorization}/capture", post)
|
53
|
+
end
|
54
|
+
|
55
|
+
def refund(money, authorization, options={})
|
56
|
+
if authorization.nil?
|
57
|
+
return Response.new(false, 'Não é possível estornar uma transação sem uma prévia captura.')
|
58
|
+
end
|
59
|
+
|
60
|
+
void(authorization, options)
|
61
|
+
end
|
62
|
+
|
63
|
+
def void(authorization, options={})
|
64
|
+
if authorization.nil?
|
65
|
+
return Response.new(false, 'Não é possível estornar uma transação autorizada sem uma prévia autorização.')
|
66
|
+
end
|
67
|
+
|
68
|
+
post = {}
|
69
|
+
commit(:post, "transactions/#{authorization}/refund", post)
|
70
|
+
end
|
71
|
+
|
72
|
+
def verify(payment_method, options={})
|
73
|
+
MultiResponse.run(:use_first_response) do |r|
|
74
|
+
r.process { authorize(127, payment_method, options) }
|
75
|
+
r.process(:ignore_result) { void(r.authorization, options) }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def supports_scrubbing?
|
80
|
+
true
|
81
|
+
end
|
82
|
+
|
83
|
+
def scrub(transcript)
|
84
|
+
transcript.
|
85
|
+
gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
|
86
|
+
gsub(%r((card_number=)\d+), '\1[FILTERED]').
|
87
|
+
gsub(%r((card_cvv=)\d+), '\1[FILTERED]')
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def add_amount(post, money)
|
93
|
+
post[:amount] = amount(money)
|
94
|
+
end
|
95
|
+
|
96
|
+
def add_payment_method(post, payment_method)
|
97
|
+
post[:payment_method] = 'credit_card'
|
98
|
+
add_credit_card(post, payment_method)
|
99
|
+
end
|
100
|
+
|
101
|
+
def add_credit_card(post, credit_card)
|
102
|
+
post[:card_number] = credit_card.number
|
103
|
+
post[:card_holder_name] = credit_card.name
|
104
|
+
post[:card_expiration_date] = "#{credit_card.month}/#{credit_card.year}"
|
105
|
+
post[:card_cvv] = credit_card.verification_value
|
106
|
+
end
|
107
|
+
|
108
|
+
def add_metadata(post, options={})
|
109
|
+
post[:metadata] = {}
|
110
|
+
post[:metadata][:order_id] = options[:order_id]
|
111
|
+
post[:metadata][:ip] = options[:ip]
|
112
|
+
post[:metadata][:customer] = options[:customer]
|
113
|
+
post[:metadata][:invoice] = options[:invoice]
|
114
|
+
post[:metadata][:merchant] = options[:merchant]
|
115
|
+
post[:metadata][:description] = options[:description]
|
116
|
+
post[:metadata][:email] = options[:email]
|
117
|
+
end
|
118
|
+
|
119
|
+
def parse(body)
|
120
|
+
JSON.parse(body)
|
121
|
+
end
|
122
|
+
|
123
|
+
def post_data(params)
|
124
|
+
return nil unless params
|
125
|
+
|
126
|
+
params.map do |key, value|
|
127
|
+
next if value != false && value.blank?
|
128
|
+
if value.is_a?(Hash)
|
129
|
+
h = {}
|
130
|
+
value.each do |k, v|
|
131
|
+
h["#{key}[#{k}]"] = v unless v.blank?
|
132
|
+
end
|
133
|
+
post_data(h)
|
134
|
+
elsif value.is_a?(Array)
|
135
|
+
value.map { |v| "#{key}[]=#{CGI.escape(v.to_s)}" }.join("&")
|
136
|
+
else
|
137
|
+
"#{key}=#{CGI.escape(value.to_s)}"
|
138
|
+
end
|
139
|
+
end.compact.join("&")
|
140
|
+
end
|
141
|
+
|
142
|
+
def headers(options = {})
|
143
|
+
{
|
144
|
+
"Authorization" => "Basic " + Base64.encode64(@api_key.to_s + ":x").strip,
|
145
|
+
"User-Agent" => "Pagar.me/1 ActiveMerchant/#{ActiveMerchant::VERSION}",
|
146
|
+
"Accept-Encoding" => "deflate"
|
147
|
+
}
|
148
|
+
end
|
149
|
+
|
150
|
+
def api_request(method, endpoint, parameters = nil, options = {})
|
151
|
+
raw_response = response = nil
|
152
|
+
begin
|
153
|
+
raw_response = ssl_request(method, self.live_url + endpoint, post_data(parameters), headers(options))
|
154
|
+
response = parse(raw_response)
|
155
|
+
rescue ResponseError => e
|
156
|
+
raw_response = e.response.body
|
157
|
+
response = response_error(raw_response)
|
158
|
+
rescue JSON::ParserError
|
159
|
+
response = json_error(raw_response)
|
160
|
+
end
|
161
|
+
response
|
162
|
+
end
|
163
|
+
|
164
|
+
def commit(method, url, parameters, options = {})
|
165
|
+
response = api_request(method, url, parameters, options)
|
166
|
+
|
167
|
+
Response.new(
|
168
|
+
success_from(response),
|
169
|
+
message_from(response),
|
170
|
+
response,
|
171
|
+
authorization: authorization_from(response),
|
172
|
+
test: test?,
|
173
|
+
error_code: error_code_from(response)
|
174
|
+
)
|
175
|
+
end
|
176
|
+
|
177
|
+
def response_error(raw_response)
|
178
|
+
begin
|
179
|
+
parse(raw_response)
|
180
|
+
rescue JSON::ParserError
|
181
|
+
json_error(raw_response)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def json_error(raw_response)
|
186
|
+
msg = 'Resposta inválida retornada pela API do Pagar.me. Por favor entre em contato com suporte@pagar.me se você continuar recebendo essa mensagem.'
|
187
|
+
msg += " (A resposta retornada pela API foi #{raw_response.inspect})"
|
188
|
+
{
|
189
|
+
"errors" => [{
|
190
|
+
"message" => msg
|
191
|
+
}]
|
192
|
+
}
|
193
|
+
end
|
194
|
+
|
195
|
+
def success_from(response)
|
196
|
+
success_purchase = response.key?("status") && response["status"] == "paid"
|
197
|
+
success_authorize = response.key?("status") && response["status"] == "authorized"
|
198
|
+
success_refund = response.key?("status") && response["status"] == "refunded"
|
199
|
+
|
200
|
+
success_purchase || success_authorize || success_refund
|
201
|
+
end
|
202
|
+
|
203
|
+
def failure_from(response)
|
204
|
+
response.key?("status") && response["status"] == "refused"
|
205
|
+
end
|
206
|
+
|
207
|
+
def message_from(response)
|
208
|
+
if success_from(response)
|
209
|
+
case response["status"]
|
210
|
+
when "paid"
|
211
|
+
"Transação aprovada"
|
212
|
+
when "authorized"
|
213
|
+
"Transação autorizada"
|
214
|
+
when "refunded"
|
215
|
+
"Transação estornada"
|
216
|
+
else
|
217
|
+
"Transação com status '#{response["status"]}'"
|
218
|
+
end
|
219
|
+
elsif failure_from(response)
|
220
|
+
"Transação recusada"
|
221
|
+
elsif response.key?("errors")
|
222
|
+
response["errors"][0]["message"]
|
223
|
+
else
|
224
|
+
msg = json_error(response)
|
225
|
+
msg["errors"][0]["message"]
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
def authorization_from(response)
|
230
|
+
if success_from(response)
|
231
|
+
response["id"]
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
def test?()
|
236
|
+
@api_key.start_with?("ak_test")
|
237
|
+
end
|
238
|
+
|
239
|
+
def error_code_from(response)
|
240
|
+
if failure_from(response)
|
241
|
+
STANDARD_ERROR_CODE_MAPPING["refused"]
|
242
|
+
elsif response.key?("errors")
|
243
|
+
STANDARD_ERROR_CODE_MAPPING["processing_error"]
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
@@ -0,0 +1,190 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
class PayJunctionV2Gateway < Gateway
|
4
|
+
self.display_name = "PayJunction"
|
5
|
+
self.homepage_url = "https://www.payjunction.com/"
|
6
|
+
|
7
|
+
self.test_url = "https://api.payjunctionlabs.com/transactions"
|
8
|
+
self.live_url = "https://api.payjunction.com/transactions"
|
9
|
+
|
10
|
+
self.supported_countries = ["US"]
|
11
|
+
self.default_currency = "USD"
|
12
|
+
self.money_format = :dollars
|
13
|
+
self.supported_cardtypes = [:visa, :master, :american_express, :discover]
|
14
|
+
|
15
|
+
def initialize(options={})
|
16
|
+
requires!(options, :api_login, :api_password, :api_key)
|
17
|
+
super
|
18
|
+
end
|
19
|
+
|
20
|
+
def purchase(amount, payment_method, options={})
|
21
|
+
post = {}
|
22
|
+
add_invoice(post, amount, options)
|
23
|
+
add_payment_method(post, payment_method)
|
24
|
+
|
25
|
+
commit("purchase", post)
|
26
|
+
end
|
27
|
+
|
28
|
+
def authorize(amount, payment_method, options={})
|
29
|
+
post = {}
|
30
|
+
post[:status] = "HOLD"
|
31
|
+
add_invoice(post, amount, options)
|
32
|
+
add_payment_method(post, payment_method)
|
33
|
+
|
34
|
+
commit("authorize", post)
|
35
|
+
end
|
36
|
+
|
37
|
+
def capture(amount, authorization, options={})
|
38
|
+
post = {}
|
39
|
+
post[:status] = "CAPTURE"
|
40
|
+
post[:transactionId] = authorization
|
41
|
+
add_invoice(post, amount, options)
|
42
|
+
|
43
|
+
commit("capture", post)
|
44
|
+
end
|
45
|
+
|
46
|
+
def void(authorization, options={})
|
47
|
+
post = {}
|
48
|
+
post[:status] = "VOID"
|
49
|
+
post[:transactionId] = authorization
|
50
|
+
|
51
|
+
commit("void", post)
|
52
|
+
end
|
53
|
+
|
54
|
+
def refund(amount, authorization, options={})
|
55
|
+
post = {}
|
56
|
+
post[:action] = "REFUND"
|
57
|
+
post[:transactionId] = authorization
|
58
|
+
add_invoice(post, amount, options)
|
59
|
+
|
60
|
+
commit("refund", post)
|
61
|
+
end
|
62
|
+
|
63
|
+
def credit(amount, payment_method, options={})
|
64
|
+
post = {}
|
65
|
+
post[:action] = "REFUND"
|
66
|
+
add_invoice(post, amount, options)
|
67
|
+
add_payment_method(post, payment_method)
|
68
|
+
|
69
|
+
commit("credit", post)
|
70
|
+
end
|
71
|
+
|
72
|
+
def verify(credit_card, options={})
|
73
|
+
MultiResponse.run(:use_first_response) do |r|
|
74
|
+
r.process { authorize(100, credit_card, options) }
|
75
|
+
r.process(:ignore_result) { void(r.authorization, options) }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def store(payment_method, options = {})
|
80
|
+
verify(payment_method, options)
|
81
|
+
end
|
82
|
+
|
83
|
+
def supports_scrubbing?
|
84
|
+
true
|
85
|
+
end
|
86
|
+
|
87
|
+
def scrub(transcript)
|
88
|
+
transcript.
|
89
|
+
gsub(%r((Authorization: Basic )\w+), '\1[FILTERED]').
|
90
|
+
gsub(%r((X-Pj-Application-Key: )[\w-]+), '\1[FILTERED]').
|
91
|
+
gsub(%r((cardNumber=)\d+), '\1[FILTERED]').
|
92
|
+
gsub(%r((cardCvv=)\d+), '\1[FILTERED]')
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
96
|
+
|
97
|
+
def add_invoice(post, money, options)
|
98
|
+
post[:amountBase] = amount(money) if money
|
99
|
+
post[:invoiceNumber] = options[:order_id] if options[:order_id]
|
100
|
+
end
|
101
|
+
|
102
|
+
def add_payment_method(post, payment_method)
|
103
|
+
if payment_method.is_a? Integer
|
104
|
+
post[:transactionId] = payment_method
|
105
|
+
else
|
106
|
+
post[:cardNumber] = payment_method.number
|
107
|
+
post[:cardExpMonth] = format(payment_method.month, :two_digits)
|
108
|
+
post[:cardExpYear] = format(payment_method.year, :four_digits)
|
109
|
+
post[:cardCvv] = payment_method.verification_value
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def commit(action, params)
|
114
|
+
response = begin
|
115
|
+
parse(ssl_invoke(action, params))
|
116
|
+
rescue ResponseError => e
|
117
|
+
parse(e.response.body)
|
118
|
+
end
|
119
|
+
|
120
|
+
success = success_from(response)
|
121
|
+
Response.new(
|
122
|
+
success,
|
123
|
+
message_from(response),
|
124
|
+
response,
|
125
|
+
authorization: success ? authorization_from(response) : nil,
|
126
|
+
error_code: success ? nil : error_from(response),
|
127
|
+
test: test?
|
128
|
+
)
|
129
|
+
end
|
130
|
+
|
131
|
+
def ssl_invoke(action, params)
|
132
|
+
if ["purchase", "authorize", "refund", "credit"].include?(action)
|
133
|
+
ssl_post(url(), post_data(params), headers)
|
134
|
+
else
|
135
|
+
ssl_request(:put, url(params), post_data(params), headers)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
def headers
|
140
|
+
{
|
141
|
+
"Authorization" => "Basic " + Base64.encode64("#{@options[:api_login]}:#{@options[:api_password]}").strip,
|
142
|
+
"Content-Type" => "application/x-www-form-urlencoded;charset=UTF-8",
|
143
|
+
"Accept" => "application/json",
|
144
|
+
"X-PJ-Application-Key" => "#{@options[:api_key]}"
|
145
|
+
}
|
146
|
+
end
|
147
|
+
|
148
|
+
def post_data(params)
|
149
|
+
params.map {|k, v| "#{k}=#{CGI.escape(v.to_s)}"}.join('&')
|
150
|
+
end
|
151
|
+
|
152
|
+
def url(params={})
|
153
|
+
test? ? "#{test_url}/#{params[:transactionId]}" : "#{live_url}/#{params[:transactionId]}"
|
154
|
+
end
|
155
|
+
|
156
|
+
def parse(body)
|
157
|
+
begin
|
158
|
+
JSON.parse(body)
|
159
|
+
rescue JSON::ParserError
|
160
|
+
message = "Invalid JSON response received from PayJunctionV2Gateway. Please contact PayJunctionV2Gateway if you continue to receive this message."
|
161
|
+
message += " (The raw response returned by the API was #{body.inspect})"
|
162
|
+
{
|
163
|
+
"errors" => [{
|
164
|
+
"message" => message
|
165
|
+
}]
|
166
|
+
}
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def success_from(response)
|
171
|
+
return response["response"]["approved"] if response["response"]
|
172
|
+
false
|
173
|
+
end
|
174
|
+
|
175
|
+
def message_from(response)
|
176
|
+
return response["response"]["message"] if response["response"]
|
177
|
+
|
178
|
+
response["errors"].inject(""){ |message,error| error["message"] + "|" + message } if response["errors"]
|
179
|
+
end
|
180
|
+
|
181
|
+
def authorization_from(response)
|
182
|
+
response["transactionId"]
|
183
|
+
end
|
184
|
+
|
185
|
+
def error_from(response)
|
186
|
+
response["response"]["code"] if response["response"]
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
@@ -30,24 +30,26 @@ module ActiveMerchant
|
|
30
30
|
super
|
31
31
|
end
|
32
32
|
|
33
|
-
def purchase(amount,
|
33
|
+
def purchase(amount, payment_method, options = {})
|
34
34
|
params = {transaction_type: 'purchase'}
|
35
35
|
|
36
36
|
add_invoice(params, options)
|
37
|
-
|
37
|
+
add_payment_method(params, payment_method)
|
38
38
|
add_address(params, options)
|
39
39
|
add_amount(params, amount, options)
|
40
|
+
add_soft_descriptors(params, options)
|
40
41
|
|
41
42
|
commit(params, options)
|
42
43
|
end
|
43
44
|
|
44
|
-
def authorize(amount,
|
45
|
+
def authorize(amount, payment_method, options = {})
|
45
46
|
params = {transaction_type: 'authorize'}
|
46
47
|
|
47
48
|
add_invoice(params, options)
|
48
|
-
|
49
|
+
add_payment_method(params, payment_method)
|
49
50
|
add_address(params, options)
|
50
51
|
add_amount(params, amount, options)
|
52
|
+
add_soft_descriptors(params, options)
|
51
53
|
|
52
54
|
commit(params, options)
|
53
55
|
end
|
@@ -57,6 +59,7 @@ module ActiveMerchant
|
|
57
59
|
|
58
60
|
add_authorization_info(params, authorization)
|
59
61
|
add_amount(params, amount, options)
|
62
|
+
add_soft_descriptors(params, options)
|
60
63
|
|
61
64
|
commit(params, options)
|
62
65
|
end
|
@@ -71,7 +74,7 @@ module ActiveMerchant
|
|
71
74
|
end
|
72
75
|
|
73
76
|
def void(authorization, options = {})
|
74
|
-
params = {transaction_type: '
|
77
|
+
params = {transaction_type: 'void'}
|
75
78
|
|
76
79
|
add_authorization_info(params, authorization)
|
77
80
|
add_amount(params, amount_from_authorization(authorization), options)
|
@@ -79,6 +82,26 @@ module ActiveMerchant
|
|
79
82
|
commit(params, options)
|
80
83
|
end
|
81
84
|
|
85
|
+
def verify(credit_card, options={})
|
86
|
+
MultiResponse.run(:use_first_response) do |r|
|
87
|
+
r.process { authorize(100, credit_card, options) }
|
88
|
+
r.process(:ignore_result) { void(r.authorization, options) }
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def supports_scrubbing?
|
93
|
+
true
|
94
|
+
end
|
95
|
+
|
96
|
+
def scrub(transcript)
|
97
|
+
transcript.
|
98
|
+
gsub(%r((Token: )(\w|-)+), '\1[FILTERED]').
|
99
|
+
gsub(%r((\\?"card_number\\?":\\?")\d+), '\1[FILTERED]').
|
100
|
+
gsub(%r((\\?"cvv\\?":\\?")\d+), '\1[FILTERED]').
|
101
|
+
gsub(%r((\\?"account_number\\?":\\?")\d+), '\1[FILTERED]').
|
102
|
+
gsub(%r((\\?"routing_number\\?":\\?")\d+), '\1[FILTERED]')
|
103
|
+
end
|
104
|
+
|
82
105
|
private
|
83
106
|
|
84
107
|
def add_invoice(params, options)
|
@@ -96,6 +119,14 @@ module ActiveMerchant
|
|
96
119
|
params[:method] = method
|
97
120
|
end
|
98
121
|
|
122
|
+
def add_payment_method(params, payment_method)
|
123
|
+
if payment_method.is_a? Check
|
124
|
+
add_echeck(params, payment_method)
|
125
|
+
else
|
126
|
+
add_creditcard(params, payment_method)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
99
130
|
def add_creditcard(params, creditcard)
|
100
131
|
credit_card = {}
|
101
132
|
|
@@ -109,6 +140,19 @@ module ActiveMerchant
|
|
109
140
|
params[:credit_card] = credit_card
|
110
141
|
end
|
111
142
|
|
143
|
+
def add_echeck(params, echeck)
|
144
|
+
tele_check = {}
|
145
|
+
|
146
|
+
tele_check[:check_number] = echeck.number
|
147
|
+
tele_check[:check_type] = "P"
|
148
|
+
tele_check[:routing_number] = echeck.routing_number
|
149
|
+
tele_check[:account_number] = echeck.account_number
|
150
|
+
tele_check[:accountholder_name] = "#{echeck.first_name} #{echeck.last_name}"
|
151
|
+
|
152
|
+
params[:method] = 'tele_check'
|
153
|
+
params[:tele_check] = tele_check
|
154
|
+
end
|
155
|
+
|
112
156
|
def add_address(params, options)
|
113
157
|
address = options[:billing_address]
|
114
158
|
return unless address
|
@@ -128,6 +172,10 @@ module ActiveMerchant
|
|
128
172
|
params[:amount] = amount(money)
|
129
173
|
end
|
130
174
|
|
175
|
+
def add_soft_descriptors(params, options)
|
176
|
+
params[:soft_descriptors] = options[:soft_descriptors] if options[:soft_descriptors]
|
177
|
+
end
|
178
|
+
|
131
179
|
def commit(params, options)
|
132
180
|
url = if options[:integration]
|
133
181
|
integration_url
|
@@ -141,12 +189,9 @@ module ActiveMerchant
|
|
141
189
|
url = "#{url}/#{transaction_id}"
|
142
190
|
end
|
143
191
|
|
144
|
-
success = false
|
145
192
|
begin
|
146
193
|
body = params.to_json
|
147
|
-
|
148
|
-
response = parse(raw_response)
|
149
|
-
success = (response['transaction_status'] == 'approved')
|
194
|
+
response = parse(ssl_post(url, body, headers(body)))
|
150
195
|
rescue ResponseError => e
|
151
196
|
response = response_error(e.response.body)
|
152
197
|
rescue JSON::ParserError
|
@@ -154,17 +199,21 @@ module ActiveMerchant
|
|
154
199
|
end
|
155
200
|
|
156
201
|
Response.new(
|
157
|
-
|
158
|
-
handle_message(response,
|
202
|
+
success_from(response),
|
203
|
+
handle_message(response, success_from(response)),
|
159
204
|
response,
|
160
205
|
test: test?,
|
161
206
|
authorization: authorization_from(params, response),
|
162
207
|
avs_result: {code: response['avs']},
|
163
208
|
cvv_result: response['cvv2'],
|
164
|
-
error_code: error_code(response,
|
209
|
+
error_code: error_code(response, success_from(response))
|
165
210
|
)
|
166
211
|
end
|
167
212
|
|
213
|
+
def success_from(response)
|
214
|
+
response['transaction_status'] == 'approved'
|
215
|
+
end
|
216
|
+
|
168
217
|
def authorization_from(params, response)
|
169
218
|
[
|
170
219
|
response['transaction_id'],
|
@@ -10,7 +10,7 @@ module ActiveMerchant #:nodoc:
|
|
10
10
|
# Set the default partner to PayPal
|
11
11
|
base.partner = 'PayPal'
|
12
12
|
|
13
|
-
base.supported_countries = ['US', 'CA', '
|
13
|
+
base.supported_countries = ['US', 'CA', 'NZ', 'AU']
|
14
14
|
|
15
15
|
base.class_attribute :timeout
|
16
16
|
base.timeout = 60
|
@@ -48,6 +48,11 @@ module ActiveMerchant #:nodoc:
|
|
48
48
|
authorize(0, payment, options)
|
49
49
|
end
|
50
50
|
|
51
|
+
def verify_credentials
|
52
|
+
response = void("0")
|
53
|
+
response.params["result"] != "26"
|
54
|
+
end
|
55
|
+
|
51
56
|
# Adds or modifies a recurring Payflow profile. See the Payflow Pro Recurring Billing Guide for more details:
|
52
57
|
# https://www.paypal.com/en_US/pdf/PayflowPro_RecurringBilling_Guide.pdf
|
53
58
|
#
|
@@ -88,6 +93,7 @@ module ActiveMerchant #:nodoc:
|
|
88
93
|
@express ||= PayflowExpressGateway.new(@options)
|
89
94
|
end
|
90
95
|
|
96
|
+
|
91
97
|
private
|
92
98
|
def build_sale_or_authorization_request(action, money, funding_source, options)
|
93
99
|
if funding_source.is_a?(String)
|
@@ -16,7 +16,7 @@ module ActiveMerchant #:nodoc:
|
|
16
16
|
# However, regular accounts with DPS only support VISA and Mastercard
|
17
17
|
self.supported_cardtypes = [ :visa, :master, :american_express, :diners_club, :jcb ]
|
18
18
|
|
19
|
-
self.supported_countries = %w[ AU
|
19
|
+
self.supported_countries = %w[ AU FJ GB HK IE MY NZ PG SG US ]
|
20
20
|
|
21
21
|
self.homepage_url = 'http://www.paymentexpress.com/'
|
22
22
|
self.display_name = 'PaymentExpress'
|