tlconnor-activemerchant 1.20.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (195) hide show
  1. data/CHANGELOG +805 -0
  2. data/CONTRIBUTORS +274 -0
  3. data/MIT-LICENSE +20 -0
  4. data/gem-public_cert.pem +20 -0
  5. data/lib/active_merchant.rb +63 -0
  6. data/lib/active_merchant/billing.rb +9 -0
  7. data/lib/active_merchant/billing/avs_result.rb +98 -0
  8. data/lib/active_merchant/billing/base.rb +57 -0
  9. data/lib/active_merchant/billing/check.rb +68 -0
  10. data/lib/active_merchant/billing/credit_card.rb +264 -0
  11. data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
  12. data/lib/active_merchant/billing/credit_card_methods.rb +129 -0
  13. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  14. data/lib/active_merchant/billing/expiry_date.rb +34 -0
  15. data/lib/active_merchant/billing/gateway.rb +170 -0
  16. data/lib/active_merchant/billing/gateways.rb +18 -0
  17. data/lib/active_merchant/billing/gateways/authorize_net.rb +694 -0
  18. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +944 -0
  19. data/lib/active_merchant/billing/gateways/barclays_epdq.rb +308 -0
  20. data/lib/active_merchant/billing/gateways/beanstream.rb +167 -0
  21. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +388 -0
  22. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  23. data/lib/active_merchant/billing/gateways/blue_pay.rb +11 -0
  24. data/lib/active_merchant/billing/gateways/bogus.rb +142 -0
  25. data/lib/active_merchant/billing/gateways/braintree.rb +17 -0
  26. data/lib/active_merchant/billing/gateways/braintree/braintree_common.rb +9 -0
  27. data/lib/active_merchant/billing/gateways/braintree_blue.rb +308 -0
  28. data/lib/active_merchant/billing/gateways/braintree_orange.rb +21 -0
  29. data/lib/active_merchant/billing/gateways/card_save.rb +23 -0
  30. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  31. data/lib/active_merchant/billing/gateways/certo_direct.rb +279 -0
  32. data/lib/active_merchant/billing/gateways/cyber_source.rb +430 -0
  33. data/lib/active_merchant/billing/gateways/data_cash.rb +597 -0
  34. data/lib/active_merchant/billing/gateways/efsnet.rb +235 -0
  35. data/lib/active_merchant/billing/gateways/elavon.rb +135 -0
  36. data/lib/active_merchant/billing/gateways/epay.rb +274 -0
  37. data/lib/active_merchant/billing/gateways/eway.rb +277 -0
  38. data/lib/active_merchant/billing/gateways/eway_managed.rb +265 -0
  39. data/lib/active_merchant/billing/gateways/exact.rb +227 -0
  40. data/lib/active_merchant/billing/gateways/federated_canada.rb +168 -0
  41. data/lib/active_merchant/billing/gateways/first_pay.rb +177 -0
  42. data/lib/active_merchant/billing/gateways/garanti.rb +262 -0
  43. data/lib/active_merchant/billing/gateways/ideal/ideal_base.rb +250 -0
  44. data/lib/active_merchant/billing/gateways/ideal/ideal_rabobank.pem +13 -0
  45. data/lib/active_merchant/billing/gateways/ideal/ideal_response.rb +29 -0
  46. data/lib/active_merchant/billing/gateways/ideal_rabobank.rb +55 -0
  47. data/lib/active_merchant/billing/gateways/inspire.rb +221 -0
  48. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  49. data/lib/active_merchant/billing/gateways/iridium.rb +258 -0
  50. data/lib/active_merchant/billing/gateways/jetpay.rb +276 -0
  51. data/lib/active_merchant/billing/gateways/linkpoint.rb +454 -0
  52. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +157 -0
  53. data/lib/active_merchant/billing/gateways/merchant_ware.rb +289 -0
  54. data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
  55. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +220 -0
  56. data/lib/active_merchant/billing/gateways/moneris.rb +239 -0
  57. data/lib/active_merchant/billing/gateways/nab_transact.rb +244 -0
  58. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  59. data/lib/active_merchant/billing/gateways/netaxept.rb +239 -0
  60. data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
  61. data/lib/active_merchant/billing/gateways/nmi.rb +13 -0
  62. data/lib/active_merchant/billing/gateways/ogone.rb +330 -0
  63. data/lib/active_merchant/billing/gateways/optimal_payment.rb +277 -0
  64. data/lib/active_merchant/billing/gateways/orbital.rb +344 -0
  65. data/lib/active_merchant/billing/gateways/orbital/orbital_soft_descriptors.rb +46 -0
  66. data/lib/active_merchant/billing/gateways/pay_junction.rb +397 -0
  67. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  68. data/lib/active_merchant/billing/gateways/paybox_direct.rb +207 -0
  69. data/lib/active_merchant/billing/gateways/payflow.rb +261 -0
  70. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +208 -0
  71. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +39 -0
  72. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +13 -0
  73. data/lib/active_merchant/billing/gateways/payflow_express.rb +222 -0
  74. data/lib/active_merchant/billing/gateways/payflow_express_uk.rb +15 -0
  75. data/lib/active_merchant/billing/gateways/payflow_uk.rb +21 -0
  76. data/lib/active_merchant/billing/gateways/payment_express.rb +235 -0
  77. data/lib/active_merchant/billing/gateways/paypal.rb +121 -0
  78. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +354 -0
  79. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +49 -0
  80. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  81. data/lib/active_merchant/billing/gateways/paypal_express.rb +229 -0
  82. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +25 -0
  83. data/lib/active_merchant/billing/gateways/paystation.rb +201 -0
  84. data/lib/active_merchant/billing/gateways/plugnpay.rb +298 -0
  85. data/lib/active_merchant/billing/gateways/psigate.rb +219 -0
  86. data/lib/active_merchant/billing/gateways/psl_card.rb +304 -0
  87. data/lib/active_merchant/billing/gateways/qbms.rb +297 -0
  88. data/lib/active_merchant/billing/gateways/quantum.rb +282 -0
  89. data/lib/active_merchant/billing/gateways/quickpay.rb +298 -0
  90. data/lib/active_merchant/billing/gateways/realex.rb +315 -0
  91. data/lib/active_merchant/billing/gateways/sage.rb +146 -0
  92. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  93. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +116 -0
  94. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  95. data/lib/active_merchant/billing/gateways/sage_pay.rb +320 -0
  96. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  97. data/lib/active_merchant/billing/gateways/samurai.rb +121 -0
  98. data/lib/active_merchant/billing/gateways/secure_net.rb +330 -0
  99. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  100. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +280 -0
  101. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  102. data/lib/active_merchant/billing/gateways/skip_jack.rb +458 -0
  103. data/lib/active_merchant/billing/gateways/smart_ps.rb +271 -0
  104. data/lib/active_merchant/billing/gateways/stripe.rb +244 -0
  105. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  106. data/lib/active_merchant/billing/gateways/transax.rb +25 -0
  107. data/lib/active_merchant/billing/gateways/trust_commerce.rb +423 -0
  108. data/lib/active_merchant/billing/gateways/usa_epay.rb +23 -0
  109. data/lib/active_merchant/billing/gateways/usa_epay_advanced.rb +1496 -0
  110. data/lib/active_merchant/billing/gateways/usa_epay_transaction.rb +206 -0
  111. data/lib/active_merchant/billing/gateways/verifi.rb +233 -0
  112. data/lib/active_merchant/billing/gateways/viaklix.rb +189 -0
  113. data/lib/active_merchant/billing/gateways/wirecard.rb +318 -0
  114. data/lib/active_merchant/billing/gateways/worldpay.rb +280 -0
  115. data/lib/active_merchant/billing/integrations.rb +17 -0
  116. data/lib/active_merchant/billing/integrations/action_view_helper.rb +72 -0
  117. data/lib/active_merchant/billing/integrations/authorize_net_sim.rb +38 -0
  118. data/lib/active_merchant/billing/integrations/authorize_net_sim/helper.rb +228 -0
  119. data/lib/active_merchant/billing/integrations/authorize_net_sim/notification.rb +340 -0
  120. data/lib/active_merchant/billing/integrations/bogus.rb +23 -0
  121. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  122. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  123. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  124. data/lib/active_merchant/billing/integrations/chronopay.rb +23 -0
  125. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +120 -0
  126. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +158 -0
  127. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  128. data/lib/active_merchant/billing/integrations/direc_pay.rb +41 -0
  129. data/lib/active_merchant/billing/integrations/direc_pay/helper.rb +200 -0
  130. data/lib/active_merchant/billing/integrations/direc_pay/notification.rb +76 -0
  131. data/lib/active_merchant/billing/integrations/direc_pay/return.rb +32 -0
  132. data/lib/active_merchant/billing/integrations/direc_pay/status.rb +37 -0
  133. data/lib/active_merchant/billing/integrations/directebanking.rb +47 -0
  134. data/lib/active_merchant/billing/integrations/directebanking/helper.rb +90 -0
  135. data/lib/active_merchant/billing/integrations/directebanking/notification.rb +120 -0
  136. data/lib/active_merchant/billing/integrations/directebanking/return.rb +11 -0
  137. data/lib/active_merchant/billing/integrations/dwolla.rb +30 -0
  138. data/lib/active_merchant/billing/integrations/dwolla/helper.rb +31 -0
  139. data/lib/active_merchant/billing/integrations/dwolla/notification.rb +55 -0
  140. data/lib/active_merchant/billing/integrations/dwolla/return.rb +38 -0
  141. data/lib/active_merchant/billing/integrations/e_payment_plans.rb +48 -0
  142. data/lib/active_merchant/billing/integrations/e_payment_plans/helper.rb +34 -0
  143. data/lib/active_merchant/billing/integrations/e_payment_plans/notification.rb +84 -0
  144. data/lib/active_merchant/billing/integrations/gestpay.rb +25 -0
  145. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  146. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  147. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +85 -0
  148. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  149. data/lib/active_merchant/billing/integrations/helper.rb +113 -0
  150. data/lib/active_merchant/billing/integrations/hi_trust.rb +27 -0
  151. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  152. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  153. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  154. data/lib/active_merchant/billing/integrations/moneybookers.rb +26 -0
  155. data/lib/active_merchant/billing/integrations/moneybookers/helper.rb +59 -0
  156. data/lib/active_merchant/billing/integrations/moneybookers/notification.rb +129 -0
  157. data/lib/active_merchant/billing/integrations/nochex.rb +88 -0
  158. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  159. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  160. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  161. data/lib/active_merchant/billing/integrations/notification.rb +62 -0
  162. data/lib/active_merchant/billing/integrations/payflow_link.rb +21 -0
  163. data/lib/active_merchant/billing/integrations/payflow_link/helper.rb +100 -0
  164. data/lib/active_merchant/billing/integrations/payflow_link/notification.rb +78 -0
  165. data/lib/active_merchant/billing/integrations/paypal.rb +39 -0
  166. data/lib/active_merchant/billing/integrations/paypal/helper.rb +119 -0
  167. data/lib/active_merchant/billing/integrations/paypal/notification.rb +154 -0
  168. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  169. data/lib/active_merchant/billing/integrations/quickpay.rb +21 -0
  170. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +72 -0
  171. data/lib/active_merchant/billing/integrations/quickpay/notification.rb +74 -0
  172. data/lib/active_merchant/billing/integrations/return.rb +42 -0
  173. data/lib/active_merchant/billing/integrations/sage_pay_form.rb +37 -0
  174. data/lib/active_merchant/billing/integrations/sage_pay_form/encryption.rb +33 -0
  175. data/lib/active_merchant/billing/integrations/sage_pay_form/helper.rb +127 -0
  176. data/lib/active_merchant/billing/integrations/sage_pay_form/notification.rb +210 -0
  177. data/lib/active_merchant/billing/integrations/sage_pay_form/return.rb +31 -0
  178. data/lib/active_merchant/billing/integrations/two_checkout.rb +22 -0
  179. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +59 -0
  180. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +114 -0
  181. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  182. data/lib/active_merchant/billing/integrations/valitor.rb +33 -0
  183. data/lib/active_merchant/billing/integrations/valitor/helper.rb +86 -0
  184. data/lib/active_merchant/billing/integrations/valitor/notification.rb +13 -0
  185. data/lib/active_merchant/billing/integrations/valitor/response_fields.rb +97 -0
  186. data/lib/active_merchant/billing/integrations/valitor/return.rb +13 -0
  187. data/lib/active_merchant/billing/integrations/world_pay.rb +27 -0
  188. data/lib/active_merchant/billing/integrations/world_pay/helper.rb +100 -0
  189. data/lib/active_merchant/billing/integrations/world_pay/notification.rb +160 -0
  190. data/lib/active_merchant/billing/response.rb +32 -0
  191. data/lib/active_merchant/version.rb +3 -0
  192. data/lib/activemerchant.rb +1 -0
  193. data/lib/support/gateway_support.rb +58 -0
  194. data/lib/support/outbound_hosts.rb +25 -0
  195. metadata +411 -0
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/smart_ps.rb'
2
+ require File.dirname(__FILE__) + '/braintree/braintree_common'
3
+
4
+ module ActiveMerchant #:nodoc:
5
+ module Billing #:nodoc:
6
+ class BraintreeOrangeGateway < SmartPs
7
+ include BraintreeCommon
8
+
9
+ self.display_name = 'Braintree (Orange Platform)'
10
+
11
+ def api_url
12
+ 'https://secure.braintreepaymentgateway.com/api/transact.php'
13
+ end
14
+
15
+ def add_processor(post, options)
16
+ post[:processor_id] = options[:processor] unless options[:processor].nil?
17
+ end
18
+ end
19
+ end
20
+ end
21
+
@@ -0,0 +1,23 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class CardSaveGateway < IridiumGateway
4
+ #CardSave lets you handle failovers on payments by providing 3 gateways in case one happens to be down
5
+ #URLS = ['https://gw1.cardsaveonlinepayments.com:4430/','https://gw2.cardsaveonlinepayments.com:4430/','https://gw3.cardsaveonlinepayments.com:4430/']
6
+
7
+ self.money_format = :cents
8
+ self.default_currency = 'GBP'
9
+ self.supported_cardtypes = [ :visa, :switch, :maestro, :master, :solo, :american_express, :jcb ]
10
+ self.supported_countries = [ 'GB' ]
11
+ self.homepage_url = 'http://www.cardsave.net/'
12
+ self.display_name = 'CardSave'
13
+
14
+ def initialize(options={})
15
+ super
16
+ @test_url = 'https://gw1.cardsaveonlinepayments.com:4430/'
17
+ @live_url = 'https://gw1.cardsaveonlinepayments.com:4430/'
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+
@@ -0,0 +1,230 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ #
4
+ # CardStream supports the following credit cards, which are auto-detected by
5
+ # the gateway based on the card number used:
6
+ # * AM American Express
7
+ # * Diners Club
8
+ # * Electron
9
+ # * JCB
10
+ # * UK Maestro
11
+ # * Maestro International
12
+ # * Mastercard
13
+ # * Solo
14
+ # * Style
15
+ # * Switch
16
+ # * Visa Credit
17
+ # * Visa Debit
18
+ # * Visa Purchasing
19
+ #
20
+ class CardStreamGateway < Gateway
21
+ URL = 'https://gateway.cardstream.com/process.ashx'
22
+
23
+ self.money_format = :cents
24
+ self.default_currency = 'GBP'
25
+ self.supported_countries = ['GB']
26
+ self.supported_cardtypes = [:visa, :master, :american_express, :diners_club, :discover, :jcb, :maestro, :solo, :switch]
27
+ self.homepage_url = 'http://www.cardstream.com/'
28
+ self.display_name = 'CardStream'
29
+
30
+ APPROVED = '00'
31
+
32
+ CURRENCY_CODES = {
33
+ "AUD"=> '036',
34
+ "CAD"=> '124',
35
+ "CZK"=> '203',
36
+ "DKK"=> '208',
37
+ "HKD"=> '344',
38
+ "ICK"=> '352',
39
+ "JPY"=> '392',
40
+ "NOK"=> '578',
41
+ "SGD"=> '702',
42
+ "SEK"=> '752',
43
+ "CHF"=> '756',
44
+ "GBP"=> '826',
45
+ "USD"=> '840',
46
+ "EUR"=> '978'
47
+ }
48
+
49
+ TRANSACTIONS = {
50
+ :purchase => 'ESALE_KEYED',
51
+ :refund => 'EREFUND_KEYED',
52
+ :authorization => 'ESALE_KEYED'
53
+ }
54
+
55
+ CVV_CODE = {
56
+ '0' => 'U',
57
+ '1' => 'P',
58
+ '2' => 'M',
59
+ '4' => 'N'
60
+ }
61
+
62
+ # 0 - No additional information available.
63
+ # 1 - Postcode not checked.
64
+ # 2 - Postcode matched.
65
+ # 4 - Postcode not matched.
66
+ # 8 - Postcode partially matched.
67
+ AVS_POSTAL_MATCH = {
68
+ "0" => nil,
69
+ "1" => nil,
70
+ "2" => "Y",
71
+ "4" => "N",
72
+ "8" => "N"
73
+ }
74
+
75
+ # 0 - No additional information available.
76
+ # 1 - Address numeric not checked.
77
+ # 2 - Address numeric matched.
78
+ # 4 - Address numeric not matched.
79
+ # 8 - Address numeric partially matched.
80
+ AVS_STREET_MATCH = {
81
+ "0" => nil,
82
+ "1" => nil,
83
+ "2" => "Y",
84
+ "4" => "N",
85
+ "8" => "N"
86
+ }
87
+
88
+ def initialize(options = {})
89
+ requires!(options, :login, :password)
90
+ @options = options
91
+ super
92
+ end
93
+
94
+ def purchase(money, credit_card, options = {})
95
+ requires!(options, :order_id)
96
+
97
+ post = {}
98
+
99
+ add_amount(post, money, options)
100
+ add_invoice(post, money, credit_card, options)
101
+ add_credit_card(post, credit_card)
102
+ add_address(post, options)
103
+ add_customer_data(post, options)
104
+
105
+ commit(:purchase, post)
106
+ end
107
+
108
+ private
109
+
110
+ def add_amount(post, money, options)
111
+ add_pair(post, :Amount, amount(money), :required => true)
112
+ add_pair(post, :CurrencyCode, currency_code(options[:currency] || currency(money)), :required => true)
113
+ end
114
+
115
+ def add_customer_data(post, options)
116
+ add_pair(post, :BillingEmail, options[:email])
117
+ add_pair(post, :BillingPhoneNumber, options[:phone])
118
+ end
119
+
120
+ def add_address(post, options)
121
+ address = options[:billing_address] || options[:address]
122
+
123
+ return if address.nil?
124
+
125
+ add_pair(post, :BillingStreet, address[:address1])
126
+ add_pair(post, :BillingHouseNumber, address[:address2])
127
+ add_pair(post, :BillingCity, address[:city])
128
+ add_pair(post, :BillingState, address[:state])
129
+ add_pair(post, :BillingPostCode, address[:zip])
130
+ end
131
+
132
+ def add_invoice(post, money, credit_card, options)
133
+ add_pair(post, :TransactionUnique, options[:order_id], :required => true)
134
+ add_pair(post, :OrderDesc, options[:description] || options[:order_id], :required => true)
135
+
136
+ if [ 'american_express', 'diners_club' ].include?(card_brand(credit_card).to_s)
137
+ add_pair(post, :AEIT1Quantity, 1)
138
+ add_pair(post, :AEIT1Description, (options[:description] || options[:order_id]).slice(0, 15))
139
+ add_pair(post, :AEIT1GrossValue, amount(money))
140
+ end
141
+ end
142
+
143
+ def add_credit_card(post, credit_card)
144
+ add_pair(post, :CardName, credit_card.name, :required => true)
145
+ add_pair(post, :CardNumber, credit_card.number, :required => true)
146
+
147
+ add_pair(post, :ExpiryDateMM, format(credit_card.month, :two_digits), :required => true)
148
+ add_pair(post, :ExpiryDateYY, format(credit_card.year, :two_digits), :required => true)
149
+
150
+ if requires_start_date_or_issue_number?(credit_card)
151
+ add_pair(post, :StartDateMM, format(credit_card.start_month, :two_digits))
152
+ add_pair(post, :StartDateYY, format(credit_card.start_year, :two_digits))
153
+
154
+ add_pair(post, :IssueNumber, credit_card.issue_number)
155
+ end
156
+
157
+ add_pair(post, :CV2, credit_card.verification_value)
158
+ end
159
+
160
+ def commit(action, parameters)
161
+ response = parse( ssl_post(URL, post_data(action, parameters)) )
162
+
163
+ Response.new(response[:response_code] == APPROVED, message_from(response), response,
164
+ :test => test?,
165
+ :authorization => response[:cross_reference],
166
+ :cvv_result => CVV_CODE[ response[:avscv2_response_code].to_s[0, 1] ],
167
+ :avs_result => {
168
+ :street_match => AVS_STREET_MATCH[ response[:avscv2_response_code].to_s[2, 1] ],
169
+ :postal_match => AVS_POSTAL_MATCH[ response[:avscv2_response_code].to_s[1, 1] ]
170
+ }
171
+ )
172
+ end
173
+
174
+ def message_from(results)
175
+ results[:response_code] == APPROVED ? "APPROVED" : results[:message]
176
+ end
177
+
178
+ def post_data(action, parameters = {})
179
+ parameters.update(
180
+ :MerchantPassword => @options[:password],
181
+ :MerchantID => @options[:login],
182
+ :MessageType => TRANSACTIONS[action],
183
+ :CallBack => "disable",
184
+ :DuplicateDelay => "0",
185
+ :EchoCardType => "YES",
186
+ :EchoAmount => "YES",
187
+ :EchoAVSCV2ResponseCode => "YES",
188
+ :ReturnAVSCV2Message => "YES",
189
+ :CountryCode => '826' # 826 for UK based merchant
190
+ )
191
+
192
+ add_pair(parameters, :Dispatch, action == :authorization ? "LATER" : "NOW")
193
+
194
+ parameters.collect { |key, value| "VP#{key}=#{CGI.escape(value.to_s)}" }.join("&")
195
+ end
196
+
197
+ # VPCrossReference
198
+ # The value in VPCrossReference on a success transaction will contain
199
+ # a unique reference that you may use to run future transactions.
200
+ # Please note that cross reference transactions must come a static IP
201
+ # addressed that has been pre-registered with Cardstream. To
202
+ # register an IP address please send it to support@cardstream.com
203
+ # with your Cardstream issued merchant ID and it will be added to
204
+ # your account.
205
+ def parse(body)
206
+ result = {}
207
+ pairs = body.split("&")
208
+ pairs.each do |pair|
209
+ a = pair.split("=")
210
+ result[a[0].gsub(/^VP/,'').underscore.to_sym] = a[1]
211
+ end
212
+
213
+ result
214
+ end
215
+
216
+ def test?
217
+ @options[:test] || Base.gateway_mode == :test
218
+ end
219
+
220
+ def currency_code(currency)
221
+ CURRENCY_CODES[currency]
222
+ end
223
+
224
+ def add_pair(post, key, value, options = {})
225
+ post[key] = value if !value.blank? || options[:required]
226
+ end
227
+ end
228
+ end
229
+ end
230
+
@@ -0,0 +1,279 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class CertoDirectGateway < Gateway
4
+ class_attribute :gateway_url
5
+ self.gateway_url = "https://secure.certodirect.com/gateway/process/v2"
6
+
7
+ self.supported_countries = [
8
+ "BE", "BG", "CZ", "DK", "DE", "EE", "IE", "EL", "ES", "FR",
9
+ "IT", "CY", "LV", "LT", "LU", "HU", "MT", "NL", "AT", "PL",
10
+ "PT", "RO", "SI", "SK", "FI", "SE", "UK"
11
+ ]
12
+
13
+ self.supported_cardtypes = [:visa, :master, :american_express, :discover]
14
+ self.homepage_url = 'http://www.certodirect.com/'
15
+ self.display_name = 'CertoDirect'
16
+
17
+ # Creates a new CertoDirectGateway
18
+ #
19
+ # The gateway requires that a valid login and password be passed
20
+ # in the +options+ hash.
21
+ #
22
+ # ==== Options
23
+ #
24
+ # * <tt>:login</tt> -- The CertoDirect Shop ID (REQUIRED)
25
+ # * <tt>:password</tt> -- The CertoDirect Shop Password. (REQUIRED)
26
+ # * <tt>:test</tt> -- +true+ or +false+. If true, perform transactions against the test server.
27
+ # Otherwise, perform transactions against the production server.
28
+ def initialize(options = {})
29
+ requires!(options, :login, :password)
30
+ @options = options
31
+ super
32
+ end
33
+
34
+ # Perform a purchase, which is essentially an authorization and capture in a single operation.
35
+ #
36
+ # ==== Parameters
37
+ #
38
+ # * <tt>money</tt> -- The amount to be purchased as an Integer value in cents.
39
+ # * <tt>credit_card</tt> -- The CreditCard details for the transaction.
40
+ # * <tt>options</tt> -- A hash of optional parameters.
41
+ def purchase(money, credit_card, options = {})
42
+ requires!(options, :email, :currency, :ip, :description)
43
+
44
+ commit(build_sale_request(money, credit_card, options))
45
+ end
46
+
47
+ # Refund a transaction.
48
+ #
49
+ # This transaction indicates to the gateway that
50
+ # money should flow from the merchant to the customer.
51
+ #
52
+ # ==== Parameters
53
+ #
54
+ # * <tt>money</tt> -- The amount to be credited to the customer as an Integer value in cents.
55
+ # * <tt>identification</tt> -- The ID of the original order against which the refund is being issued.
56
+ # * <tt>options</tt> -- A hash of parameters.
57
+ def refund(money, identification, options = {})
58
+ requires!(options, :reason)
59
+
60
+ commit(build_refund_request(money, identification, options))
61
+ end
62
+
63
+ # Performs an authorization, which reserves the funds on the customer's credit card, but does not
64
+ # charge the card.
65
+ #
66
+ # ==== Parameters
67
+ #
68
+ # * <tt>money</tt> -- The amount to be authorized as an Integer value in cents.
69
+ # * <tt>credit_card</tt> -- The CreditCard details for the transaction.
70
+ # * <tt>options</tt> -- A hash of optional parameters.
71
+ def authorize(money, credit_card, options = {})
72
+ requires!(options, :email, :currency, :ip, :description)
73
+
74
+ commit(build_authorize_request(money, credit_card, options))
75
+ end
76
+
77
+ # Captures the funds from an authorized transaction.
78
+ #
79
+ # ==== Parameters
80
+ #
81
+ # * <tt>money</tt> -- The amount to be captured as an Integer value in cents.
82
+ # * <tt>identification</tt> -- The authorization returned from the previous authorize request.
83
+ def capture(money, identification, options = {})
84
+ commit(build_capture_request(money, identification))
85
+ end
86
+
87
+ # Void a previous transaction
88
+ #
89
+ # ==== Parameters
90
+ #
91
+ # * <tt>money</tt> -- The amount to be captured as an Integer value in cents.
92
+ # * <tt>identification</tt> - The authorization returned from the previous authorize request.
93
+ def void(money, identification, options = {})
94
+ commit(build_void_request(money, identification))
95
+ end
96
+
97
+ # Create a recurring payment.
98
+ #
99
+ # ==== Parameters
100
+ #
101
+ # * <tt>options</tt> -- A hash of parameters.
102
+ #
103
+ # ==== Options
104
+ #
105
+ def recurring(identification, options={})
106
+ commit(build_recurring_request(identification, options))
107
+ end
108
+
109
+
110
+ private
111
+
112
+ def commit(request_xml)
113
+ begin
114
+ response = Hash.from_xml(ssl_post(gateway_url, request_xml, headers))
115
+ Response.new(success?(response),
116
+ message(response),
117
+ response,
118
+ :test => test?,
119
+ :authorization => authorization(response))
120
+ rescue ResponseError => e
121
+ raise e unless e.response.code == '403'
122
+ response = Hash.from_xml(e.response.body)['response']
123
+ Response.new(false, message(response), {}, :test => test?)
124
+ end
125
+ end
126
+
127
+ def build_sale_request(money, credit_card, options)
128
+ build_request_xml('Sale') do |xml|
129
+ add_order(xml, money, credit_card, options)
130
+ end
131
+ end
132
+
133
+ def build_authorize_request(money, credit_card, options)
134
+ build_request_xml('Authorize') do |xml|
135
+ add_order(xml, money, credit_card, options)
136
+ end
137
+ end
138
+
139
+ def build_refund_request(money, identification, options)
140
+ build_request_xml('Refund') do |xml|
141
+ add_reference_info(xml, money, identification, options)
142
+ xml.tag! 'reason', options[:reason]
143
+ end
144
+ end
145
+
146
+ def build_capture_request(money, identification)
147
+ build_request_xml('Capture') do |xml|
148
+ add_reference_info(xml, money, identification, options)
149
+ end
150
+ end
151
+
152
+ def build_void_request(money, identification)
153
+ build_request_xml('Void') do |xml|
154
+ add_reference_info(xml, money, identification, options)
155
+ end
156
+ end
157
+
158
+ def build_recurring_request(identification, options)
159
+ build_request_xml('Sale') do |xml|
160
+ xml.tag! 'order' do |xml|
161
+ xml.tag!('test', 'true') if test?
162
+ xml.tag! 'initial_order_id', identification, :type => 'integer'
163
+
164
+ add_order_details(xml, options[:amount], options) if has_any_order_details_key?(options)
165
+ add_address(xml, 'billing_address', options[:billing_address]) if options[:billing_address]
166
+ add_address(xml, 'shipping_address', options[:shipping_address]) if options[:shipping_address]
167
+ end
168
+ end
169
+ end
170
+
171
+ def build_request_xml(type, &block)
172
+ xml = Builder::XmlMarkup.new(:indent => 2)
173
+ xml.tag! 'transaction' do
174
+ xml.tag! 'type', type
175
+ yield(xml)
176
+ end
177
+ xml.target!
178
+ end
179
+
180
+ def add_order(xml, money, credit_card, options)
181
+ xml.tag! 'order' do
182
+ xml.tag!('test', 'true') if test?
183
+
184
+ xml.tag!('return_url', options[:return_url]) if options[:return_url]
185
+ xml.tag!('cancel_url', options[:cancel_url]) if options[:cancel_url]
186
+
187
+ xml.tag! 'payment_method_type', 'CreditCard'
188
+ xml.tag! 'payment_method' do
189
+ xml.tag! 'number', credit_card.number
190
+ xml.tag! 'exp_month', "%02i" % credit_card.month
191
+ xml.tag! 'exp_year', credit_card.year
192
+ xml.tag! 'holder', credit_card.name
193
+ xml.tag! 'verification_value', credit_card.verification_value
194
+ end
195
+
196
+ add_order_details(xml, money, options)
197
+ add_address(xml, 'billing_address', options[:billing_address]) if options[:billing_address]
198
+ add_address(xml, 'shipping_address', options[:shipping_address]) if options[:shipping_address]
199
+ end
200
+ end
201
+
202
+ def add_order_details(xml, money, options)
203
+ xml.tag! 'details' do
204
+ xml.tag!('amount', localized_amount(money, options[:currency]), :type => 'decimal') if money
205
+ xml.tag!('currency', options[:currency]) if options[:currency]
206
+ xml.tag!('email', options[:email]) if options[:email]
207
+ xml.tag!('ip', options[:ip]) if options[:ip]
208
+ xml.tag!('shipping', options[:shipping], :type => 'decimal') if options[:shipping]
209
+ xml.tag!('description', options[:description]) if options[:description]
210
+ end
211
+ end
212
+
213
+ def add_reference_info(xml, money, identification, options)
214
+ xml.tag! 'order_id', identification, :type => 'integer'
215
+ xml.tag! 'amount', localized_amount(money, options[:currency]), :type => 'decimal'
216
+ end
217
+
218
+ def add_address(xml, address_type, address)
219
+ xml.tag! address_type do
220
+ xml.tag! 'address', address[:address1]
221
+ xml.tag! 'city', address[:city]
222
+ xml.tag! 'country', address[:country]
223
+ xml.tag! 'first_name', address[:first_name]
224
+ xml.tag! 'last_name', address[:last_name]
225
+ xml.tag! 'state', address[:state]
226
+ xml.tag! 'phone', address[:phone]
227
+ xml.tag! 'zip', address[:zip]
228
+ end
229
+ end
230
+
231
+ def has_any_order_details_key?(options)
232
+ [ :currency, :amount, :email, :ip, :shipping, :description ].any? do |key|
233
+ options.has_key?(key)
234
+ end
235
+ end
236
+
237
+ def success?(response)
238
+ %w(completed forwarding).include?(state(response)) and
239
+ status(response) == 'success'
240
+ end
241
+
242
+ def error?(response)
243
+ response['errors']
244
+ end
245
+
246
+ def state(response)
247
+ response["transaction"].try(:[], "state")
248
+ end
249
+
250
+ def status(response)
251
+ response['transaction'].try(:[], 'response').try(:[], 'status')
252
+ end
253
+
254
+ def authorization(response)
255
+ error?(response) ? nil : response["transaction"]["order"]['id'].to_s
256
+ end
257
+
258
+ def message(response)
259
+ return response['errors'].join('; ') if error?(response)
260
+
261
+ if state(response) == 'completed'
262
+ response["transaction"]["response"]["message"]
263
+ else
264
+ response['transaction']['message']
265
+ end
266
+ end
267
+
268
+ def headers
269
+ { 'authorization' => basic_auth,
270
+ 'Accept' => 'application/xml',
271
+ 'Content-Type' => 'application/xml' }
272
+ end
273
+
274
+ def basic_auth
275
+ 'Basic ' + ["#{@options[:login]}:#{@options[:password]}"].pack('m').delete("\r\n")
276
+ end
277
+ end
278
+ end
279
+ end