maedana-activemerchant 1.9.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. data/CHANGELOG +571 -0
  2. data/CONTRIBUTORS +170 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +150 -0
  5. data/gem-public_cert.pem +20 -0
  6. data/lib/active_merchant.rb +49 -0
  7. data/lib/active_merchant/billing.rb +9 -0
  8. data/lib/active_merchant/billing/avs_result.rb +98 -0
  9. data/lib/active_merchant/billing/base.rb +57 -0
  10. data/lib/active_merchant/billing/check.rb +68 -0
  11. data/lib/active_merchant/billing/credit_card.rb +161 -0
  12. data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
  13. data/lib/active_merchant/billing/credit_card_methods.rb +125 -0
  14. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  15. data/lib/active_merchant/billing/expiry_date.rb +34 -0
  16. data/lib/active_merchant/billing/gateway.rb +169 -0
  17. data/lib/active_merchant/billing/gateways.rb +18 -0
  18. data/lib/active_merchant/billing/gateways/authorize_net.rb +654 -0
  19. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +736 -0
  20. data/lib/active_merchant/billing/gateways/beanstream.rb +102 -0
  21. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +244 -0
  22. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  23. data/lib/active_merchant/billing/gateways/bogus.rb +102 -0
  24. data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
  25. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  26. data/lib/active_merchant/billing/gateways/braintree_blue.rb +210 -0
  27. data/lib/active_merchant/billing/gateways/braintree_orange.rb +17 -0
  28. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  29. data/lib/active_merchant/billing/gateways/cyber_source.rb +406 -0
  30. data/lib/active_merchant/billing/gateways/data_cash.rb +593 -0
  31. data/lib/active_merchant/billing/gateways/efsnet.rb +229 -0
  32. data/lib/active_merchant/billing/gateways/elavon.rb +134 -0
  33. data/lib/active_merchant/billing/gateways/eway.rb +277 -0
  34. data/lib/active_merchant/billing/gateways/exact.rb +222 -0
  35. data/lib/active_merchant/billing/gateways/first_pay.rb +172 -0
  36. data/lib/active_merchant/billing/gateways/garanti.rb +222 -0
  37. data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
  38. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  39. data/lib/active_merchant/billing/gateways/iridium.rb +253 -0
  40. data/lib/active_merchant/billing/gateways/jetpay.rb +270 -0
  41. data/lib/active_merchant/billing/gateways/linkpoint.rb +449 -0
  42. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +154 -0
  43. data/lib/active_merchant/billing/gateways/merchant_ware.rb +283 -0
  44. data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
  45. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
  46. data/lib/active_merchant/billing/gateways/moneris.rb +205 -0
  47. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  48. data/lib/active_merchant/billing/gateways/netaxept.rb +234 -0
  49. data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
  50. data/lib/active_merchant/billing/gateways/ogone.rb +279 -0
  51. data/lib/active_merchant/billing/gateways/pay_junction.rb +392 -0
  52. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  53. data/lib/active_merchant/billing/gateways/paybox_direct.rb +203 -0
  54. data/lib/active_merchant/billing/gateways/payflow.rb +236 -0
  55. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +207 -0
  56. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  57. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  58. data/lib/active_merchant/billing/gateways/payflow_express.rb +138 -0
  59. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  60. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  61. data/lib/active_merchant/billing/gateways/payment_express.rb +230 -0
  62. data/lib/active_merchant/billing/gateways/paypal.rb +121 -0
  63. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +326 -0
  64. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +38 -0
  65. data/lib/active_merchant/billing/gateways/paypal/paypal_payment_details_response.rb +70 -0
  66. data/lib/active_merchant/billing/gateways/paypal_adaptive_payments.rb +298 -0
  67. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  68. data/lib/active_merchant/billing/gateways/paypal_express.rb +145 -0
  69. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +20 -0
  70. data/lib/active_merchant/billing/gateways/paypal_express_recurring.rb +310 -0
  71. data/lib/active_merchant/billing/gateways/plugnpay.rb +292 -0
  72. data/lib/active_merchant/billing/gateways/psigate.rb +214 -0
  73. data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
  74. data/lib/active_merchant/billing/gateways/quickpay.rb +213 -0
  75. data/lib/active_merchant/billing/gateways/realex.rb +200 -0
  76. data/lib/active_merchant/billing/gateways/sage.rb +146 -0
  77. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  78. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
  79. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  80. data/lib/active_merchant/billing/gateways/sage_pay.rb +315 -0
  81. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  82. data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
  83. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  84. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +157 -0
  85. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  86. data/lib/active_merchant/billing/gateways/skip_jack.rb +453 -0
  87. data/lib/active_merchant/billing/gateways/smart_ps.rb +265 -0
  88. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  89. data/lib/active_merchant/billing/gateways/transax.rb +25 -0
  90. data/lib/active_merchant/billing/gateways/trust_commerce.rb +418 -0
  91. data/lib/active_merchant/billing/gateways/usa_epay.rb +194 -0
  92. data/lib/active_merchant/billing/gateways/verifi.rb +228 -0
  93. data/lib/active_merchant/billing/gateways/viaklix.rb +189 -0
  94. data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
  95. data/lib/active_merchant/billing/integrations.rb +17 -0
  96. data/lib/active_merchant/billing/integrations/action_view_helper.rb +68 -0
  97. data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
  98. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  99. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  100. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  101. data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
  102. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
  103. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
  104. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  105. data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
  106. data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +188 -0
  107. data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
  108. data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
  109. data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
  110. data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
  111. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  112. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  113. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
  114. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  115. data/lib/active_merchant/billing/integrations/helper.rb +96 -0
  116. data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
  117. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  118. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  119. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  120. data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
  121. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  122. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  123. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  124. data/lib/active_merchant/billing/integrations/notification.rb +62 -0
  125. data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
  126. data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
  127. data/lib/active_merchant/billing/integrations/paypal/notification.rb +154 -0
  128. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  129. data/lib/active_merchant/billing/integrations/quickpay.rb +17 -0
  130. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +72 -0
  131. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
  132. data/lib/active_merchant/billing/integrations/return.rb +37 -0
  133. data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
  134. data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
  135. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +109 -0
  136. data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +204 -0
  137. data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +27 -0
  138. data/lib/active_merchant/billing/integrations/two_checkout.rb +23 -0
  139. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +59 -0
  140. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +114 -0
  141. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  142. data/lib/active_merchant/billing/response.rb +32 -0
  143. data/lib/active_merchant/common.rb +14 -0
  144. data/lib/active_merchant/common/connection.rb +172 -0
  145. data/lib/active_merchant/common/country.rb +328 -0
  146. data/lib/active_merchant/common/error.rb +26 -0
  147. data/lib/active_merchant/common/post_data.rb +24 -0
  148. data/lib/active_merchant/common/posts_data.rb +47 -0
  149. data/lib/active_merchant/common/requires_parameters.rb +16 -0
  150. data/lib/active_merchant/common/utils.rb +18 -0
  151. data/lib/active_merchant/common/validateable.rb +76 -0
  152. data/lib/active_merchant/version.rb +3 -0
  153. data/lib/certs/cacert.pem +7815 -0
  154. data/lib/maedana-activemerchant.rb +1 -0
  155. data/lib/support/gateway_support.rb +58 -0
  156. data/lib/support/outbound_hosts.rb +25 -0
  157. metadata +270 -0
@@ -0,0 +1,144 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class SallieMaeGateway < Gateway
4
+ URL = 'https://trans.salliemae.com/cgi-bin/process.cgi'
5
+
6
+ # The countries the gateway supports merchants from as 2 digit ISO country codes
7
+ self.supported_countries = ['US']
8
+
9
+ # The card types supported by the payment gateway
10
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
11
+
12
+ # The homepage URL of the gateway
13
+ self.homepage_url = 'http://www.salliemae.com/'
14
+
15
+ # The name of the gateway
16
+ self.display_name = 'Sallie Mae'
17
+
18
+ def initialize(options = {})
19
+ requires!(options, :login)
20
+ @options = options
21
+ super
22
+ end
23
+
24
+ def test?
25
+ @options[:login] == "TEST0"
26
+ end
27
+
28
+ def authorize(money, creditcard, options = {})
29
+ post = PostData.new
30
+ add_invoice(post, options)
31
+ add_creditcard(post, creditcard)
32
+ add_address(post, creditcard, options)
33
+ add_customer_data(post, options)
34
+
35
+ commit(:authonly, money, post)
36
+ end
37
+
38
+ def purchase(money, creditcard, options = {})
39
+ post = PostData.new
40
+ add_invoice(post, options)
41
+ add_creditcard(post, creditcard)
42
+ add_address(post, creditcard, options)
43
+ add_customer_data(post, options)
44
+
45
+ commit(:sale, money, post)
46
+ end
47
+
48
+ def capture(money, authorization, options = {})
49
+ post = PostData.new
50
+ post[:postonly] = authorization
51
+ commit(:capture, money, post)
52
+ end
53
+
54
+ private
55
+
56
+ def add_customer_data(post, options)
57
+ if address = options[:billing_address] || options[:shipping_address] || options[:address]
58
+ post[:ci_phone] = address[:phone].to_s
59
+ end
60
+
61
+ post[:ci_email] = options[:email].to_s unless options[:email].blank?
62
+ post[:ci_IP] = options[:ip].to_s unless options[:ip].blank?
63
+ end
64
+
65
+ def add_address(post, creditcard, options)
66
+ if address = options[:billing_address] || options[:address]
67
+ post[:ci_billaddr1] = address[:address1].to_s
68
+ post[:ci_billaddr2] = address[:address2].to_s unless address[:address2].blank?
69
+ post[:ci_billcity] = address[:city].to_s
70
+ post[:ci_billstate] = address[:state].to_s
71
+ post[:ci_billzip] = address[:zip].to_s
72
+ end
73
+
74
+ if shipping_address = options[:shipping_address] || options[:address]
75
+ post[:ci_shipaddr1] = shipping_address[:address1].to_s
76
+ post[:ci_shipaddr2] = shipping_address[:address2].to_s unless shipping_address[:address2].blank?
77
+ post[:ci_shipcity] = shipping_address[:city].to_s
78
+ post[:ci_shipstate] = shipping_address[:state].to_s
79
+ post[:ci_shipzip] = shipping_address[:zip].to_s
80
+ end
81
+ end
82
+
83
+ def add_invoice(post, options)
84
+ memo = "OrderID: #{options[:order_id]}\nDescription: #{options[:description]}"
85
+ post[:ci_memo] = memo
86
+ end
87
+
88
+ def add_creditcard(post, creditcard)
89
+ post[:ccnum] = creditcard.number.to_s
90
+ post[:ccname] = creditcard.name.to_s
91
+ post[:cvv2] = creditcard.verification_value.to_s if creditcard.verification_value?
92
+ post[:expmon] = creditcard.month.to_s
93
+ post[:expyear] = creditcard.year.to_s
94
+ end
95
+
96
+ def parse(body)
97
+ h = {}
98
+ body.gsub!("<html><body><plaintext>", "")
99
+ body.
100
+ split("\r\n").
101
+ map do |i|
102
+ a = i.split("=")
103
+ h[a.first] = a.last unless a.first.nil?
104
+ end
105
+ h
106
+ end
107
+
108
+ def commit(action, money, parameters)
109
+ parameters[:acctid] = @options[:login].to_s
110
+ parameters[:subid] = @options[:sub_id].to_s unless @options[:sub_id].blank?
111
+ parameters[:amount] = amount(money)
112
+
113
+ case action
114
+ when :sale
115
+ parameters[:action] = "ns_quicksale_cc"
116
+ when :authonly
117
+ parameters[:action] = "ns_quicksale_cc"
118
+ parameters[:authonly] = 1
119
+ when :capture
120
+ parameters[:action] = "ns_quicksale_cc"
121
+ end
122
+
123
+ response = parse(ssl_post(URL, parameters.to_post_data) || "")
124
+ Response.new(successful?(response), message_from(response), response,
125
+ :test => test?,
126
+ :authorization => response["refcode"]
127
+ )
128
+ end
129
+
130
+ def successful?(response)
131
+ response["Status"] == "Accepted"
132
+ end
133
+
134
+ def message_from(response)
135
+ if successful?(response)
136
+ "Accepted"
137
+ else
138
+ response["Reason"].split(":")[2].capitalize unless response["Reason"].nil?
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end
144
+
@@ -0,0 +1,330 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class SecureNetGateway < Gateway
4
+
5
+ API_VERSION = "4.0"
6
+
7
+ TRANSACTIONS = {
8
+ :auth_only => "0000", #
9
+ :partial_auth_only => "0001",
10
+ :auth_capture => "0100", #
11
+ :partial_auth_capture => "0101",
12
+ :prior_auth_capture => "0200",
13
+ :capture_only => "0300", #
14
+ :void => "0400", #
15
+ :partial_void => "0401",
16
+ :credit => "0500", #
17
+ :credit_authonly => "0501",
18
+ :credit_priorauthcapture => "0502",
19
+ :force_credit => "0600",
20
+ :force_credit_authonly => "0601",
21
+ :force_credit_priorauthcapture => "0602",
22
+ :verification => "0700",
23
+ :auth_increment => "0800",
24
+ :issue => "0900",
25
+ :activate => "0901",
26
+ :redeem => "0902",
27
+ :redeem_partial => "0903",
28
+ :deactivate => "0904",
29
+ :reactivate => "0905",
30
+ :inquiry_balance => "0906"
31
+ }
32
+
33
+ XML_ATTRIBUTES = { 'xmlns' => "http://gateway.securenet.com/API/Contracts",
34
+ 'xmlns:i' => "http://www.w3.org/2001/XMLSchema-instance"
35
+ }
36
+ NIL_ATTRIBUTE = { 'i:nil' => "true" }
37
+
38
+ # SUCCESS = "true"
39
+ # SENSITIVE_FIELDS = [ :verification_str2, :expiry_date, :card_number ]
40
+
41
+ self.supported_countries = ['US']
42
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
43
+ self.homepage_url = 'http://www.securenet.com/'
44
+ self.display_name = 'SecureNet'
45
+ # self.wiredump_device = STDOUT
46
+
47
+ # TEST_URL = 'https://certify.securenet.com/api/Gateway.svc'
48
+ TEST_URL = 'https://certify.securenet.com/API/gateway.svc/webHttp/ProcessTransaction'
49
+ LIVE_URL = 'https://gateway.securenet.com/api/Gateway.svc'
50
+
51
+ APPROVED, DECLINED, ERROR = 1, 2, 3
52
+
53
+ RESPONSE_CODE, RESPONSE_REASON_CODE, RESPONSE_REASON_TEXT = 0, 2, 3
54
+ AVS_RESULT_CODE, CARD_CODE_RESPONSE_CODE, TRANSACTION_ID = 5, 6, 8
55
+
56
+ CARD_CODE_ERRORS = %w( N S )
57
+ AVS_ERRORS = %w( A E N R W Z )
58
+
59
+ def initialize(options = {})
60
+ requires!(options, :login, :password)
61
+ @options = options
62
+ super
63
+ end
64
+
65
+ def authorize(money, creditcard, options = {})
66
+ commit(build_sale_or_authorization_request(creditcard, options, :auth_only), money)
67
+ end
68
+
69
+ def purchase(money, creditcard, options = {})
70
+ commit(build_sale_or_authorization_request(creditcard, options, :auth_capture), money)
71
+ end
72
+
73
+ def capture(money, creditcard, authorization, options = {})
74
+ commit(build_capture_request(authorization, creditcard, options, :prior_auth_capture), money)
75
+ end
76
+
77
+ def void(money, creditcard, authorization, options = {})
78
+ commit(build_void_request(authorization, creditcard, options, :void), money)
79
+ end
80
+
81
+ def credit(money, creditcard, authorization, options = {})
82
+ commit(build_credit_request(authorization, creditcard, options, :credit), money)
83
+ end
84
+
85
+ private
86
+ def commit(request, money)
87
+ xml = build_request(request, money)
88
+ data = ssl_post(TEST_URL, xml, "Content-Type" => "text/xml")
89
+ response = parse(data)
90
+
91
+ test_mode = test?
92
+ Response.new(success?(response), message_from(response), response,
93
+ :test => test_mode,
94
+ :authorization => response[:transactionid],
95
+ :avs_result => { :code => response[:avs_result_code] },
96
+ :cvv_result => response[:card_code_response_code]
97
+ )
98
+ end
99
+
100
+ def build_request(request, money)
101
+ xml = Builder::XmlMarkup.new
102
+
103
+ xml.instruct!
104
+ xml.tag!("TRANSACTION", XML_ATTRIBUTES) do
105
+ xml.tag! 'AMOUNT', amount(money)
106
+ xml << request
107
+ end
108
+
109
+ xml.target!
110
+ end
111
+
112
+ def build_sale_or_authorization_request(creditcard, options, action)
113
+ xml = Builder::XmlMarkup.new
114
+
115
+ add_credit_card(xml, creditcard)
116
+ xml.tag! 'CODE', TRANSACTIONS[action]
117
+ add_customer_data(xml, options)
118
+ add_address(xml, creditcard, options)
119
+ xml.tag! 'DCI', 0 # No duplicate checking will be done, except for ORDERID
120
+ xml.tag! 'INSTALLMENT_SEQUENCENUM', 1
121
+ add_invoice(xml, options)
122
+ add_merchant_key(xml, options)
123
+ xml.tag! 'METHOD', 'CC'
124
+ xml.tag! 'ORDERID', options[:order_id]#'30'.to_i.to_s#'22'# @options[:order_id]
125
+ xml.tag! 'OVERRIDE_FROM', 0 # Docs say not required, but doesn't work without it
126
+ xml.tag! 'RETAIL_LANENUM', '0' # Docs say string, but it's an integer!?
127
+ xml.tag! 'TEST', 'TRUE'
128
+ xml.tag! 'TOTAL_INSTALLMENTCOUNT', 0
129
+ xml.tag! 'TRANSACTION_SERVICE', 0
130
+
131
+ xml.target!
132
+ end
133
+
134
+ def build_capture_or_credit_request(identification, options)
135
+ xml = Builder::XmlMarkup.new
136
+
137
+ add_identification(xml, identification)
138
+ add_customer_data(xml, options)
139
+
140
+ xml.target!
141
+ end
142
+
143
+ def build_capture_request(authorization, creditcard, options, action)
144
+ xml = Builder::XmlMarkup.new
145
+
146
+ add_credit_card(xml, creditcard)
147
+ xml.tag! 'CODE', TRANSACTIONS[action]
148
+ add_customer_data(xml, options)
149
+ xml.tag! 'DCI', 0 # No duplicate checking will be done, except for ORDERID
150
+ xml.tag! 'INSTALLMENT_SEQUENCENUM', 1
151
+ add_merchant_key(xml, options)
152
+ xml.tag! 'METHOD', 'CC'
153
+ xml.tag! 'ORDERID', options[:order_id]#'30'.to_i.to_s#'22'# @options[:order_id]
154
+ xml.tag! 'OVERRIDE_FROM', 0 # Docs say not required, but doesn't work without it
155
+ xml.tag! 'REF_TRANSID', authorization
156
+ xml.tag! 'RETAIL_LANENUM', '0' # Docs say string, but it's an integer!?
157
+ xml.tag! 'TEST', 'TRUE'
158
+ xml.tag! 'TOTAL_INSTALLMENTCOUNT', 0
159
+ xml.tag! 'TRANSACTION_SERVICE', 0
160
+
161
+ xml.target!
162
+ end
163
+
164
+ def build_credit_request(authorization, creditcard, options, action)
165
+ # requires!(options, :card_number)
166
+ xml = Builder::XmlMarkup.new
167
+
168
+ add_credit_card(xml, creditcard)
169
+ xml.tag! 'CODE', TRANSACTIONS[action]
170
+ add_customer_data(xml, options)
171
+ xml.tag! 'DCI', 0 # No duplicate checking will be done, except for ORDERID
172
+ xml.tag! 'INSTALLMENT_SEQUENCENUM', 1
173
+ add_merchant_key(xml, options)
174
+ xml.tag! 'METHOD', 'CC'
175
+ xml.tag! 'ORDERID', options[:order_id]#'30'.to_i.to_s#'22'# @options[:order_id]
176
+ xml.tag! 'OVERRIDE_FROM', 0 # Docs say not required, but doesn't work without it
177
+ xml.tag! 'REF_TRANSID', authorization
178
+ xml.tag! 'RETAIL_LANENUM', '0' # Docs say string, but it's an integer!?
179
+ xml.tag! 'TEST', 'TRUE'
180
+ xml.tag! 'TOTAL_INSTALLMENTCOUNT', 0
181
+ xml.tag! 'TRANSACTION_SERVICE', 0
182
+
183
+ xml.target!
184
+ end
185
+
186
+ def build_void_request(authorization, creditcard, options, action)
187
+ xml = Builder::XmlMarkup.new
188
+
189
+ add_credit_card(xml, creditcard)
190
+ xml.tag! 'CODE', TRANSACTIONS[action]
191
+ add_customer_data(xml, options)
192
+ xml.tag! 'DCI', 0 # No duplicate checking will be done, except for ORDERID
193
+ xml.tag! 'INSTALLMENT_SEQUENCENUM', 1
194
+ add_merchant_key(xml, options)
195
+ xml.tag! 'METHOD', 'CC'
196
+ xml.tag! 'ORDERID', options[:order_id]#'30'.to_i.to_s#'22'# @options[:order_id]
197
+ xml.tag! 'OVERRIDE_FROM', 0 # Docs say not required, but doesn't work without it
198
+ xml.tag! 'REF_TRANSID', authorization
199
+ xml.tag! 'RETAIL_LANENUM', '0' # Docs say string, but it's an integer!?
200
+ xml.tag! 'TEST', 'TRUE'
201
+ xml.tag! 'TOTAL_INSTALLMENTCOUNT', 0
202
+ xml.tag! 'TRANSACTION_SERVICE', 0
203
+
204
+ xml.target!
205
+ end
206
+
207
+ #########################################################################
208
+ # FUNCTIONS RELATED TO BUILDING THE XML
209
+ #########################################################################
210
+ def add_credit_card(xml, creditcard)
211
+ xml.tag!("CARD") do
212
+ xml.tag! 'CARDCODE', creditcard.verification_value if creditcard.verification_value?
213
+ xml.tag! 'CARDNUMBER', creditcard.number
214
+ xml.tag! 'EXPDATE', expdate(creditcard)
215
+ end
216
+ end
217
+
218
+ def expdate(creditcard)
219
+ year = sprintf("%.4i", creditcard.year)
220
+ month = sprintf("%.2i", creditcard.month)
221
+
222
+ "#{month}#{year[-2..-1]}"
223
+ end
224
+
225
+ def add_customer_data(xml, options)
226
+ if options.has_key? :customer
227
+ xml.tag! 'CUSTOMERID', options[:customer]
228
+ end
229
+
230
+ if options.has_key? :ip
231
+ xml.tag! 'CUSTOMERIP', options[:ip]
232
+ end
233
+ end
234
+
235
+ def add_address(xml, creditcard, options)
236
+
237
+ if address = options[:billing_address] || options[:address]
238
+ xml.tag!("CUSTOMER_BILL") do
239
+ xml.tag! 'ADDRESS', address[:address1].to_s
240
+ xml.tag! 'CITY', address[:city].to_s
241
+ xml.tag! 'COMPANY', address[:company].to_s
242
+ xml.tag! 'COUNTRY', address[:country].to_s
243
+ if options.has_key? :email
244
+ xml.tag! 'EMAIL', options[:email]
245
+ # xml.tag! 'EMAIL', 'myemail@yahoo.com'
246
+ xml.tag! 'EMAILRECEIPT', 'FALSE'
247
+ end
248
+ xml.tag! 'FIRSTNAME', creditcard.first_name
249
+ xml.tag! 'LASTNAME', creditcard.last_name
250
+ xml.tag! 'PHONE', address[:phone].to_s
251
+ xml.tag! 'STATE', address[:state].blank? ? 'n/a' : address[:state]
252
+ xml.tag! 'ZIP', address[:zip].to_s
253
+ end
254
+ end
255
+
256
+ if address = options[:shipping_address]
257
+ xml.tag!("CUSTOMER_SHIP") do
258
+ xml.tag! 'ADDRESS', address[:address1].to_s
259
+ xml.tag! 'CITY', address[:city].to_s
260
+ xml.tag! 'COMPANY', address[:company].to_s
261
+ xml.tag! 'COUNTRY', address[:country].to_s
262
+ xml.tag! 'FIRSTNAME', address[:first_name].to_s
263
+ xml.tag! 'LASTNAME', address[:last_name].to_s
264
+ xml.tag! 'STATE', address[:state].blank? ? 'n/a' : address[:state]
265
+ xml.tag! 'ZIP', address[:zip].to_s
266
+ end
267
+ else
268
+ xml.tag!('CUSTOMER_SHIP', NIL_ATTRIBUTE) do
269
+ end
270
+ end
271
+
272
+ end
273
+
274
+ def add_invoice(xml, options)
275
+ xml.tag! 'INVOICEDESC', options[:description]
276
+ xml.tag! 'INVOICENUM', 'inv-8'
277
+ end
278
+
279
+ def add_merchant_key(xml, options)
280
+ xml.tag!("MERCHANT_KEY") do
281
+ xml.tag! 'GROUPID', 0
282
+ xml.tag! 'SECUREKEY', @options[:password]
283
+ xml.tag! 'SECURENETID', @options[:login]
284
+ end
285
+ end
286
+
287
+ #########################################################################
288
+ # FUNCTIONS RELATED TO THE RESPONSE
289
+ #########################################################################
290
+ def success?(response)
291
+ response[:response_code].to_i == APPROVED
292
+ end
293
+
294
+ def message_from(response)
295
+ if response[:response_code].to_i == DECLINED
296
+ return CVVResult.messages[ response[:card_code_response_code] ] if CARD_CODE_ERRORS.include?(response[:card_code_response_code])
297
+ return AVSResult.messages[ response[:avs_result_code] ] if AVS_ERRORS.include?(response[:avs_result_code])
298
+ end
299
+
300
+ return response[:response_reason_text].nil? ? '' : response[:response_reason_text][0..-1]
301
+ end
302
+
303
+ def parse(xml)
304
+ response = {}
305
+ xml = REXML::Document.new(xml)
306
+ root = REXML::XPath.first(xml, "//GATEWAYRESPONSE")# ||
307
+ # root = REXML::XPath.first(xml, "//ProcessTransactionResponse")# ||
308
+ # REXML::XPath.first(xml, "//ErrorResponse")
309
+ if root
310
+ root.elements.to_a.each do |node|
311
+ recurring_parse_element(response, node)
312
+ end
313
+ end
314
+
315
+ response
316
+ end
317
+
318
+ def recurring_parse_element(response, node)
319
+ if node.has_elements?
320
+ node.elements.each{|e| recurring_parse_element(response, e) }
321
+ else
322
+ response[node.name.underscore.to_sym] = node.text
323
+ end
324
+ end
325
+
326
+
327
+ end
328
+ end
329
+ end
330
+