maedana-activemerchant 1.9.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +571 -0
- data/CONTRIBUTORS +170 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +150 -0
- data/gem-public_cert.pem +20 -0
- data/lib/active_merchant.rb +49 -0
- data/lib/active_merchant/billing.rb +9 -0
- data/lib/active_merchant/billing/avs_result.rb +98 -0
- data/lib/active_merchant/billing/base.rb +57 -0
- data/lib/active_merchant/billing/check.rb +68 -0
- data/lib/active_merchant/billing/credit_card.rb +161 -0
- data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
- data/lib/active_merchant/billing/credit_card_methods.rb +125 -0
- data/lib/active_merchant/billing/cvv_result.rb +38 -0
- data/lib/active_merchant/billing/expiry_date.rb +34 -0
- data/lib/active_merchant/billing/gateway.rb +169 -0
- data/lib/active_merchant/billing/gateways.rb +18 -0
- data/lib/active_merchant/billing/gateways/authorize_net.rb +654 -0
- data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +736 -0
- data/lib/active_merchant/billing/gateways/beanstream.rb +102 -0
- data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +244 -0
- data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
- data/lib/active_merchant/billing/gateways/bogus.rb +102 -0
- data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
- data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
- data/lib/active_merchant/billing/gateways/braintree_blue.rb +210 -0
- data/lib/active_merchant/billing/gateways/braintree_orange.rb +17 -0
- data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
- data/lib/active_merchant/billing/gateways/cyber_source.rb +406 -0
- data/lib/active_merchant/billing/gateways/data_cash.rb +593 -0
- data/lib/active_merchant/billing/gateways/efsnet.rb +229 -0
- data/lib/active_merchant/billing/gateways/elavon.rb +134 -0
- data/lib/active_merchant/billing/gateways/eway.rb +277 -0
- data/lib/active_merchant/billing/gateways/exact.rb +222 -0
- data/lib/active_merchant/billing/gateways/first_pay.rb +172 -0
- data/lib/active_merchant/billing/gateways/garanti.rb +222 -0
- data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
- data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
- data/lib/active_merchant/billing/gateways/iridium.rb +253 -0
- data/lib/active_merchant/billing/gateways/jetpay.rb +270 -0
- data/lib/active_merchant/billing/gateways/linkpoint.rb +449 -0
- data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +154 -0
- data/lib/active_merchant/billing/gateways/merchant_ware.rb +283 -0
- data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
- data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
- data/lib/active_merchant/billing/gateways/moneris.rb +205 -0
- data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
- data/lib/active_merchant/billing/gateways/netaxept.rb +234 -0
- data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
- data/lib/active_merchant/billing/gateways/ogone.rb +279 -0
- data/lib/active_merchant/billing/gateways/pay_junction.rb +392 -0
- data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
- data/lib/active_merchant/billing/gateways/paybox_direct.rb +203 -0
- data/lib/active_merchant/billing/gateways/payflow.rb +236 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +207 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
- data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
- data/lib/active_merchant/billing/gateways/payflow_express.rb +138 -0
- data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
- data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
- data/lib/active_merchant/billing/gateways/payment_express.rb +230 -0
- data/lib/active_merchant/billing/gateways/paypal.rb +121 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +326 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +38 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_payment_details_response.rb +70 -0
- data/lib/active_merchant/billing/gateways/paypal_adaptive_payments.rb +298 -0
- data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
- data/lib/active_merchant/billing/gateways/paypal_express.rb +145 -0
- data/lib/active_merchant/billing/gateways/paypal_express_common.rb +20 -0
- data/lib/active_merchant/billing/gateways/paypal_express_recurring.rb +310 -0
- data/lib/active_merchant/billing/gateways/plugnpay.rb +292 -0
- data/lib/active_merchant/billing/gateways/psigate.rb +214 -0
- data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
- data/lib/active_merchant/billing/gateways/quickpay.rb +213 -0
- data/lib/active_merchant/billing/gateways/realex.rb +200 -0
- data/lib/active_merchant/billing/gateways/sage.rb +146 -0
- data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
- data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
- data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
- data/lib/active_merchant/billing/gateways/sage_pay.rb +315 -0
- data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
- data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
- data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
- data/lib/active_merchant/billing/gateways/secure_pay_au.rb +157 -0
- data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
- data/lib/active_merchant/billing/gateways/skip_jack.rb +453 -0
- data/lib/active_merchant/billing/gateways/smart_ps.rb +265 -0
- data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
- data/lib/active_merchant/billing/gateways/transax.rb +25 -0
- data/lib/active_merchant/billing/gateways/trust_commerce.rb +418 -0
- data/lib/active_merchant/billing/gateways/usa_epay.rb +194 -0
- data/lib/active_merchant/billing/gateways/verifi.rb +228 -0
- data/lib/active_merchant/billing/gateways/viaklix.rb +189 -0
- data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
- data/lib/active_merchant/billing/integrations.rb +17 -0
- data/lib/active_merchant/billing/integrations/action_view_helper.rb +68 -0
- data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
- data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
- data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
- data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
- data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
- data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
- data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
- data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +188 -0
- data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
- data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
- data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
- data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
- data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
- data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
- data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
- data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/helper.rb +96 -0
- data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
- data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
- data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
- data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
- data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
- data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
- data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
- data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/notification.rb +62 -0
- data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
- data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
- data/lib/active_merchant/billing/integrations/paypal/notification.rb +154 -0
- data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
- data/lib/active_merchant/billing/integrations/quickpay.rb +17 -0
- data/lib/active_merchant/billing/integrations/quickpay/helper.rb +72 -0
- data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
- data/lib/active_merchant/billing/integrations/return.rb +37 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +109 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +204 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +27 -0
- data/lib/active_merchant/billing/integrations/two_checkout.rb +23 -0
- data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +59 -0
- data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +114 -0
- data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
- data/lib/active_merchant/billing/response.rb +32 -0
- data/lib/active_merchant/common.rb +14 -0
- data/lib/active_merchant/common/connection.rb +172 -0
- data/lib/active_merchant/common/country.rb +328 -0
- data/lib/active_merchant/common/error.rb +26 -0
- data/lib/active_merchant/common/post_data.rb +24 -0
- data/lib/active_merchant/common/posts_data.rb +47 -0
- data/lib/active_merchant/common/requires_parameters.rb +16 -0
- data/lib/active_merchant/common/utils.rb +18 -0
- data/lib/active_merchant/common/validateable.rb +76 -0
- data/lib/active_merchant/version.rb +3 -0
- data/lib/certs/cacert.pem +7815 -0
- data/lib/maedana-activemerchant.rb +1 -0
- data/lib/support/gateway_support.rb +58 -0
- data/lib/support/outbound_hosts.rb +25 -0
- metadata +270 -0
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module ActiveMerchant #:nodoc:
|
4
|
+
module Billing #:nodoc:
|
5
|
+
module Integrations #:nodoc:
|
6
|
+
module Quickpay
|
7
|
+
class Notification < ActiveMerchant::Billing::Integrations::Notification
|
8
|
+
def complete?
|
9
|
+
status == '000'
|
10
|
+
end
|
11
|
+
|
12
|
+
def item_id
|
13
|
+
params['ordernumber']
|
14
|
+
end
|
15
|
+
|
16
|
+
def transaction_id
|
17
|
+
params['transaction']
|
18
|
+
end
|
19
|
+
|
20
|
+
def received_at
|
21
|
+
Time.parse("20#{params['time']}")
|
22
|
+
end
|
23
|
+
|
24
|
+
def gross
|
25
|
+
"%.2f" % (gross_cents / 100.0)
|
26
|
+
end
|
27
|
+
|
28
|
+
def gross_cents
|
29
|
+
params['amount'].to_i
|
30
|
+
end
|
31
|
+
|
32
|
+
def test?
|
33
|
+
params['testmode'] == 'Yes'
|
34
|
+
end
|
35
|
+
|
36
|
+
def status
|
37
|
+
params['qpstat']
|
38
|
+
end
|
39
|
+
|
40
|
+
def currency
|
41
|
+
params['currency']
|
42
|
+
end
|
43
|
+
|
44
|
+
# Provide access to raw fields from quickpay
|
45
|
+
%w(msgtype ordernumber state chstat chstatmsg qpstat qpstatmsg merchant merchantemail cardtype cardnumber).each do |attr|
|
46
|
+
define_method(attr) do
|
47
|
+
params[attr]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
MD5_CHECK_FIELDS = [
|
52
|
+
:msgtype, :ordernumber, :amount, :currency, :time, :state,
|
53
|
+
:chstat, :chstatmsg, :qpstat, :qpstatmsg, :merchant, :merchantemail,
|
54
|
+
:transaction, :cardtype, :cardnumber, :testmode
|
55
|
+
]
|
56
|
+
|
57
|
+
def generate_md5string
|
58
|
+
MD5_CHECK_FIELDS.map { |key| params[key.to_s] } * "" + @options[:md5secret]
|
59
|
+
end
|
60
|
+
|
61
|
+
def generate_md5check
|
62
|
+
Digest::MD5.hexdigest(generate_md5string)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Quickpay doesn't do acknowledgements of callback notifications
|
66
|
+
# Instead it uses and MD5 hash of all parameters
|
67
|
+
def acknowledge
|
68
|
+
generate_md5check == params['md5check']
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
module Integrations #:nodoc:
|
4
|
+
class Return
|
5
|
+
attr_accessor :params
|
6
|
+
attr_reader :notification
|
7
|
+
|
8
|
+
def initialize(query_string, options = {})
|
9
|
+
@params = parse(query_string)
|
10
|
+
@options = options
|
11
|
+
end
|
12
|
+
|
13
|
+
# Successful by default. Overridden in the child class
|
14
|
+
def success?
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
18
|
+
def message
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
def parse(query_string)
|
23
|
+
return {} if query_string.blank?
|
24
|
+
|
25
|
+
query_string.split('&').inject({}) do |memo, chunk|
|
26
|
+
next if chunk.empty?
|
27
|
+
key, value = chunk.split('=', 2)
|
28
|
+
next if key.empty?
|
29
|
+
value = value.nil? ? nil : CGI.unescape(value)
|
30
|
+
memo[CGI.unescape(key)] = value
|
31
|
+
memo
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
module Integrations #:nodoc:
|
4
|
+
module SagePayForm
|
5
|
+
autoload :Helper, File.dirname(__FILE__) + '/sage_pay_form/helper.rb'
|
6
|
+
autoload :Return, File.dirname(__FILE__) + '/sage_pay_form/return.rb'
|
7
|
+
autoload :Notification, File.dirname(__FILE__) + '/sage_pay_form/notification.rb'
|
8
|
+
autoload :Encryption, File.dirname(__FILE__) + '/sage_pay_form/encryption.rb'
|
9
|
+
|
10
|
+
mattr_accessor :production_url
|
11
|
+
mattr_accessor :test_url
|
12
|
+
mattr_accessor :simulate_url
|
13
|
+
self.production_url = 'https://live.sagepay.com/gateway/service/vspform-register.vsp'
|
14
|
+
self.test_url = 'https://test.sagepay.com/gateway/service/vspform-register.vsp'
|
15
|
+
self.simulate_url = 'https://test.sagepay.com/Simulator/VSPFormGateway.asp'
|
16
|
+
|
17
|
+
def self.return(query_string, options = {})
|
18
|
+
Return.new(query_string, options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.service_url
|
22
|
+
mode = ActiveMerchant::Billing::Base.integration_mode
|
23
|
+
case mode
|
24
|
+
when :production
|
25
|
+
self.production_url
|
26
|
+
when :test
|
27
|
+
self.test_url
|
28
|
+
when :simulate
|
29
|
+
self.simulate_url
|
30
|
+
else
|
31
|
+
raise StandardError, "Integration mode set to an invalid value: #{mode}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
module Integrations #:nodoc:
|
4
|
+
module SagePayForm
|
5
|
+
module Encryption
|
6
|
+
def sage_encrypt(plaintext, key)
|
7
|
+
ActiveSupport::Base64.encode64s(sage_encrypt_xor(plaintext, key))
|
8
|
+
end
|
9
|
+
|
10
|
+
def sage_decrypt(ciphertext, key)
|
11
|
+
sage_encrypt_xor(ActiveSupport::Base64.decode64(ciphertext), key)
|
12
|
+
end
|
13
|
+
|
14
|
+
def sage_encrypt_salt(min, max)
|
15
|
+
length = rand(max - min + 1) + min
|
16
|
+
SecureRandom.base64(length + 4)[0, length]
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def sage_encrypt_xor(data, key)
|
22
|
+
raise 'No key provided' if key.blank?
|
23
|
+
|
24
|
+
key *= (data.length.to_f / key.length.to_f).ceil
|
25
|
+
key = key[0, data.length]
|
26
|
+
|
27
|
+
data.bytes.zip(key.bytes).map { |b1, b2| (b1 ^ b2).chr }.join
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module ActiveMerchant #:nodoc:
|
4
|
+
module Billing #:nodoc:
|
5
|
+
module Integrations #:nodoc:
|
6
|
+
module SagePayForm
|
7
|
+
class Helper < ActiveMerchant::Billing::Integrations::Helper
|
8
|
+
include Encryption
|
9
|
+
|
10
|
+
mapping :credential2, 'EncryptKey'
|
11
|
+
|
12
|
+
mapping :account, 'Vendor'
|
13
|
+
mapping :amount, 'Amount'
|
14
|
+
mapping :currency, 'Currency'
|
15
|
+
|
16
|
+
mapping :order, 'VendorTxCode'
|
17
|
+
|
18
|
+
mapping :customer,
|
19
|
+
:first_name => 'BillingFirstnames',
|
20
|
+
:last_name => 'BillingSurname',
|
21
|
+
:email => 'CustomerEMail',
|
22
|
+
:phone => 'BillingPhone'
|
23
|
+
|
24
|
+
mapping :billing_address,
|
25
|
+
:city => 'BillingCity',
|
26
|
+
:address1 => 'BillingAddress1',
|
27
|
+
:address2 => 'BillingAddress2',
|
28
|
+
:state => 'BillingState',
|
29
|
+
:zip => 'BillingPostCode',
|
30
|
+
:country => 'BillingCountry'
|
31
|
+
|
32
|
+
mapping :shipping_address,
|
33
|
+
:city => 'DeliveryCity',
|
34
|
+
:address1 => 'DeliveryAddress1',
|
35
|
+
:address2 => 'DeliveryAddress2',
|
36
|
+
:state => 'DeliveryState',
|
37
|
+
:zip => 'DeliveryPostCode',
|
38
|
+
:country => 'DeliveryCountry'
|
39
|
+
|
40
|
+
mapping :return_url, 'SuccessURL'
|
41
|
+
mapping :description, 'Description'
|
42
|
+
|
43
|
+
def form_fields
|
44
|
+
fields['DeliveryFirstnames'] ||= fields['BillingFirstnames']
|
45
|
+
fields['DeliverySurname'] ||= fields['BillingSurname']
|
46
|
+
|
47
|
+
fields['FailureURL'] ||= fields['SuccessURL']
|
48
|
+
|
49
|
+
crypt_skip = ['Vendor', 'EncryptKey']
|
50
|
+
crypt_skip << 'BillingState' unless fields['BillingCountry'] == 'US'
|
51
|
+
crypt_skip << 'DeliveryState' unless fields['DeliveryCountry'] == 'US'
|
52
|
+
|
53
|
+
key = fields['EncryptKey']
|
54
|
+
@crypt ||= create_crypt_field(fields.except(*crypt_skip), key)
|
55
|
+
|
56
|
+
{
|
57
|
+
'VPSProtocol' => '2.23',
|
58
|
+
'TxType' => 'PAYMENT',
|
59
|
+
'Vendor' => @fields['Vendor'],
|
60
|
+
'Crypt' => @crypt
|
61
|
+
}
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def create_crypt_field(fields, key)
|
67
|
+
parts = fields.map { |k, v| "#{k}=#{sanitize(k, v)}" unless v.nil? }.compact.shuffle
|
68
|
+
parts.unshift(sage_encrypt_salt(key.length, key.length * 2))
|
69
|
+
sage_encrypt(parts.join('&'), key)
|
70
|
+
end
|
71
|
+
|
72
|
+
def sanitize(key, value)
|
73
|
+
reject = exact = nil
|
74
|
+
|
75
|
+
case key
|
76
|
+
when /URL$/
|
77
|
+
# allow all
|
78
|
+
when 'VendorTxCode'
|
79
|
+
reject = /[^A-Za-z0-9{}._-]+/
|
80
|
+
when /[Nn]ames?$/
|
81
|
+
reject = %r{[^[:alpha:] /\\.'-]+}
|
82
|
+
when /(?:Address[12]|City)$/
|
83
|
+
reject = %r{[^[:alnum:] +'/\\:,.\n()-]+}
|
84
|
+
when /PostCode$/
|
85
|
+
reject = /[^A-Za-z0-9 -]+/
|
86
|
+
when /Phone$/
|
87
|
+
reject = /[^0-9A-Za-z+ ()-]+/
|
88
|
+
when 'Currency'
|
89
|
+
exact = /^[A-Z]{3}$/
|
90
|
+
when /State$/
|
91
|
+
exact = /^[A-Z]{2}$/
|
92
|
+
else
|
93
|
+
reject = /&+/
|
94
|
+
end
|
95
|
+
|
96
|
+
if exact
|
97
|
+
raise ArgumentError, "Invalid value for #{key}: #{value.inspect}" unless value =~ exact
|
98
|
+
value
|
99
|
+
elsif reject
|
100
|
+
value.gsub(reject, ' ')
|
101
|
+
else
|
102
|
+
value
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,204 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module ActiveMerchant #:nodoc:
|
4
|
+
module Billing #:nodoc:
|
5
|
+
module Integrations #:nodoc:
|
6
|
+
module SagePayForm
|
7
|
+
class Notification < ActiveMerchant::Billing::Integrations::Notification
|
8
|
+
class CryptError < StandardError; end
|
9
|
+
|
10
|
+
include Encryption
|
11
|
+
|
12
|
+
def initialize(post_data, options)
|
13
|
+
super
|
14
|
+
load_crypt_params(params['crypt'], options[:credential2])
|
15
|
+
end
|
16
|
+
|
17
|
+
# Was the transaction complete?
|
18
|
+
def complete?
|
19
|
+
status_code == 'OK'
|
20
|
+
end
|
21
|
+
|
22
|
+
# Text version of #complete?, since we don't support Pending.
|
23
|
+
def status
|
24
|
+
complete? ? 'Completed' : 'Failed'
|
25
|
+
end
|
26
|
+
|
27
|
+
# Status of transaction. List of possible values:
|
28
|
+
# <tt>OK</tt>:: Transaction completed successfully.
|
29
|
+
# <tt>NOTAUTHED</tt>:: Incorrect card details / insufficient funds.
|
30
|
+
# <tt>MALFORMED</tt>:: Invalid input data.
|
31
|
+
# <tt>INVALID</tt>:: Valid input data, but some fields are incorrect.
|
32
|
+
# <tt>ABORT</tt>:: User hit cancel button or went idle for 15+ minutes.
|
33
|
+
# <tt>REJECTED</tt>:: Rejected by account fraud screening rules.
|
34
|
+
# <tt>AUTHENTICATED</tt>:: Authenticated card details secured at SagePay.
|
35
|
+
# <tt>REGISTERED</tt>:: Non-authenticated card details secured at SagePay.
|
36
|
+
# <tt>ERROR</tt>:: Problem internal to SagePay.
|
37
|
+
def status_code
|
38
|
+
params['Status']
|
39
|
+
end
|
40
|
+
|
41
|
+
# Check this if #completed? is false.
|
42
|
+
def message
|
43
|
+
params['StatusDetail']
|
44
|
+
end
|
45
|
+
|
46
|
+
# Vendor-supplied code (:order mapping).
|
47
|
+
def item_id
|
48
|
+
params['VendorTxCode']
|
49
|
+
end
|
50
|
+
|
51
|
+
# Internal SagePay code, typically "{LONG-UUID}".
|
52
|
+
def transaction_id
|
53
|
+
params['VPSTxId']
|
54
|
+
end
|
55
|
+
|
56
|
+
# Authorization number (only if #completed?).
|
57
|
+
def auth_id
|
58
|
+
params['TxAuthNo']
|
59
|
+
end
|
60
|
+
|
61
|
+
# Total amount (no fees).
|
62
|
+
def gross
|
63
|
+
params['Amount']
|
64
|
+
end
|
65
|
+
|
66
|
+
# AVS and CV2 check results. Possible values:
|
67
|
+
# <tt>ALL MATCH</tt>::
|
68
|
+
# <tt>SECURITY CODE MATCH ONLY</tt>::
|
69
|
+
# <tt>ADDRESS MATCH ONLY</tt>::
|
70
|
+
# <tt>NO DATA MATCHES</tt>::
|
71
|
+
# <tt>DATA NOT CHECKED</tt>::
|
72
|
+
def avs_cv2_result
|
73
|
+
params['AVSCV2']
|
74
|
+
end
|
75
|
+
|
76
|
+
# Numeric address check. Possible values:
|
77
|
+
# <tt>NOTPROVIDED</tt>::
|
78
|
+
# <tt>NOTCHECKED</tt>::
|
79
|
+
# <tt>MATCHED</tt>::
|
80
|
+
# <tt>NOTMATCHED</tt>::
|
81
|
+
def address_result
|
82
|
+
params['AddressResult']
|
83
|
+
end
|
84
|
+
|
85
|
+
# Post code check. Possible values:
|
86
|
+
# <tt>NOTPROVIDED</tt>::
|
87
|
+
# <tt>NOTCHECKED</tt>::
|
88
|
+
# <tt>MATCHED</tt>::
|
89
|
+
# <tt>NOTMATCHED</tt>::
|
90
|
+
def post_code_result
|
91
|
+
params['PostCodeResult']
|
92
|
+
end
|
93
|
+
|
94
|
+
# CV2 code check. Possible values:
|
95
|
+
# <tt>NOTPROVIDED</tt>::
|
96
|
+
# <tt>NOTCHECKED</tt>::
|
97
|
+
# <tt>MATCHED</tt>::
|
98
|
+
# <tt>NOTMATCHED</tt>::
|
99
|
+
def cv2_result
|
100
|
+
params['CV2Result']
|
101
|
+
end
|
102
|
+
|
103
|
+
# Was the Gift Aid box checked?
|
104
|
+
def gift_aid?
|
105
|
+
params['GiftAid'] == '1'
|
106
|
+
end
|
107
|
+
|
108
|
+
# Result of 3D Secure checks. Possible values:
|
109
|
+
# <tt>OK</tt>:: Authenticated correctly.
|
110
|
+
# <tt>NOTCHECKED</tt>:: Authentication not performed.
|
111
|
+
# <tt>NOTAVAILABLE</tt>:: Card not auth-capable, or auth is otherwise impossible.
|
112
|
+
# <tt>NOTAUTHED</tt>:: User failed authentication.
|
113
|
+
# <tt>INCOMPLETE</tt>:: Authentication unable to complete.
|
114
|
+
# <tt>ERROR</tt>:: Unable to attempt authentication due to data / service errors.
|
115
|
+
def buyer_auth_result
|
116
|
+
params['3DSecureStatus']
|
117
|
+
end
|
118
|
+
|
119
|
+
# Encoded 3D Secure result code.
|
120
|
+
def buyer_auth_result_code
|
121
|
+
params['CAVV']
|
122
|
+
end
|
123
|
+
|
124
|
+
# Address confirmation status. PayPal only. Possible values:
|
125
|
+
# <tt>NONE</tt>::
|
126
|
+
# <tt>CONFIRMED</tt>::
|
127
|
+
# <tt>UNCONFIRMED</tt>::
|
128
|
+
def address_status
|
129
|
+
params['AddressStatus']
|
130
|
+
end
|
131
|
+
|
132
|
+
# Payer verification. Undocumented.
|
133
|
+
def payer_verified?
|
134
|
+
params['PayerStatus'] == 'VERIFIED'
|
135
|
+
end
|
136
|
+
|
137
|
+
# Credit card type. Possible values:
|
138
|
+
# <tt>VISA</tt>:: Visa
|
139
|
+
# <tt>MC</tt>:: MasterCard
|
140
|
+
# <tt>DELTA</tt>:: Delta
|
141
|
+
# <tt>SOLO</tt>:: Solo
|
142
|
+
# <tt>MAESTRO</tt>:: Maestro (UK and International)
|
143
|
+
# <tt>UKE</tt>:: Visa Electron
|
144
|
+
# <tt>AMEX</tt>:: American Express
|
145
|
+
# <tt>DC</tt>:: Diners Club
|
146
|
+
# <tt>JCB</tt>:: JCB
|
147
|
+
# <tt>LASER</tt>:: Laser
|
148
|
+
# <tt>PAYPAL</tt>:: PayPal
|
149
|
+
def credit_card_type
|
150
|
+
params['CardType']
|
151
|
+
end
|
152
|
+
|
153
|
+
# Last four digits of credit card.
|
154
|
+
def credit_card_last_4_digits
|
155
|
+
params['Last4Digits']
|
156
|
+
end
|
157
|
+
|
158
|
+
# Used by composition methods, but not supplied by SagePay.
|
159
|
+
def currency
|
160
|
+
nil
|
161
|
+
end
|
162
|
+
|
163
|
+
def test?
|
164
|
+
false
|
165
|
+
end
|
166
|
+
|
167
|
+
def acknowledge
|
168
|
+
true
|
169
|
+
end
|
170
|
+
|
171
|
+
private
|
172
|
+
|
173
|
+
def load_crypt_params(crypt, key)
|
174
|
+
raise MissingCryptData if crypt.blank?
|
175
|
+
raise MissingCryptKey if key.blank?
|
176
|
+
|
177
|
+
crypt_data = sage_decrypt(crypt.gsub(' ', '+'), key)
|
178
|
+
raise InvalidCryptData unless crypt_data =~ /(^|&)Status=/
|
179
|
+
|
180
|
+
params.clear
|
181
|
+
parse(crypt_data)
|
182
|
+
end
|
183
|
+
|
184
|
+
class MissingCryptKey < CryptError
|
185
|
+
def message
|
186
|
+
'No merchant decryption key supplied'
|
187
|
+
end
|
188
|
+
end
|
189
|
+
class MissingCryptData < CryptError
|
190
|
+
def message
|
191
|
+
'No data received from SagePay'
|
192
|
+
end
|
193
|
+
end
|
194
|
+
class InvalidCryptData < CryptError
|
195
|
+
def message
|
196
|
+
'Invalid data received from SagePay'
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|