activemerchant 1.4.2 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (227) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG +78 -0
  3. data/{CONTRIBUTERS → CONTRIBUTORS} +44 -0
  4. data/{README → README.rdoc} +4 -1
  5. data/Rakefile +7 -13
  6. data/lib/active_merchant.rb +11 -21
  7. data/lib/active_merchant/billing/avs_result.rb +13 -10
  8. data/lib/active_merchant/billing/base.rb +2 -2
  9. data/lib/active_merchant/billing/check.rb +1 -1
  10. data/lib/active_merchant/billing/credit_card_methods.rb +2 -2
  11. data/lib/active_merchant/billing/expiry_date.rb +10 -4
  12. data/lib/active_merchant/billing/gateway.rb +7 -6
  13. data/lib/active_merchant/billing/gateways.rb +18 -3
  14. data/lib/active_merchant/billing/gateways/authorize_net.rb +20 -12
  15. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb +40 -6
  16. data/lib/active_merchant/billing/gateways/authorize_net_cim.rb.orig +736 -0
  17. data/lib/active_merchant/billing/gateways/braintree.rb +6 -211
  18. data/lib/active_merchant/billing/gateways/data_cash.rb +5 -7
  19. data/lib/active_merchant/billing/gateways/elavon.rb +134 -0
  20. data/lib/active_merchant/billing/gateways/eway.rb +7 -2
  21. data/lib/active_merchant/billing/gateways/first_pay.rb +172 -0
  22. data/lib/active_merchant/billing/gateways/instapay.rb +164 -0
  23. data/lib/active_merchant/billing/gateways/jetpay.rb +270 -0
  24. data/lib/active_merchant/billing/gateways/linkpoint.rb +65 -12
  25. data/lib/active_merchant/billing/gateways/merchant_e_solutions.rb +154 -0
  26. data/lib/active_merchant/billing/gateways/merchant_ware.rb +283 -0
  27. data/lib/active_merchant/billing/gateways/modern_payments_cim.rb +12 -6
  28. data/lib/active_merchant/billing/gateways/ogone.rb +279 -0
  29. data/lib/active_merchant/billing/gateways/pay_secure.rb +1 -1
  30. data/lib/active_merchant/billing/gateways/payflow/payflow_common_api.rb +1 -1
  31. data/lib/active_merchant/billing/gateways/payflow/payflow_express_response.rb +1 -1
  32. data/lib/active_merchant/billing/gateways/payflow_express.rb +1 -1
  33. data/lib/active_merchant/billing/gateways/payment_express.rb +20 -32
  34. data/lib/active_merchant/billing/gateways/paypal.rb +22 -9
  35. data/lib/active_merchant/billing/gateways/paypal/paypal_common_api.rb +2 -1
  36. data/lib/active_merchant/billing/gateways/paypal_ca.rb +1 -1
  37. data/lib/active_merchant/billing/gateways/psl_card.rb +4 -6
  38. data/lib/active_merchant/billing/gateways/sage/sage_core.rb +7 -1
  39. data/lib/active_merchant/billing/gateways/{protx.rb → sage_pay.rb} +60 -35
  40. data/lib/active_merchant/billing/gateways/sallie_mae.rb +144 -0
  41. data/lib/active_merchant/billing/gateways/secure_pay.rb +1 -1
  42. data/lib/active_merchant/billing/gateways/skip_jack.rb +23 -10
  43. data/lib/active_merchant/billing/gateways/smart_ps.rb +265 -0
  44. data/lib/active_merchant/billing/gateways/transax.rb +25 -0
  45. data/lib/active_merchant/billing/gateways/viaklix.rb +38 -14
  46. data/lib/active_merchant/billing/gateways/wirecard.rb +15 -2
  47. data/lib/active_merchant/billing/integrations.rb +18 -11
  48. data/lib/active_merchant/billing/integrations/bogus.rb +4 -3
  49. data/lib/active_merchant/billing/integrations/chronopay.rb +4 -3
  50. data/lib/active_merchant/billing/integrations/chronopay/notification.rb +3 -1
  51. data/lib/active_merchant/billing/integrations/gestpay.rb +4 -5
  52. data/lib/active_merchant/billing/integrations/gestpay/notification.rb +3 -1
  53. data/lib/active_merchant/billing/integrations/hi_trust.rb +4 -3
  54. data/lib/active_merchant/billing/integrations/nochex.rb +4 -3
  55. data/lib/active_merchant/billing/integrations/nochex/notification.rb +1 -1
  56. data/lib/active_merchant/billing/integrations/paypal.rb +3 -4
  57. data/lib/active_merchant/billing/integrations/paypal/helper.rb +9 -8
  58. data/lib/active_merchant/billing/integrations/quickpay.rb +2 -3
  59. data/lib/active_merchant/billing/integrations/quickpay/helper.rb +1 -1
  60. data/lib/active_merchant/billing/integrations/two_checkout.rb +3 -3
  61. data/lib/active_merchant/lib/connection.rb +170 -0
  62. data/lib/active_merchant/lib/country.rb +4 -1
  63. data/lib/active_merchant/lib/posts_data.rb +22 -84
  64. data/test/fixtures.yml +39 -1
  65. data/test/remote/gateways/remote_authorize_net_cim_test.rb +2 -1
  66. data/test/remote/gateways/remote_authorize_net_test.rb +1 -1
  67. data/test/remote/gateways/remote_beanstream_interac_test.rb +1 -1
  68. data/test/remote/gateways/remote_beanstream_test.rb +1 -1
  69. data/test/remote/gateways/remote_braintree_test.rb +2 -9
  70. data/test/remote/gateways/remote_card_stream_test.rb +1 -1
  71. data/test/remote/gateways/remote_cyber_source_test.rb +1 -1
  72. data/test/remote/gateways/remote_data_cash_test.rb +1 -2
  73. data/test/remote/gateways/remote_efsnet_test.rb +1 -1
  74. data/test/remote/gateways/remote_elavon_test.rb +66 -0
  75. data/test/remote/gateways/remote_eway_test.rb +1 -1
  76. data/test/remote/gateways/remote_exact_test.rb +1 -1
  77. data/test/remote/gateways/remote_first_pay_test.rb +87 -0
  78. data/test/remote/gateways/remote_instapay_test.rb +61 -0
  79. data/test/remote/gateways/remote_jetpay_test.rb +103 -0
  80. data/test/remote/gateways/remote_linkpoint_test.rb +11 -2
  81. data/test/remote/gateways/remote_merchant_e_solutions_test.rb +173 -0
  82. data/test/remote/gateways/remote_merchant_ware_test.rb +113 -0
  83. data/test/remote/gateways/remote_modern_payments_cim_test.rb +1 -1
  84. data/test/remote/gateways/remote_modern_payments_test.rb +23 -9
  85. data/test/remote/gateways/remote_moneris_test.rb +1 -1
  86. data/test/remote/gateways/remote_net_registry_test.rb +1 -1
  87. data/test/remote/gateways/remote_netbilling_test.rb +1 -1
  88. data/test/remote/gateways/remote_ogone_test.rb +115 -0
  89. data/test/remote/gateways/remote_pay_junction_test.rb +1 -1
  90. data/test/remote/gateways/remote_pay_secure_test.rb +1 -1
  91. data/test/remote/gateways/remote_payflow_express_test.rb +1 -1
  92. data/test/remote/gateways/remote_payflow_test.rb +1 -1
  93. data/test/remote/gateways/remote_payflow_uk_test.rb +1 -1
  94. data/test/remote/gateways/remote_payment_express_test.rb +17 -7
  95. data/test/remote/gateways/remote_paypal_express_test.rb +1 -1
  96. data/test/remote/gateways/remote_paypal_test.rb +26 -2
  97. data/test/remote/gateways/remote_plugnpay_test.rb +1 -1
  98. data/test/remote/gateways/remote_psigate_test.rb +1 -1
  99. data/test/remote/gateways/remote_psl_card_test.rb +1 -3
  100. data/test/remote/gateways/remote_quickpay_test.rb +1 -1
  101. data/test/remote/gateways/remote_realex_test.rb +1 -1
  102. data/test/remote/gateways/remote_sage_bankcard_test.rb +1 -1
  103. data/test/remote/gateways/remote_sage_pay_test.rb +219 -0
  104. data/test/remote/gateways/remote_sage_test.rb +1 -1
  105. data/test/remote/gateways/remote_sage_virtual_check_test.rb +1 -1
  106. data/test/remote/gateways/remote_sallie_mae_test.rb +51 -0
  107. data/test/remote/gateways/remote_secure_pay_au_test.rb +1 -1
  108. data/test/remote/gateways/remote_secure_pay_tech_test.rb +1 -1
  109. data/test/remote/gateways/remote_secure_pay_test.rb +2 -2
  110. data/test/remote/gateways/remote_skipjack_test.rb +1 -1
  111. data/test/remote/gateways/remote_trans_first_test.rb +1 -1
  112. data/test/remote/gateways/remote_transax_test.rb +112 -0
  113. data/test/remote/gateways/remote_trust_commerce_test.rb +1 -1
  114. data/test/remote/gateways/remote_usa_epay_test.rb +1 -1
  115. data/test/remote/gateways/remote_verifi_test.rb +1 -1
  116. data/test/remote/gateways/remote_viaklix_test.rb +1 -1
  117. data/test/remote/gateways/remote_wirecard_test.rb +34 -0
  118. data/test/remote/integrations/remote_gestpay_integration_test.rb +1 -1
  119. data/test/remote/integrations/remote_paypal_integration_test.rb +1 -1
  120. data/test/test_helper.rb +81 -89
  121. data/test/unit/avs_result_test.rb +1 -1
  122. data/test/unit/base_test.rb +1 -2
  123. data/test/unit/check_test.rb +1 -1
  124. data/test/unit/connection_test.rb +129 -0
  125. data/test/unit/country_code_test.rb +1 -1
  126. data/test/unit/country_test.rb +1 -1
  127. data/test/unit/credit_card_formatting_test.rb +1 -1
  128. data/test/unit/credit_card_methods_test.rb +10 -1
  129. data/test/unit/credit_card_test.rb +1 -1
  130. data/test/unit/cvv_result_test.rb +1 -1
  131. data/test/unit/expiry_date_test.rb +13 -2
  132. data/test/unit/gateways/authorize_net_cim_test.rb +39 -1
  133. data/test/unit/gateways/authorize_net_test.rb +1 -1
  134. data/test/unit/gateways/beanstream_interac_test.rb +1 -1
  135. data/test/unit/gateways/beanstream_test.rb +1 -1
  136. data/test/unit/gateways/bogus_test.rb +1 -1
  137. data/test/unit/gateways/braintree_test.rb +16 -14
  138. data/test/unit/gateways/card_stream_test.rb +1 -1
  139. data/test/unit/gateways/cyber_source_test.rb +1 -1
  140. data/test/unit/gateways/data_cash_test.rb +2 -1
  141. data/test/unit/gateways/efsnet_test.rb +1 -1
  142. data/test/unit/gateways/elavon_test.rb +139 -0
  143. data/test/unit/gateways/eway_test.rb +1 -1
  144. data/test/unit/gateways/exact_test.rb +1 -1
  145. data/test/unit/gateways/first_pay_test.rb +125 -0
  146. data/test/unit/gateways/gateway_test.rb +1 -1
  147. data/test/unit/gateways/instapay_test.rb +102 -0
  148. data/test/unit/gateways/jetpay_test.rb +185 -0
  149. data/test/unit/gateways/linkpoint_test.rb +37 -7
  150. data/test/unit/gateways/merchant_e_solutions_test.rb +169 -0
  151. data/test/unit/gateways/merchant_ware_test.rb +188 -0
  152. data/test/unit/gateways/modern_payments_cim_test.rb +25 -34
  153. data/test/unit/gateways/moneris_test.rb +1 -1
  154. data/test/unit/gateways/net_registry_test.rb +1 -1
  155. data/test/unit/gateways/netbilling_test.rb +1 -1
  156. data/test/unit/gateways/ogone_test.rb +319 -0
  157. data/test/unit/gateways/pay_junction_test.rb +1 -1
  158. data/test/unit/gateways/pay_secure_test.rb +1 -1
  159. data/test/unit/gateways/payflow_express_test.rb +2 -2
  160. data/test/unit/gateways/payflow_express_uk_test.rb +73 -1
  161. data/test/unit/gateways/payflow_test.rb +1 -1
  162. data/test/unit/gateways/payflow_uk_test.rb +1 -1
  163. data/test/unit/gateways/payment_express_test.rb +3 -3
  164. data/test/unit/gateways/paypal_express_test.rb +1 -1
  165. data/test/unit/gateways/paypal_test.rb +50 -1
  166. data/test/unit/gateways/plugnpay_test.rb +1 -1
  167. data/test/unit/gateways/psigate_test.rb +1 -1
  168. data/test/unit/gateways/psl_card_test.rb +1 -1
  169. data/test/unit/gateways/quickpay_test.rb +1 -1
  170. data/test/unit/gateways/realex_test.rb +1 -1
  171. data/test/unit/gateways/sage_bankcard_test.rb +36 -2
  172. data/test/unit/gateways/{protx_test.rb → sage_pay_test.rb} +49 -32
  173. data/test/unit/gateways/sage_virtual_check_test.rb +1 -1
  174. data/test/unit/gateways/sallie_mae_test.rb +53 -0
  175. data/test/unit/gateways/secure_pay_au_test.rb +1 -1
  176. data/test/unit/gateways/secure_pay_tech_test.rb +1 -1
  177. data/test/unit/gateways/secure_pay_test.rb +24 -10
  178. data/test/unit/gateways/skip_jack_test.rb +81 -1
  179. data/test/unit/gateways/trans_first_test.rb +1 -1
  180. data/test/unit/gateways/trust_commerce_test.rb +1 -1
  181. data/test/unit/gateways/usa_epay_test.rb +1 -1
  182. data/test/unit/gateways/verifi_test.rb +1 -1
  183. data/test/unit/gateways/viaklix_test.rb +1 -1
  184. data/test/unit/gateways/wirecard_test.rb +19 -1
  185. data/test/unit/generators/test_generator_helper.rb +1 -1
  186. data/test/unit/integrations/action_view_helper_test.rb +1 -1
  187. data/test/unit/integrations/bogus_module_test.rb +1 -1
  188. data/test/unit/integrations/chronopay_module_test.rb +1 -1
  189. data/test/unit/integrations/gestpay_module_test.rb +1 -1
  190. data/test/unit/integrations/helpers/bogus_helper_test.rb +1 -1
  191. data/test/unit/integrations/helpers/chronopay_helper_test.rb +1 -1
  192. data/test/unit/integrations/helpers/gestpay_helper_test.rb +1 -1
  193. data/test/unit/integrations/helpers/hi_trust_helper_test.rb +1 -1
  194. data/test/unit/integrations/helpers/nochex_helper_test.rb +1 -1
  195. data/test/unit/integrations/helpers/paypal_helper_test.rb +11 -2
  196. data/test/unit/integrations/helpers/quickpay_helper_test.rb +1 -1
  197. data/test/unit/integrations/helpers/two_checkout_helper_test.rb +1 -1
  198. data/test/unit/integrations/hi_trust_module_test.rb +1 -1
  199. data/test/unit/integrations/nochex_module_test.rb +1 -1
  200. data/test/unit/integrations/notifications/chronopay_notification_test.rb +1 -1
  201. data/test/unit/integrations/notifications/gestpay_notification_test.rb +1 -1
  202. data/test/unit/integrations/notifications/hi_trust_notification_test.rb +1 -1
  203. data/test/unit/integrations/notifications/nochex_notification_test.rb +2 -2
  204. data/test/unit/integrations/notifications/notification_test.rb +1 -1
  205. data/test/unit/integrations/notifications/paypal_notification_test.rb +1 -1
  206. data/test/unit/integrations/notifications/quickpay_notification_test.rb +1 -1
  207. data/test/unit/integrations/notifications/two_checkout_notification_test.rb +1 -1
  208. data/test/unit/integrations/paypal_module_test.rb +1 -1
  209. data/test/unit/integrations/quickpay_module_test.rb +1 -1
  210. data/test/unit/integrations/returns/chronopay_return_test.rb +1 -1
  211. data/test/unit/integrations/returns/gestpay_return_test.rb +1 -1
  212. data/test/unit/integrations/returns/hi_trust_return_test.rb +1 -1
  213. data/test/unit/integrations/returns/nochex_return_test.rb +1 -1
  214. data/test/unit/integrations/returns/paypal_return_test.rb +1 -1
  215. data/test/unit/integrations/returns/return_test.rb +1 -1
  216. data/test/unit/integrations/returns/two_checkout_return_test.rb +1 -1
  217. data/test/unit/integrations/two_checkout_module_test.rb +1 -1
  218. data/test/unit/post_data_test.rb +1 -1
  219. data/test/unit/posts_data_test.rb +14 -66
  220. data/test/unit/response_test.rb +1 -1
  221. data/test/unit/utils_test.rb +1 -1
  222. data/test/unit/validateable_test.rb +1 -1
  223. metadata +41 -45
  224. metadata.gz.sig +0 -0
  225. data/test/extra/binding_of_caller.rb +0 -80
  226. data/test/extra/breakpoint.rb +0 -547
  227. data/test/remote/gateways/remote_protx_test.rb +0 -184
@@ -0,0 +1,279 @@
1
+ require 'rexml/document'
2
+
3
+ module ActiveMerchant #:nodoc:
4
+ module Billing #:nodoc:
5
+ # = Ogone DirectLink Gateway
6
+ #
7
+ # DirectLink is the API version of the Ogone Payment Platform. It allows server to server
8
+ # communication between Ogone systems and your e-commerce website.
9
+ #
10
+ # This implementation follows the specification provided in the DirectLink integration
11
+ # guide version 2.4 (December 2008), available here:
12
+ # https://secure.ogone.com/ncol/Ogone_DirectLink_EN.pdf
13
+ #
14
+ # It also features aliases, which allow to store/unstore credit cards, as specified in
15
+ # the Alias Manager Option guide version 2.2 available here:
16
+ # https://secure.ogone.com/ncol/Ogone_Alias_EN.pdf
17
+ #
18
+ # It was last tested on Release 04.79 of Ogone e-Commerce (dated 11/02/2009).
19
+ #
20
+ # For any questions or comments, please contact Nicolas Jacobeus (nj@belighted.com).
21
+ #
22
+ # == Example use:
23
+ #
24
+ # gateway = ActiveMerchant::Billing::OgoneGateway.new(
25
+ # :login => "my_ogone_psp_id",
26
+ # :user => "my_ogone_user_id",
27
+ # :password => "my_ogone_pswd",
28
+ # :signature => "my_ogone_sha1_signature" # extra security, only if you configured your Ogone environment so
29
+ # )
30
+ #
31
+ # # set up credit card obj as in main ActiveMerchant example
32
+ # creditcard = ActiveMerchant::Billing::CreditCard.new(
33
+ # :type => 'visa',
34
+ # :number => '4242424242424242',
35
+ # :month => 8,
36
+ # :year => 2009,
37
+ # :first_name => 'Bob',
38
+ # :last_name => 'Bobsen'
39
+ # )
40
+ #
41
+ # # run request
42
+ # response = gateway.purchase(1000, creditcard, :order_id => "1") # charge 10 EUR
43
+ #
44
+ # If you don't provide an :order_id, the gateway will generate a random one for you.
45
+ #
46
+ # puts response.success? # Check whether the transaction was successful
47
+ # puts response.message # Retrieve the message returned by Ogone
48
+ # puts response.authorization # Retrieve the unique transaction ID returned by Ogone
49
+ #
50
+ # To use the alias feature, simply add :alias in the options hash:
51
+ #
52
+ # gateway.purchase(1000, creditcard, :order_id => "1", :alias => "myawesomecustomer") # associates the alias to that creditcard
53
+ # gateway.purchase(2000, nil, :order_id => "2", :alias => "myawesomecustomer") # don't need to know the creditcard for subsequent orders
54
+ #
55
+ class OgoneGateway < Gateway
56
+
57
+ URLS = {
58
+ :test => { :order => 'https://secure.ogone.com/ncol/test/orderdirect.asp',
59
+ :maintenance => 'https://secure.ogone.com/ncol/test/maintenancedirect.asp' },
60
+ :production => { :order => 'https://secure.ogone.com/ncol/prod/orderdirect.asp',
61
+ :maintenance => 'https://secure.ogone.com/ncol/prod/maintenancedirect.asp' }
62
+ }
63
+
64
+ CVV_MAPPING = { 'OK' => 'M',
65
+ 'KO' => 'N',
66
+ 'NO' => 'P' }
67
+
68
+ AVS_MAPPING = { 'OK' => 'M',
69
+ 'KO' => 'N',
70
+ 'NO' => 'R' }
71
+ SUCCESS_MESSAGE = "The transaction was successful"
72
+
73
+ self.supported_countries = ['BE', 'DE', 'FR', 'NL', 'AT', 'CH']
74
+ # also supports Airplus and UATP
75
+ self.supported_cardtypes = [:visa, :master, :american_express, :diners_club, :discover, :jcb, :maestro]
76
+ self.homepage_url = 'http://www.ogone.com/'
77
+ self.display_name = 'Ogone'
78
+ self.default_currency = 'EUR'
79
+ self.money_format = :cents
80
+
81
+ def initialize(options = {})
82
+ requires!(options, :login, :user, :password)
83
+ @options = options
84
+ super
85
+ end
86
+
87
+ # Verify and reserve the specified amount on the account, without actually doing the transaction.
88
+ def authorize(money, payment_source, options = {})
89
+ post = {}
90
+ add_invoice(post, options)
91
+ add_payment_source(post, payment_source, options)
92
+ add_address(post, payment_source, options)
93
+ add_customer_data(post, options)
94
+ add_money(post, money, options)
95
+ commit('RES', post)
96
+ end
97
+
98
+ # Verify and transfer the specified amount.
99
+ def purchase(money, payment_source, options = {})
100
+ post = {}
101
+ add_invoice(post, options)
102
+ add_payment_source(post, payment_source, options)
103
+ add_address(post, payment_source, options)
104
+ add_customer_data(post, options)
105
+ add_money(post, money, options)
106
+ commit('SAL', post)
107
+ end
108
+
109
+ # Complete a previously authorized transaction.
110
+ def capture(money, authorization, options = {})
111
+ post = {}
112
+ add_authorization(post, reference_from(authorization))
113
+ add_invoice(post, options)
114
+ add_customer_data(post, options)
115
+ add_money(post, money, options)
116
+ commit('SAL', post)
117
+ end
118
+
119
+ # Cancels a previously authorized transaction.
120
+ def void(identification, options = {})
121
+ post = {}
122
+ add_authorization(post, reference_from(identification))
123
+ commit('DES', post)
124
+ end
125
+
126
+ # Credit the specified account by a specific amount.
127
+ def credit(money, identification_or_credit_card, options = {})
128
+ if reference_transaction?(identification_or_credit_card)
129
+ # Referenced credit: refund of a settled transaction
130
+ perform_reference_credit(money, identification_or_credit_card, options)
131
+ else # must be a credit card or card reference
132
+ perform_non_referenced_credit(money, identification_or_credit_card, options)
133
+ end
134
+ end
135
+
136
+ def test?
137
+ @options[:test] || super
138
+ end
139
+
140
+ private
141
+ def reference_from(authorization)
142
+ authorization.split(";").first
143
+ end
144
+
145
+ def reference_transaction?(identifier)
146
+ return false unless identifier.is_a?(String)
147
+ reference, action = identifier.split(";")
148
+ !action.nil?
149
+ end
150
+
151
+ def perform_reference_credit(money, payment_target, options = {})
152
+ post = {}
153
+ add_authorization(post, reference_from(payment_target))
154
+ add_money(post, money, options)
155
+ commit('RFD', post)
156
+ end
157
+
158
+ def perform_non_referenced_credit(money, payment_target, options = {})
159
+ # Non-referenced credit: acts like a reverse purchase
160
+ post = {}
161
+ add_invoice(post, options)
162
+ add_payment_source(post, payment_target, options)
163
+ add_address(post, payment_target, options)
164
+ add_customer_data(post, options)
165
+ add_money(post, money, options)
166
+ commit('RFD', post)
167
+ end
168
+
169
+ def add_payment_source(post, payment_source, options)
170
+ if payment_source.is_a?(String)
171
+ add_alias(post, payment_source)
172
+ add_eci(post, '9')
173
+ else
174
+ add_alias(post, options[:store])
175
+ add_creditcard(post, payment_source)
176
+ end
177
+ end
178
+
179
+ def add_eci(post, eci)
180
+ add_pair post, 'ECI', eci
181
+ end
182
+
183
+ def add_alias(post, _alias)
184
+ add_pair post, 'ALIAS', _alias
185
+ end
186
+
187
+ def add_authorization(post, authorization)
188
+ add_pair post, 'PAYID', authorization
189
+ end
190
+
191
+ def add_money(post, money, options)
192
+ add_pair post, 'currency', options[:currency] || currency(money)
193
+ add_pair post, 'amount', amount(money)
194
+ end
195
+
196
+ def add_customer_data(post, options)
197
+ add_pair post, 'EMAIL', options[:email]
198
+ add_pair post, 'REMOTE_ADDR', options[:ip]
199
+ end
200
+
201
+ def add_address(post, creditcard, options)
202
+ return unless options[:billing_address]
203
+ add_pair post, 'Owneraddress', options[:billing_address][:address1]
204
+ add_pair post, 'OwnerZip', options[:billing_address][:zip]
205
+ add_pair post, 'ownertown', options[:billing_address][:city]
206
+ add_pair post, 'ownercty', options[:billing_address][:country]
207
+ add_pair post, 'ownertelno', options[:billing_address][:phone]
208
+ end
209
+
210
+ def add_invoice(post, options)
211
+ add_pair post, 'orderID', options[:order_id] || generate_unique_id[0...30]
212
+ add_pair post, 'COM', options[:description]
213
+ end
214
+
215
+ def add_creditcard(post, creditcard)
216
+ add_pair post, 'CN', creditcard.name
217
+ add_pair post, 'CARDNO', creditcard.number
218
+ add_pair post, 'ED', "%02d%02s" % [creditcard.month, creditcard.year.to_s[-2..-1]]
219
+ add_pair post, 'CVC', creditcard.verification_value
220
+ end
221
+
222
+ def parse(body)
223
+ xml = REXML::Document.new(body)
224
+ xml.root.attributes
225
+ end
226
+
227
+ def commit(action, parameters)
228
+ add_pair parameters, 'PSPID', @options[:login]
229
+ add_pair parameters, 'USERID', @options[:user]
230
+ add_pair parameters, 'PSWD', @options[:password]
231
+ url = URLS[test? ? :test : :production][parameters['PAYID'] ? :maintenance : :order ]
232
+ response = parse(ssl_post(url, post_data(action, parameters)))
233
+ options = { :authorization => [response["PAYID"], action].join(";"),
234
+ :test => test?,
235
+ :avs_result => { :code => AVS_MAPPING[response["AAVCheck"]] },
236
+ :cvv_result => CVV_MAPPING[response["CVCCheck"]] }
237
+ Response.new(successful?(response), message_from(response), response, options)
238
+ end
239
+
240
+ def successful?(response)
241
+ response["NCERROR"] == "0"
242
+ end
243
+
244
+ def message_from(response)
245
+ if successful?(response)
246
+ SUCCESS_MESSAGE
247
+ else
248
+ format_error_message(response["NCERRORPLUS"])
249
+ end
250
+ end
251
+
252
+ def format_error_message(message)
253
+ raw_message = message.to_s.strip
254
+ case raw_message
255
+ when /\|/
256
+ raw_message.split("|").join(", ").capitalize
257
+ when /\//
258
+ raw_message.split("/").first.to_s.capitalize
259
+ else
260
+ raw_message.to_s.capitalize
261
+ end
262
+ end
263
+
264
+ def post_data(action, parameters = {})
265
+ add_pair parameters, 'Operation' , action
266
+ if @options[:signature] # the user wants a SHA-1 signature
267
+ string = ['orderID','amount','currency','CARDNO','PSPID','Operation','ALIAS'].map{|s|parameters[s]}.join + @options[:signature]
268
+ add_pair parameters, 'SHASign' , Digest::SHA1.hexdigest(string)
269
+ end
270
+ parameters.collect { |key, value| "#{key}=#{CGI.escape(value.to_s)}" }.join("&")
271
+ end
272
+
273
+ def add_pair(post, key, value, options = {})
274
+ post[key] = value if !value.blank? || options[:required]
275
+ end
276
+
277
+ end
278
+ end
279
+ end
@@ -100,7 +100,7 @@ module ActiveMerchant #:nodoc:
100
100
 
101
101
  def parse(body)
102
102
  response = {}
103
- body.collect do |l|
103
+ body.to_s.each_line do |l|
104
104
  key, value = l.split(":", 2)
105
105
  response[key.to_s.downcase.to_sym] = value.strip
106
106
  end
@@ -182,7 +182,7 @@ module ActiveMerchant #:nodoc:
182
182
  {
183
183
  "Content-Type" => "text/xml",
184
184
  "Content-Length" => content_length.to_s,
185
- "X-VPS-Timeout" => timeout.to_s,
185
+ "X-VPS-Client-Timeout" => timeout.to_s,
186
186
  "X-VPS-VIT-Integration-Product" => "ActiveMerchant",
187
187
  "X-VPS-VIT-Runtime-Version" => RUBY_VERSION,
188
188
  "X-VPS-Request-ID" => Utils.generate_unique_id
@@ -26,7 +26,7 @@ module ActiveMerchant #:nodoc:
26
26
  { 'name' => full_name,
27
27
  'company' => nil,
28
28
  'address1' => @params['street'],
29
- 'address2' => nil,
29
+ 'address2' => @params['shiptostreet2'],
30
30
  'city' => @params['city'],
31
31
  'state' => @params['state'],
32
32
  'country' => @params['country'],
@@ -8,7 +8,7 @@ module ActiveMerchant #:nodoc:
8
8
  include PayflowCommonAPI
9
9
  include PaypalExpressCommon
10
10
 
11
- self.test_redirect_url = 'https://test-expresscheckout.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token='
11
+ self.test_redirect_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token='
12
12
  self.homepage_url = 'https://www.paypal.com/cgi-bin/webscr?cmd=xpt/merchant/ExpressCheckoutIntro-outside'
13
13
  self.display_name = 'PayPal Express Checkout'
14
14
 
@@ -44,26 +44,15 @@ module ActiveMerchant #:nodoc:
44
44
 
45
45
  # Funds are transferred immediately.
46
46
  def purchase(money, payment_source, options = {})
47
-
48
- credit_card = payment_source if payment_source.respond_to?(:number)
49
-
50
- if credit_card
51
- options[:credit_card] = credit_card
52
- else
53
- options[:token] = payment_source
54
- end
55
-
56
- request = build_purchase_or_authorization_request(money, options)
47
+ request = build_purchase_or_authorization_request(money, payment_source, options)
57
48
  commit(:purchase, request)
58
49
  end
59
50
 
60
51
  # NOTE: Perhaps in options we allow a transaction note to be inserted
61
52
  # Verifies that funds are available for the requested card and amount and reserves the specified amount.
62
53
  # See: http://www.paymentexpress.com/technical_resources/ecommerce_nonhosted/pxpost.html#Authcomplete
63
- def authorize(money, credit_card, options = {})
64
- options[:credit_card] = credit_card
65
-
66
- request = build_purchase_or_authorization_request(money, options)
54
+ def authorize(money, payment_source, options = {})
55
+ request = build_purchase_or_authorization_request(money, payment_source, options)
67
56
  commit(:authorization, request)
68
57
  end
69
58
 
@@ -95,17 +84,19 @@ module ActiveMerchant #:nodoc:
95
84
 
96
85
  private
97
86
 
98
- def build_purchase_or_authorization_request(money, options)
87
+ def build_purchase_or_authorization_request(money, payment_source, options)
99
88
  result = new_transaction
100
-
101
- returning result do |r|
102
- add_credit_card(r, options[:credit_card]) if options[:credit_card]
103
- add_billing_token(r, options[:token]) if options[:token]
104
-
105
- add_amount(r, money, options)
106
- add_invoice(r, options)
107
- add_address_verification_data(r, options)
89
+
90
+ if payment_source.is_a?(String)
91
+ add_billing_token(result, payment_source)
92
+ else
93
+ add_credit_card(result, payment_source)
108
94
  end
95
+
96
+ add_amount(result, money, options)
97
+ add_invoice(result, options)
98
+ add_address_verification_data(result, options)
99
+ result
109
100
  end
110
101
 
111
102
  def build_capture_or_credit_request(money, identification, options)
@@ -114,18 +105,15 @@ module ActiveMerchant #:nodoc:
114
105
  add_amount(result, money, options)
115
106
  add_invoice(result, options)
116
107
  add_reference(result, identification)
117
-
118
108
  result
119
109
  end
120
110
 
121
111
  def build_token_request(credit_card, options)
122
112
  result = new_transaction
123
-
124
- returning result do |r|
125
- add_credit_card(r, credit_card)
126
- add_amount(r, 100, options) #need to make an auth request for $1
127
- add_token_request(r, options)
128
- end
113
+ add_credit_card(result, credit_card)
114
+ add_amount(result, 100, options) #need to make an auth request for $1
115
+ add_token_request(result, options)
116
+ result
129
117
  end
130
118
 
131
119
  def add_credentials(xml)
@@ -179,8 +167,8 @@ module ActiveMerchant #:nodoc:
179
167
  address = options[:billing_address] || options[:address]
180
168
  return if address.nil?
181
169
 
182
- xml.add_element("EnableAvsData").text = 0
183
- xml.add_element("AvsAction").text = 0
170
+ xml.add_element("EnableAvsData").text = 1
171
+ xml.add_element("AvsAction").text = 1
184
172
 
185
173
  xml.add_element("AvsStreetAddress").text = address[:address1]
186
174
  xml.add_element("AvsPostCode").text = address[:zip]
@@ -11,14 +11,14 @@ module ActiveMerchant #:nodoc:
11
11
  self.homepage_url = 'https://www.paypal.com/cgi-bin/webscr?cmd=_wp-pro-overview-outside'
12
12
  self.display_name = 'PayPal Website Payments Pro (US)'
13
13
 
14
- def authorize(money, credit_card, options = {})
14
+ def authorize(money, credit_card_or_referenced_id, options = {})
15
15
  requires!(options, :ip)
16
- commit 'DoDirectPayment', build_sale_or_authorization_request('Authorization', money, credit_card, options)
16
+ commit define_transaction_type(credit_card_or_referenced_id), build_sale_or_authorization_request('Authorization', money, credit_card_or_referenced_id, options)
17
17
  end
18
18
 
19
- def purchase(money, credit_card, options = {})
19
+ def purchase(money, credit_card_or_referenced_id, options = {})
20
20
  requires!(options, :ip)
21
- commit 'DoDirectPayment', build_sale_or_authorization_request('Sale', money, credit_card, options)
21
+ commit define_transaction_type(credit_card_or_referenced_id), build_sale_or_authorization_request('Sale', money, credit_card_or_referenced_id, options)
22
22
  end
23
23
 
24
24
  def express
@@ -26,15 +26,28 @@ module ActiveMerchant #:nodoc:
26
26
  end
27
27
 
28
28
  private
29
- def build_sale_or_authorization_request(action, money, credit_card, options)
29
+
30
+ def define_transaction_type(transaction_arg)
31
+ if transaction_arg.is_a?(String)
32
+ return 'DoReferenceTransaction'
33
+ else
34
+ return 'DoDirectPayment'
35
+ end
36
+ end
37
+
38
+ def build_sale_or_authorization_request(action, money, credit_card_or_referenced_id, options)
39
+ transaction_type = define_transaction_type(credit_card_or_referenced_id)
40
+ reference_id = credit_card_or_referenced_id if transaction_type == "DoReferenceTransaction"
41
+
30
42
  billing_address = options[:billing_address] || options[:address]
31
43
  currency_code = options[:currency] || currency(money)
32
44
 
33
45
  xml = Builder::XmlMarkup.new :indent => 2
34
- xml.tag! 'DoDirectPaymentReq', 'xmlns' => PAYPAL_NAMESPACE do
35
- xml.tag! 'DoDirectPaymentRequest', 'xmlns:n2' => EBAY_NAMESPACE do
46
+ xml.tag! transaction_type + 'Req', 'xmlns' => PAYPAL_NAMESPACE do
47
+ xml.tag! transaction_type + 'Request', 'xmlns:n2' => EBAY_NAMESPACE do
36
48
  xml.tag! 'n2:Version', API_VERSION
37
- xml.tag! 'n2:DoDirectPaymentRequestDetails' do
49
+ xml.tag! 'n2:' + transaction_type + 'RequestDetails' do
50
+ xml.tag! 'n2:ReferenceID', reference_id if transaction_type == 'DoReferenceTransaction'
38
51
  xml.tag! 'n2:PaymentAction', action
39
52
  xml.tag! 'n2:PaymentDetails' do
40
53
  xml.tag! 'n2:OrderTotal', amount(money), 'currencyID' => currency_code
@@ -54,7 +67,7 @@ module ActiveMerchant #:nodoc:
54
67
 
55
68
  add_address(xml, 'n2:ShipToAddress', options[:shipping_address]) if options[:shipping_address]
56
69
  end
57
- add_credit_card(xml, credit_card, billing_address, options)
70
+ add_credit_card(xml, credit_card_or_referenced_id, billing_address, options) unless transaction_type == 'DoReferenceTransaction'
58
71
  xml.tag! 'n2:IPAddress', options[:ip]
59
72
  end
60
73
  end