activemerchant 1.2.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (206) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG +310 -294
  3. data/CONTRIBUTERS +13 -0
  4. data/README +55 -31
  5. data/Rakefile +21 -13
  6. data/lib/active_merchant.rb +7 -0
  7. data/lib/active_merchant/billing/avs_result.rb +95 -0
  8. data/lib/active_merchant/billing/base.rb +8 -3
  9. data/lib/active_merchant/billing/check.rb +61 -0
  10. data/lib/active_merchant/billing/credit_card.rb +104 -80
  11. data/lib/active_merchant/billing/credit_card_formatting.rb +11 -8
  12. data/lib/active_merchant/billing/credit_card_methods.rb +76 -32
  13. data/lib/active_merchant/billing/cvv_result.rb +38 -0
  14. data/lib/active_merchant/billing/expiry_date.rb +28 -0
  15. data/lib/active_merchant/billing/gateway.rb +47 -111
  16. data/lib/active_merchant/billing/gateways/authorize_net.rb +508 -121
  17. data/lib/active_merchant/billing/gateways/bogus.rb +26 -32
  18. data/lib/active_merchant/billing/gateways/brain_tree.rb +82 -70
  19. data/lib/active_merchant/billing/gateways/card_stream.rb +43 -15
  20. data/lib/active_merchant/billing/gateways/cyber_source.rb +9 -29
  21. data/lib/active_merchant/billing/gateways/data_cash.rb +18 -38
  22. data/lib/active_merchant/billing/gateways/efsnet.rb +23 -50
  23. data/lib/active_merchant/billing/gateways/eway.rb +8 -19
  24. data/lib/active_merchant/billing/gateways/exact.rb +17 -25
  25. data/lib/active_merchant/billing/gateways/linkpoint.rb +18 -25
  26. data/lib/active_merchant/billing/gateways/moneris.rb +9 -39
  27. data/lib/active_merchant/billing/gateways/net_registry.rb +113 -182
  28. data/lib/active_merchant/billing/gateways/netbilling.rb +168 -0
  29. data/lib/active_merchant/billing/gateways/pay_junction.rb +52 -73
  30. data/lib/active_merchant/billing/gateways/pay_secure.rb +120 -0
  31. data/lib/active_merchant/billing/gateways/payflow.rb +13 -14
  32. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +55 -37
  33. data/lib/active_merchant/billing/gateways/payflow/payflow_response.rb +4 -0
  34. data/lib/active_merchant/billing/gateways/payflow_express.rb +2 -4
  35. data/lib/active_merchant/billing/gateways/payment_express.rb +11 -30
  36. data/lib/active_merchant/billing/gateways/paypal.rb +3 -14
  37. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +36 -16
  38. data/lib/active_merchant/billing/gateways/paypal_express.rb +1 -2
  39. data/lib/active_merchant/billing/gateways/plugnpay.rb +7 -15
  40. data/lib/active_merchant/billing/gateways/protx.rb +24 -25
  41. data/lib/active_merchant/billing/gateways/psigate.rb +34 -71
  42. data/lib/active_merchant/billing/gateways/psl_card.rb +24 -19
  43. data/lib/active_merchant/billing/gateways/quickpay.rb +10 -24
  44. data/lib/active_merchant/billing/gateways/realex.rb +7 -19
  45. data/lib/active_merchant/billing/gateways/secure_pay_tech.rb +113 -0
  46. data/lib/active_merchant/billing/gateways/skip_jack.rb +437 -0
  47. data/lib/active_merchant/billing/gateways/trans_first.rb +5 -14
  48. data/lib/active_merchant/billing/gateways/trust_commerce.rb +100 -39
  49. data/lib/active_merchant/billing/gateways/usa_epay.rb +60 -55
  50. data/lib/active_merchant/billing/gateways/verifi.rb +32 -39
  51. data/lib/active_merchant/billing/gateways/viaklix.rb +31 -37
  52. data/lib/active_merchant/billing/integrations.rb +2 -0
  53. data/lib/active_merchant/billing/integrations/bogus.rb +5 -0
  54. data/lib/active_merchant/billing/integrations/bogus/return.rb +10 -0
  55. data/lib/active_merchant/billing/integrations/chronopay.rb +5 -0
  56. data/lib/active_merchant/billing/integrations/chronopay/return.rb +10 -0
  57. data/lib/active_merchant/billing/integrations/gestpay.rb +5 -0
  58. data/lib/active_merchant/billing/integrations/gestpay/return.rb +10 -0
  59. data/lib/active_merchant/billing/integrations/hi_trust.rb +26 -0
  60. data/lib/active_merchant/billing/integrations/hi_trust/helper.rb +58 -0
  61. data/lib/active_merchant/billing/integrations/hi_trust/notification.rb +57 -0
  62. data/lib/active_merchant/billing/integrations/hi_trust/return.rb +67 -0
  63. data/lib/active_merchant/billing/integrations/nochex.rb +5 -0
  64. data/lib/active_merchant/billing/integrations/nochex/return.rb +10 -0
  65. data/lib/active_merchant/billing/integrations/paypal.rb +5 -0
  66. data/lib/active_merchant/billing/integrations/paypal/return.rb +10 -0
  67. data/lib/active_merchant/billing/integrations/return.rb +35 -0
  68. data/lib/active_merchant/billing/integrations/two_checkout.rb +5 -0
  69. data/lib/active_merchant/billing/integrations/two_checkout/return.rb +17 -0
  70. data/lib/active_merchant/billing/response.rb +12 -8
  71. data/lib/active_merchant/lib/posts_data.rb +39 -7
  72. data/lib/active_merchant/lib/requires_parameters.rb +2 -3
  73. data/lib/active_merchant/lib/utils.rb +18 -0
  74. data/lib/active_merchant/lib/validateable.rb +3 -3
  75. data/lib/support/gateway_support.rb +22 -9
  76. data/script/destroy +14 -0
  77. data/script/generate +7 -7
  78. data/test/fixtures.yml +25 -3
  79. data/test/remote/gateways/remote_authorize_net_test.rb +145 -0
  80. data/test/remote/gateways/remote_brain_tree_test.rb +118 -0
  81. data/test/{remote_tests → remote/gateways}/remote_card_stream_test.rb +56 -68
  82. data/test/{remote_tests → remote/gateways}/remote_cyber_source_test.rb +21 -32
  83. data/test/{remote_tests → remote/gateways}/remote_data_cash_test.rb +2 -2
  84. data/test/{remote_tests → remote/gateways}/remote_efsnet_test.rb +22 -34
  85. data/test/{remote_tests → remote/gateways}/remote_eway_test.rb +18 -15
  86. data/test/{remote_tests → remote/gateways}/remote_exact_test.rb +20 -19
  87. data/test/{remote_tests → remote/gateways}/remote_linkpoint_test.rb +31 -63
  88. data/test/remote/gateways/remote_moneris_test.rb +82 -0
  89. data/test/{remote_tests → remote/gateways}/remote_net_registry_test.rb +19 -54
  90. data/test/remote/gateways/remote_netbilling_test.rb +70 -0
  91. data/test/{remote_tests → remote/gateways}/remote_pay_junction_test.rb +41 -60
  92. data/test/remote/gateways/remote_pay_secure_test.rb +39 -0
  93. data/test/{remote_tests → remote/gateways}/remote_payflow_express_test.rb +2 -2
  94. data/test/{remote_tests → remote/gateways}/remote_payflow_test.rb +34 -38
  95. data/test/{remote_tests → remote/gateways}/remote_payflow_uk_test.rb +13 -12
  96. data/test/{remote_tests → remote/gateways}/remote_payment_express_test.rb +26 -36
  97. data/test/{remote_tests → remote/gateways}/remote_paypal_express_test.rb +3 -3
  98. data/test/{remote_tests → remote/gateways}/remote_paypal_test.rb +25 -21
  99. data/test/{remote_tests → remote/gateways}/remote_plugnpay_test.rb +18 -16
  100. data/test/{remote_tests → remote/gateways}/remote_protx_test.rb +33 -33
  101. data/test/remote/gateways/remote_psigate_test.rb +50 -0
  102. data/test/{remote_tests → remote/gateways}/remote_psl_card_test.rb +27 -26
  103. data/test/{remote_tests → remote/gateways}/remote_quickpay_test.rb +48 -48
  104. data/test/{remote_tests → remote/gateways}/remote_realex_test.rb +30 -33
  105. data/test/remote/gateways/remote_secure_pay_tech_test.rb +37 -0
  106. data/test/remote/gateways/remote_secure_pay_test.rb +28 -0
  107. data/test/remote/gateways/remote_skipjack_test.rb +105 -0
  108. data/test/{remote_tests → remote/gateways}/remote_trans_first_test.rb +7 -10
  109. data/test/remote/gateways/remote_trust_commerce_test.rb +152 -0
  110. data/test/{remote_tests → remote/gateways}/remote_usa_epay_test.rb +11 -22
  111. data/test/{remote_tests → remote/gateways}/remote_verifi_test.rb +27 -27
  112. data/test/{remote_tests → remote/gateways}/remote_viaklix_test.rb +8 -18
  113. data/test/{remote_tests → remote/integrations}/remote_gestpay_integration_test.rb +1 -1
  114. data/test/{remote_tests → remote/integrations}/remote_paypal_integration_test.rb +1 -1
  115. data/test/test_helper.rb +102 -61
  116. data/test/unit/avs_result_test.rb +59 -0
  117. data/test/unit/base_test.rb +33 -39
  118. data/test/unit/check_test.rb +76 -0
  119. data/test/unit/credit_card_formatting_test.rb +10 -15
  120. data/test/unit/credit_card_methods_test.rb +132 -17
  121. data/test/unit/credit_card_test.rb +157 -228
  122. data/test/unit/cvv_result_test.rb +33 -0
  123. data/test/unit/expiry_date_test.rb +21 -0
  124. data/test/unit/gateways/authorize_net_test.rb +180 -40
  125. data/test/unit/gateways/bogus_test.rb +2 -3
  126. data/test/unit/gateways/brain_tree_test.rb +63 -29
  127. data/test/unit/gateways/card_stream_test.rb +59 -6
  128. data/test/unit/gateways/cyber_source_test.rb +59 -40
  129. data/test/unit/gateways/data_cash_test.rb +82 -1
  130. data/test/unit/gateways/efsnet_test.rb +97 -44
  131. data/test/unit/gateways/eway_test.rb +55 -42
  132. data/test/unit/gateways/exact_test.rb +93 -55
  133. data/test/unit/gateways/gateway_test.rb +7 -0
  134. data/test/unit/gateways/linkpoint_test.rb +60 -58
  135. data/test/unit/gateways/moneris_test.rb +67 -76
  136. data/test/unit/gateways/net_registry_test.rb +351 -419
  137. data/test/unit/gateways/netbilling_test.rb +54 -0
  138. data/test/unit/gateways/pay_junction_test.rb +108 -46
  139. data/test/unit/gateways/pay_secure_test.rb +71 -0
  140. data/test/unit/gateways/payflow_express_test.rb +0 -8
  141. data/test/unit/gateways/payflow_test.rb +136 -65
  142. data/test/unit/gateways/payflow_uk_test.rb +0 -38
  143. data/test/unit/gateways/payment_express_test.rb +31 -51
  144. data/test/unit/gateways/paypal_express_test.rb +8 -2
  145. data/test/unit/gateways/paypal_test.rb +213 -54
  146. data/test/unit/gateways/plugnpay_test.rb +39 -32
  147. data/test/unit/gateways/protx_test.rb +45 -33
  148. data/test/unit/gateways/psigate_test.rb +146 -87
  149. data/test/unit/gateways/psl_card_test.rb +37 -24
  150. data/test/unit/gateways/quickpay_test.rb +33 -46
  151. data/test/unit/gateways/realex_test.rb +32 -31
  152. data/test/unit/gateways/secure_pay_tech_test.rb +44 -0
  153. data/test/unit/gateways/secure_pay_test.rb +35 -26
  154. data/test/unit/gateways/skip_jack_test.rb +125 -0
  155. data/test/unit/gateways/trans_first_test.rb +24 -37
  156. data/test/unit/gateways/trust_commerce_test.rb +47 -26
  157. data/test/unit/gateways/usa_epay_test.rb +52 -41
  158. data/test/unit/gateways/verifi_test.rb +41 -35
  159. data/test/unit/gateways/viaklix_test.rb +38 -32
  160. data/test/unit/generators/test_gateway_generator.rb +46 -0
  161. data/test/unit/generators/test_generator_helper.rb +20 -0
  162. data/test/unit/generators/test_integration_generator.rb +53 -0
  163. data/test/unit/integrations/action_view_helper_test.rb +7 -14
  164. data/test/unit/integrations/bogus_module_test.rb +4 -0
  165. data/test/unit/integrations/chronopay_module_test.rb +4 -0
  166. data/test/unit/integrations/gestpay_module_test.rb +4 -0
  167. data/test/unit/integrations/helpers/hi_trust_helper_test.rb +16 -0
  168. data/test/unit/integrations/hi_trust_module_test.rb +13 -0
  169. data/test/unit/integrations/nochex_module_test.rb +4 -0
  170. data/test/unit/integrations/notifications/hi_trust_notification_test.rb +38 -0
  171. data/test/unit/integrations/paypal_module_test.rb +4 -0
  172. data/test/unit/integrations/returns/chronopay_return_test.rb +11 -0
  173. data/test/unit/integrations/returns/gestpay_return_test.rb +10 -0
  174. data/test/unit/integrations/returns/hi_trust_return_test.rb +24 -0
  175. data/test/unit/integrations/returns/nochex_return_test.rb +10 -0
  176. data/test/unit/integrations/returns/paypal_return_test.rb +10 -0
  177. data/test/unit/integrations/returns/return_test.rb +11 -0
  178. data/test/unit/integrations/returns/two_checkout_return_test.rb +24 -0
  179. data/test/unit/integrations/two_checkout_module_test.rb +4 -0
  180. data/test/unit/posts_data_test.rb +86 -0
  181. data/test/unit/response_test.rb +15 -1
  182. data/test/unit/utils_test.rb +7 -0
  183. data/test/unit/validateable_test.rb +10 -6
  184. metadata +180 -142
  185. metadata.gz.sig +0 -0
  186. data/lib/active_merchant/billing/gateways/paypal/api_cert_chain.crt +0 -35
  187. data/script/generator/base.rb +0 -45
  188. data/script/generator/generator.rb +0 -24
  189. data/script/generator/generators/gateway/gateway_generator.rb +0 -14
  190. data/script/generator/generators/gateway/templates/gateway.rb +0 -73
  191. data/script/generator/generators/gateway/templates/gateway_test.rb +0 -41
  192. data/script/generator/generators/gateway/templates/remote_gateway_test.rb +0 -56
  193. data/script/generator/generators/integration/integration_generator.rb +0 -25
  194. data/script/generator/generators/integration/templates/helper.rb +0 -34
  195. data/script/generator/generators/integration/templates/helper_test.rb +0 -54
  196. data/script/generator/generators/integration/templates/integration.rb +0 -18
  197. data/script/generator/generators/integration/templates/module_test.rb +0 -9
  198. data/script/generator/generators/integration/templates/notification.rb +0 -100
  199. data/script/generator/generators/integration/templates/notification_test.rb +0 -41
  200. data/script/generator/manifest.rb +0 -20
  201. data/test/remote_tests/remote_authorize_net_test.rb +0 -113
  202. data/test/remote_tests/remote_brain_tree_test.rb +0 -78
  203. data/test/remote_tests/remote_moneris_test.rb +0 -110
  204. data/test/remote_tests/remote_psigate_test.rb +0 -87
  205. data/test/remote_tests/remote_secure_pay_test.rb +0 -36
  206. data/test/remote_tests/remote_trust_commerce_test.rb +0 -136
@@ -0,0 +1,113 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class SecurePayTechGateway < Gateway
4
+ class SecurePayTechPostData < PostData
5
+ self.required_fields = [ :OrderReference, :CardNumber, :CardExpiry, :CardHolderName, :CardType, :MerchantID, :MerchantKey, :Amount, :Currency ]
6
+ end
7
+
8
+ URL = 'https://tx.securepaytech.com/web/HttpPostPurchase'
9
+
10
+ PAYMENT_GATEWAY_RESPONSES = {
11
+ 1 => "Transaction OK",
12
+ 2 => "Insufficient funds",
13
+ 3 => "Card expired",
14
+ 4 => "Card declined",
15
+ 5 => "Server error",
16
+ 6 => "Communications error",
17
+ 7 => "Unsupported transaction type",
18
+ 8 => "Bad or malformed request",
19
+ 9 => "Invalid card number"
20
+ }
21
+
22
+ self.default_currency = 'NZD'
23
+ self.supported_countries = ['NZ']
24
+ self.supported_cardtypes = [:visa, :master, :american_express, :diners_club]
25
+ self.homepage_url = 'http://www.securepaytech.com/'
26
+ self.display_name = 'SecurePayTech'
27
+
28
+ def initialize(options = {})
29
+ requires!(options, :login, :password)
30
+ @options = options
31
+ super
32
+ end
33
+
34
+ def purchase(money, creditcard, options = {})
35
+ post = SecurePayTechPostData.new
36
+
37
+ add_invoice(post, money, options)
38
+ add_creditcard(post, creditcard)
39
+
40
+ commit(:purchase, post)
41
+ end
42
+
43
+ private
44
+
45
+ def add_invoice(post, money, options)
46
+ post[:Amount] = amount(money)
47
+ post[:Currency] = options[:currency] || currency(money)
48
+
49
+ post[:OrderReference] = options[:order_id]
50
+ end
51
+
52
+ def add_creditcard(post, creditcard)
53
+ post[:CardNumber] = creditcard.number
54
+ post[:CardExpiry] = expdate(creditcard)
55
+ post[:CardHolderName] = creditcard.name
56
+
57
+ if creditcard.verification_value?
58
+ post[:EnableCSC] = 1
59
+ post[:CSC] = creditcard.verification_value
60
+ end
61
+
62
+ # SPT will autodetect this
63
+ post[:CardType] = 0
64
+ end
65
+
66
+ def parse(body)
67
+ response = CGI.unescape(body).split(',')
68
+
69
+ result = {}
70
+ result[:result_code] = response[0].to_i
71
+
72
+ if response.length == 2
73
+ result[:fail_reason] = response[1]
74
+ else
75
+ result[:merchant_transaction_reference] = response[1]
76
+ result[:receipt_number] = response[2]
77
+ result[:transaction_number] = response[3]
78
+ result[:authorisation_id] = response[4]
79
+ result[:batch_number] = response[5]
80
+ end
81
+
82
+ result
83
+ end
84
+
85
+ def commit(action, post)
86
+ response = parse( ssl_post(URL, post_data(action, post) ) )
87
+
88
+ Response.new(response[:result_code] == 1, message_from(response), response,
89
+ :test => test?,
90
+ :authorization => response[:merchant_transaction_reference]
91
+ )
92
+ end
93
+
94
+ def message_from(result)
95
+ PAYMENT_GATEWAY_RESPONSES[result[:result_code]]
96
+ end
97
+
98
+ def post_data(action, post)
99
+ post[:MerchantID] = @options[:login]
100
+ post[:MerchantKey] = @options[:password]
101
+ post.to_s
102
+ end
103
+
104
+ def expdate(creditcard)
105
+ year = sprintf("%.4i", creditcard.year)
106
+ month = sprintf("%.2i", creditcard.month)
107
+
108
+ "#{month}#{year[-2..-1]}"
109
+ end
110
+ end
111
+ end
112
+ end
113
+
@@ -0,0 +1,437 @@
1
+ module ActiveMerchant #:nodoc:
2
+ module Billing #:nodoc:
3
+ class SkipJackGateway < Gateway
4
+ API_VERSION = '?.?'
5
+ LIVE_URL = "https://www.skipjackic.com/scripts/evolvcc.dll"
6
+ TEST_URL = "https://developer.skipjackic.com/scripts/evolvcc.dll"
7
+
8
+ ACTIONS = {
9
+ :authorization => 'AuthorizeAPI',
10
+ :change_status => 'SJAPI_TransactionChangeStatusRequest',
11
+ :get_status => 'SJAPI_TransactionStatusRequest'
12
+ }
13
+
14
+ SUCCESS_MESSAGE = 'The transaction was successful.'
15
+
16
+ MONETARY_CHANGE_STATUSES = ['AUTHORIZE', 'AUTHORIZE ADDITIONAL', 'CREDIT', 'SPLITSETTLE']
17
+
18
+ CARD_CODE_ERRORS = %w( N S "" )
19
+
20
+ CARD_CODE_MESSAGES = {
21
+ "M" => "Card verification number matched",
22
+ "N" => "Card verification number didn't match",
23
+ "P" => "Card verification number was not processed",
24
+ "S" => "Card verification number should be on card but was not indicated",
25
+ "U" => "Issuer was not certified for card verification",
26
+ "" => "Transaction failed because incorrect card verification number was entered or no number was entered"
27
+ }
28
+
29
+ AVS_ERRORS = %w( A B C E I N O P R W Z )
30
+
31
+ AVS_MESSAGES = {
32
+ "A" => "Street address matches billing information, zip/postal code does not",
33
+ "B" => "Street address match for international transaction. Postal code not verified due to incompatible formats",
34
+ "C" => "Street address and postal code not verified for internation transaction due to incompatible formats",
35
+ "D" => "Street address and postal code match for international transaction",
36
+ "E" => "Address verification service error",
37
+ "I" => "Address information not verified by international issuer",
38
+ "M" => "Street address and postal code match for international transaction",
39
+ "N" => "Neither street address nor zip/postal match billing information",
40
+ "O" => "Non-US issuer does not participate",
41
+ "P" => "Postal codes match for international transaction but street address not verified due to incompatible formats",
42
+ "P" => "Address verification not applicable for this transaction",
43
+ "R" => "Payment gateway was unavailable or timed out",
44
+ "S" => "Address verification service not supported by issuer",
45
+ "U" => "Address information is unavailable",
46
+ "W" => "9-digit zip/postal code matches billing information, street address does not",
47
+ "X" => "Street address and 9-digit zip/postal code matches billing information",
48
+ "Y" => "Street address and 5-digit zip/postal code matches billing information",
49
+ "Z" => "5-digit zip/postal code matches billing information, street address does not",
50
+ }
51
+
52
+ CHANGE_STATUS_ERROR_MESSAGES = {
53
+ '0' => 'Success',
54
+ '-1' => 'Invalid Command',
55
+ '-2' => 'Parameter Missing',
56
+ '-3' => 'Failed retrieving response',
57
+ '-4' => 'Invalid Status',
58
+ '-5' => 'Failed reading security flags',
59
+ '-6' => 'Developer serial number not found',
60
+ '-7' => 'Invalid Serial Number'
61
+ }
62
+
63
+ TRANSACTION_CURRENT_STATUS = {
64
+ '0' => 'Idle',
65
+ '1' => 'Authorized',
66
+ '2' => 'Denied',
67
+ '3' => 'Settled',
68
+ '4' => 'Credited',
69
+ '5' => 'Deleted',
70
+ '6' => 'Archived',
71
+ '7' => 'Pre-Authorized',
72
+ '8' => 'Split Settled'
73
+ }
74
+
75
+ TRANSACTION_PENDING_STATUS = {
76
+ '0' => 'Idle',
77
+ '1' => 'Pending Credit',
78
+ '2' => 'Pending Settlement',
79
+ '3' => 'Pending Authorization',
80
+ '4' => 'Pending Manual Settlement',
81
+ '5' => 'Pending Recurring'
82
+ }
83
+
84
+ RETURN_CODE_MESSAGES = {
85
+ '-1' => 'Data was not by received intact by Skipjack Transaction Network.',
86
+ '0' => 'Communication Failure. Error in Request and Response at IP level.',
87
+ '1' => 'Valid Data. Authorization request was valid.',
88
+ '-35' => 'Invalid credit card number. Retry with correct credit card number.',
89
+ '-37' => 'Merchant Processor Unavailable. Skipjack is unable to communicate with payment Processor. Retry',
90
+ '-39' => 'Length or value of HTML Serial. Number Invalid serial number. Check HTML Serial Number length and that it is a correct/valid number. Confirm you are sending to the correct environment (Development or Production)',
91
+ '-51' => 'The value or length for billing zip code is incorrect.',
92
+ '-52' => 'The value or length for shipping zip code is incorrect.',
93
+ '-53' => 'The value or length for credit card expiration month is incorrect.',
94
+ '-54' => 'The value or length of the month or year of the credit card account number was incorrect.',
95
+ '-55' => 'The value or length or billing street address is incorrect.',
96
+ '-56' => 'The value or length of the shipping address is incorrect.',
97
+ '-57' => 'The length of the transaction amount must be at least 3 digits long (excluding the decimal place).',
98
+ '-58' => 'Length or value in Merchant Name Merchant Name associated with Skipjack account is misconfigured or invalid',
99
+ '-59' => 'Length or value in Merchant Address Merchant Address associated with Skipjack account is misconfigured or invalid',
100
+ '-60' => 'Length or value in Merchant State Merchant State associated with Skipjack account is misconfigured or invalid',
101
+ '-61' => 'The value or length for shipping state/province is empty.',
102
+ '-62' => 'The value for length orderstring is empty.',
103
+ '-64' => 'The value for the phone number is incorrect.',
104
+ '-65' => 'The value or length for billing name is empty.',
105
+ '-66' => 'The value or length for billing e-mail is empty.',
106
+ '-67' => 'The value or length for billing street address is empty.',
107
+ '-68' => 'The value or length for billing city is empty.',
108
+ '-69' => 'The value or length for billing state is empty.',
109
+ '-70' => 'Empty zipcode Zip Code field is empty.',
110
+ '-71' => 'Empty ordernumber Ordernumber field is empty.',
111
+ '-72' => 'Empty accountnumber Accountnumber field is empty',
112
+ '-73' => 'Empty month Month field is empty.',
113
+ '-74' => 'Empty year Year field is empty.',
114
+ '-75' => 'Empty serialnumber Serialnumber field is empty.',
115
+ '-76' => 'Empty transactionamount Transaction amount field is empty.',
116
+ '-77' => 'Empty orderstring Orderstring field is empty.',
117
+ '-78' => 'Empty shiptophone Shiptophone field is empty.',
118
+ '-79' => 'The value or length for billing name is empty.',
119
+ '-80' => 'Length shipto name Error in the length or value of shiptophone.',
120
+ '-81' => 'Length or value of Customer location',
121
+ '-82' => 'The value or length for billing state is empty.',
122
+ '-83' => 'The value or length for shipping phone is empty.',
123
+ '-84' => 'There is already an existing pending transaction in the register sharing the posted Order Number.',
124
+ '-85' => 'Airline leg info invalid Airline leg field value is invalid or empty.',
125
+ '-86' => 'Airline ticket info invalid Airline ticket info field is invalid or empty',
126
+ '-87' => 'Point of Sale check routing number must be 9 numeric digits Point of Sale check routing number is invalid or empty.',
127
+ '-88' => 'Point of Sale check account number missing or invalid Point of Sale check account number is invalid or empty.',
128
+ '-89' => 'Point of Sale check MICR missing or invalid Point of Sale check MICR invalid or empty.',
129
+ '-90' => 'Point of Sale check number missing or invalid Point of Sale check number invalid or empty.',
130
+ '-91' => 'CVV2 Invalid or empty “Make CVV a required field feature” enabled (New feature 01 April 2006) in the Merchant Account Setup interface but no CVV code was sent in the transaction data.',
131
+ '-92' => 'Approval Code Invalid Approval Code Invalid. Approval Code is a 6 digit code.',
132
+ '-93' => 'Blind Credits Request Refused “Allow Blind Credits” option must be enabled on the Skipjack Merchant Account.',
133
+ '-94' => 'Blind Credits Failed',
134
+ '-95' => 'Voice Authorization Request Refused Voice Authorization option must be enabled on the Skipjack Merchant Account.',
135
+ '-96' => 'Voice Authorizations Failed',
136
+ '-97' => 'Fraud Rejection Violates Velocity Settling.',
137
+ '-98' => 'Invalid Discount Amount',
138
+ '-99' => 'POS PIN Debit Pin Block Debit-specific',
139
+ '-100' => 'POS PIN Debit Invalid Key Serial Number Debit-specific',
140
+ '-101' => 'Invalid Authentication Data Data for Verified by Visa/MC Secure Code is invalid.',
141
+ '-102' => 'Authentication Data Not Allowed',
142
+ '-103' => 'POS Check Invalid Birth Date POS check dateofbirth variable contains a birth date in an incorrect format. Use MM/DD/YYYY format for this variable.',
143
+ '-104' => 'POS Check Invalid Identification Type POS check identificationtype variable contains a identification type value which is invalid. Use the single digit value where Social Security Number=1, Drivers License=2 for this variable.',
144
+ '-105' => 'Invalid trackdata Track Data is in invalid format.',
145
+ '-106' => 'POS Check Invalid Account Type',
146
+ '-107' => 'POS PIN Debit Invalid Sequence Number',
147
+ '-108' => 'Invalid Transaction ID',
148
+ '-109' => 'Invalid From Account Type',
149
+ '-110' => 'Pos Error Invalid To Account Type',
150
+ '-112' => 'Pos Error Invalid Auth Option',
151
+ '-113' => 'Pos Error Transaction Failed',
152
+ '-114' => 'Pos Error Invalid Incoming Eci',
153
+ '-115' => 'POS Check Invalid Check Type',
154
+ '-116' => 'POS Check Invalid Lane Number POS Check lane or cash register number is invalid. Use a valid lane or cash register number that has been configured in the Skipjack Merchant Account.',
155
+ '-117' => 'POS Check Invalid Cashier Number'
156
+ }
157
+
158
+ self.supported_countries = ['US', 'CA']
159
+ self.supported_cardtypes = [:visa, :master, :american_express, :jcb, :discover, :diners_club]
160
+ self.homepage_url = 'http://www.skipjack.com/'
161
+ self.display_name = 'SkipJack'
162
+
163
+ # Creates a new SkipJackGateway
164
+ #
165
+ # The gateway requires that a valid login and password be passed
166
+ # in the +options+ hash.
167
+ #
168
+ # ==== Options
169
+ #
170
+ # * <tt>:login</tt> -- The SkipJack Merchant Serial Number.
171
+ # * <tt>:password</tt> -- The SkipJack Developer Serial Number.
172
+ # * <tt>:test => +true+ or +false+</tt> -- Use the test or live SkipJack url.
173
+ def initialize(options = {})
174
+ requires!(options, :login, :password)
175
+ @options = options
176
+ super
177
+ end
178
+
179
+ def test?
180
+ @options[:test] || super
181
+ end
182
+
183
+ def authorize(money, creditcard, options = {})
184
+ requires!(options, :order_id, :email)
185
+ post = {}
186
+ add_invoice(post, options)
187
+ add_creditcard(post, creditcard)
188
+ add_address(post, options)
189
+ add_customer_data(post, options)
190
+ commit(:authorization, money, post)
191
+ end
192
+
193
+ def purchase(money, creditcard, options = {})
194
+ post = {}
195
+ authorization = authorize(money, creditcard, options)
196
+ if authorization.success?
197
+ capture(money, authorization.authorization)
198
+ end
199
+ end
200
+
201
+ # Captures the funds from an authorized transaction.
202
+ #
203
+ # ==== Parameters
204
+ #
205
+ # * <tt>money</tt> -- The amount to be capture as an Integer in cents.
206
+ # * <tt>authorization</tt> -- The authorization returned from the previous authorize request.
207
+ # * <tt>options</tt> -- A hash of optional parameters.
208
+ #
209
+ # ==== Options
210
+ #
211
+ # * <tt>:force_settlement</tt> -- Force the settlement to occur as soon as possible. This option is not supported by other gateways. See the SkipJack API reference for more details
212
+ def capture(money, authorization, options = {})
213
+ post = { }
214
+ add_status_action(post, 'SETTLE')
215
+ add_forced_settlement(post, options)
216
+ add_transaction_id(post, authorization)
217
+ commit(:change_status, money, post)
218
+ end
219
+
220
+ def void(authorization, options = {})
221
+ post = {}
222
+ add_status_action(post, 'DELETE')
223
+ add_forced_settlement(post, options)
224
+ add_transaction_id(post, authorization)
225
+ commit(:change_status, nil, post)
226
+ end
227
+
228
+ def credit(money, identification, options = {})
229
+ post = {}
230
+ add_status_action(post, 'CREDIT')
231
+ add_forced_settlement(post, options)
232
+ add_transaction_id(post, identification)
233
+ commit(:change_status, money, post)
234
+ end
235
+
236
+ def status(order_id)
237
+ post = { }
238
+ post[:szOrderNumber] = :order_id
239
+ commit(:get_status, nil, post)
240
+ end
241
+
242
+ private
243
+ def add_forced_settlement(post, options)
244
+ post[:szForceSettlement] = options[:force_settlment] ? 1 : 0
245
+ end
246
+
247
+ def add_status_action(post, action)
248
+ post[:szDesiredStatus] = action
249
+ end
250
+
251
+ def commit(action, money, parameters)
252
+ response = parse( ssl_post( url_for(action), post_data(action, money, parameters) ), action )
253
+
254
+ # Pass along the original transaction id in the case an update transaction
255
+ Response.new(response[:success], message_from(response, action), response,
256
+ :test => test?,
257
+ :authorization => response[:szTransactionFileName] || parameters[:szTransactionId],
258
+ :avs_result => { :code => response[:szAVSResponseCode] },
259
+ :cvv_result => response[:szCVV2ResponseCode]
260
+ )
261
+ end
262
+
263
+ def url_for(action)
264
+ result = test? ? TEST_URL : LIVE_URL
265
+ result += "?#{ACTIONS[action]}"
266
+ end
267
+
268
+ def add_credentials(params, action)
269
+ if action == :authorization
270
+ params[:SerialNumber] = @options[:login]
271
+ params[:DeveloperSerialNumber] = @options[:password]
272
+ else
273
+ params[:szSerialNumber] = @options[:login]
274
+ params[:szDeveloperSerialNumber] = @options[:password]
275
+ end
276
+ end
277
+
278
+ def add_amount(params, action, money)
279
+ if action == :authorization
280
+ params[:TransactionAmount] = amount(money)
281
+ else
282
+ params[:szAmount] = amount(money) if MONETARY_CHANGE_STATUSES.include?(params[:szDesiredStatus])
283
+ end
284
+ end
285
+
286
+ def parse(body, action)
287
+ case action
288
+ when :authorization
289
+ parse_authorization_response(body)
290
+ when :get_status
291
+ parse_status_response(body, [ :SerialNumber, :TransactionAmount, :TransactionStatusCode, :TransactionStatusMessage, :OrderNumber, :TransactionDateTime, :TransactionID, :ApprovalCode, :BatchNumber ])
292
+ else
293
+ parse_status_response(body, [ :SerialNumber, :TransactionAmount, :DesiredStatus, :StatusResponse, :StatusResponseMessage, :OrderNumber, :AuditID ])
294
+ end
295
+ end
296
+
297
+ def split_lines(body)
298
+ body.split(/[\r\n]+/)
299
+ end
300
+
301
+ def split_line(line)
302
+ line.split(/","/).collect { |key| key.sub(/"*([^"]*)"*/, '\1').strip; }
303
+ end
304
+
305
+ def authorize_response_map(body)
306
+ lines = split_lines(body)
307
+ keys, values = split_line(lines[0]), split_line(lines[1])
308
+ Hash[*(keys.zip(values).flatten)].symbolize_keys
309
+ end
310
+
311
+ def parse_authorization_response(body)
312
+ result = authorize_response_map(body)
313
+ result[:success] = (result[:szIsApproved] == '1')
314
+ result
315
+ end
316
+
317
+ def parse_status_response(body, response_keys)
318
+ lines = split_lines(body)
319
+
320
+ keys = [ :szSerialNumber, :szErrorCode, :szNumberRecords]
321
+ values = split_line(lines[0])[0..2]
322
+
323
+ result = Hash[*(keys.zip(values).flatten)]
324
+
325
+ result[:szErrorMessage] = ''
326
+ result[:success] = (result[:szErrorCode] == '0')
327
+
328
+ if result[:success]
329
+ lines[1..-1].each do |line|
330
+ values = split_line(line)
331
+ response_keys.each_with_index do |key, index|
332
+ result[key] = values[index]
333
+ end
334
+ end
335
+ else
336
+ result[:szErrorMessage] = lines[1]
337
+ end
338
+ result
339
+ end
340
+
341
+ def post_data(action, money, params = {})
342
+ add_credentials(params, action)
343
+ add_amount(params, action, money)
344
+ params.collect { |key, value| "#{key.to_s}=#{CGI.escape(value.to_s)}" }.join("&")
345
+ end
346
+
347
+ def add_transaction_id(post, transaction_id)
348
+ post[:szTransactionId] = transaction_id
349
+ end
350
+
351
+ def add_invoice(post, options)
352
+ post[:OrderNumber] = sanitize_order_id(options[:order_id])
353
+ post[:CustomerCode] = options[:customer].to_s.slice(0, 17)
354
+ post[:InvoiceNumber] = options[:invoice]
355
+ post[:OrderDescription] = options[:description]
356
+
357
+ if order_items = options[:items]
358
+ post[:OrderString] = order_items.collect { |item| "#{item[:sku]}~#{item[:description].tr('~','-')}~#{item[:declared_value]}~#{item[:quantity]}~#{item[:taxable]}~~~~~~~~#{item[:tax_rate]}~||"}.join
359
+ else
360
+ post[:OrderString] = '1~None~0.00~0~N~||'
361
+ end
362
+ end
363
+
364
+ def add_creditcard(post, creditcard)
365
+ post[:AccountNumber] = creditcard.number
366
+ post[:Month] = creditcard.month
367
+ post[:Year] = creditcard.year
368
+ post[:CVV2] = creditcard.verification_value if creditcard.verification_value?
369
+ post[:SJName] = creditcard.name
370
+ end
371
+
372
+ def add_customer_data(post, options)
373
+ post[:Email] = options[:email]
374
+ end
375
+
376
+ def add_address(post, options)
377
+ if address = options[:billing_address] || options[:address]
378
+ post[:StreetAddress] = address[:address1]
379
+ post[:StreetAddress2] = address[:address2]
380
+ post[:City] = address[:city]
381
+ post[:State] = address[:state]
382
+ post[:ZipCode] = address[:zip]
383
+ post[:Country] = address[:country]
384
+ post[:Phone] = address[:phone]
385
+ post[:Fax] = address[:fax]
386
+ end
387
+
388
+ if address = options[:shipping_address]
389
+ post[:ShipToName] = address[:name]
390
+ post[:ShipToStreetAddress] = address[:address1]
391
+ post[:ShipToStreetAddress2] = address[:address2]
392
+ post[:ShipToCity] = address[:city]
393
+ post[:ShipToState] = address[:state]
394
+ post[:ShipToZipCode] = address[:zip]
395
+ post[:ShipToCountry] = address[:country]
396
+ post[:ShipToPhone] = address[:phone]
397
+ post[:ShipToFax] = address[:fax]
398
+ end
399
+
400
+ # The phone number for the shipping address is required
401
+ # Use the billing address phone number if a shipping address
402
+ # phone number wasn't provided
403
+ post[:ShipToPhone] = post[:Phone] if post[:ShipToPhone].blank?
404
+ end
405
+
406
+ def message_from(response, action)
407
+ case action
408
+ when :authorization
409
+ message_from_authorization(response)
410
+ when :get_status
411
+ message_from_status(response)
412
+ else
413
+ message_from_status(response)
414
+ end
415
+ end
416
+
417
+ def message_from_authorization(response)
418
+ if response[:success]
419
+ return SUCCESS_MESSAGE
420
+ else
421
+ return CARD_CODE_MESSAGES[response[:szCVV2ResponseCode]] if CARD_CODE_ERRORS.include?(response[:szCVV2ResponseCode])
422
+ return AVS_MESSAGES[response[:szAVSResponseMessage]] if AVS_ERRORS.include?(response[:szAVSResponseCode])
423
+ return RETURN_CODE_MESSAGES[response[:szReturnCode]] if response[:szReturnCode] != '1'
424
+ return response[:szAuthorizationDeclinedMessage]
425
+ end
426
+ end
427
+
428
+ def message_from_status(response)
429
+ response[:success] ? SUCCESS_MESSAGE : response[:szErrorMessage]
430
+ end
431
+
432
+ def sanitize_order_id(value)
433
+ value.to_s.gsub(/[^\w.]/, '')
434
+ end
435
+ end
436
+ end
437
+ end