yetanothernguyen-activemerchant 1.16.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +711 -0
- data/CONTRIBUTORS +245 -0
- data/MIT-LICENSE +20 -0
- data/gem-public_cert.pem +20 -0
- data/lib/active_merchant.rb +52 -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 +178 -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 +170 -0
- data/lib/active_merchant/billing/gateways.rb +18 -0
- data/lib/active_merchant/billing/gateways/authorize_net.rb +672 -0
- data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +858 -0
- data/lib/active_merchant/billing/gateways/barclays_epdq.rb +308 -0
- data/lib/active_merchant/billing/gateways/beanstream.rb +139 -0
- data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +282 -0
- data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
- data/lib/active_merchant/billing/gateways/blue_pay.rb +11 -0
- data/lib/active_merchant/billing/gateways/bogus.rb +142 -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 +303 -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 +430 -0
- data/lib/active_merchant/billing/gateways/data_cash.rb +597 -0
- data/lib/active_merchant/billing/gateways/efsnet.rb +235 -0
- data/lib/active_merchant/billing/gateways/elavon.rb +134 -0
- data/lib/active_merchant/billing/gateways/epay.rb +268 -0
- data/lib/active_merchant/billing/gateways/eway.rb +277 -0
- data/lib/active_merchant/billing/gateways/eway_managed.rb +231 -0
- data/lib/active_merchant/billing/gateways/exact.rb +222 -0
- data/lib/active_merchant/billing/gateways/federated_canada.rb +168 -0
- data/lib/active_merchant/billing/gateways/first_pay.rb +177 -0
- data/lib/active_merchant/billing/gateways/garanti.rb +262 -0
- data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +250 -0
- data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
- data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
- data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +55 -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 +258 -0
- data/lib/active_merchant/billing/gateways/jetpay.rb +276 -0
- data/lib/active_merchant/billing/gateways/linkpoint.rb +454 -0
- data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +156 -0
- data/lib/active_merchant/billing/gateways/merchant_ware.rb +289 -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 +209 -0
- data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
- data/lib/active_merchant/billing/gateways/netaxept.rb +239 -0
- data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
- data/lib/active_merchant/billing/gateways/nmi.rb +13 -0
- data/lib/active_merchant/billing/gateways/ogone.rb +292 -0
- data/lib/active_merchant/billing/gateways/orbital.rb +321 -0
- data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +46 -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 +207 -0
- data/lib/active_merchant/billing/gateways/payflow.rb +253 -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 +222 -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 +235 -0
- data/lib/active_merchant/billing/gateways/paypal.rb +121 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +351 -0
- data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +49 -0
- data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
- data/lib/active_merchant/billing/gateways/paypal_express.rb +177 -0
- data/lib/active_merchant/billing/gateways/paypal_express_common.rb +25 -0
- data/lib/active_merchant/billing/gateways/paystation.rb +201 -0
- data/lib/active_merchant/billing/gateways/plugnpay.rb +298 -0
- data/lib/active_merchant/billing/gateways/psigate.rb +219 -0
- data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
- data/lib/active_merchant/billing/gateways/qbms.rb +293 -0
- data/lib/active_merchant/billing/gateways/quantum.rb +282 -0
- data/lib/active_merchant/billing/gateways/quickpay.rb +223 -0
- data/lib/active_merchant/billing/gateways/realex.rb +311 -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 +320 -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 +193 -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 +271 -0
- data/lib/active_merchant/billing/gateways/stripe.rb +212 -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 +423 -0
- data/lib/active_merchant/billing/gateways/usa_epay.rb +194 -0
- data/lib/active_merchant/billing/gateways/verifi.rb +233 -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/gateways/worldpay.rb +280 -0
- data/lib/active_merchant/billing/integrations.rb +17 -0
- data/lib/active_merchant/billing/integrations/action_view_helper.rb +70 -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 +200 -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/directebanking.rb +47 -0
- data/lib/active_merchant/billing/integrations/directebanking/helper.rb +90 -0
- data/lib/active_merchant/billing/integrations/directebanking/notification.rb +120 -0
- data/lib/active_merchant/billing/integrations/directebanking/return.rb +11 -0
- data/lib/active_merchant/billing/integrations/e_payment_plans.rb +48 -0
- data/lib/active_merchant/billing/integrations/e_payment_plans/helper.rb +34 -0
- data/lib/active_merchant/billing/integrations/e_payment_plans/notification.rb +84 -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/migs.rb +22 -0
- data/lib/active_merchant/billing/integrations/migs/helper.rb +64 -0
- data/lib/active_merchant/billing/integrations/migs/return.rb +54 -0
- data/lib/active_merchant/billing/integrations/moneybookers.rb +26 -0
- data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +59 -0
- data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +129 -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 +21 -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 +42 -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 +111 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +210 -0
- data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +31 -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/integrations/valitor.rb +33 -0
- data/lib/active_merchant/billing/integrations/valitor/helper.rb +86 -0
- data/lib/active_merchant/billing/integrations/valitor/notification.rb +13 -0
- data/lib/active_merchant/billing/integrations/valitor/response_fields.rb +97 -0
- data/lib/active_merchant/billing/integrations/valitor/return.rb +13 -0
- data/lib/active_merchant/billing/integrations/world_pay.rb +27 -0
- data/lib/active_merchant/billing/integrations/world_pay/helper.rb +100 -0
- data/lib/active_merchant/billing/integrations/world_pay/notification.rb +160 -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 +177 -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 +63 -0
- data/lib/active_merchant/common/requires_parameters.rb +16 -0
- data/lib/active_merchant/common/utils.rb +22 -0
- data/lib/active_merchant/common/validateable.rb +81 -0
- data/lib/active_merchant/railtie.rb +9 -0
- data/lib/active_merchant/version.rb +3 -0
- data/lib/activemerchant.rb +1 -0
- data/lib/certs/cacert.pem +7815 -0
- data/lib/support/gateway_support.rb +58 -0
- data/lib/support/outbound_hosts.rb +25 -0
- metadata +281 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'active_merchant/billing/integrations/valitor/response_fields'
|
2
|
+
|
3
|
+
module ActiveMerchant #:nodoc:
|
4
|
+
module Billing #:nodoc:
|
5
|
+
module Integrations #:nodoc:
|
6
|
+
module Valitor
|
7
|
+
class Return < ActiveMerchant::Billing::Integrations::Return
|
8
|
+
include ResponseFields
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/world_pay/helper.rb'
|
2
|
+
require File.dirname(__FILE__) + '/world_pay/notification.rb'
|
3
|
+
|
4
|
+
module ActiveMerchant #:nodoc:
|
5
|
+
module Billing #:nodoc:
|
6
|
+
module Integrations #:nodoc:
|
7
|
+
module WorldPay
|
8
|
+
|
9
|
+
# production and test have the same endpoint
|
10
|
+
mattr_accessor :production_url
|
11
|
+
self.production_url = 'https://secure.wp3.rbsworldpay.com/wcc/purchase'
|
12
|
+
|
13
|
+
def self.service_url
|
14
|
+
production_url
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.notification(post, options = {})
|
18
|
+
Notification.new(post, options)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.return(post, options = {})
|
22
|
+
Return.new(post, options)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
module Integrations #:nodoc:
|
4
|
+
module WorldPay
|
5
|
+
class Helper < ActiveMerchant::Billing::Integrations::Helper
|
6
|
+
mapping :account, 'instId'
|
7
|
+
mapping :amount, 'amount'
|
8
|
+
mapping :order, 'cartId'
|
9
|
+
mapping :currency, 'currency'
|
10
|
+
|
11
|
+
mapping :customer, :email => 'email',
|
12
|
+
:phone => 'tel'
|
13
|
+
|
14
|
+
mapping :billing_address, :zip => 'postcode',
|
15
|
+
:country => 'country'
|
16
|
+
|
17
|
+
mapping :description, 'desc'
|
18
|
+
mapping :notify_url, 'MC_callback'
|
19
|
+
|
20
|
+
|
21
|
+
# WorldPay supports two different test modes - :always_succeed and :always_fail
|
22
|
+
def initialize(order, account, options = {})
|
23
|
+
super
|
24
|
+
|
25
|
+
if ActiveMerchant::Billing::Base.integration_mode == :test || options[:test]
|
26
|
+
test_mode = case options[:test]
|
27
|
+
when :always_fail
|
28
|
+
101
|
29
|
+
when false
|
30
|
+
0
|
31
|
+
else
|
32
|
+
100
|
33
|
+
end
|
34
|
+
add_field('testMode', test_mode.to_s)
|
35
|
+
elsif ActiveMerchant::Billing::Base.integration_mode == :always_succeed
|
36
|
+
add_field('testMode', '100')
|
37
|
+
elsif ActiveMerchant::Billing::Base.integration_mode == :always_fail
|
38
|
+
add_field('testMode', '101')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
# WorldPay only supports a single address field so we
|
43
|
+
# have to concat together - lines are separated using
|
44
|
+
def billing_address(params={})
|
45
|
+
add_field(mappings[:billing_address][:zip], params[:zip])
|
46
|
+
add_field(mappings[:billing_address][:country], lookup_country_code(params[:country]))
|
47
|
+
|
48
|
+
address = [params[:address1], params[:address2], params[:city], params[:state]].compact
|
49
|
+
add_field('address', address.join(' '))
|
50
|
+
end
|
51
|
+
|
52
|
+
# WorldPay only supports a single name field so we have to concat
|
53
|
+
def customer(params={})
|
54
|
+
add_field(mappings[:customer][:email], params[:email])
|
55
|
+
add_field(mappings[:customer][:phone], params[:phone])
|
56
|
+
add_field('name', "#{params[:first_name]} #{params[:last_name]}")
|
57
|
+
end
|
58
|
+
|
59
|
+
# Support for a MD5 hash of selected fields to prevent tampering
|
60
|
+
# For futher information read the tech note at the address below:
|
61
|
+
# http://support.worldpay.com/kb/integration_guides/junior/integration/help/tech_notes/sjig_tn_009.html
|
62
|
+
def encrypt(secret, fields = [:amount, :currency, :account, :order])
|
63
|
+
signature_fields = fields.collect{ |field| mappings[field] }
|
64
|
+
add_field('signatureFields', signature_fields.join(':'))
|
65
|
+
|
66
|
+
field_values = fields.collect{ |field| form_fields[mappings[field]] }
|
67
|
+
signature = "#{secret}:#{field_values.join(':')}"
|
68
|
+
add_field('signature', Digest::MD5.hexdigest(signature))
|
69
|
+
end
|
70
|
+
|
71
|
+
# Add a time window for which the payment can be completed. Read the link below for how they work
|
72
|
+
# http://support.worldpay.com/kb/integration_guides/junior/integration/help/appendicies/sjig_10100.html
|
73
|
+
def valid_from(from_time)
|
74
|
+
add_field('authValidFrom', from_time.to_i.to_s + '000')
|
75
|
+
end
|
76
|
+
|
77
|
+
def valid_to(to_time)
|
78
|
+
add_field('authValidTo', to_time.to_i.to_s + '000')
|
79
|
+
end
|
80
|
+
|
81
|
+
# WorldPay supports the passing of custom parameters prefixed with the following:
|
82
|
+
# C_ : These parameters can be used in the response pages hosted on WorldPay's site
|
83
|
+
# M_ : These parameters are passed through to the callback script (if enabled)
|
84
|
+
# MC_ or CM_ : These parameters are availble both in the response and callback contexts
|
85
|
+
def response_params(params={})
|
86
|
+
params.each{|k,v| add_field("C_#{k}",v)}
|
87
|
+
end
|
88
|
+
|
89
|
+
def callback_params(params={})
|
90
|
+
params.each{|k,v| add_field("M_#{k}",v)}
|
91
|
+
end
|
92
|
+
|
93
|
+
def combined_params(params={})
|
94
|
+
params.each{|k,v| add_field("MC_#{k}",v)}
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,160 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
module Integrations #:nodoc:
|
4
|
+
module WorldPay
|
5
|
+
class Notification < ActiveMerchant::Billing::Integrations::Notification
|
6
|
+
def complete?
|
7
|
+
status == 'Completed'
|
8
|
+
end
|
9
|
+
|
10
|
+
def account
|
11
|
+
params['instId']
|
12
|
+
end
|
13
|
+
|
14
|
+
def item_id
|
15
|
+
params['cartId']
|
16
|
+
end
|
17
|
+
|
18
|
+
def transaction_id
|
19
|
+
params['transId']
|
20
|
+
end
|
21
|
+
|
22
|
+
# Time this payment was received by the client in UTC time.
|
23
|
+
def received_at
|
24
|
+
Time.at(params['transTime'].to_i / 1000).utc
|
25
|
+
end
|
26
|
+
|
27
|
+
# Callback password set in the WorldPay CMS
|
28
|
+
def security_key
|
29
|
+
params['callbackPW']
|
30
|
+
end
|
31
|
+
|
32
|
+
# the money amount we received in X.2 decimal.
|
33
|
+
def gross
|
34
|
+
params['authAmount']
|
35
|
+
end
|
36
|
+
|
37
|
+
def currency
|
38
|
+
params['authCurrency']
|
39
|
+
end
|
40
|
+
|
41
|
+
# Was this a test transaction?
|
42
|
+
def test?
|
43
|
+
params.key?('testMode') && params['testMode'] != '0'
|
44
|
+
end
|
45
|
+
|
46
|
+
def status
|
47
|
+
params['transStatus'] == 'Y' ? 'Completed' : 'Cancelled'
|
48
|
+
end
|
49
|
+
|
50
|
+
def name
|
51
|
+
params['name']
|
52
|
+
end
|
53
|
+
|
54
|
+
def address
|
55
|
+
params['address']
|
56
|
+
end
|
57
|
+
|
58
|
+
def postcode
|
59
|
+
params['postcode']
|
60
|
+
end
|
61
|
+
|
62
|
+
def country
|
63
|
+
params['country']
|
64
|
+
end
|
65
|
+
|
66
|
+
def phone_number
|
67
|
+
params['tel']
|
68
|
+
end
|
69
|
+
|
70
|
+
def fax_number
|
71
|
+
params['fax']
|
72
|
+
end
|
73
|
+
|
74
|
+
def email_address
|
75
|
+
params['email']
|
76
|
+
end
|
77
|
+
|
78
|
+
def card_type
|
79
|
+
params['cardType']
|
80
|
+
end
|
81
|
+
|
82
|
+
# WorldPay extended fraud checks returned as a 4 character string
|
83
|
+
# 1st char: Credit card CVV check
|
84
|
+
# 2nd char: Postcode AVS check
|
85
|
+
# 3rd char: Address AVS check
|
86
|
+
# 4th char: Country comparison check
|
87
|
+
# Possible values are:
|
88
|
+
# :not_supported - 0
|
89
|
+
# :not_checked - 1
|
90
|
+
# :matched - 2
|
91
|
+
# :not_matched - 4
|
92
|
+
# :partial_match - 8
|
93
|
+
def cvv_status
|
94
|
+
return avs_value_to_symbol(params['AVS'][0].chr)
|
95
|
+
end
|
96
|
+
|
97
|
+
def postcode_status
|
98
|
+
return avs_value_to_symbol(params['AVS'][1].chr)
|
99
|
+
end
|
100
|
+
|
101
|
+
def address_status
|
102
|
+
return avs_value_to_symbol(params['AVS'][2].chr)
|
103
|
+
end
|
104
|
+
|
105
|
+
def country_status
|
106
|
+
return avs_value_to_symbol(params['AVS'][3].chr)
|
107
|
+
end
|
108
|
+
|
109
|
+
def acknowledge
|
110
|
+
return true
|
111
|
+
end
|
112
|
+
|
113
|
+
# WorldPay supports the passing of custom parameters through to the callback script
|
114
|
+
def custom_params
|
115
|
+
return @custom_params ||= read_custom_params
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
private
|
120
|
+
|
121
|
+
# Take the posted data and move the relevant data into a hash
|
122
|
+
def parse(post)
|
123
|
+
@raw = post
|
124
|
+
for line in post.split('&')
|
125
|
+
key, value = *line.scan( %r{^(\w+)\=(.*)$} ).flatten
|
126
|
+
params[key] = value
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
# Read the custom params into a hash
|
131
|
+
def read_custom_params
|
132
|
+
custom = {}
|
133
|
+
params.each do |key, value|
|
134
|
+
if /\A(M_|MC_|CM_)/ === key
|
135
|
+
custom[key.gsub(/\A(M_|MC_|CM_)/, '').to_sym] = value
|
136
|
+
end
|
137
|
+
end
|
138
|
+
custom
|
139
|
+
end
|
140
|
+
|
141
|
+
# Convert a AVS value to a symbol - see above for more about AVS
|
142
|
+
def avs_value_to_symbol(value)
|
143
|
+
case value.to_s
|
144
|
+
when '8'
|
145
|
+
:partial_match
|
146
|
+
when '4'
|
147
|
+
:no_match
|
148
|
+
when '2'
|
149
|
+
:matched
|
150
|
+
when '1'
|
151
|
+
:not_checked
|
152
|
+
else
|
153
|
+
:not_supported
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module ActiveMerchant #:nodoc:
|
2
|
+
module Billing #:nodoc:
|
3
|
+
|
4
|
+
class Error < ActiveMerchantError #:nodoc:
|
5
|
+
end
|
6
|
+
|
7
|
+
class Response
|
8
|
+
attr_reader :params, :message, :test, :authorization, :avs_result, :cvv_result
|
9
|
+
|
10
|
+
def success?
|
11
|
+
@success
|
12
|
+
end
|
13
|
+
|
14
|
+
def test?
|
15
|
+
@test
|
16
|
+
end
|
17
|
+
|
18
|
+
def fraud_review?
|
19
|
+
@fraud_review
|
20
|
+
end
|
21
|
+
|
22
|
+
def initialize(success, message, params = {}, options = {})
|
23
|
+
@success, @message, @params = success, message, params.stringify_keys
|
24
|
+
@test = options[:test] || false
|
25
|
+
@authorization = options[:authorization]
|
26
|
+
@fraud_review = options[:fraud_review]
|
27
|
+
@avs_result = AVSResult.new(options[:avs_result]).to_hash
|
28
|
+
@cvv_result = CVVResult.new(options[:cvv_result]).to_hash
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module ActiveMerchant
|
2
|
+
autoload :Connection, 'active_merchant/common/connection'
|
3
|
+
autoload :Country, 'active_merchant/common/country'
|
4
|
+
autoload :ActiveMerchantError, 'active_merchant/common/error'
|
5
|
+
autoload :ConnectionError, 'active_merchant/common/error'
|
6
|
+
autoload :RetriableConnectionError, 'active_merchant/common/error'
|
7
|
+
autoload :ResponseError, 'active_merchant/common/error'
|
8
|
+
autoload :ClientCertificateError, 'active_merchant/common/error'
|
9
|
+
autoload :PostData, 'active_merchant/common/post_data'
|
10
|
+
autoload :PostsData, 'active_merchant/common/posts_data'
|
11
|
+
autoload :RequiresParameters, 'active_merchant/common/requires_parameters'
|
12
|
+
autoload :Utils, 'active_merchant/common/utils'
|
13
|
+
autoload :Validateable, 'active_merchant/common/validateable'
|
14
|
+
end
|
@@ -0,0 +1,177 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'net/https'
|
4
|
+
require 'benchmark'
|
5
|
+
|
6
|
+
module ActiveMerchant
|
7
|
+
class ConnectionError < ActiveMerchantError # :nodoc:
|
8
|
+
end
|
9
|
+
|
10
|
+
class RetriableConnectionError < ConnectionError # :nodoc:
|
11
|
+
end
|
12
|
+
|
13
|
+
class ResponseError < ActiveMerchantError # :nodoc:
|
14
|
+
attr_reader :response
|
15
|
+
|
16
|
+
def initialize(response, message = nil)
|
17
|
+
@response = response
|
18
|
+
@message = message
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
"Failed with #{response.code} #{response.message if response.respond_to?(:message)}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Connection
|
27
|
+
MAX_RETRIES = 3
|
28
|
+
OPEN_TIMEOUT = 60
|
29
|
+
READ_TIMEOUT = 60
|
30
|
+
VERIFY_PEER = true
|
31
|
+
RETRY_SAFE = false
|
32
|
+
RUBY_184_POST_HEADERS = { "Content-Type" => "application/x-www-form-urlencoded" }
|
33
|
+
|
34
|
+
attr_accessor :endpoint
|
35
|
+
attr_accessor :open_timeout
|
36
|
+
attr_accessor :read_timeout
|
37
|
+
attr_accessor :verify_peer
|
38
|
+
attr_accessor :retry_safe
|
39
|
+
attr_accessor :pem
|
40
|
+
attr_accessor :pem_password
|
41
|
+
attr_accessor :wiredump_device
|
42
|
+
attr_accessor :logger
|
43
|
+
attr_accessor :tag
|
44
|
+
attr_accessor :ignore_http_status
|
45
|
+
|
46
|
+
def initialize(endpoint)
|
47
|
+
@endpoint = endpoint.is_a?(URI) ? endpoint : URI.parse(endpoint)
|
48
|
+
@open_timeout = OPEN_TIMEOUT
|
49
|
+
@read_timeout = READ_TIMEOUT
|
50
|
+
@retry_safe = RETRY_SAFE
|
51
|
+
@verify_peer = VERIFY_PEER
|
52
|
+
@ignore_http_status = false
|
53
|
+
end
|
54
|
+
|
55
|
+
def request(method, body, headers = {})
|
56
|
+
retry_exceptions do
|
57
|
+
begin
|
58
|
+
info "#{method.to_s.upcase} #{endpoint}", tag
|
59
|
+
|
60
|
+
result = nil
|
61
|
+
|
62
|
+
realtime = Benchmark.realtime do
|
63
|
+
result = case method
|
64
|
+
when :get
|
65
|
+
raise ArgumentError, "GET requests do not support a request body" if body
|
66
|
+
http.get(endpoint.request_uri, headers)
|
67
|
+
when :post
|
68
|
+
debug body
|
69
|
+
http.post(endpoint.request_uri, body, RUBY_184_POST_HEADERS.merge(headers))
|
70
|
+
else
|
71
|
+
raise ArgumentError, "Unsupported request method #{method.to_s.upcase}"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
info "--> %d %s (%d %.4fs)" % [result.code, result.message, result.body ? result.body.length : 0, realtime], tag
|
76
|
+
debug result.body
|
77
|
+
result
|
78
|
+
rescue EOFError => e
|
79
|
+
raise ConnectionError, "The remote server dropped the connection"
|
80
|
+
rescue Errno::ECONNRESET => e
|
81
|
+
raise ConnectionError, "The remote server reset the connection"
|
82
|
+
rescue Errno::ECONNREFUSED => e
|
83
|
+
raise RetriableConnectionError, "The remote server refused the connection"
|
84
|
+
rescue OpenSSL::X509::CertificateError => e
|
85
|
+
raise ClientCertificateError, "The remote server did not accept the provided SSL certificate"
|
86
|
+
rescue Timeout::Error, Errno::ETIMEDOUT => e
|
87
|
+
raise ConnectionError, "The connection to the remote server timed out"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
def http
|
94
|
+
http = Net::HTTP.new(endpoint.host, endpoint.port)
|
95
|
+
configure_debugging(http)
|
96
|
+
configure_timeouts(http)
|
97
|
+
configure_ssl(http)
|
98
|
+
configure_cert(http)
|
99
|
+
http
|
100
|
+
end
|
101
|
+
|
102
|
+
def configure_debugging(http)
|
103
|
+
http.set_debug_output(wiredump_device)
|
104
|
+
end
|
105
|
+
|
106
|
+
def configure_timeouts(http)
|
107
|
+
http.open_timeout = open_timeout
|
108
|
+
http.read_timeout = read_timeout
|
109
|
+
end
|
110
|
+
|
111
|
+
def configure_ssl(http)
|
112
|
+
return unless endpoint.scheme == "https"
|
113
|
+
|
114
|
+
http.use_ssl = true
|
115
|
+
|
116
|
+
if verify_peer
|
117
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
118
|
+
http.ca_file = File.dirname(__FILE__) + '/../../certs/cacert.pem'
|
119
|
+
else
|
120
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def configure_cert(http)
|
125
|
+
return if pem.blank?
|
126
|
+
|
127
|
+
http.cert = OpenSSL::X509::Certificate.new(pem)
|
128
|
+
|
129
|
+
if pem_password
|
130
|
+
http.key = OpenSSL::PKey::RSA.new(pem, pem_password)
|
131
|
+
else
|
132
|
+
http.key = OpenSSL::PKey::RSA.new(pem)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def retry_exceptions
|
137
|
+
retries = MAX_RETRIES
|
138
|
+
begin
|
139
|
+
yield
|
140
|
+
rescue RetriableConnectionError => e
|
141
|
+
retries -= 1
|
142
|
+
retry unless retries.zero?
|
143
|
+
raise ConnectionError, e.message
|
144
|
+
rescue ConnectionError
|
145
|
+
retries -= 1
|
146
|
+
retry if retry_safe && !retries.zero?
|
147
|
+
raise
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
def handle_response(response)
|
152
|
+
if @ignore_http_status then
|
153
|
+
return response.body
|
154
|
+
else
|
155
|
+
case response.code.to_i
|
156
|
+
when 200...300
|
157
|
+
response.body
|
158
|
+
else
|
159
|
+
raise ResponseError.new(response)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def debug(message, tag = nil)
|
165
|
+
log(:debug, message, tag)
|
166
|
+
end
|
167
|
+
|
168
|
+
def info(message, tag = nil)
|
169
|
+
log(:info, message, tag)
|
170
|
+
end
|
171
|
+
|
172
|
+
def log(level, message, tag)
|
173
|
+
message = "[#{tag}] #{message}" if tag
|
174
|
+
logger.send(level, message) if logger
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|