seamusabshere-active_merchant 1.4.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (277) hide show
  1. data/CHANGELOG +399 -0
  2. data/CONTRIBUTERS +90 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README +133 -0
  5. data/Rakefile +161 -0
  6. data/active_merchant.gemspec +17 -0
  7. data/gem-public_cert.pem +20 -0
  8. data/generators/gateway/USAGE +5 -0
  9. data/generators/gateway/gateway_generator.rb +61 -0
  10. data/generators/gateway/templates/gateway.rb +77 -0
  11. data/generators/gateway/templates/gateway_test.rb +49 -0
  12. data/generators/gateway/templates/remote_gateway_test.rb +57 -0
  13. data/generators/integration/USAGE +5 -0
  14. data/generators/integration/integration_generator.rb +68 -0
  15. data/generators/integration/templates/helper.rb +34 -0
  16. data/generators/integration/templates/helper_test.rb +54 -0
  17. data/generators/integration/templates/integration.rb +18 -0
  18. data/generators/integration/templates/module_test.rb +9 -0
  19. data/generators/integration/templates/notification.rb +100 -0
  20. data/generators/integration/templates/notification_test.rb +41 -0
  21. data/init.rb +3 -0
  22. data/lib/active_merchant.rb +76 -0
  23. data/lib/active_merchant/billing/avs_result.rb +95 -0
  24. data/lib/active_merchant/billing/base.rb +57 -0
  25. data/lib/active_merchant/billing/check.rb +68 -0
  26. data/lib/active_merchant/billing/credit_card.rb +157 -0
  27. data/lib/active_merchant/billing/credit_card_formatting.rb +21 -0
  28. data/lib/active_merchant/billing/credit_card_methods.rb +125 -0
  29. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  30. data/lib/active_merchant/billing/expiry_date.rb +28 -0
  31. data/lib/active_merchant/billing/gateway.rb +162 -0
  32. data/lib/active_merchant/billing/gateways.rb +3 -0
  33. data/lib/active_merchant/billing/gateways/authorize_net.rb +646 -0
  34. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +702 -0
  35. data/lib/active_merchant/billing/gateways/beanstream.rb +102 -0
  36. data/lib/active_merchant/billing/gateways/beanstream/beanstream_core.rb +233 -0
  37. data/lib/active_merchant/billing/gateways/beanstream_interac.rb +54 -0
  38. data/lib/active_merchant/billing/gateways/bogus.rb +86 -0
  39. data/lib/active_merchant/billing/gateways/braintree.rb +222 -0
  40. data/lib/active_merchant/billing/gateways/card_stream.rb +230 -0
  41. data/lib/active_merchant/billing/gateways/cyber_source.rb +406 -0
  42. data/lib/active_merchant/billing/gateways/data_cash.rb +595 -0
  43. data/lib/active_merchant/billing/gateways/efsnet.rb +229 -0
  44. data/lib/active_merchant/billing/gateways/eway.rb +272 -0
  45. data/lib/active_merchant/billing/gateways/exact.rb +222 -0
  46. data/lib/active_merchant/billing/gateways/linkpoint.rb +396 -0
  47. data/lib/active_merchant/billing/gateways/modern_payments.rb +36 -0
  48. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +214 -0
  49. data/lib/active_merchant/billing/gateways/moneris.rb +205 -0
  50. data/lib/active_merchant/billing/gateways/net_registry.rb +189 -0
  51. data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
  52. data/lib/active_merchant/billing/gateways/pay_junction.rb +392 -0
  53. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  54. data/lib/active_merchant/billing/gateways/payflow.rb +236 -0
  55. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +213 -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 +242 -0
  62. data/lib/active_merchant/billing/gateways/paypal.rb +108 -0
  63. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +325 -0
  64. data/lib/active_merchant/billing/gateways/paypal/paypal_express_response.rb +38 -0
  65. data/lib/active_merchant/billing/gateways/paypal_ca.rb +13 -0
  66. data/lib/active_merchant/billing/gateways/paypal_express.rb +130 -0
  67. data/lib/active_merchant/billing/gateways/paypal_express_common.rb +20 -0
  68. data/lib/active_merchant/billing/gateways/plugnpay.rb +292 -0
  69. data/lib/active_merchant/billing/gateways/protx.rb +284 -0
  70. data/lib/active_merchant/billing/gateways/psigate.rb +214 -0
  71. data/lib/active_merchant/billing/gateways/psl_card.rb +302 -0
  72. data/lib/active_merchant/billing/gateways/quickpay.rb +183 -0
  73. data/lib/active_merchant/billing/gateways/realex.rb +200 -0
  74. data/lib/active_merchant/billing/gateways/sage.rb +145 -0
  75. data/lib/active_merchant/billing/gateways/sage/sage_bankcard.rb +88 -0
  76. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +110 -0
  77. data/lib/active_merchant/billing/gateways/sage/sage_virtual_check.rb +97 -0
  78. data/lib/active_merchant/billing/gateways/secure_pay.rb +31 -0
  79. data/lib/active_merchant/billing/gateways/secure_pay_au.rb +157 -0
  80. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  81. data/lib/active_merchant/billing/gateways/skip_jack.rb +439 -0
  82. data/lib/active_merchant/billing/gateways/trans_first.rb +127 -0
  83. data/lib/active_merchant/billing/gateways/trust_commerce.rb +414 -0
  84. data/lib/active_merchant/billing/gateways/usa_epay.rb +194 -0
  85. data/lib/active_merchant/billing/gateways/verifi.rb +228 -0
  86. data/lib/active_merchant/billing/gateways/viaklix.rb +165 -0
  87. data/lib/active_merchant/billing/gateways/wirecard.rb +305 -0
  88. data/lib/active_merchant/billing/integrations.rb +21 -0
  89. data/lib/active_merchant/billing/integrations/action_view_helper.rb +79 -0
  90. data/lib/active_merchant/billing/integrations/bogus.rb +22 -0
  91. data/lib/active_merchant/billing/integrations/bogus/helper.rb +17 -0
  92. data/lib/active_merchant/billing/integrations/bogus/notification.rb +11 -0
  93. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  94. data/lib/active_merchant/billing/integrations/chronopay.rb +22 -0
  95. data/lib/active_merchant/billing/integrations/chronopay/helper.rb +81 -0
  96. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +156 -0
  97. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  98. data/lib/active_merchant/billing/integrations/gestpay.rb +26 -0
  99. data/lib/active_merchant/billing/integrations/gestpay/common.rb +42 -0
  100. data/lib/active_merchant/billing/integrations/gestpay/helper.rb +70 -0
  101. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +83 -0
  102. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  103. data/lib/active_merchant/billing/integrations/helper.rb +93 -0
  104. data/lib/active_merchant/billing/integrations/hi_trust.rb +26 -0
  105. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  106. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +59 -0
  107. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  108. data/lib/active_merchant/billing/integrations/nochex.rb +87 -0
  109. data/lib/active_merchant/billing/integrations/nochex/helper.rb +68 -0
  110. data/lib/active_merchant/billing/integrations/nochex/notification.rb +94 -0
  111. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  112. data/lib/active_merchant/billing/integrations/notification.rb +62 -0
  113. data/lib/active_merchant/billing/integrations/paypal.rb +40 -0
  114. data/lib/active_merchant/billing/integrations/paypal/helper.rb +118 -0
  115. data/lib/active_merchant/billing/integrations/paypal/notification.rb +154 -0
  116. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  117. data/lib/active_merchant/billing/integrations/return.rb +35 -0
  118. data/lib/active_merchant/billing/integrations/two_checkout.rb +23 -0
  119. data/lib/active_merchant/billing/integrations/two_checkout/helper.rb +59 -0
  120. data/lib/active_merchant/billing/integrations/two_checkout/notification.rb +114 -0
  121. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  122. data/lib/active_merchant/billing/response.rb +32 -0
  123. data/lib/active_merchant/lib/country.rb +298 -0
  124. data/lib/active_merchant/lib/error.rb +4 -0
  125. data/lib/active_merchant/lib/post_data.rb +22 -0
  126. data/lib/active_merchant/lib/posts_data.rb +89 -0
  127. data/lib/active_merchant/lib/requires_parameters.rb +16 -0
  128. data/lib/active_merchant/lib/utils.rb +18 -0
  129. data/lib/active_merchant/lib/validateable.rb +76 -0
  130. data/lib/certs/cacert.pem +7815 -0
  131. data/lib/support/gateway_support.rb +58 -0
  132. data/lib/tasks/cia.rb +90 -0
  133. data/script/destroy +14 -0
  134. data/script/generate +14 -0
  135. data/test/extra/binding_of_caller.rb +80 -0
  136. data/test/extra/breakpoint.rb +547 -0
  137. data/test/fixtures.yml +301 -0
  138. data/test/remote/gateways/remote_authorize_net_cim_test.rb +459 -0
  139. data/test/remote/gateways/remote_authorize_net_test.rb +145 -0
  140. data/test/remote/gateways/remote_beanstream_interac_test.rb +53 -0
  141. data/test/remote/gateways/remote_beanstream_test.rb +150 -0
  142. data/test/remote/gateways/remote_braintree_test.rb +154 -0
  143. data/test/remote/gateways/remote_card_stream_test.rb +148 -0
  144. data/test/remote/gateways/remote_cyber_source_test.rb +144 -0
  145. data/test/remote/gateways/remote_data_cash_test.rb +357 -0
  146. data/test/remote/gateways/remote_efsnet_test.rb +81 -0
  147. data/test/remote/gateways/remote_eway_test.rb +74 -0
  148. data/test/remote/gateways/remote_exact_test.rb +60 -0
  149. data/test/remote/gateways/remote_linkpoint_test.rb +112 -0
  150. data/test/remote/gateways/remote_modern_payments_cim_test.rb +58 -0
  151. data/test/remote/gateways/remote_modern_payments_test.rb +43 -0
  152. data/test/remote/gateways/remote_moneris_test.rb +82 -0
  153. data/test/remote/gateways/remote_net_registry_test.rb +85 -0
  154. data/test/remote/gateways/remote_netbilling_test.rb +70 -0
  155. data/test/remote/gateways/remote_pay_junction_test.rb +143 -0
  156. data/test/remote/gateways/remote_pay_secure_test.rb +39 -0
  157. data/test/remote/gateways/remote_payflow_express_test.rb +50 -0
  158. data/test/remote/gateways/remote_payflow_test.rb +237 -0
  159. data/test/remote/gateways/remote_payflow_uk_test.rb +173 -0
  160. data/test/remote/gateways/remote_payment_express_test.rb +126 -0
  161. data/test/remote/gateways/remote_paypal_express_test.rb +49 -0
  162. data/test/remote/gateways/remote_paypal_test.rb +167 -0
  163. data/test/remote/gateways/remote_plugnpay_test.rb +72 -0
  164. data/test/remote/gateways/remote_protx_test.rb +184 -0
  165. data/test/remote/gateways/remote_psigate_test.rb +50 -0
  166. data/test/remote/gateways/remote_psl_card_test.rb +106 -0
  167. data/test/remote/gateways/remote_quickpay_test.rb +182 -0
  168. data/test/remote/gateways/remote_realex_test.rb +224 -0
  169. data/test/remote/gateways/remote_sage_bankcard_test.rb +109 -0
  170. data/test/remote/gateways/remote_sage_test.rb +87 -0
  171. data/test/remote/gateways/remote_sage_virtual_check_test.rb +62 -0
  172. data/test/remote/gateways/remote_secure_pay_au_test.rb +40 -0
  173. data/test/remote/gateways/remote_secure_pay_tech_test.rb +37 -0
  174. data/test/remote/gateways/remote_secure_pay_test.rb +28 -0
  175. data/test/remote/gateways/remote_skipjack_test.rb +105 -0
  176. data/test/remote/gateways/remote_trans_first_test.rb +34 -0
  177. data/test/remote/gateways/remote_trust_commerce_test.rb +152 -0
  178. data/test/remote/gateways/remote_usa_epay_test.rb +46 -0
  179. data/test/remote/gateways/remote_verifi_test.rb +107 -0
  180. data/test/remote/gateways/remote_viaklix_test.rb +43 -0
  181. data/test/remote/gateways/remote_wirecard_test.rb +77 -0
  182. data/test/remote/integrations/remote_gestpay_integration_test.rb +37 -0
  183. data/test/remote/integrations/remote_paypal_integration_test.rb +26 -0
  184. data/test/test_helper.rb +191 -0
  185. data/test/unit/avs_result_test.rb +59 -0
  186. data/test/unit/base_test.rb +55 -0
  187. data/test/unit/check_test.rb +88 -0
  188. data/test/unit/country_code_test.rb +33 -0
  189. data/test/unit/country_test.rb +64 -0
  190. data/test/unit/credit_card_formatting_test.rb +19 -0
  191. data/test/unit/credit_card_methods_test.rb +170 -0
  192. data/test/unit/credit_card_test.rb +311 -0
  193. data/test/unit/cvv_result_test.rb +33 -0
  194. data/test/unit/expiry_date_test.rb +21 -0
  195. data/test/unit/gateways/authorize_net_cim_test.rb +638 -0
  196. data/test/unit/gateways/authorize_net_test.rb +291 -0
  197. data/test/unit/gateways/beanstream_interac_test.rb +51 -0
  198. data/test/unit/gateways/beanstream_test.rb +108 -0
  199. data/test/unit/gateways/bogus_test.rb +42 -0
  200. data/test/unit/gateways/braintree_test.rb +116 -0
  201. data/test/unit/gateways/card_stream_test.rb +90 -0
  202. data/test/unit/gateways/cyber_source_test.rb +188 -0
  203. data/test/unit/gateways/data_cash_test.rb +132 -0
  204. data/test/unit/gateways/efsnet_test.rb +123 -0
  205. data/test/unit/gateways/eway_test.rb +118 -0
  206. data/test/unit/gateways/exact_test.rb +156 -0
  207. data/test/unit/gateways/gateway_test.rb +48 -0
  208. data/test/unit/gateways/linkpoint_test.rb +167 -0
  209. data/test/unit/gateways/modern_payments_cim_test.rb +171 -0
  210. data/test/unit/gateways/moneris_test.rb +158 -0
  211. data/test/unit/gateways/net_registry_test.rb +416 -0
  212. data/test/unit/gateways/netbilling_test.rb +54 -0
  213. data/test/unit/gateways/pay_junction_test.rb +123 -0
  214. data/test/unit/gateways/pay_secure_test.rb +71 -0
  215. data/test/unit/gateways/payflow_express_test.rb +173 -0
  216. data/test/unit/gateways/payflow_express_uk_test.rb +14 -0
  217. data/test/unit/gateways/payflow_test.rb +301 -0
  218. data/test/unit/gateways/payflow_uk_test.rb +30 -0
  219. data/test/unit/gateways/payment_express_test.rb +195 -0
  220. data/test/unit/gateways/paypal_express_test.rb +382 -0
  221. data/test/unit/gateways/paypal_test.rb +520 -0
  222. data/test/unit/gateways/plugnpay_test.rb +86 -0
  223. data/test/unit/gateways/protx_test.rb +122 -0
  224. data/test/unit/gateways/psigate_test.rb +169 -0
  225. data/test/unit/gateways/psl_card_test.rb +64 -0
  226. data/test/unit/gateways/quickpay_test.rb +112 -0
  227. data/test/unit/gateways/realex_test.rb +151 -0
  228. data/test/unit/gateways/sage_bankcard_test.rb +162 -0
  229. data/test/unit/gateways/sage_virtual_check_test.rb +71 -0
  230. data/test/unit/gateways/secure_pay_au_test.rb +207 -0
  231. data/test/unit/gateways/secure_pay_tech_test.rb +44 -0
  232. data/test/unit/gateways/secure_pay_test.rb +87 -0
  233. data/test/unit/gateways/skip_jack_test.rb +133 -0
  234. data/test/unit/gateways/trans_first_test.rb +112 -0
  235. data/test/unit/gateways/trust_commerce_test.rb +78 -0
  236. data/test/unit/gateways/usa_epay_test.rb +128 -0
  237. data/test/unit/gateways/verifi_test.rb +96 -0
  238. data/test/unit/gateways/viaklix_test.rb +78 -0
  239. data/test/unit/gateways/wirecard_test.rb +232 -0
  240. data/test/unit/generators/test_gateway_generator.rb +46 -0
  241. data/test/unit/generators/test_generator_helper.rb +20 -0
  242. data/test/unit/generators/test_integration_generator.rb +53 -0
  243. data/test/unit/integrations/action_view_helper_test.rb +50 -0
  244. data/test/unit/integrations/bogus_module_test.rb +20 -0
  245. data/test/unit/integrations/chronopay_module_test.rb +13 -0
  246. data/test/unit/integrations/gestpay_module_test.rb +14 -0
  247. data/test/unit/integrations/helpers/bogus_helper_test.rb +28 -0
  248. data/test/unit/integrations/helpers/chronopay_helper_test.rb +67 -0
  249. data/test/unit/integrations/helpers/gestpay_helper_test.rb +100 -0
  250. data/test/unit/integrations/helpers/hi_trust_helper_test.rb +16 -0
  251. data/test/unit/integrations/helpers/nochex_helper_test.rb +53 -0
  252. data/test/unit/integrations/helpers/paypal_helper_test.rb +162 -0
  253. data/test/unit/integrations/helpers/two_checkout_helper_test.rb +92 -0
  254. data/test/unit/integrations/hi_trust_module_test.rb +13 -0
  255. data/test/unit/integrations/nochex_module_test.rb +13 -0
  256. data/test/unit/integrations/notifications/chronopay_notification_test.rb +66 -0
  257. data/test/unit/integrations/notifications/gestpay_notification_test.rb +60 -0
  258. data/test/unit/integrations/notifications/hi_trust_notification_test.rb +59 -0
  259. data/test/unit/integrations/notifications/nochex_notification_test.rb +51 -0
  260. data/test/unit/integrations/notifications/notification_test.rb +54 -0
  261. data/test/unit/integrations/notifications/paypal_notification_test.rb +85 -0
  262. data/test/unit/integrations/notifications/two_checkout_notification_test.rb +55 -0
  263. data/test/unit/integrations/paypal_module_test.rb +28 -0
  264. data/test/unit/integrations/returns/chronopay_return_test.rb +11 -0
  265. data/test/unit/integrations/returns/gestpay_return_test.rb +10 -0
  266. data/test/unit/integrations/returns/hi_trust_return_test.rb +24 -0
  267. data/test/unit/integrations/returns/nochex_return_test.rb +10 -0
  268. data/test/unit/integrations/returns/paypal_return_test.rb +10 -0
  269. data/test/unit/integrations/returns/return_test.rb +11 -0
  270. data/test/unit/integrations/returns/two_checkout_return_test.rb +24 -0
  271. data/test/unit/integrations/two_checkout_module_test.rb +13 -0
  272. data/test/unit/post_data_test.rb +55 -0
  273. data/test/unit/posts_data_test.rb +100 -0
  274. data/test/unit/response_test.rb +28 -0
  275. data/test/unit/utils_test.rb +7 -0
  276. data/test/unit/validateable_test.rb +60 -0
  277. metadata +454 -0
@@ -0,0 +1,10 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ module Integrations #:nodoc:
4
+ module Paypal
5
+ class Return < ActiveMerchant::Billing::Integrations::Return
6
+ end
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,35 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ module Integrations #:nodoc:
4
+ class Return
5
+ attr_accessor :params
6
+
7
+ def initialize(query_string)
8
+ @params = parse(query_string)
9
+ end
10
+
11
+ # Successful by default. Overridden in the child class
12
+ def success?
13
+ true
14
+ end
15
+
16
+ def message
17
+
18
+ end
19
+
20
+ def parse(query_string)
21
+ return {} if query_string.blank?
22
+
23
+ query_string.split('&').inject({}) do |memo, chunk|
24
+ next if chunk.empty?
25
+ key, value = chunk.split('=', 2)
26
+ next if key.empty?
27
+ value = value.nil? ? nil : CGI.unescape(value)
28
+ memo[CGI.unescape(key)] = value
29
+ memo
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + '/two_checkout/helper.rb'
2
+ require File.dirname(__FILE__) + '/two_checkout/notification.rb'
3
+ require File.dirname(__FILE__) + '/two_checkout/return.rb'
4
+
5
+ module ActiveMerchant #:nodoc:
6
+ module Billing #:nodoc:
7
+ module Integrations #:nodoc:
8
+ module TwoCheckout
9
+
10
+ mattr_accessor :service_url
11
+ self.service_url = 'https://www.2checkout.com/2co/buyer/purchase'
12
+
13
+ def self.notification(post)
14
+ Notification.new(post)
15
+ end
16
+
17
+ def self.return(query_string)
18
+ Return.new(query_string)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,59 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ module Integrations #:nodoc:
4
+ module TwoCheckout
5
+ class Helper < ActiveMerchant::Billing::Integrations::Helper
6
+ def initialize(order, account, options = {})
7
+ super
8
+ add_field('fixed', 'Y')
9
+
10
+ if ActiveMerchant::Billing::Base.integration_mode == :test || options[:test]
11
+ add_field('demo', 'Y')
12
+ end
13
+ end
14
+
15
+ # The 2checkout vendor account number
16
+ mapping :account, 'sid'
17
+
18
+ # he total amount to be billed, in decimal form, without a currency symbol. (8 characters, decimal, 2 characters: Example: 99999999.99)
19
+ mapping :amount, 'total'
20
+
21
+ # a unique order id from your program. (128 characters max)
22
+ mapping :order, 'cart_order_id'
23
+
24
+
25
+ mapping :customer, :email => 'email',
26
+ :phone => 'phone'
27
+
28
+ mapping :billing_address, :city => 'city',
29
+ :address1 => 'street_address',
30
+ :address2 => 'street_address2',
31
+ :state => 'state',
32
+ :zip => 'zip',
33
+ :country => 'country'
34
+
35
+ mapping :shipping_address, :city => 'ship_city',
36
+ :address1 => 'ship_street_address',
37
+ :state => 'ship_state',
38
+ :zip => 'ship_zip',
39
+ :country => 'ship_country'
40
+
41
+ mapping :invoice, 'merchant_order_id'
42
+
43
+ # Does nothing, since we've disabled the Continue Shopping button by using the fixed = Y field
44
+ mapping :return_url, 'return_url'
45
+
46
+ #mapping :description, ''
47
+ #mapping :tax, ''
48
+ #mapping :shipping, ''
49
+
50
+ def customer(params = {})
51
+ add_field(mappings[:customer][:email], params[:email])
52
+ add_field(mappings[:customer][:phone], params[:phone])
53
+ add_field('card_holder_name', "#{params[:first_name]} #{params[:last_name]}")
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,114 @@
1
+ require 'net/http'
2
+ require 'base64'
3
+ require 'digest/md5'
4
+
5
+ module ActiveMerchant #:nodoc:
6
+ module Billing #:nodoc:
7
+ module Integrations #:nodoc:
8
+ module TwoCheckout
9
+ class Notification < ActiveMerchant::Billing::Integrations::Notification
10
+ # order_number 2Checkout.com order number
11
+ # card_holder_name Card holder's name
12
+ # street_address Card holder's address
13
+ # city Card holder's city
14
+ # state Card holder's state
15
+ # zip Card holder's zip
16
+ # country Card holder's country
17
+ # email Card holder's email
18
+ # phone Card holder's phone
19
+ # credit_card_processed Y if successful, K if waiting for approval
20
+ # total Total purchase amount
21
+ # ship_name Shipping information
22
+ # ship_street_address Shipping information
23
+ # ship_city Shipping information
24
+ # ship_state Shipping information
25
+ # ship_zip Shipping information
26
+ # ship_country Shipping information
27
+ # product_id 2Checkout product ID for purchased items will append a number if more than one item.
28
+ # ex. product_id,product_id1,product_id2
29
+ # quantity quantity of corresponding product will append a number if more than one item.
30
+ # ex. quantity,quantity1,quantity2
31
+ # merchant_product_id your product ID for purchased items will append a number if more than one item.
32
+ # ex. merchant_product_id,merchant_product_id1,merchant_product_id2
33
+ # product_description your description for purchased items will append a number if more than one item.
34
+ # ex. product_description,product_description1,product_description2
35
+
36
+ def currency
37
+ 'USD'
38
+ end
39
+
40
+ def complete?
41
+ status == 'Completed'
42
+ end
43
+
44
+ def item_id
45
+ params['cart_order_id']
46
+ end
47
+
48
+ def transaction_id
49
+ params['order_number']
50
+ end
51
+
52
+ def received_at
53
+ params['']
54
+ end
55
+
56
+ def payer_email
57
+ params['email']
58
+ end
59
+
60
+ def receiver_email
61
+ params['']
62
+ end
63
+
64
+ # The MD5 Hash
65
+ def security_key
66
+ params['key']
67
+ end
68
+
69
+ # the money amount we received in X.2 decimal.
70
+ def gross
71
+ params['total']
72
+ end
73
+
74
+ # Was this a test transaction? # Use the hash
75
+ def test?
76
+ params['demo'] == 'Y'
77
+ end
78
+
79
+ def status
80
+ case params['credit_card_processed']
81
+ when 'Y'
82
+ 'Completed'
83
+ when 'K'
84
+ 'Pending'
85
+ else
86
+ 'Failed'
87
+ end
88
+ end
89
+
90
+ def verify(secret)
91
+ return false if security_key.blank?
92
+
93
+ Digest::MD5.hexdigest("#{secret}#{params['sid']}#{transaction_id}#{gross}").upcase == security_key.upcase
94
+ end
95
+
96
+ def acknowledge
97
+ true
98
+ end
99
+
100
+ private
101
+
102
+ def parse(post)
103
+ @raw = post.to_s
104
+ for line in @raw.split('&')
105
+ key, value = *line.scan( %r{^(\w+)\=(.*)$} ).flatten
106
+ params[key] = CGI.unescape(value || '')
107
+ end
108
+ end
109
+
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,17 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ module Integrations #:nodoc:
4
+ module TwoCheckout
5
+ class Return < ActiveMerchant::Billing::Integrations::Return
6
+ def success?
7
+ params['credit_card_processed'] == 'Y'
8
+ end
9
+
10
+ def message
11
+
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,32 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+
4
+ class Error < ActiveMerchantError #:nodoc:
5
+ end
6
+
7
+ class Response
8
+ attr_reader :params, :message, :test, :authorization, :avs_result, :cvv_result
9
+
10
+ def success?
11
+ @success
12
+ end
13
+
14
+ def test?
15
+ @test
16
+ end
17
+
18
+ def fraud_review?
19
+ @fraud_review
20
+ end
21
+
22
+ def initialize(success, message, params = {}, options = {})
23
+ @success, @message, @params = success, message, params.stringify_keys
24
+ @test = options[:test] || false
25
+ @authorization = options[:authorization]
26
+ @fraud_review = options[:fraud_review]
27
+ @avs_result = AVSResult.new(options[:avs_result]).to_hash
28
+ @cvv_result = CVVResult.new(options[:cvv_result]).to_hash
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,298 @@
1
+ module ActiveMerchant #:nodoc:
2
+ class InvalidCountryCodeError < StandardError
3
+ end
4
+
5
+ class CountryCodeFormatError < StandardError
6
+ end
7
+
8
+ class CountryCode
9
+ attr_reader :value, :format
10
+ def initialize(value)
11
+ @value = value.to_s.upcase
12
+ detect_format
13
+ end
14
+
15
+ def to_s
16
+ value
17
+ end
18
+
19
+ private
20
+
21
+ def detect_format
22
+ case @value
23
+ when /^[[:alpha:]]{2}$/
24
+ @format = :alpha2
25
+ when /^[[:alpha:]]{3}$/
26
+ @format = :alpha3
27
+ when /^[[:digit:]]{3}$/
28
+ @format = :numeric
29
+ else
30
+ raise CountryCodeFormatError, "The country code is not formatted correctly #{@value}"
31
+ end
32
+ end
33
+ end
34
+
35
+ class Country
36
+ include RequiresParameters
37
+ attr_reader :name
38
+
39
+ def initialize(options = {})
40
+ requires!(options, :name, :alpha2, :alpha3, :numeric)
41
+ @name = options.delete(:name)
42
+ @codes = options.collect{|k,v| CountryCode.new(v)}
43
+ end
44
+
45
+ def code(format)
46
+ @codes.select{|c| c.format == format}
47
+ end
48
+
49
+ def to_s
50
+ @name
51
+ end
52
+
53
+ COUNTRIES = [
54
+ { :alpha2 => 'AF', :name => 'Afghanistan', :alpha3 => 'AFG', :numeric => '004' },
55
+ { :alpha2 => 'AL', :name => 'Albania', :alpha3 => 'ALB', :numeric => '008' },
56
+ { :alpha2 => 'DZ', :name => 'Algeria', :alpha3 => 'DZA', :numeric => '012' },
57
+ { :alpha2 => 'AS', :name => 'American Samoa', :alpha3 => 'ASM', :numeric => '016' },
58
+ { :alpha2 => 'AD', :name => 'Andorra', :alpha3 => 'AND', :numeric => '020' },
59
+ { :alpha2 => 'AO', :name => 'Angola', :alpha3 => 'AGO', :numeric => '024' },
60
+ { :alpha2 => 'AI', :name => 'Anguilla', :alpha3 => 'AIA', :numeric => '660' },
61
+ { :alpha2 => 'AG', :name => 'Antigua and Barbuda', :alpha3 => 'ATG', :numeric => '028' },
62
+ { :alpha2 => 'AR', :name => 'Argentina', :alpha3 => 'ARG', :numeric => '032' },
63
+ { :alpha2 => 'AM', :name => 'Armenia', :alpha3 => 'ARM', :numeric => '051' },
64
+ { :alpha2 => 'AW', :name => 'Aruba', :alpha3 => 'ABW', :numeric => '533' },
65
+ { :alpha2 => 'AU', :name => 'Australia', :alpha3 => 'AUS', :numeric => '036' },
66
+ { :alpha2 => 'AT', :name => 'Austria', :alpha3 => 'AUT', :numeric => '040' },
67
+ { :alpha2 => 'AX', :name => 'Åland Islands', :alpha3 => 'ALA', :numeric => '248' },
68
+ { :alpha2 => 'AZ', :name => 'Azerbaijan', :alpha3 => 'AZE', :numeric => '031' },
69
+ { :alpha2 => 'BS', :name => 'Bahamas', :alpha3 => 'BHS', :numeric => '044' },
70
+ { :alpha2 => 'BH', :name => 'Bahrain', :alpha3 => 'BHR', :numeric => '048' },
71
+ { :alpha2 => 'BD', :name => 'Bangladesh', :alpha3 => 'BGD', :numeric => '050' },
72
+ { :alpha2 => 'BB', :name => 'Barbados', :alpha3 => 'BRB', :numeric => '052' },
73
+ { :alpha2 => 'BY', :name => 'Belarus', :alpha3 => 'BLR', :numeric => '112' },
74
+ { :alpha2 => 'BE', :name => 'Belgium', :alpha3 => 'BEL', :numeric => '056' },
75
+ { :alpha2 => 'BZ', :name => 'Belize', :alpha3 => 'BLZ', :numeric => '084' },
76
+ { :alpha2 => 'BJ', :name => 'Benin', :alpha3 => 'BEN', :numeric => '204' },
77
+ { :alpha2 => 'BM', :name => 'Bermuda', :alpha3 => 'BMU', :numeric => '060' },
78
+ { :alpha2 => 'BT', :name => 'Bhutan', :alpha3 => 'BTN', :numeric => '064' },
79
+ { :alpha2 => 'BO', :name => 'Bolivia', :alpha3 => 'BOL', :numeric => '068' },
80
+ { :alpha2 => 'BA', :name => 'Bosnia and Herzegovina', :alpha3 => 'BIH', :numeric => '070' },
81
+ { :alpha2 => 'BW', :name => 'Botswana', :alpha3 => 'BWA', :numeric => '072' },
82
+ { :alpha2 => 'BR', :name => 'Brazil', :alpha3 => 'BRA', :numeric => '076' },
83
+ { :alpha2 => 'BN', :name => 'Brunei Darussalam', :alpha3 => 'BRN', :numeric => '096' },
84
+ { :alpha2 => 'BG', :name => 'Bulgaria', :alpha3 => 'BGR', :numeric => '100' },
85
+ { :alpha2 => 'BF', :name => 'Burkina Faso', :alpha3 => 'BFA', :numeric => '854' },
86
+ { :alpha2 => 'BI', :name => 'Burundi', :alpha3 => 'BDI', :numeric => '108' },
87
+ { :alpha2 => 'KH', :name => 'Cambodia', :alpha3 => 'KHM', :numeric => '116' },
88
+ { :alpha2 => 'CM', :name => 'Cameroon', :alpha3 => 'CMR', :numeric => '120' },
89
+ { :alpha2 => 'CA', :name => 'Canada', :alpha3 => 'CAN', :numeric => '124' },
90
+ { :alpha2 => 'CV', :name => 'Cape Verde', :alpha3 => 'CPV', :numeric => '132' },
91
+ { :alpha2 => 'KY', :name => 'Cayman Islands', :alpha3 => 'CYM', :numeric => '136' },
92
+ { :alpha2 => 'CF', :name => 'Central African Republic', :alpha3 => 'CAF', :numeric => '140' },
93
+ { :alpha2 => 'TD', :name => 'Chad', :alpha3 => 'TCD', :numeric => '148' },
94
+ { :alpha2 => 'CL', :name => 'Chile', :alpha3 => 'CHL', :numeric => '152' },
95
+ { :alpha2 => 'CN', :name => 'China', :alpha3 => 'CHN', :numeric => '156' },
96
+ { :alpha2 => 'CO', :name => 'Colombia', :alpha3 => 'COL', :numeric => '170' },
97
+ { :alpha2 => 'KM', :name => 'Comoros', :alpha3 => 'COM', :numeric => '174' },
98
+ { :alpha2 => 'CG', :name => 'Congo', :alpha3 => 'COG', :numeric => '178' },
99
+ { :alpha2 => 'CD', :name => 'Congo, the Democratic Republic of the', :alpha3 => 'COD', :numeric => '180' },
100
+ { :alpha2 => 'CK', :name => 'Cook Islands', :alpha3 => 'COK', :numeric => '184' },
101
+ { :alpha2 => 'CR', :name => 'Costa Rica', :alpha3 => 'CRI', :numeric => '188' },
102
+ { :alpha2 => 'CI', :name => 'Cote D\'Ivoire', :alpha3 => 'CIV', :numeric => '384' },
103
+ { :alpha2 => 'HR', :name => 'Croatia', :alpha3 => 'HRV', :numeric => '191' },
104
+ { :alpha2 => 'CU', :name => 'Cuba', :alpha3 => 'CUB', :numeric => '192' },
105
+ { :alpha2 => 'CY', :name => 'Cyprus', :alpha3 => 'CYP', :numeric => '196' },
106
+ { :alpha2 => 'CZ', :name => 'Czech Republic', :alpha3 => 'CZE', :numeric => '203' },
107
+ { :alpha2 => 'DK', :name => 'Denmark', :alpha3 => 'DNK', :numeric => '208' },
108
+ { :alpha2 => 'DJ', :name => 'Djibouti', :alpha3 => 'DJI', :numeric => '262' },
109
+ { :alpha2 => 'DM', :name => 'Dominica', :alpha3 => 'DMA', :numeric => '212' },
110
+ { :alpha2 => 'DO', :name => 'Dominican Republic', :alpha3 => 'DOM', :numeric => '214' },
111
+ { :alpha2 => 'EC', :name => 'Ecuador', :alpha3 => 'ECU', :numeric => '218' },
112
+ { :alpha2 => 'EG', :name => 'Egypt', :alpha3 => 'EGY', :numeric => '818' },
113
+ { :alpha2 => 'SV', :name => 'El Salvador', :alpha3 => 'SLV', :numeric => '222' },
114
+ { :alpha2 => 'GQ', :name => 'Equatorial Guinea', :alpha3 => 'GNQ', :numeric => '226' },
115
+ { :alpha2 => 'ER', :name => 'Eritrea', :alpha3 => 'ERI', :numeric => '232' },
116
+ { :alpha2 => 'EE', :name => 'Estonia', :alpha3 => 'EST', :numeric => '233' },
117
+ { :alpha2 => 'ET', :name => 'Ethiopia', :alpha3 => 'ETH', :numeric => '231' },
118
+ { :alpha2 => 'FK', :name => 'Falkland Islands (Malvinas)', :alpha3 => 'FLK', :numeric => '238' },
119
+ { :alpha2 => 'FO', :name => 'Faroe Islands', :alpha3 => 'FRO', :numeric => '234' },
120
+ { :alpha2 => 'FJ', :name => 'Fiji', :alpha3 => 'FJI', :numeric => '242' },
121
+ { :alpha2 => 'FI', :name => 'Finland', :alpha3 => 'FIN', :numeric => '246' },
122
+ { :alpha2 => 'FR', :name => 'France', :alpha3 => 'FRA', :numeric => '250' },
123
+ { :alpha2 => 'GF', :name => 'French Guiana', :alpha3 => 'GUF', :numeric => '254' },
124
+ { :alpha2 => 'PF', :name => 'French Polynesia', :alpha3 => 'PYF', :numeric => '258' },
125
+ { :alpha2 => 'GA', :name => 'Gabon', :alpha3 => 'GAB', :numeric => '266' },
126
+ { :alpha2 => 'GM', :name => 'Gambia', :alpha3 => 'GMB', :numeric => '270' },
127
+ { :alpha2 => 'GE', :name => 'Georgia', :alpha3 => 'GEO', :numeric => '268' },
128
+ { :alpha2 => 'DE', :name => 'Germany', :alpha3 => 'DEU', :numeric => '276' },
129
+ { :alpha2 => 'GH', :name => 'Ghana', :alpha3 => 'GHA', :numeric => '288' },
130
+ { :alpha2 => 'GI', :name => 'Gibraltar', :alpha3 => 'GIB', :numeric => '292' },
131
+ { :alpha2 => 'GR', :name => 'Greece', :alpha3 => 'GRC', :numeric => '300' },
132
+ { :alpha2 => 'GL', :name => 'Greenland', :alpha3 => 'GRL', :numeric => '304' },
133
+ { :alpha2 => 'GD', :name => 'Grenada', :alpha3 => 'GRD', :numeric => '308' },
134
+ { :alpha2 => 'GP', :name => 'Guadeloupe', :alpha3 => 'GLP', :numeric => '312' },
135
+ { :alpha2 => 'GU', :name => 'Guam', :alpha3 => 'GUM', :numeric => '316' },
136
+ { :alpha2 => 'GT', :name => 'Guatemala', :alpha3 => 'GTM', :numeric => '320' },
137
+ { :alpha2 => 'GN', :name => 'Guinea', :alpha3 => 'GIN', :numeric => '324' },
138
+ { :alpha2 => 'GW', :name => 'Guinea-Bissau', :alpha3 => 'GNB', :numeric => '624' },
139
+ { :alpha2 => 'GY', :name => 'Guyana', :alpha3 => 'GUY', :numeric => '328' },
140
+ { :alpha2 => 'HT', :name => 'Haiti', :alpha3 => 'HTI', :numeric => '332' },
141
+ { :alpha2 => 'VA', :name => 'Holy See (Vatican City State)', :alpha3 => 'VAT', :numeric => '336' },
142
+ { :alpha2 => 'HN', :name => 'Honduras', :alpha3 => 'HND', :numeric => '340' },
143
+ { :alpha2 => 'HK', :name => 'Hong Kong', :alpha3 => 'HKG', :numeric => '344' },
144
+ { :alpha2 => 'HU', :name => 'Hungary', :alpha3 => 'HUN', :numeric => '348' },
145
+ { :alpha2 => 'IS', :name => 'Iceland', :alpha3 => 'ISL', :numeric => '352' },
146
+ { :alpha2 => 'IN', :name => 'India', :alpha3 => 'IND', :numeric => '356' },
147
+ { :alpha2 => 'ID', :name => 'Indonesia', :alpha3 => 'IDN', :numeric => '360' },
148
+ { :alpha2 => 'IR', :name => 'Iran, Islamic Republic of', :alpha3 => 'IRN', :numeric => '364' },
149
+ { :alpha2 => 'IQ', :name => 'Iraq', :alpha3 => 'IRQ', :numeric => '368' },
150
+ { :alpha2 => 'IE', :name => 'Ireland', :alpha3 => 'IRL', :numeric => '372' },
151
+ { :alpha2 => 'IL', :name => 'Israel', :alpha3 => 'ISR', :numeric => '376' },
152
+ { :alpha2 => 'IT', :name => 'Italy', :alpha3 => 'ITA', :numeric => '380' },
153
+ { :alpha2 => 'JM', :name => 'Jamaica', :alpha3 => 'JAM', :numeric => '388' },
154
+ { :alpha2 => 'JP', :name => 'Japan', :alpha3 => 'JPN', :numeric => '392' },
155
+ { :alpha2 => 'JO', :name => 'Jordan', :alpha3 => 'JOR', :numeric => '400' },
156
+ { :alpha2 => 'KZ', :name => 'Kazakhstan', :alpha3 => 'KAZ', :numeric => '398' },
157
+ { :alpha2 => 'KE', :name => 'Kenya', :alpha3 => 'KEN', :numeric => '404' },
158
+ { :alpha2 => 'KI', :name => 'Kiribati', :alpha3 => 'KIR', :numeric => '296' },
159
+ { :alpha2 => 'KP', :name => 'Korea, Democratic People\'s Republic of', :alpha3 => 'PRK', :numeric => '408' },
160
+ { :alpha2 => 'KR', :name => 'Korea, Republic of', :alpha3 => 'KOR', :numeric => '410' },
161
+ { :alpha2 => 'KW', :name => 'Kuwait', :alpha3 => 'KWT', :numeric => '414' },
162
+ { :alpha2 => 'KG', :name => 'Kyrgyzstan', :alpha3 => 'KGZ', :numeric => '417' },
163
+ { :alpha2 => 'LA', :name => 'Lao People\'s Democratic Republic', :alpha3 => 'LAO', :numeric => '418' },
164
+ { :alpha2 => 'LV', :name => 'Latvia', :alpha3 => 'LVA', :numeric => '428' },
165
+ { :alpha2 => 'LB', :name => 'Lebanon', :alpha3 => 'LBN', :numeric => '422' },
166
+ { :alpha2 => 'LS', :name => 'Lesotho', :alpha3 => 'LSO', :numeric => '426' },
167
+ { :alpha2 => 'LR', :name => 'Liberia', :alpha3 => 'LBR', :numeric => '430' },
168
+ { :alpha2 => 'LY', :name => 'Libyan Arab Jamahiriya', :alpha3 => 'LBY', :numeric => '434' },
169
+ { :alpha2 => 'LI', :name => 'Liechtenstein', :alpha3 => 'LIE', :numeric => '438' },
170
+ { :alpha2 => 'LT', :name => 'Lithuania', :alpha3 => 'LTU', :numeric => '440' },
171
+ { :alpha2 => 'LU', :name => 'Luxembourg', :alpha3 => 'LUX', :numeric => '442' },
172
+ { :alpha2 => 'MO', :name => 'Macao', :alpha3 => 'MAC', :numeric => '446' },
173
+ { :alpha2 => 'MK', :name => 'Macedonia, the Former Yugoslav Republic of', :alpha3 => 'MKD', :numeric => '807' },
174
+ { :alpha2 => 'MG', :name => 'Madagascar', :alpha3 => 'MDG', :numeric => '450' },
175
+ { :alpha2 => 'MW', :name => 'Malawi', :alpha3 => 'MWI', :numeric => '454' },
176
+ { :alpha2 => 'MY', :name => 'Malaysia', :alpha3 => 'MYS', :numeric => '458' },
177
+ { :alpha2 => 'MV', :name => 'Maldives', :alpha3 => 'MDV', :numeric => '462' },
178
+ { :alpha2 => 'ML', :name => 'Mali', :alpha3 => 'MLI', :numeric => '466' },
179
+ { :alpha2 => 'MT', :name => 'Malta', :alpha3 => 'MLT', :numeric => '470' },
180
+ { :alpha2 => 'MH', :name => 'Marshall Islands', :alpha3 => 'MHL', :numeric => '584' },
181
+ { :alpha2 => 'MQ', :name => 'Martinique', :alpha3 => 'MTQ', :numeric => '474' },
182
+ { :alpha2 => 'MR', :name => 'Mauritania', :alpha3 => 'MRT', :numeric => '478' },
183
+ { :alpha2 => 'MU', :name => 'Mauritius', :alpha3 => 'MUS', :numeric => '480' },
184
+ { :alpha2 => 'MX', :name => 'Mexico', :alpha3 => 'MEX', :numeric => '484' },
185
+ { :alpha2 => 'FM', :name => 'Micronesia, Federated States of', :alpha3 => 'FSM', :numeric => '583' },
186
+ { :alpha2 => 'MD', :name => 'Moldova, Republic of', :alpha3 => 'MDA', :numeric => '498' },
187
+ { :alpha2 => 'MC', :name => 'Monaco', :alpha3 => 'MCO', :numeric => '492' },
188
+ { :alpha2 => 'MN', :name => 'Mongolia', :alpha3 => 'MNG', :numeric => '496' },
189
+ { :alpha2 => 'MS', :name => 'Montserrat', :alpha3 => 'MSR', :numeric => '500' },
190
+ { :alpha2 => 'MA', :name => 'Morocco', :alpha3 => 'MAR', :numeric => '504' },
191
+ { :alpha2 => 'MZ', :name => 'Mozambique', :alpha3 => 'MOZ', :numeric => '508' },
192
+ { :alpha2 => 'MM', :name => 'Myanmar', :alpha3 => 'MMR', :numeric => '104' },
193
+ { :alpha2 => 'NA', :name => 'Namibia', :alpha3 => 'NAM', :numeric => '516' },
194
+ { :alpha2 => 'NR', :name => 'Nauru', :alpha3 => 'NRU', :numeric => '520' },
195
+ { :alpha2 => 'NP', :name => 'Nepal', :alpha3 => 'NPL', :numeric => '524' },
196
+ { :alpha2 => 'NL', :name => 'Netherlands', :alpha3 => 'NLD', :numeric => '528' },
197
+ { :alpha2 => 'AN', :name => 'Netherlands Antilles', :alpha3 => 'ANT', :numeric => '530' },
198
+ { :alpha2 => 'NC', :name => 'New Caledonia', :alpha3 => 'NCL', :numeric => '540' },
199
+ { :alpha2 => 'NZ', :name => 'New Zealand', :alpha3 => 'NZL', :numeric => '554' },
200
+ { :alpha2 => 'NI', :name => 'Nicaragua', :alpha3 => 'NIC', :numeric => '558' },
201
+ { :alpha2 => 'NE', :name => 'Niger', :alpha3 => 'NER', :numeric => '562' },
202
+ { :alpha2 => 'NG', :name => 'Nigeria', :alpha3 => 'NGA', :numeric => '566' },
203
+ { :alpha2 => 'NU', :name => 'Niue', :alpha3 => 'NIU', :numeric => '570' },
204
+ { :alpha2 => 'NF', :name => 'Norfolk Island', :alpha3 => 'NFK', :numeric => '574' },
205
+ { :alpha2 => 'MP', :name => 'Northern Mariana Islands', :alpha3 => 'MNP', :numeric => '580' },
206
+ { :alpha2 => 'NO', :name => 'Norway', :alpha3 => 'NOR', :numeric => '578' },
207
+ { :alpha2 => 'OM', :name => 'Oman', :alpha3 => 'OMN', :numeric => '512' },
208
+ { :alpha2 => 'PK', :name => 'Pakistan', :alpha3 => 'PAK', :numeric => '586' },
209
+ { :alpha2 => 'PW', :name => 'Palau', :alpha3 => 'PLW', :numeric => '585' },
210
+ { :alpha2 => 'PA', :name => 'Panama', :alpha3 => 'PAN', :numeric => '591' },
211
+ { :alpha2 => 'PG', :name => 'Papua New Guinea', :alpha3 => 'PNG', :numeric => '598' },
212
+ { :alpha2 => 'PY', :name => 'Paraguay', :alpha3 => 'PRY', :numeric => '600' },
213
+ { :alpha2 => 'PE', :name => 'Peru', :alpha3 => 'PER', :numeric => '604' },
214
+ { :alpha2 => 'PH', :name => 'Philippines', :alpha3 => 'PHL', :numeric => '608' },
215
+ { :alpha2 => 'PN', :name => 'Pitcairn', :alpha3 => 'PCN', :numeric => '612' },
216
+ { :alpha2 => 'PL', :name => 'Poland', :alpha3 => 'POL', :numeric => '616' },
217
+ { :alpha2 => 'PT', :name => 'Portugal', :alpha3 => 'PRT', :numeric => '620' },
218
+ { :alpha2 => 'PR', :name => 'Puerto Rico', :alpha3 => 'PRI', :numeric => '630' },
219
+ { :alpha2 => 'QA', :name => 'Qatar', :alpha3 => 'QAT', :numeric => '634' },
220
+ { :alpha2 => 'RE', :name => 'Reunion', :alpha3 => 'REU', :numeric => '638' },
221
+ { :alpha2 => 'RO', :name => 'Romania', :alpha3 => 'ROM', :numeric => '642' },
222
+ { :alpha2 => 'RU', :name => 'Russian Federation', :alpha3 => 'RUS', :numeric => '643' },
223
+ { :alpha2 => 'RW', :name => 'Rwanda', :alpha3 => 'RWA', :numeric => '646' },
224
+ { :alpha2 => 'SH', :name => 'Saint Helena', :alpha3 => 'SHN', :numeric => '654' },
225
+ { :alpha2 => 'KN', :name => 'Saint Kitts and Nevis', :alpha3 => 'KNA', :numeric => '659' },
226
+ { :alpha2 => 'LC', :name => 'Saint Lucia', :alpha3 => 'LCA', :numeric => '662' },
227
+ { :alpha2 => 'PM', :name => 'Saint Pierre and Miquelon', :alpha3 => 'SPM', :numeric => '666' },
228
+ { :alpha2 => 'VC', :name => 'Saint Vincent and the Grenadines', :alpha3 => 'VCT', :numeric => '670' },
229
+ { :alpha2 => 'WS', :name => 'Samoa', :alpha3 => 'WSM', :numeric => '882' },
230
+ { :alpha2 => 'SM', :name => 'San Marino', :alpha3 => 'SMR', :numeric => '674' },
231
+ { :alpha2 => 'ST', :name => 'Sao Tome and Principe', :alpha3 => 'STP', :numeric => '678' },
232
+ { :alpha2 => 'SA', :name => 'Saudi Arabia', :alpha3 => 'SAU', :numeric => '682' },
233
+ { :alpha2 => 'SN', :name => 'Senegal', :alpha3 => 'SEN', :numeric => '686' },
234
+ { :alpha2 => 'SC', :name => 'Seychelles', :alpha3 => 'SYC', :numeric => '690' },
235
+ { :alpha2 => 'SL', :name => 'Sierra Leone', :alpha3 => 'SLE', :numeric => '694' },
236
+ { :alpha2 => 'SG', :name => 'Singapore', :alpha3 => 'SGP', :numeric => '702' },
237
+ { :alpha2 => 'SK', :name => 'Slovakia', :alpha3 => 'SVK', :numeric => '703' },
238
+ { :alpha2 => 'SI', :name => 'Slovenia', :alpha3 => 'SVN', :numeric => '705' },
239
+ { :alpha2 => 'SB', :name => 'Solomon Islands', :alpha3 => 'SLB', :numeric => '090' },
240
+ { :alpha2 => 'SO', :name => 'Somalia', :alpha3 => 'SOM', :numeric => '706' },
241
+ { :alpha2 => 'ZA', :name => 'South Africa', :alpha3 => 'ZAF', :numeric => '710' },
242
+ { :alpha2 => 'ES', :name => 'Spain', :alpha3 => 'ESP', :numeric => '724' },
243
+ { :alpha2 => 'LK', :name => 'Sri Lanka', :alpha3 => 'LKA', :numeric => '144' },
244
+ { :alpha2 => 'SD', :name => 'Sudan', :alpha3 => 'SDN', :numeric => '736' },
245
+ { :alpha2 => 'SR', :name => 'Suriname', :alpha3 => 'SUR', :numeric => '740' },
246
+ { :alpha2 => 'SJ', :name => 'Svalbard and Jan Mayen', :alpha3 => 'SJM', :numeric => '744' },
247
+ { :alpha2 => 'SZ', :name => 'Swaziland', :alpha3 => 'SWZ', :numeric => '748' },
248
+ { :alpha2 => 'SE', :name => 'Sweden', :alpha3 => 'SWE', :numeric => '752' },
249
+ { :alpha2 => 'CH', :name => 'Switzerland', :alpha3 => 'CHE', :numeric => '756' },
250
+ { :alpha2 => 'SY', :name => 'Syrian Arab Republic', :alpha3 => 'SYR', :numeric => '760' },
251
+ { :alpha2 => 'TW', :name => 'Taiwan, Province of China', :alpha3 => 'TWN', :numeric => '158' },
252
+ { :alpha2 => 'TJ', :name => 'Tajikistan', :alpha3 => 'TJK', :numeric => '762' },
253
+ { :alpha2 => 'TZ', :name => 'Tanzania, United Republic of', :alpha3 => 'TZA', :numeric => '834' },
254
+ { :alpha2 => 'TH', :name => 'Thailand', :alpha3 => 'THA', :numeric => '764' },
255
+ { :alpha2 => 'TG', :name => 'Togo', :alpha3 => 'TGO', :numeric => '768' },
256
+ { :alpha2 => 'TK', :name => 'Tokelau', :alpha3 => 'TKL', :numeric => '772' },
257
+ { :alpha2 => 'TO', :name => 'Tonga', :alpha3 => 'TON', :numeric => '776' },
258
+ { :alpha2 => 'TT', :name => 'Trinidad and Tobago', :alpha3 => 'TTO', :numeric => '780' },
259
+ { :alpha2 => 'TN', :name => 'Tunisia', :alpha3 => 'TUN', :numeric => '788' },
260
+ { :alpha2 => 'TR', :name => 'Turkey', :alpha3 => 'TUR', :numeric => '792' },
261
+ { :alpha2 => 'TM', :name => 'Turkmenistan', :alpha3 => 'TKM', :numeric => '795' },
262
+ { :alpha2 => 'TC', :name => 'Turks and Caicos Islands', :alpha3 => 'TCA', :numeric => '796' },
263
+ { :alpha2 => 'TV', :name => 'Tuvalu', :alpha3 => 'TUV', :numeric => '798' },
264
+ { :alpha2 => 'UG', :name => 'Uganda', :alpha3 => 'UGA', :numeric => '800' },
265
+ { :alpha2 => 'UA', :name => 'Ukraine', :alpha3 => 'UKR', :numeric => '804' },
266
+ { :alpha2 => 'AE', :name => 'United Arab Emirates', :alpha3 => 'ARE', :numeric => '784' },
267
+ { :alpha2 => 'GB', :name => 'United Kingdom', :alpha3 => 'GBR', :numeric => '826' },
268
+ { :alpha2 => 'US', :name => 'United States', :alpha3 => 'USA', :numeric => '840' },
269
+ { :alpha2 => 'UY', :name => 'Uruguay', :alpha3 => 'URY', :numeric => '858' },
270
+ { :alpha2 => 'UZ', :name => 'Uzbekistan', :alpha3 => 'UZB', :numeric => '860' },
271
+ { :alpha2 => 'VU', :name => 'Vanuatu', :alpha3 => 'VUT', :numeric => '548' },
272
+ { :alpha2 => 'VE', :name => 'Venezuela', :alpha3 => 'VEN', :numeric => '862' },
273
+ { :alpha2 => 'VN', :name => 'Viet Nam', :alpha3 => 'VNM', :numeric => '704' },
274
+ { :alpha2 => 'VG', :name => 'Virgin Islands, British', :alpha3 => 'VGB', :numeric => '092' },
275
+ { :alpha2 => 'VI', :name => 'Virgin Islands, U.S.', :alpha3 => 'VIR', :numeric => '850' },
276
+ { :alpha2 => 'WF', :name => 'Wallis and Futuna', :alpha3 => 'WLF', :numeric => '876' },
277
+ { :alpha2 => 'EH', :name => 'Western Sahara', :alpha3 => 'ESH', :numeric => '732' },
278
+ { :alpha2 => 'YE', :name => 'Yemen', :alpha3 => 'YEM', :numeric => '887' },
279
+ { :alpha2 => 'ZM', :name => 'Zambia', :alpha3 => 'ZMB', :numeric => '894' },
280
+ { :alpha2 => 'ZW', :name => 'Zimbabwe', :alpha3 => 'ZWE', :numeric => '716' }
281
+ ]
282
+
283
+ def self.find(name)
284
+ raise InvalidCountryCodeError, "Cannot lookup country for an empty name" if name.blank?
285
+
286
+ case name.length
287
+ when 2, 3
288
+ upcase_name = name.upcase
289
+ country_code = CountryCode.new(name)
290
+ country = COUNTRIES.detect{|c| c[country_code.format] == upcase_name }
291
+ else
292
+ country = COUNTRIES.detect{|c| c[:name] == name }
293
+ end
294
+ raise InvalidCountryCodeError, "No country could be found for the country #{name}" if country.nil?
295
+ Country.new(country.dup)
296
+ end
297
+ end
298
+ end