yetanothernguyen-activemerchant 1.16.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 +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,311 @@
|
|
1
|
+
require 'rexml/document'
|
2
|
+
require 'digest/sha1'
|
3
|
+
|
4
|
+
module ActiveMerchant
|
5
|
+
module Billing
|
6
|
+
# Realex is the leading CC gateway in Ireland
|
7
|
+
# see http://www.realexpayments.com
|
8
|
+
# Contributed by John Ward (john@ward.name)
|
9
|
+
# see http://thinedgeofthewedge.blogspot.com
|
10
|
+
#
|
11
|
+
# Realex works using the following
|
12
|
+
# login - The unique id of the merchant
|
13
|
+
# password - The secret is used to digitally sign the request
|
14
|
+
# account - This is an optional third part of the authentication process
|
15
|
+
# and is used if the merchant wishes do distuinguish cc traffic from the different sources
|
16
|
+
# by using a different account. This must be created in advance
|
17
|
+
#
|
18
|
+
# the Realex team decided to make the orderid unique per request,
|
19
|
+
# so if validation fails you can not correct and resend using the
|
20
|
+
# same order id
|
21
|
+
class RealexGateway < Gateway
|
22
|
+
URL = 'https://epage.payandshop.com/epage-remote.cgi'
|
23
|
+
|
24
|
+
CARD_MAPPING = {
|
25
|
+
'master' => 'MC',
|
26
|
+
'visa' => 'VISA',
|
27
|
+
'american_express' => 'AMEX',
|
28
|
+
'diners_club' => 'DINERS',
|
29
|
+
'switch' => 'SWITCH',
|
30
|
+
'solo' => 'SWITCH',
|
31
|
+
'laser' => 'LASER'
|
32
|
+
}
|
33
|
+
|
34
|
+
self.money_format = :cents
|
35
|
+
self.default_currency = 'EUR'
|
36
|
+
self.supported_cardtypes = [ :visa, :master, :american_express, :diners_club, :switch, :solo, :laser ]
|
37
|
+
self.supported_countries = [ 'IE', 'GB' ]
|
38
|
+
self.homepage_url = 'http://www.realexpayments.com/'
|
39
|
+
self.display_name = 'Realex'
|
40
|
+
|
41
|
+
SUCCESS, DECLINED = "Successful", "Declined"
|
42
|
+
BANK_ERROR = REALEX_ERROR = "Gateway is in maintenance. Please try again later."
|
43
|
+
ERROR = CLIENT_DEACTIVATED = "Gateway Error"
|
44
|
+
|
45
|
+
def initialize(options = {})
|
46
|
+
requires!(options, :login, :password)
|
47
|
+
options[:refund_hash] = Digest::SHA1.hexdigest(options[:rebate_secret]) if options.has_key?(:rebate_secret)
|
48
|
+
@options = options
|
49
|
+
super
|
50
|
+
end
|
51
|
+
|
52
|
+
def purchase(money, credit_card, options = {})
|
53
|
+
requires!(options, :order_id)
|
54
|
+
|
55
|
+
request = build_purchase_or_authorization_request(:purchase, money, credit_card, options)
|
56
|
+
commit(request)
|
57
|
+
end
|
58
|
+
|
59
|
+
def authorize(money, creditcard, options = {})
|
60
|
+
requires!(options, :order_id)
|
61
|
+
|
62
|
+
request = build_purchase_or_authorization_request(:authorization, money, creditcard, options)
|
63
|
+
commit(request)
|
64
|
+
end
|
65
|
+
|
66
|
+
def capture(money, authorization, options = {})
|
67
|
+
request = build_capture_request(authorization, options)
|
68
|
+
commit(request)
|
69
|
+
end
|
70
|
+
|
71
|
+
def refund(money, authorization, options = {})
|
72
|
+
request = build_refund_request(money, authorization, options)
|
73
|
+
commit(request)
|
74
|
+
end
|
75
|
+
|
76
|
+
def credit(money, authorization, options = {})
|
77
|
+
deprecated CREDIT_DEPRECATION_MESSAGE
|
78
|
+
refund(money, authorization, options)
|
79
|
+
end
|
80
|
+
|
81
|
+
def void(authorization, options = {})
|
82
|
+
request = build_void_request(authorization, options)
|
83
|
+
commit(request)
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
def commit(request)
|
88
|
+
response = parse(ssl_post(URL, request))
|
89
|
+
|
90
|
+
Response.new(response[:result] == "00", message_from(response), response,
|
91
|
+
:test => response[:message] =~ /\[ test system \]/,
|
92
|
+
:authorization => authorization_from(response),
|
93
|
+
:cvv_result => response[:cvnresult],
|
94
|
+
:avs_result => {
|
95
|
+
:street_match => response[:avspostcoderesponse],
|
96
|
+
:postal_match => response[:avspostcoderesponse]
|
97
|
+
}
|
98
|
+
)
|
99
|
+
end
|
100
|
+
|
101
|
+
def parse(xml)
|
102
|
+
response = {}
|
103
|
+
|
104
|
+
xml = REXML::Document.new(xml)
|
105
|
+
xml.elements.each('//response/*') do |node|
|
106
|
+
|
107
|
+
if (node.elements.size == 0)
|
108
|
+
response[node.name.downcase.to_sym] = normalize(node.text)
|
109
|
+
else
|
110
|
+
node.elements.each do |childnode|
|
111
|
+
name = "#{node.name.downcase}_#{childnode.name.downcase}"
|
112
|
+
response[name.to_sym] = normalize(childnode.text)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
end unless xml.root.nil?
|
117
|
+
|
118
|
+
response
|
119
|
+
end
|
120
|
+
|
121
|
+
def authorization_from(parsed)
|
122
|
+
[parsed[:orderid], parsed[:pasref], parsed[:authcode]].join(';')
|
123
|
+
end
|
124
|
+
|
125
|
+
def build_purchase_or_authorization_request(action, money, credit_card, options)
|
126
|
+
timestamp = new_timestamp
|
127
|
+
xml = Builder::XmlMarkup.new :indent => 2
|
128
|
+
xml.tag! 'request', 'timestamp' => timestamp, 'type' => 'auth' do
|
129
|
+
add_merchant_details(xml, options)
|
130
|
+
xml.tag! 'orderid', sanitize_order_id(options[:order_id])
|
131
|
+
add_amount(xml, money, options)
|
132
|
+
add_card(xml, credit_card)
|
133
|
+
xml.tag! 'autosettle', 'flag' => auto_settle_flag(action)
|
134
|
+
add_signed_digest(xml, timestamp, @options[:login], sanitize_order_id(options[:order_id]), amount(money), (options[:currency] || currency(money)), credit_card.number)
|
135
|
+
add_comments(xml, options)
|
136
|
+
add_address_and_customer_info(xml, options)
|
137
|
+
end
|
138
|
+
xml.target!
|
139
|
+
end
|
140
|
+
|
141
|
+
def build_capture_request(authorization, options)
|
142
|
+
timestamp = new_timestamp
|
143
|
+
xml = Builder::XmlMarkup.new :indent => 2
|
144
|
+
xml.tag! 'request', 'timestamp' => timestamp, 'type' => 'settle' do
|
145
|
+
add_merchant_details(xml, options)
|
146
|
+
add_transaction_identifiers(xml, authorization, options)
|
147
|
+
add_comments(xml, options)
|
148
|
+
add_signed_digest(xml, timestamp, @options[:login], sanitize_order_id(options[:order_id]), nil, nil, nil)
|
149
|
+
end
|
150
|
+
xml.target!
|
151
|
+
end
|
152
|
+
|
153
|
+
def build_refund_request(money, authorization, options)
|
154
|
+
timestamp = new_timestamp
|
155
|
+
xml = Builder::XmlMarkup.new :indent => 2
|
156
|
+
xml.tag! 'request', 'timestamp' => timestamp, 'type' => 'rebate' do
|
157
|
+
add_merchant_details(xml, options)
|
158
|
+
add_transaction_identifiers(xml, authorization, options)
|
159
|
+
xml.tag! 'amount', amount(money), 'currency' => options[:currency] || currency(money)
|
160
|
+
xml.tag! 'refundhash', @options[:refund_hash] if @options[:refund_hash]
|
161
|
+
xml.tag! 'autosettle', 'flag' => 1
|
162
|
+
add_comments(xml, options)
|
163
|
+
add_signed_digest(xml, timestamp, @options[:login], sanitize_order_id(options[:order_id]), amount(money), (options[:currency] || currency(money)), nil)
|
164
|
+
end
|
165
|
+
xml.target!
|
166
|
+
end
|
167
|
+
|
168
|
+
def build_void_request(authorization, options)
|
169
|
+
timestamp = new_timestamp
|
170
|
+
xml = Builder::XmlMarkup.new :indent => 2
|
171
|
+
xml.tag! 'request', 'timestamp' => timestamp, 'type' => 'void' do
|
172
|
+
add_merchant_details(xml, options)
|
173
|
+
add_transaction_identifiers(xml, authorization, options)
|
174
|
+
add_comments(xml, options)
|
175
|
+
add_signed_digest(xml, timestamp, @options[:login], sanitize_order_id(options[:order_id]), nil, nil, nil)
|
176
|
+
end
|
177
|
+
xml.target!
|
178
|
+
end
|
179
|
+
|
180
|
+
def add_address_and_customer_info(xml, options)
|
181
|
+
billing_address = options[:billing_address] || options[:address]
|
182
|
+
shipping_address = options[:shipping_address]
|
183
|
+
|
184
|
+
return unless billing_address || shipping_address || options[:customer] || options[:invoice] || options[:ip]
|
185
|
+
|
186
|
+
xml.tag! 'tssinfo' do
|
187
|
+
xml.tag! 'custnum', options[:customer] if options[:customer]
|
188
|
+
xml.tag! 'prodid', options[:invoice] if options[:invoice]
|
189
|
+
xml.tag! 'custipaddress', options[:ip] if options[:ip]
|
190
|
+
|
191
|
+
if billing_address
|
192
|
+
xml.tag! 'address', 'type' => 'billing' do
|
193
|
+
xml.tag! 'code', avs_input_code( billing_address )
|
194
|
+
xml.tag! 'country', billing_address[:country]
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
if shipping_address
|
199
|
+
xml.tag! 'address', 'type' => 'shipping' do
|
200
|
+
xml.tag! 'code', shipping_address[:zip]
|
201
|
+
xml.tag! 'country', shipping_address[:country]
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
def add_merchant_details(xml, options)
|
208
|
+
xml.tag! 'merchantid', @options[:login]
|
209
|
+
if options[:account] || @options[:account]
|
210
|
+
xml.tag! 'account', (options[:account] || @options[:account])
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
def add_transaction_identifiers(xml, authorization, options)
|
215
|
+
options[:order_id], pasref, authcode = authorization.split(';')
|
216
|
+
xml.tag! 'orderid', sanitize_order_id(options[:order_id])
|
217
|
+
xml.tag! 'pasref', pasref
|
218
|
+
xml.tag! 'authcode', authcode
|
219
|
+
end
|
220
|
+
|
221
|
+
def add_comments(xml, options)
|
222
|
+
return unless options[:description]
|
223
|
+
xml.tag! 'comments' do
|
224
|
+
xml.tag! 'comment', options[:description], 'id' => 1
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
def add_amount(xml, money, options)
|
229
|
+
xml.tag! 'amount', amount(money), 'currency' => options[:currency] || currency(money)
|
230
|
+
end
|
231
|
+
|
232
|
+
def add_card(xml, credit_card)
|
233
|
+
xml.tag! 'card' do
|
234
|
+
xml.tag! 'number', credit_card.number
|
235
|
+
xml.tag! 'expdate', expiry_date(credit_card)
|
236
|
+
xml.tag! 'chname', credit_card.name
|
237
|
+
xml.tag! 'type', CARD_MAPPING[card_brand(credit_card).to_s]
|
238
|
+
xml.tag! 'issueno', credit_card.issue_number
|
239
|
+
xml.tag! 'cvn' do
|
240
|
+
xml.tag! 'number', credit_card.verification_value
|
241
|
+
xml.tag! 'presind', (options['presind'] || (credit_card.verification_value? ? 1 : nil))
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
def avs_input_code(address)
|
247
|
+
address.values_at(:zip, :address1).map{ |v| extract_digits(v) }.join('|')
|
248
|
+
end
|
249
|
+
|
250
|
+
def extract_digits(string)
|
251
|
+
return "" if string.nil?
|
252
|
+
string.gsub(/[\D]/,'')
|
253
|
+
end
|
254
|
+
|
255
|
+
def new_timestamp
|
256
|
+
Time.now.strftime('%Y%m%d%H%M%S')
|
257
|
+
end
|
258
|
+
|
259
|
+
def add_signed_digest(xml, *values)
|
260
|
+
string = Digest::SHA1.hexdigest(values.join("."))
|
261
|
+
xml.tag! 'sha1hash', Digest::SHA1.hexdigest([string, @options[:password]].join("."))
|
262
|
+
end
|
263
|
+
|
264
|
+
def auto_settle_flag(action)
|
265
|
+
action == :authorization ? '0' : '1'
|
266
|
+
end
|
267
|
+
|
268
|
+
def expiry_date(credit_card)
|
269
|
+
"#{format(credit_card.month, :two_digits)}#{format(credit_card.year, :two_digits)}"
|
270
|
+
end
|
271
|
+
|
272
|
+
def normalize(field)
|
273
|
+
case field
|
274
|
+
when "true" then true
|
275
|
+
when "false" then false
|
276
|
+
when "" then nil
|
277
|
+
when "null" then nil
|
278
|
+
else field
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
def message_from(response)
|
283
|
+
message = nil
|
284
|
+
case response[:result]
|
285
|
+
when "00"
|
286
|
+
message = SUCCESS
|
287
|
+
when "101"
|
288
|
+
message = response[:message]
|
289
|
+
when "102", "103"
|
290
|
+
message = DECLINED
|
291
|
+
when /^2[0-9][0-9]/
|
292
|
+
message = BANK_ERROR
|
293
|
+
when /^3[0-9][0-9]/
|
294
|
+
message = REALEX_ERROR
|
295
|
+
when /^5[0-9][0-9]/
|
296
|
+
message = response[:message]
|
297
|
+
when "600", "601", "603"
|
298
|
+
message = ERROR
|
299
|
+
when "666"
|
300
|
+
message = CLIENT_DEACTIVATED
|
301
|
+
else
|
302
|
+
message = DECLINED
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
def sanitize_order_id(order_id)
|
307
|
+
order_id.to_s.gsub(/[^a-zA-Z0-9\-_]/, '')
|
308
|
+
end
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/sage/sage_bankcard'
|
2
|
+
require File.dirname(__FILE__) + '/sage/sage_virtual_check'
|
3
|
+
|
4
|
+
module ActiveMerchant #:nodoc:
|
5
|
+
module Billing #:nodoc:
|
6
|
+
class SageGateway < Gateway
|
7
|
+
self.supported_countries = SageBankcardGateway.supported_countries
|
8
|
+
self.supported_cardtypes = SageBankcardGateway.supported_cardtypes
|
9
|
+
|
10
|
+
# Creates a new SageGateway
|
11
|
+
#
|
12
|
+
# The gateway requires that a valid login and password be passed
|
13
|
+
# in the +options+ hash.
|
14
|
+
#
|
15
|
+
# ==== Options
|
16
|
+
#
|
17
|
+
# * <tt>:login</tt> - The Sage Payment Solutions Merchant ID Number.
|
18
|
+
# * <tt>:password</tt> - The Sage Payment Solutions Merchant Key Number.
|
19
|
+
def initialize(options = {})
|
20
|
+
requires!(options, :login, :password)
|
21
|
+
@options = options
|
22
|
+
super
|
23
|
+
end
|
24
|
+
|
25
|
+
# Performs an authorization transaction
|
26
|
+
#
|
27
|
+
# ==== Parameters
|
28
|
+
# * <tt>money</tt> - The amount to be authorized as an integer value in cents.
|
29
|
+
# * <tt>credit_card</tt> - The CreditCard object to be used as the funding source for the transaction.
|
30
|
+
# * <tt>options</tt> - A hash of optional parameters.
|
31
|
+
# * <tt>:order_id</tt> - A unique reference for this order. (maximum of 20 characters).
|
32
|
+
# * <tt>:email</tt> - The customer's email address
|
33
|
+
# * <tt>:customer</tt> - The Customer Number for Purchase Card Level II Transactions
|
34
|
+
# * <tt>:billing_address</tt> - The customer's billing address as a hash of address information.
|
35
|
+
# * <tt>:address1</tt> - The billing address street
|
36
|
+
# * <tt>:city</tt> - The billing address city
|
37
|
+
# * <tt>:state</tt> - The billing address state
|
38
|
+
# * <tt>:country</tt> - The 2 digit ISO billing address country code
|
39
|
+
# * <tt>:zip</tt> - The billing address zip code
|
40
|
+
# * <tt>:phone</tt> - The billing address phone number
|
41
|
+
# * <tt>:fax</tt> - The billing address fax number
|
42
|
+
# * <tt>:shipping_address</tt> - The customer's shipping address as a hash of address information.
|
43
|
+
# * <tt>:name</tt> - The name at the shipping address
|
44
|
+
# * <tt>:address1</tt> - The shipping address street
|
45
|
+
# * <tt>:city</tt> - The shipping address city
|
46
|
+
# * <tt>:state</tt> - The shipping address state code
|
47
|
+
# * <tt>:country</tt> - The 2 digit ISO shipping address country code
|
48
|
+
# * <tt>:zip</tt> - The shipping address zip code
|
49
|
+
# * <tt>:tax</tt> - The tax amount for the transaction as an Integer value in cents. Maps to Sage <tt>T_tax</tt>.
|
50
|
+
# * <tt>:shipping</tt> - The shipping amount for the transaction as an Integer value in cents. Maps to Sage <tt>T_shipping</tt>.
|
51
|
+
def authorize(money, credit_card, options = {})
|
52
|
+
bankcard.authorize(money, credit_card, options)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Performs a purchase, which is essentially an authorization and capture in a single operation.
|
56
|
+
#
|
57
|
+
# ==== Parameters
|
58
|
+
#
|
59
|
+
# * <tt>money</tt> - The amount to be authorized as an integer value in cents.
|
60
|
+
# * <tt>source</tt> - The CreditCard or Check object to be used as the funding source for the transaction.
|
61
|
+
# * <tt>options</tt> - A hash of optional parameters.
|
62
|
+
# * <tt>:order_id</tt> - A unique reference for this order. (maximum of 20 characters).
|
63
|
+
# * <tt>:email</tt> - The customer's email address
|
64
|
+
# * <tt>:customer</tt> - The Customer Number for Purchase Card Level II Transactions
|
65
|
+
# * <tt>:billing_address</tt> - The customer's billing address as a hash of address information.
|
66
|
+
# * <tt>:address1</tt> - The billing address street
|
67
|
+
# * <tt>:city</tt> - The billing address city
|
68
|
+
# * <tt>:state</tt> - The billing address state
|
69
|
+
# * <tt>:country</tt> - The 2 digit ISO billing address country code
|
70
|
+
# * <tt>:zip</tt> - The billing address zip code
|
71
|
+
# * <tt>:phone</tt> - The billing address phone number
|
72
|
+
# * <tt>:fax</tt> - The billing address fax number
|
73
|
+
# * <tt>:shipping_address</tt> - The customer's shipping address as a hash of address information.
|
74
|
+
# * <tt>:name</tt> - The name at the shipping address
|
75
|
+
# * <tt>:address1</tt> - The shipping address street
|
76
|
+
# * <tt>:city</tt> - The shipping address city
|
77
|
+
# * <tt>:state</tt> - The shipping address state code
|
78
|
+
# * <tt>:country</tt> - The 2 digit ISO shipping address country code
|
79
|
+
# * <tt>:zip</tt> - The shipping address zip code
|
80
|
+
# * <tt>:tax</tt> - The tax amount for the transaction as an integer value in cents. Maps to Sage <tt>T_tax</tt>.
|
81
|
+
# * <tt>:shipping</tt> - The shipping amount for the transaction as an integer value in cents. Maps to Sage <tt>T_shipping</tt>.
|
82
|
+
#
|
83
|
+
# ==== Additional options in the +options+ hash for when using a Check as the funding source
|
84
|
+
# * <tt>:originator_id</tt> - 10 digit originator. If not provided, Sage will use the default Originator ID for the specific customer type.
|
85
|
+
# * <tt>:addenda</tt> - Transaction addenda.
|
86
|
+
# * <tt>:ssn</tt> - The customer's Social Security Number.
|
87
|
+
# * <tt>:drivers_license_state</tt> - The customer's drivers license state code.
|
88
|
+
# * <tt>:drivers_license_number</tt> - The customer's drivers license number.
|
89
|
+
# * <tt>:date_of_birth</tt> - The customer's date of birth as a Time or Date object or a string in the format <tt>mm/dd/yyyy</tt>.
|
90
|
+
def purchase(money, source, options = {})
|
91
|
+
if card_brand(source) == "check"
|
92
|
+
virtual_check.purchase(money, source, options)
|
93
|
+
else
|
94
|
+
bankcard.purchase(money, source, options)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# Captures authorized funds.
|
99
|
+
#
|
100
|
+
# ==== Parameters
|
101
|
+
#
|
102
|
+
# * <tt>money</tt> - The amount to be authorized as an integer value in cents. Sage doesn't support changing the capture amount, so the full amount of the initial transaction will be captured.
|
103
|
+
# * <tt>reference</tt> - The authorization reference string returned by the original transaction's Response#authorization.
|
104
|
+
def capture(money, reference, options = {})
|
105
|
+
bankcard.capture(money, reference, options)
|
106
|
+
end
|
107
|
+
|
108
|
+
# Voids a prior transaction. Works for both CreditCard and Check transactions.
|
109
|
+
#
|
110
|
+
# ==== Parameters
|
111
|
+
#
|
112
|
+
# * <tt>reference</tt> - The authorization reference string returned by the original transaction's Response#authorization.
|
113
|
+
def void(reference, options = {})
|
114
|
+
if reference.split(";").last == "virtual_check"
|
115
|
+
virtual_check.void(reference, options)
|
116
|
+
else
|
117
|
+
bankcard.void(reference, options)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
# Performs a credit transaction. (Sage +Credit+ transaction).
|
122
|
+
#
|
123
|
+
# ==== Parameters
|
124
|
+
#
|
125
|
+
# * <tt>money</tt> - The amount to be authorized as an integer value in cents.
|
126
|
+
# * <tt>source</tt> - The CreditCard or Check object to be used as the target for the credit.
|
127
|
+
def credit(money, source, options = {})
|
128
|
+
if card_brand(source) == "check"
|
129
|
+
virtual_check.credit(money, source, options)
|
130
|
+
else
|
131
|
+
bankcard.credit(money, source, options)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
private
|
136
|
+
def bankcard
|
137
|
+
@bankcard ||= SageBankcardGateway.new(@options)
|
138
|
+
end
|
139
|
+
|
140
|
+
def virtual_check
|
141
|
+
@virtual_check ||= SageVirtualCheckGateway.new(@options)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|